* Numeric token: number / percentage / dimension. * @param {string} input input * @param {number} pos position at the first numeric/sign code point * @param {MutableToken} out token to populate * @returns {MutableToken | undefined} the resulting token, or undefined at EOF
(input, pos, out)
| 748 | * @returns {MutableToken | undefined} the resulting token, or undefined at EOF |
| 749 | */ |
| 750 | function consumeANumericToken(input, pos, out) { |
| 751 | const start = pos; |
| 752 | pos = _consumeANumber(input, pos); |
| 753 | const first = input.charCodeAt(pos); |
| 754 | // A unit can only begin with `-`, `\`, or an ident-start code point — exactly |
| 755 | // the cases where the §4 "would start an ident sequence" check can be true. For |
| 756 | // a plain number (next char is whitespace / `;` / `,` / `)` / EOF, the common |
| 757 | // case) skip the two lookahead reads and the call entirely. |
| 758 | if ( |
| 759 | (first === CC_HYPHEN_MINUS || |
| 760 | first === CC_REVERSE_SOLIDUS || |
| 761 | _isIdentStartCodePointCC(first)) && |
| 762 | _ifThreeCodePointsWouldStartAnIdentSequence( |
| 763 | input, |
| 764 | pos, |
| 765 | first, |
| 766 | input.charCodeAt(pos + 1), |
| 767 | input.charCodeAt(pos + 2) |
| 768 | ) |
| 769 | ) { |
| 770 | out.unitStart = pos; |
| 771 | pos = _consumeAnIdentSequence(input, pos); |
| 772 | return fill(out, TT_DIMENSION, start, pos); |
| 773 | } |
| 774 | if (first === CC_PERCENTAGE) { |
| 775 | return fill(out, TT_PERCENTAGE, start, pos + 1); |
| 776 | } |
| 777 | return fill(out, TT_NUMBER, start, pos); |
| 778 | } |
| 779 | |
| 780 | /** |
| 781 | * Consume an unquoted url token. Caller has already eaten `url(` and |
no test coverage detected