Skip to content

Commit

Permalink
Fix special char representation for toString()
Browse files Browse the repository at this point in the history
  • Loading branch information
danny0838 committed Apr 7, 2024
1 parent fa0642c commit e72cb73
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions parse-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ class DelimToken extends CSSParserToken {
}
this.value = val;
}
toString() { return `DELIM(${this.value})`; }
toString() { return `DELIM(${JSON.stringify(this.value)})`; }
toJSON() { return {type:this.type, value:this.value}; }
toSource() {
if(this.value == "\\") return "\\\n";
Expand All @@ -632,7 +632,7 @@ class IdentToken extends CSSParserToken {
super("IDENT");
this.value = val;
}
toString() { return `IDENT(${this.value})`; }
toString() { return `IDENT(${JSON.stringify(this.value)})`; }
toJSON() { return {type:this.type, value:this.value}; }
toSource() { return escapeIdent(this.value); }
}
Expand All @@ -643,7 +643,7 @@ class FunctionToken extends CSSParserToken {
this.value = val;
this.mirror = CloseParenToken;
}
toString() { return `FUNCTION(${this.value})`; }
toString() { return `FUNCTION(${JSON.stringify(this.value)})`; }
toJSON() { return {type:this.type, value:this.value}; }
toSource() { return escapeIdent(this.value) + "("; }
}
Expand All @@ -653,7 +653,7 @@ class AtKeywordToken extends CSSParserToken {
super("AT-KEYWORD");
this.value = val;
}
toString() { return `AT(${this.value})`; }
toString() { return `AT(${JSON.stringify(this.value)})`; }
toJSON() { return {type:this.type, value:this.value }; }
toSource() { return "@" + escapeIdent(this.value); }
}
Expand All @@ -664,7 +664,7 @@ class HashToken extends CSSParserToken {
this.value = val;
this.isIdent = isIdent;
}
toString() { return `HASH(${this.value})`; }
toString() { return `HASH(${JSON.stringify(this.value)})`; }
toJSON() { return {type:this.type, value:this.value, isIdent:this.isIdent}; }
toSource() {
if(this.isIdent) {
Expand All @@ -679,7 +679,7 @@ class StringToken extends CSSParserToken {
super("STRING");
this.value = val;
}
toString() { return `STRING(${this.value})`; }
toString() { return `STRING(${JSON.stringify(this.value)})`; }
toJSON() { return {type:this.type, value:this.value}; }
toSource() { return `"${escapeString(this.value)}"`; }
}
Expand All @@ -689,7 +689,7 @@ class URLToken extends CSSParserToken {
super("URL");
this.value = val;
}
toString() { return `URL(${this.value})`; }
toString() { return `URL(${JSON.stringify(this.value)})`; }
toJSON() { return {type:this.type, value:this.value}; }
toSource() { return `url("${escapeString(this.value)}")`; }
}
Expand Down Expand Up @@ -732,7 +732,7 @@ class DimensionToken extends CSSParserToken {
this.sign = sign;
}
toString() {
return `DIM(${formatNumber(this.value, this.sign)}, ${this.unit})`;
return `DIM(${formatNumber(this.value, this.sign)}, ${JSON.stringify(this.unit)})`;
}
toJSON() { return {type:this.type, value:this.value, isInteger:this.isInteger, unit:this.unit, sign:this.sign}; }
toSource() {
Expand Down

0 comments on commit e72cb73

Please sign in to comment.