Skip to content

Commit 79cb64d

Browse files
authored
Do not duplicate words between property and colon (#49)
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.
1 parent 1728651 commit 79cb64d

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

‎lib/safe-parser.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ class SafeParser extends Parser {
3838
decl(tokens) {
3939
if (tokens.length > 1 && tokens.some(i => i[0] === 'word')) {
4040
super.decl(tokens)
41+
// Words before colon are already in raws.between,
42+
// so remove their copy added by unknownWord()
43+
this.spaces = ''
4144
}
4245
}
4346

‎test/parse.test.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ test('fixes 2 properties in safe mode', () => {
7878
equal(root.first.nodes.length, 1)
7979
equal(root.first.first.prop, 'color')
8080
equal(root.first.first.raws.between, ' one: ')
81+
equal(root.toString(), 'a { color one: white; one }')
8182
})
8283

8384
test('fixes nameless at-rule in safe mode', () => {

0 commit comments

Comments
 (0)