Skip to content

Commit d126bea

Browse files
committed
refactor: switch to Once() API.
1 parent 0f8b224 commit d126bea

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/index.js

Lines changed: 17 additions & 12 deletions
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+
Once(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
}

src/lib/transform.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import reducer from './reducer';
88
import stringifier from './stringifier';
99

1010
const MATCH_CALC = /((?:-(moz|webkit)-)?calc)/i;
11-
const processed = Symbol('postcss-calc-processed');
1211

1312
function transformValue(value, options, result, item) {
1413
return valueParser(value).walk(node => {
@@ -60,9 +59,6 @@ function transformSelector(value, options, result, item) {
6059
}
6160

6261
export default (node, property, options, result) => {
63-
if (node[processed]) {
64-
return;
65-
}
6662
const value = property === "selector"
6763
? transformSelector(node[property], options, result, node)
6864
: transformValue(node[property], options, result, node);
@@ -78,5 +74,4 @@ export default (node, property, options, result) => {
7874
} else {
7975
node[property] = value;
8076
}
81-
node[processed] = true;
8277
};

0 commit comments

Comments
 (0)