Skip to content

Commit

Permalink
refactor: switch to Once() API.
Browse files Browse the repository at this point in the history
  • Loading branch information
ludofischer committed Nov 24, 2020
1 parent 0f8b224 commit d126bea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
29 changes: 17 additions & 12 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,25 @@ function pluginCreator(opts) {
mediaQueries: false,
selectors: false
}, opts);

return {
postcssPlugin: 'postcss-calc',
Declaration(node, {result}) {
transform(node, "value", options, result);
},
AtRule(node, {result}) {
if (options.mediaQueries) {
transform(node, "params", options, result);
}
},
Rule(node, {result}) {
if (options.selectors) {
transform(node, "selector", options, result);
}
Once(css, { result }) {
css.walk(node => {
const { type } = node;

if (type === 'decl') {
transform(node, "value", options, result);
}

if (type === 'atrule' && options.mediaQueries) {
transform(node, "params", options, result);
}

if (type === 'rule' && options.selectors) {
transform(node, "selector", options, result);
}
});
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions src/lib/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import reducer from './reducer';
import stringifier from './stringifier';

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

function transformValue(value, options, result, item) {
return valueParser(value).walk(node => {
Expand Down Expand Up @@ -60,9 +59,6 @@ function transformSelector(value, options, result, item) {
}

export default (node, property, options, result) => {
if (node[processed]) {
return;
}
const value = property === "selector"
? transformSelector(node[property], options, result, node)
: transformValue(node[property], options, result, node);
Expand All @@ -78,5 +74,4 @@ export default (node, property, options, result) => {
} else {
node[property] = value;
}
node[processed] = true;
};

0 comments on commit d126bea

Please sign in to comment.