@@ -106,6 +106,7 @@ exports.EnumToken = void 0;
106106 EnumToken[EnumToken["MediaFeatureAndTokenType"] = 89] = "MediaFeatureAndTokenType";
107107 EnumToken[EnumToken["MediaFeatureOrTokenType"] = 90] = "MediaFeatureOrTokenType";
108108 EnumToken[EnumToken["PseudoPageTokenType"] = 91] = "PseudoPageTokenType";
109+ EnumToken[EnumToken["PseudoElementTokenType"] = 92] = "PseudoElementTokenType";
109110 /* aliases */
110111 EnumToken[EnumToken["Time"] = 25] = "Time";
111112 EnumToken[EnumToken["Iden"] = 7] = "Iden";
@@ -3880,8 +3881,9 @@ function renderToken(token, options = {}, cache = Object.create(null), reducer,
38803881 return '';
38813882 }
38823883 case exports.EnumToken.PseudoClassTokenType:
3884+ case exports.EnumToken.PseudoElementTokenType:
38833885 // https://www.w3.org/TR/selectors-4/#single-colon-pseudos
3884- if (token.typ == exports.EnumToken.PseudoClassTokenType && ['::before', '::after', '::first-line', '::first-letter'].includes(token.val)) {
3886+ if (token.typ == exports.EnumToken.PseudoElementTokenType && ['::before', '::after', '::first-line', '::first-letter'].includes(token.val)) {
38853887 return token.val.slice(1);
38863888 }
38873889 case exports.EnumToken.UrlTokenTokenType:
@@ -12008,8 +12010,8 @@ function validateCompoundSelector(tokens, root, options) {
1200812010 tokens.shift();
1200912011 consumeWhitespace(tokens);
1201012012 }
12011- while (tokens.length > 0 && tokens[0].typ == exports.EnumToken.PseudoClassTokenType) {
12012- const isPseudoElement = tokens[0].val.startsWith('::') ;
12013+ while (tokens.length > 0 && ( tokens[0].typ == exports.EnumToken.PseudoElementTokenType || tokens[0].typ == exports.EnumToken. PseudoClassTokenType) ) {
12014+ const isPseudoElement = tokens[0].typ == exports.EnumToken.PseudoElementTokenType ;
1201312015 if (
1201412016 // https://developer.mozilla.org/en-US/docs/Web/CSS/WebKit_Extensions#pseudo-elements
1201512017 !(isPseudoElement && tokens[0].val.startsWith('::-webkit-')) &&
@@ -16314,11 +16316,11 @@ async function parseNode(results, context, stats, options, errors, src, map, raw
1631416316 const node = {
1631516317 typ: exports.EnumToken.AtRuleNodeType,
1631616318 nam: renderToken(atRule, { removeComments: true }),
16317- tokens: t,
16319+ // tokens: t,
1631816320 val: raw.join('')
1631916321 };
1632016322 Object.defineProperties(node, {
16321- tokens: { ...definedPropertySettings, enumerable: true , value: tokens.slice() },
16323+ tokens: { ...definedPropertySettings, enumerable: false , value: tokens.slice() },
1632216324 raw: { ...definedPropertySettings, value: raw }
1632316325 });
1632416326 if (delim.typ == exports.EnumToken.BlockStartTokenType) {
@@ -16443,7 +16445,7 @@ async function parseNode(results, context, stats, options, errors, src, map, raw
1644316445 };
1644416446 Object.defineProperty(node, 'tokens', {
1644516447 ...definedPropertySettings,
16446- enumerable: true ,
16448+ enumerable: false ,
1644716449 value: tokens.slice()
1644816450 });
1644916451 let raw = [...uniq.values()];
@@ -16916,10 +16918,16 @@ function getTokenType(val, hint) {
1691616918 val: val.slice(0, -1),
1691716919 chi: []
1691816920 }
16919- : {
16920- typ: exports.EnumToken.PseudoClassTokenType,
16921+ : (
16922+ // https://www.w3.org/TR/selectors-4/#single-colon-pseudos
16923+ val.startsWith('::') || [':before', ':after', ':first-line', ':first-letter'].includes(val) ? {
16924+ typ: exports.EnumToken.PseudoElementTokenType,
1692116925 val
16922- };
16926+ } :
16927+ {
16928+ typ: exports.EnumToken.PseudoClassTokenType,
16929+ val
16930+ });
1692316931 }
1692416932 if (isAtKeyword(val)) {
1692516933 return {
@@ -17613,7 +17621,14 @@ function expandRule(node) {
1761317621 rule.sel = splitRule(ast.sel).reduce((a, b) => a.concat([b.join('') + r]), []).join(',');
1761417622 }
1761517623 else {
17616- selRule.forEach(arr => combinators.includes(arr[0].charAt(0)) ? arr.unshift(ast.sel) : arr.unshift(ast.sel, ' '));
17624+ // selRule = splitRule(selRule.reduce((acc, curr) => acc + (acc.length > 0 ? ',' : '') + curr.join(''), ''));
17625+ const arSelf = splitRule(ast.sel).filter(r => r.every(t => t != ':before' && t != ':after' && !t.startsWith('::'))).reduce((acc, curr) => acc.concat([curr.join('')]), []).join(',');
17626+ if (arSelf.length == 0) {
17627+ ast.chi.splice(i--, 1);
17628+ continue;
17629+ }
17630+ //
17631+ selRule.forEach(arr => combinators.includes(arr[0].charAt(0)) ? arr.unshift(arSelf) : arr.unshift(arSelf, ' '));
1761717632 rule.sel = selRule.reduce((acc, curr) => {
1761817633 acc.push(curr.join(''));
1761917634 return acc;
@@ -17624,8 +17639,14 @@ function expandRule(node) {
1762417639 let childSelectorCompound = [];
1762517640 let withCompound = [];
1762617641 let withoutCompound = [];
17627- const rules = splitRule(ast.sel);
17642+ // pseudo elements cannot be used with '&'
17643+ // https://www.w3.org/TR/css-nesting-1/#example-7145ff1e
17644+ const rules = splitRule(ast.sel).filter(r => r.every(t => t != ':before' && t != ':after' && !t.startsWith('::')));
1762817645 const parentSelector = !node.sel.includes('&');
17646+ if (rules.length == 0) {
17647+ ast.chi.splice(i--, 1);
17648+ continue;
17649+ }
1762917650 for (const sel of (rule.raw ?? splitRule(rule.sel))) {
1763017651 const s = sel.join('');
1763117652 if (s.includes('&') || parentSelector) {
@@ -19322,7 +19343,7 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
1932219343 return s.join('');
1932319344 }).join(',');
1932419345 // @ts-ignore
19325- let sel = wrap ? node.optimized.optimized[0] + `:is(${rule})` : rule;
19346+ let sel = wrap ? node.optimized.optimized.join('') + `:is(${rule})` : rule;
1932619347 if (rule.includes('&')) {
1932719348 // @ts-ignore
1932819349 rule = replaceCompound(rule, node.optimized.optimized[0]);
0 commit comments