* Per-character dispatcher. The outer loop has already advanced past * the lead code point (`pos - 1` is the lead). * @param {string} input input * @param {number} pos position just past the lead code point * @param {number} cc the lead code point (`input.charCodeAt(pos - 1)`, already read by th
(input, pos, cc, out)
| 1043 | * @returns {MutableToken | undefined} the resulting token, or undefined at EOF |
| 1044 | */ |
| 1045 | function consumeAToken(input, pos, cc, out) { |
| 1046 | // `u` / `U` would start a unicode-range token in the spec; those are not |
| 1047 | // produced, so they map to HC_IDENT and fall through to ident-like. |
| 1048 | switch (cc < 128 ? _charClass[cc] : HC_IDENT) { |
| 1049 | // Run of whitespace → one <whitespace-token>. |
| 1050 | case HC_WHITESPACE: |
| 1051 | return consumeSpace(input, pos, out); |
| 1052 | // `"` / `'` → <string-token> (or <bad-string-token> on a raw newline). |
| 1053 | case HC_STRING: |
| 1054 | return consumeAStringToken(input, pos, out); |
| 1055 | // One-code-point token: its type is looked up in `_singleTT` (the `(` `)` |
| 1056 | // `,` `:` `;` `[` `]` `{` `}` set), so all of them share this arm. |
| 1057 | case HC_SINGLE: |
| 1058 | return fill(out, _singleTT[cc], pos - 1, pos); |
| 1059 | // `#` → <hash-token> if an ident/escape follows, else a <delim-token>. |
| 1060 | case HC_NUMBER_SIGN: |
| 1061 | return consumeNumberSign(input, pos, out); |
| 1062 | // `+` → <number-token> if it starts a number, else a <delim-token>. |
| 1063 | case HC_PLUS_SIGN: |
| 1064 | return consumePlusSign(input, pos, out); |
| 1065 | // `-` → number / <CDC-token> (`-->`) / ident / <delim-token>. |
| 1066 | case HC_HYPHEN_MINUS: |
| 1067 | return consumeHyphenMinus(input, pos, out); |
| 1068 | // `.` → <number-token> if a digit follows, else a <delim-token>. |
| 1069 | case HC_FULL_STOP: |
| 1070 | return consumeFullStop(input, pos, out); |
| 1071 | // `<` → <CDO-token> (`<!--`), else a <delim-token>. |
| 1072 | case HC_LESS_THAN: |
| 1073 | return consumeLessThan(input, pos, out); |
| 1074 | // `@` → <at-keyword-token> if an ident follows, else a <delim-token>. |
| 1075 | case HC_AT_SIGN: |
| 1076 | return consumeCommercialAt(input, pos, out); |
| 1077 | // `\` → ident-like token if it's a valid escape, else a <delim-token>. |
| 1078 | case HC_REVERSE_SOLIDUS: |
| 1079 | return consumeReverseSolidus(input, pos, out); |
| 1080 | // Digit → numeric token; `pos - 1` re-includes the digit the caller passed. |
| 1081 | case HC_DIGIT: |
| 1082 | return consumeANumericToken(input, pos - 1, out); |
| 1083 | // Ident-start (letter / `_` / non-ASCII, incl. `u`/`U`) → ident / function / |
| 1084 | // url token; `pos - 1` re-includes the lead code point. |
| 1085 | case HC_IDENT: |
| 1086 | return consumeAnIdentLikeToken(input, pos - 1, out); |
| 1087 | default: |
| 1088 | // HC_DELIM. EOF is impossible here (caller guarded with the outer |
| 1089 | // loop's `pos < input.length` check). Anything else: a <delim-token>. |
| 1090 | return fill(out, TT_DELIM, pos - 1, pos); |
| 1091 | } |
| 1092 | } |
| 1093 | |
| 1094 | /** |
| 1095 | * Read one raw token (comment / whitespace / value token) starting at byte |
no test coverage detected