* Read one raw token (comment / whitespace / value token) starting at byte * `pos`, writing it into the caller-supplied `out` and returning `out`. The * token's `end` is the next read position. Returns `undefined` at end-of-input — * `pos >= length`, an unterminated comment, or a string ending on
(input, pos, out)
| 1106 | * @returns {MutableToken | undefined} the token, or undefined at EOF |
| 1107 | */ |
| 1108 | function readToken(input, pos, out) { |
| 1109 | if (pos >= input.length) return undefined; |
| 1110 | const cc = input.charCodeAt(pos); |
| 1111 | class="cm">// Comment: `/*…*/` is yielded as a token (filtered by `next`). |
| 1112 | if (cc === CC_SOLIDUS && input.charCodeAt(pos + 1) === CC_ASTERISK) { |
| 1113 | const start = pos; |
| 1114 | class="cm">// Jump to the closing `*/` in one native scan instead of a per-character |
| 1115 | class="cm">// loop — comment bodies (license banners, source comments) can be long. |
| 1116 | class="cm">// No close: unterminated comment runs to EOF so ranges cover all input. |
| 1117 | const close = input.indexOf(class="st">"*/", pos + 2); |
| 1118 | return fill( |
| 1119 | out, |
| 1120 | TT_COMMENT, |
| 1121 | start, |
| 1122 | close === -1 ? input.length : close + 2 |
| 1123 | ); |
| 1124 | } |
| 1125 | class="cm">// `consumeAToken` dispatches on the lead code point at `pos` (it expects the |
| 1126 | class="cm">// position just past the lead and the already-read lead code point). |
| 1127 | return consumeAToken(input, pos + 1, cc, out); |
| 1128 | } |
| 1129 | |
| 1130 | class="cm">// AST shape mirrors tabatkins/parse-css (the CSS Syntax Level 3 reference), with two deviations: nodes carry a `range` byte offset pair + a lazy `loc` getter, and have no methods beyond it. |
| 1131 |
no test coverage detected