Skip to content

Commit 2e294ae

Browse files
committed
adding replacements for declaration values
1 parent 514e8ac commit 2e294ae

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/wip.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
const matchImports = /^(.+?)\s+from\s+(?:"([^"]+)"|'([^']+)')$/
22
const matchLet = /(?:,\s+|^)([\w-]+):?\s+("[^"]*"|'[^']*'|[^,]+)\s?/g
3+
const matchConstName = /[\w-]+/g
34

45
export default css => {
56
let declarations = {}
67
css.eachAtRule(/^-?let$/, 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
}

0 commit comments

Comments
 (0)