MCPcopy
hub / github.com/webpack/webpack / consumeAnIdentLikeToken

Function consumeAnIdentLikeToken

lib/css/syntax.js:846–887  ·  view source on GitHub ↗

* Consume an ident-like token: ident / function / url / bad-url. * @param {string} input input * @param {number} pos position at the first ident-start code point * @param {MutableToken} out token to populate * @returns {MutableToken | undefined} the resulting token, or undefined at EOF

(input, pos, out)

Source from the content-addressed store, hash-verified

844 * @returns {MutableToken | undefined} the resulting token, or undefined at EOF
845 */
846function consumeAnIdentLikeToken(input, pos, out) {
847 const start = pos;
848 pos = _consumeAnIdentSequence(input, pos);
849 // `url` case-insensitively (ASCII lower via `| 0x20`) without a
850 // `slice().toLowerCase()` allocation per identifier; an escaped ident can't
851 // be exactly 3 raw chars, so the length gate keeps this equivalent.
852 if (
853 pos - start === 3 &&
854 (input.charCodeAt(start) | 0x20) === CC_LOWER_U &&
855 (input.charCodeAt(start + 1) | 0x20) === CC_LOWER_R &&
856 (input.charCodeAt(start + 2) | 0x20) === CC_LOWER_L &&
857 input.charCodeAt(pos) === CC_LEFT_PARENTHESIS
858 ) {
859 pos++;
860 const end = pos;
861 while (
862 _isWhiteSpace(input.charCodeAt(pos)) &&
863 _isWhiteSpace(input.charCodeAt(pos + 1))
864 ) {
865 pos++;
866 }
867 if (
868 input.charCodeAt(pos) === CC_QUOTATION_MARK ||
869 input.charCodeAt(pos) === CC_APOSTROPHE ||
870 (_isWhiteSpace(input.charCodeAt(pos)) &&
871 (input.charCodeAt(pos + 1) === CC_QUOTATION_MARK ||
872 input.charCodeAt(pos + 1) === CC_APOSTROPHE))
873 ) {
874 // End at `end` (the `(`'s closer position), not `pos` — the
875 // lookahead-eaten whitespace must be re-tokenized as a whitespace
876 // token rather than swallowed silently. The reader resumes at
877 // `token.end`, so returning `end` here does that.
878 return fill(out, TT_FUNCTION, start, end);
879 }
880 return consumeAUrlToken(input, pos, start, out);
881 }
882 if (input.charCodeAt(pos) === CC_LEFT_PARENTHESIS) {
883 pos++;
884 return fill(out, TT_FUNCTION, start, pos);
885 }
886 return fill(out, TT_IDENTIFIER, start, pos);
887}
888
889/**
890 * `<` — CDO or delim.

Callers 3

consumeHyphenMinusFunction · 0.85
consumeReverseSolidusFunction · 0.85
consumeATokenFunction · 0.85

Calls 4

_consumeAnIdentSequenceFunction · 0.85
_isWhiteSpaceFunction · 0.85
fillFunction · 0.85
consumeAUrlTokenFunction · 0.85

Tested by

no test coverage detected