Skip to content

Commit 594eda7

Browse files
committed
Improve QualifiedRule.toSource()
1 parent 5de8d2f commit 594eda7

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

parse-css.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,15 +1311,17 @@ class QualifiedRule extends CSSParserRule {
13111311
}
13121312
toSource(indent=0) {
13131313
let s = printIndent(indent);
1314-
s += this.prelude.map(x=>x.toSource()).join("");
1315-
s += "{\n";
1316-
if(this.declarations.length) {
1317-
s += this.declarations.map(x=>x.toSource(indent+1)).join("\n") + "\n";
1318-
}
1319-
if(this.rules.length) {
1320-
s += this.rules.map(x=>x.toSource(indent+1)).join("\n") + "\n";
1314+
let prelude = this.prelude.map(x => x.toSource()).join("");
1315+
while (prelude.endsWith(' ')) { prelude = prelude.slice(0, -1); }
1316+
s += prelude + " ";
1317+
if (this.declarations.length || this.rules.length) {
1318+
s += "{\n" +
1319+
this.declarations.map(x => x.toSource(indent+1) + "\n").join("") +
1320+
this.rules.map(x => x.toSource(indent+1) + "\n").join("") +
1321+
printIndent(indent) + "}";
1322+
} else {
1323+
s += "{ }";
13211324
}
1322-
s += printIndent(indent) + "}";
13231325
return s;
13241326
}
13251327
}

0 commit comments

Comments
 (0)