MCPcopy
hub / github.com/webpack/webpack / processDashedIdentInVarFunction

Method processDashedIdentInVarFunction

lib/css/CssParser.js:1724–1788  ·  view source on GitHub ↗
(fn)

Source from the content-addressed store, hash-verified

1722 */
1723 // Per-`var()`/`style()` dashed-ident scan + dispatch. Warm path (custom-property-heavy CSS has thousands of these), so it dispatches inline rather than allocating a descriptor per call.
1724 const processDashedIdentInVarFunction = (fn) => {
1725 /** @type {Token | undefined} */
1726 let identNode;
1727 let identIdx = -1;
1728 const fv = A.children(fn);
1729 for (let i = 0; i < fv.length; i++) {
1730 const cv = fv[i];
1731 if (A.type(cv) === NodeType.Whitespace) continue;
1732 if (A.type(cv) === NodeType.Ident) {
1733 identNode = /** @type {Token} */ (cv);
1734 identIdx = i;
1735 }
1736 break;
1737 }
1738 if (!identNode) return;
1739
1740 const identStart = A.start(identNode);
1741 const identEnd = A.end(identNode);
1742 // `isDashedIdentifier` on the value without slicing it: a literal `--`
1743 // prefix of length >= 3 (escaped dashes don't match, same as the string
1744 // form, since the raw bytes aren't `--`).
1745 if (
1746 identEnd - identStart < 3 ||
1747 input.charCodeAt(identStart) !== CC_HYPHEN_MINUS ||
1748 input.charCodeAt(identStart + 1) !== CC_HYPHEN_MINUS
1749 ) {
1750 return;
1751 }
1752
1753 let j = identIdx + 1;
1754 while (j < fv.length && A.type(fv[j]) === NodeType.Whitespace) {
1755 j++;
1756 }
1757
1758 if (
1759 j >= fv.length ||
1760 A.type(fv[j]) !== NodeType.Ident ||
1761 !equalsLowerCase(A.value(fv[j]), "from")
1762 ) {
1763 emitDashedIdentExport(identStart, identEnd);
1764 return;
1765 }
1766
1767 const fromIdent = fv[j];
1768 j++;
1769 while (j < fv.length && A.type(fv[j]) === NodeType.Whitespace) {
1770 j++;
1771 }
1772 if (j >= fv.length) return;
1773
1774 const src = fv[j];
1775 if (A.type(src) === NodeType.Ident && A.value(src) === "global") {
1776 emitDashedIdentFromGlobal(identEnd, A.end(src));
1777 return;
1778 }
1779 if (A.type(src) === NodeType.String) {
1780 emitDashedIdentImport(
1781 identStart,

Callers

nothing calls this directly

Calls 4

equalsLowerCaseFunction · 0.85
sliceMethod · 0.80
typeMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected