MCPcopy
hub / github.com/webpack/webpack / handleAttributeSelector

Method handleAttributeSelector

lib/css/CssParser.js:1919–1988  ·  view source on GitHub ↗
(block)

Source from the content-addressed store, hash-verified

1917 * @returns {void}
1918 */
1919 const handleAttributeSelector = (block) => {
1920 const attrParts = A.children(block);
1921 let ai = 0;
1922 while (
1923 ai < attrParts.length &&
1924 A.type(attrParts[ai]) === NodeType.Whitespace
1925 ) {
1926 ai++;
1927 }
1928 const attrNameNode = attrParts[ai];
1929 if (!attrNameNode || A.type(attrNameNode) !== NodeType.Ident) return;
1930 const attrName = A.unescaped(attrNameNode);
1931 if (!equalsLowerCase(attrName, "class")) return;
1932 ai++;
1933 while (
1934 ai < attrParts.length &&
1935 A.type(attrParts[ai]) === NodeType.Whitespace
1936 ) {
1937 ai++;
1938 }
1939 // `=` or `~=` (two `Delim` tokens for the latter).
1940 const op1 = attrParts[ai];
1941 if (!op1 || A.type(op1) !== NodeType.Delim) return;
1942 const op1v = A.value(op1);
1943 if (op1v === "~") {
1944 ai++;
1945 const op2 = attrParts[ai];
1946 if (!op2 || A.type(op2) !== NodeType.Delim || A.value(op2) !== "=") {
1947 return;
1948 }
1949 } else if (op1v !== "=") {
1950 return;
1951 }
1952 ai++;
1953 while (
1954 ai < attrParts.length &&
1955 A.type(attrParts[ai]) === NodeType.Whitespace
1956 ) {
1957 ai++;
1958 }
1959 const attrValueNode = attrParts[ai];
1960 if (!attrValueNode) return;
1961 /** @type {number} */
1962 let classNameStart;
1963 /** @type {number} */
1964 let classNameEnd;
1965 if (A.type(attrValueNode) === NodeType.String) {
1966 classNameStart = A.start(attrValueNode) + 1;
1967 classNameEnd = A.end(attrValueNode) - 1;
1968 } else if (A.type(attrValueNode) === NodeType.Ident) {
1969 classNameStart = A.start(attrValueNode);
1970 classNameEnd = A.end(attrValueNode);
1971 } else {
1972 return;
1973 }
1974 const className = unescapeRange(classNameStart, classNameEnd);
1975 const { line: sl, column: sc } = locConverter.get(classNameStart);
1976 const { line: el, column: ec } = locConverter.get(classNameEnd);

Callers

nothing calls this directly

Calls 5

equalsLowerCaseFunction · 0.85
unescapedMethod · 0.80
typeMethod · 0.45
valueMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected