File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change 11const matchImports = / ^ ( .+ ?) \s + f r o m \s + (?: " ( [ ^ " ] + ) " | ' ( [ ^ ' ] + ) ' ) $ /
22const matchLet = / (?: , \s + | ^ ) ( [ \w - ] + ) : ? \s + ( " [ ^ " ] * " | ' [ ^ ' ] * ' | [ ^ , ] + ) \s ? / g
3+ const matchConstName = / [ \w - ] + / g
34
45export default css => {
56 let declarations = { }
67 css . eachAtRule ( / ^ - ? l e t $ / , atRule => {
7- console . log ( atRule . params )
8-
98 let matches
109 while ( matches = matchLet . exec ( atRule . params ) ) {
1110 let [ /*match*/ , key , value ] = matches
@@ -20,4 +19,15 @@ export default css => {
2019 console . log ( atRule . params )
2120 }
2221 } )
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+ } )
2333}
You can’t perform that action at this time.
0 commit comments