From cf96f698cf73eb7210f586453587f7637cb1410c Mon Sep 17 00:00:00 2001 From: Wahid Rizka Fathurrohman Date: Sat, 10 Oct 2026 11:47:21 +0700 Subject: [PATCH] Do not duplicate words between property and colon Parser#decl() keeps the words between the property and the colon in raws.between and calls unknownWord() for them. The safe parser's unknownWord() added them to the spaces before the next node too, so the output had them twice. --- lib/safe-parser.js | 3 +++ test/parse.test.js | 1 + 2 files changed, 4 insertions(+) diff --git a/lib/safe-parser.js b/lib/safe-parser.js index 4a26c24..e30519b 100644 --- a/lib/safe-parser.js +++ b/lib/safe-parser.js @@ -38,6 +38,9 @@ class SafeParser extends Parser { decl(tokens) { if (tokens.length > 1 && tokens.some(i => i[0] === 'word')) { super.decl(tokens) + // Words before colon are already in raws.between, + // so remove their copy added by unknownWord() + this.spaces = '' } } diff --git a/test/parse.test.js b/test/parse.test.js index 6e0acbb..d5fe65f 100644 --- a/test/parse.test.js +++ b/test/parse.test.js @@ -78,6 +78,7 @@ test('fixes 2 properties in safe mode', () => { equal(root.first.nodes.length, 1) equal(root.first.first.prop, 'color') equal(root.first.first.raws.between, ' one: ') + equal(root.toString(), 'a { color one: white; one }') }) test('fixes nameless at-rule in safe mode', () => {