Skip to content

Commit d128984

Browse files
committed
Add HashToken.isIdent, replacing the old HashToken.type, and use it properly.
1 parent df2089c commit d128984

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

parse-css.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,8 @@ function tokenize(str) {
151151
else if(code == 0x22) return consumeAStringToken();
152152
else if(code == 0x23) {
153153
if(namechar(next()) || areAValidEscape(next(1), next(2))) {
154-
var token = new HashToken();
155-
if(wouldStartAnIdentifier(next(1), next(2), next(3))) token.type = "id";
156-
token.value = consumeAName();
157-
return token;
154+
const isIdent = wouldStartAnIdentifier(next(1), next(2), next(3));
155+
return new HashToken(consumeAName(), isIdent);
158156
} else {
159157
return new DelimToken(code);
160158
}
@@ -722,13 +720,19 @@ class AtKeywordToken extends CSSParserToken {
722720
}
723721

724722
class HashToken extends CSSParserToken {
725-
constructor(val) {
723+
constructor(val, isIdent) {
726724
super("HASH");
727725
this.value = val;
726+
this.isIdent = isIdent;
728727
}
729728
toString() { return `HASH(${this.value})`; }
730-
toJSON() { return {type:this.type, value:this.value}; }
731-
toSource() { return "#" + escapeHash(this.value); }
729+
toJSON() { return {type:this.type, value:this.value, isIdent:this.isIdent}; }
730+
toSource() {
731+
if(this.isIdent) {
732+
return "#" + escapeIdent(this.value);
733+
}
734+
return "#" + escapeHash(this.value);
735+
}
732736
}
733737

734738
class StringToken extends CSSParserToken {

0 commit comments

Comments
 (0)