1
1
import postcss from 'postcss'
2
- import replaceSymbols , { replaceAll } from 'icss-replace-symbols'
2
+ import replaceSymbols , { replaceAll } from 'icss-replace-symbols'
3
3
4
4
const matchImports = / ^ ( .+ ?) \s + f r o m \s + ( " [ ^ " ] * " | ' [ ^ ' ] * ' | [ \w - ] + ) $ /
5
5
const matchValueDefinition = / (?: , \s + | ^ ) ( [ \w - ] + ) : ? \s + ( " [ ^ " ] * " | ' [ ^ ' ] * ' | \w + \( [ ^ \) ] + \) | [ ^ , ] + ) \s ? / g
@@ -34,12 +34,12 @@ export default (css, result) => {
34
34
let [ /*match*/ , theirName , myName = theirName ] = tokens
35
35
let importedName = createImportedName ( myName )
36
36
definitions [ myName ] = importedName
37
- return { theirName, importedName}
37
+ return { theirName, importedName }
38
38
} else {
39
39
throw new Error ( `@import statement "${ alias } " is invalid!` )
40
40
}
41
41
} )
42
- importAliases . push ( { path, imports} )
42
+ importAliases . push ( { path, imports } )
43
43
atRule . remove ( )
44
44
}
45
45
}
@@ -58,12 +58,11 @@ export default (css, result) => {
58
58
} )
59
59
60
60
/* We want to export anything defined by now, but don't add it to the CSS yet or
61
- it well get picked up by the replacement stuff */
61
+ it well get picked up by the replacement stuff */
62
62
let exportDeclarations = Object . keys ( definitions ) . map ( key => postcss . decl ( {
63
63
value : definitions [ key ] ,
64
64
prop : key ,
65
- raws : { before : "\n " } ,
66
- _autoprefixerDisabled : true
65
+ raws : { before : "\n " }
67
66
} ) )
68
67
69
68
/* If we have no definitions, don't continue */
@@ -74,24 +73,28 @@ export default (css, result) => {
74
73
75
74
/* Add export rules if any */
76
75
if ( exportDeclarations . length > 0 ) {
77
- css . prepend ( postcss . rule ( {
76
+ let exportRule = postcss . rule ( {
78
77
selector : `:export` ,
79
- raws : { after : "\n" } ,
80
- nodes : exportDeclarations
81
- } ) )
78
+ raws : { after : "\n" }
79
+ } )
80
+ exportRule . append ( exportDeclarations )
81
+ css . prepend ( exportRule )
82
82
}
83
83
84
84
/* Add import rules */
85
- importAliases . reverse ( ) . forEach ( ( { path, imports} ) => {
86
- css . prepend ( postcss . rule ( {
85
+ importAliases . reverse ( ) . forEach ( ( { path, imports } ) => {
86
+ let importRule = postcss . rule ( {
87
87
selector : `:import(${ path } )` ,
88
- raws : { after : "\n" } ,
89
- nodes : imports . map ( ( { theirName, importedName} ) => postcss . decl ( {
88
+ raws : { after : "\n" }
89
+ } )
90
+ imports . forEach ( ( { theirName, importedName } ) => {
91
+ importRule . append ( {
90
92
value : theirName ,
91
93
prop : importedName ,
92
- raws : { before : "\n " } ,
93
- _autoprefixerDisabled : true
94
- } ) )
95
- } ) )
94
+ raws : { before : "\n " }
95
+ } )
96
+ } )
97
+
98
+ css . prepend ( importRule )
96
99
} )
97
100
}
0 commit comments