1- import { plugin } from 'postcss' ;
2-
31import transform from './lib/transform' ;
42
5- export default plugin ( 'postcss-calc' , ( opts ) => {
3+ function pluginCreator ( opts ) {
64 const options = Object . assign ( {
75 precision : 5 ,
86 preserve : false ,
@@ -11,21 +9,28 @@ export default plugin('postcss-calc', (opts) => {
119 selectors : false
1210 } , opts ) ;
1311
14- return ( css , result ) => {
15- css . walk ( node => {
16- const { type } = node ;
12+ return {
13+ postcssPlugin : 'postcss-calc' ,
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+ }
1725
18- if ( type === 'decl' ) {
19- transform ( node , "value" , options , result ) ;
20- }
26+ if ( type === 'rule' && options . selectors ) {
27+ transform ( node , "selector" , options , result ) ;
28+ }
29+ } ) ;
30+ }
31+ }
32+ }
2133
22- if ( type === 'atrule' && options . mediaQueries ) {
23- transform ( node , "params" , options , result ) ;
24- }
34+ pluginCreator . postcss = true ;
2535
26- if ( type === 'rule' && options . selectors ) {
27- transform ( node , "selector" , options , result ) ;
28- }
29- } ) ;
30- } ;
31- } ) ;
36+ export default pluginCreator ;
0 commit comments