File tree 1 file changed +12
-2
lines changed
1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change 1
1
const matchImports = / ^ ( .+ ?) \s + f r o m \s + (?: " ( [ ^ " ] + ) " | ' ( [ ^ ' ] + ) ' ) $ /
2
2
const matchLet = / (?: , \s + | ^ ) ( [ \w - ] + ) : ? \s + ( " [ ^ " ] * " | ' [ ^ ' ] * ' | [ ^ , ] + ) \s ? / g
3
+ const matchConstName = / [ \w - ] + / g
3
4
4
5
export default css => {
5
6
let declarations = { }
6
7
css . eachAtRule ( / ^ - ? l e t $ / , atRule => {
7
- console . log ( atRule . params )
8
-
9
8
let matches
10
9
while ( matches = matchLet . exec ( atRule . params ) ) {
11
10
let [ /*match*/ , key , value ] = matches
@@ -20,4 +19,15 @@ export default css => {
20
19
console . log ( atRule . params )
21
20
}
22
21
} )
22
+ /* Perform replacements */
23
+ css . eachDecl ( decl => {
24
+ let matches
25
+ while ( matches = matchConstName . exec ( decl . value ) ) {
26
+ let replacement = declarations [ matches [ 0 ] ]
27
+ if ( replacement ) {
28
+ decl . value = decl . value . slice ( 0 , matches . index ) + replacement + decl . value . slice ( matchConstName . lastIndex )
29
+ matchConstName . lastIndex -= matches [ 0 ] . length - replacement . length
30
+ }
31
+ }
32
+ } )
23
33
}
You can’t perform that action at this time.
0 commit comments