@@ -310,7 +310,7 @@ const CC_EQUALS_SIGN = "=".charCodeAt(0);
310310
311311// Lexer token types (CSS Syntax Level 3 §4) plus the `<eof-token>`, numeric so
312312// the `type` slot stays compact and the consume algorithms dispatch on integer
313- // `===`. Exported with `readToken`, the lexer primitive, for the unit test .
313+ // `===`. Plain constants, not `TokenType` reads, keep the lexer's hot path cheap .
314314const TT_COMMENT = 1;
315315const TT_WHITESPACE = 2;
316316const TT_STRING = 3;
@@ -340,6 +340,40 @@ const TT_CDO = 24;
340340const TT_CDC = 25;
341341const TT_EOF = 26;
342342
343+ /**
344+ * The lexer token types by spec name, as `readToken` and `TokenStream` callers
345+ * read them.
346+ * @type {{ Comment: 1, Whitespace: 2, String: 3, BadString: 4, Hash: 5, Delim: 6, LeftParenthesis: 7, LeftSquareBracket: 8, LeftCurlyBracket: 9, RightParenthesis: 10, RightSquareBracket: 11, RightCurlyBracket: 12, Comma: 13, Colon: 14, Semicolon: 15, AtKeyword: 16, Function: 17, Url: 18, BadUrl: 19, Ident: 20, Number: 21, Percentage: 22, Dimension: 23, CDO: 24, CDC: 25, EOF: 26 }}
347+ */
348+ const TokenType = {
349+ Comment: TT_COMMENT,
350+ Whitespace: TT_WHITESPACE,
351+ String: TT_STRING,
352+ BadString: TT_BAD_STRING_TOKEN,
353+ Hash: TT_HASH,
354+ Delim: TT_DELIM,
355+ LeftParenthesis: TT_LEFT_PARENTHESIS,
356+ LeftSquareBracket: TT_LEFT_SQUARE_BRACKET,
357+ LeftCurlyBracket: TT_LEFT_CURLY_BRACKET,
358+ RightParenthesis: TT_RIGHT_PARENTHESIS,
359+ RightSquareBracket: TT_RIGHT_SQUARE_BRACKET,
360+ RightCurlyBracket: TT_RIGHT_CURLY_BRACKET,
361+ Comma: TT_COMMA,
362+ Colon: TT_COLON,
363+ Semicolon: TT_SEMICOLON,
364+ AtKeyword: TT_AT_KEYWORD,
365+ Function: TT_FUNCTION,
366+ Url: TT_URL,
367+ BadUrl: TT_BAD_URL_TOKEN,
368+ Ident: TT_IDENTIFIER,
369+ Number: TT_NUMBER,
370+ Percentage: TT_PERCENTAGE,
371+ Dimension: TT_DIMENSION,
372+ CDO: TT_CDO,
373+ CDC: TT_CDC,
374+ EOF: TT_EOF
375+ };
376+
343377// The opening bracket types (7..9) and their closers (10..12) are laid out so a
344378// closer is always `opener + 3`, which `consumeASimpleBlock` uses directly. The
345379// block char is a dense array indexed by the offset from `TT_LEFT_PARENTHESIS`.
@@ -806,7 +840,7 @@ const _consumeTheRemnantsOfABadUrl = (input, pos) => {
806840 * by `tokenToNode` for the matching type. Pass a fresh one per `readToken` call
807841 * to collect the raw token list (e.g. tests).
808842 * @typedef {object} MutableToken
809- * @property {number} type one of the `TT_*` constants
843+ * @property {number} type a `TokenType`
810844 * @property {number} start byte offset of the token's first code point
811845 * @property {number} end byte offset just past the token's last code point
812846 * @property {boolean} isId hash tokens: starts an ident sequence
@@ -832,7 +866,7 @@ const createToken = () => ({
832866 * Populate `out`'s common fields and return it — the lexer functions' return
833867 * statement (kept tiny so V8 can inline it).
834868 * @param {MutableToken} out token to populate
835- * @param {number} type one of the `TT_*` constants
869+ * @param {number} type a `TokenType`
836870 * @param {number} start byte offset of the token's first code point
837871 * @param {number} end byte offset just past the token's last code point
838872 * @returns {MutableToken} `out`
@@ -19042,65 +19076,40 @@ const _collectRuleSpans = (spans, item, text, at, path, inner) => {
1904219076};
1904319077
1904419078module.exports.A = A;
19045- module.exports.CC_0 = CC_0;
19046- module.exports.CC_APOSTROPHE = CC_APOSTROPHE;
19047- module.exports.CC_COMMA = CC_COMMA;
19048- module.exports.CC_FULL_STOP = CC_FULL_STOP;
19049- module.exports.CC_GREATER_THAN_SIGN = CC_GREATER_THAN_SIGN;
19050- module.exports.CC_HYPHEN_MINUS = CC_HYPHEN_MINUS;
19051- module.exports.CC_LEFT_PARENTHESIS = CC_LEFT_PARENTHESIS;
19052- module.exports.CC_LEFT_SQUARE = CC_LEFT_SQUARE;
19053- module.exports.CC_LOWER_D = CC_LOWER_D;
19054- module.exports.CC_LOW_LINE = CC_LOW_LINE;
19055- module.exports.CC_NUMBER_SIGN = CC_NUMBER_SIGN;
19056- module.exports.CC_PLUS_SIGN = CC_PLUS_SIGN;
19057- module.exports.CC_QUOTATION_MARK = CC_QUOTATION_MARK;
19058- module.exports.CC_REVERSE_SOLIDUS = CC_REVERSE_SOLIDUS;
19059- module.exports.CC_RIGHT_PARENTHESIS = CC_RIGHT_PARENTHESIS;
19060- module.exports.CC_RIGHT_SQUARE = CC_RIGHT_SQUARE;
19061- module.exports.CC_SPACE = CC_SPACE;
19062- module.exports.CC_TILDE = CC_TILDE;
19063- module.exports.CC_UPPER_A = CC_UPPER_A;
19064- module.exports.CC_UPPER_Z = CC_UPPER_Z;
1906519079module.exports.DARK_PROPERTY = DARK_PROPERTY;
1906619080module.exports.KEYFRAMES_AT_RULE_RE = KEYFRAMES_AT_RULE_RE;
1906719081module.exports.LIGHT_PROPERTY = LIGHT_PROPERTY;
19068- module.exports.LIST_KIND_KEYFRAME = LIST_KIND_KEYFRAME;
19069- module.exports.LIST_KIND_NESTED = LIST_KIND_NESTED;
19070- module.exports.LIST_KIND_SELECTOR = LIST_KIND_SELECTOR;
19071- module.exports.LIST_NO = LIST_NO;
19072- module.exports.LIST_UNKNOWN = LIST_UNKNOWN;
1907319082module.exports.Field = Field;
1907419083module.exports.Flag = Flag;
1907519084module.exports.Part = Part;
19085+ module.exports._CC_0 = CC_0;
19086+ module.exports._CC_APOSTROPHE = CC_APOSTROPHE;
19087+ module.exports._CC_COMMA = CC_COMMA;
19088+ module.exports._CC_FULL_STOP = CC_FULL_STOP;
19089+ module.exports._CC_GREATER_THAN_SIGN = CC_GREATER_THAN_SIGN;
19090+ module.exports._CC_HYPHEN_MINUS = CC_HYPHEN_MINUS;
19091+ module.exports._CC_LEFT_PARENTHESIS = CC_LEFT_PARENTHESIS;
19092+ module.exports._CC_LEFT_SQUARE = CC_LEFT_SQUARE;
19093+ module.exports._CC_LOWER_D = CC_LOWER_D;
19094+ module.exports._CC_LOW_LINE = CC_LOW_LINE;
19095+ module.exports._CC_NUMBER_SIGN = CC_NUMBER_SIGN;
19096+ module.exports._CC_PLUS_SIGN = CC_PLUS_SIGN;
19097+ module.exports._CC_QUOTATION_MARK = CC_QUOTATION_MARK;
19098+ module.exports._CC_REVERSE_SOLIDUS = CC_REVERSE_SOLIDUS;
19099+ module.exports._CC_RIGHT_PARENTHESIS = CC_RIGHT_PARENTHESIS;
19100+ module.exports._CC_RIGHT_SQUARE = CC_RIGHT_SQUARE;
19101+ module.exports._CC_SPACE = CC_SPACE;
19102+ module.exports._CC_TILDE = CC_TILDE;
19103+ module.exports._CC_UPPER_A = CC_UPPER_A;
19104+ module.exports._CC_UPPER_Z = CC_UPPER_Z;
19105+ module.exports._LIST_KIND_KEYFRAME = LIST_KIND_KEYFRAME;
19106+ module.exports._LIST_KIND_NESTED = LIST_KIND_NESTED;
19107+ module.exports._LIST_KIND_SELECTOR = LIST_KIND_SELECTOR;
19108+ module.exports._LIST_NO = LIST_NO;
19109+ module.exports._LIST_UNKNOWN = LIST_UNKNOWN;
1907619110module.exports._blockTokenOf = _blockTokenOf;
1907719111module.exports.NodeType = NodeType;
19078- module.exports.TT_AT_KEYWORD = TT_AT_KEYWORD;
19079- module.exports.TT_BAD_STRING_TOKEN = TT_BAD_STRING_TOKEN;
19080- module.exports.TT_BAD_URL_TOKEN = TT_BAD_URL_TOKEN;
19081- module.exports.TT_CDC = TT_CDC;
19082- module.exports.TT_CDO = TT_CDO;
19083- module.exports.TT_COLON = TT_COLON;
19084- module.exports.TT_COMMA = TT_COMMA;
19085- module.exports.TT_COMMENT = TT_COMMENT;
19086- module.exports.TT_DELIM = TT_DELIM;
19087- module.exports.TT_DIMENSION = TT_DIMENSION;
19088- module.exports.TT_EOF = TT_EOF;
19089- module.exports.TT_FUNCTION = TT_FUNCTION;
19090- module.exports.TT_HASH = TT_HASH;
19091- module.exports.TT_IDENTIFIER = TT_IDENTIFIER;
19092- module.exports.TT_LEFT_CURLY_BRACKET = TT_LEFT_CURLY_BRACKET;
19093- module.exports.TT_LEFT_PARENTHESIS = TT_LEFT_PARENTHESIS;
19094- module.exports.TT_LEFT_SQUARE_BRACKET = TT_LEFT_SQUARE_BRACKET;
19095- module.exports.TT_NUMBER = TT_NUMBER;
19096- module.exports.TT_PERCENTAGE = TT_PERCENTAGE;
19097- module.exports.TT_RIGHT_CURLY_BRACKET = TT_RIGHT_CURLY_BRACKET;
19098- module.exports.TT_RIGHT_PARENTHESIS = TT_RIGHT_PARENTHESIS;
19099- module.exports.TT_RIGHT_SQUARE_BRACKET = TT_RIGHT_SQUARE_BRACKET;
19100- module.exports.TT_SEMICOLON = TT_SEMICOLON;
19101- module.exports.TT_STRING = TT_STRING;
19102- module.exports.TT_URL = TT_URL;
19103- module.exports.TT_WHITESPACE = TT_WHITESPACE;
19112+ module.exports.TokenType = TokenType;
1910419113module.exports.TokenStream = TokenStream;
1910519114module.exports.VENDOR_PREFIX = VENDOR_PREFIX;
1910619115module.exports._IMPORTANT = _IMPORTANT;
0 commit comments