Skip to content

Commit c75eee9

Browse files
committed
refactor: switch to OnceExit() API.
1 parent 5b9aa8a commit c75eee9

File tree

2 files changed

+17
-42
lines changed

2 files changed

+17
-42
lines changed

src/__tests__/integration.js

-30
This file was deleted.

src/index.js

+17-12
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,25 @@ function pluginCreator(opts) {
88
mediaQueries: false,
99
selectors: false
1010
}, opts);
11+
1112
return {
1213
postcssPlugin: 'postcss-calc',
13-
Declaration(node, {result}) {
14-
transform(node, "value", options, result);
15-
},
16-
AtRule(node, {result}) {
17-
if (options.mediaQueries) {
18-
transform(node, "params", options, result);
19-
}
20-
},
21-
Rule(node, {result}) {
22-
if (options.selectors) {
23-
transform(node, "selector", options, result);
24-
}
14+
OnceExit(css, { result }) {
15+
css.walk(node => {
16+
const { type } = node;
17+
18+
if (type === 'decl') {
19+
transform(node, "value", options, result);
20+
}
21+
22+
if (type === 'atrule' && options.mediaQueries) {
23+
transform(node, "params", options, result);
24+
}
25+
26+
if (type === 'rule' && options.selectors) {
27+
transform(node, "selector", options, result);
28+
}
29+
});
2530
}
2631
}
2732
}

0 commit comments

Comments
 (0)