Skip to content

Commit

Permalink
refactor: switch to OnceExit() API.
Browse files Browse the repository at this point in the history
  • Loading branch information
ludofischer committed Dec 30, 2020
1 parent 5b9aa8a commit c75eee9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 42 deletions.
30 changes: 0 additions & 30 deletions src/__tests__/integration.js

This file was deleted.

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);
}
OnceExit(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

0 comments on commit c75eee9

Please sign in to comment.