@@ -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-')) &&
@@ -16318,11 +16320,11 @@ async function parseNode(results, context, stats, options, errors, src, map, raw
1631816320 const node = {
1631916321 typ: exports.EnumToken.AtRuleNodeType,
1632016322 nam: renderToken(atRule, { removeComments: true }),
16321- tokens: t,
16323+ // tokens: t,
1632216324 val: raw.join('')
1632316325 };
1632416326 Object.defineProperties(node, {
16325- tokens: { ...definedPropertySettings, enumerable: true , value: tokens.slice() },
16327+ tokens: { ...definedPropertySettings, enumerable: false , value: tokens.slice() },
1632616328 raw: { ...definedPropertySettings, value: raw }
1632716329 });
1632816330 if (delim.typ == exports.EnumToken.BlockStartTokenType) {
@@ -16447,7 +16449,7 @@ async function parseNode(results, context, stats, options, errors, src, map, raw
1644716449 };
1644816450 Object.defineProperty(node, 'tokens', {
1644916451 ...definedPropertySettings,
16450- enumerable: true ,
16452+ enumerable: false ,
1645116453 value: tokens.slice()
1645216454 });
1645316455 let raw = [...uniq.values()];
@@ -16920,10 +16922,16 @@ function getTokenType(val, hint) {
1692016922 val: val.slice(0, -1),
1692116923 chi: []
1692216924 }
16923- : {
16924- typ: exports.EnumToken.PseudoClassTokenType,
16925+ : (
16926+ // https://www.w3.org/TR/selectors-4/#single-colon-pseudos
16927+ val.startsWith('::') || [':before', ':after', ':first-line', ':first-letter'].includes(val) ? {
16928+ typ: exports.EnumToken.PseudoElementTokenType,
1692516929 val
16926- };
16930+ } :
16931+ {
16932+ typ: exports.EnumToken.PseudoClassTokenType,
16933+ val
16934+ });
1692716935 }
1692816936 if (isAtKeyword(val)) {
1692916937 return {
@@ -17617,7 +17625,14 @@ function expandRule(node) {
1761717625 rule.sel = splitRule(ast.sel).reduce((a, b) => a.concat([b.join('') + r]), []).join(',');
1761817626 }
1761917627 else {
17620- selRule.forEach(arr => combinators.includes(arr[0].charAt(0)) ? arr.unshift(ast.sel) : arr.unshift(ast.sel, ' '));
17628+ // selRule = splitRule(selRule.reduce((acc, curr) => acc + (acc.length > 0 ? ',' : '') + curr.join(''), ''));
17629+ const arSelf = splitRule(ast.sel).filter(r => r.every(t => t != ':before' && t != ':after' && !t.startsWith('::'))).reduce((acc, curr) => acc.concat([curr.join('')]), []).join(',');
17630+ if (arSelf.length == 0) {
17631+ ast.chi.splice(i--, 1);
17632+ continue;
17633+ }
17634+ //
17635+ selRule.forEach(arr => combinators.includes(arr[0].charAt(0)) ? arr.unshift(arSelf) : arr.unshift(arSelf, ' '));
1762117636 rule.sel = selRule.reduce((acc, curr) => {
1762217637 acc.push(curr.join(''));
1762317638 return acc;
@@ -17628,8 +17643,14 @@ function expandRule(node) {
1762817643 let childSelectorCompound = [];
1762917644 let withCompound = [];
1763017645 let withoutCompound = [];
17631- const rules = splitRule(ast.sel);
17646+ // pseudo elements cannot be used with '&'
17647+ // https://www.w3.org/TR/css-nesting-1/#example-7145ff1e
17648+ const rules = splitRule(ast.sel).filter(r => r.every(t => t != ':before' && t != ':after' && !t.startsWith('::')));
1763217649 const parentSelector = !node.sel.includes('&');
17650+ if (rules.length == 0) {
17651+ ast.chi.splice(i--, 1);
17652+ continue;
17653+ }
1763317654 for (const sel of (rule.raw ?? splitRule(rule.sel))) {
1763417655 const s = sel.join('');
1763517656 if (s.includes('&') || parentSelector) {
@@ -19326,7 +19347,7 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
1932619347 return s.join('');
1932719348 }).join(',');
1932819349 // @ts-ignore
19329- let sel = wrap ? node.optimized.optimized[0] + `:is(${rule})` : rule;
19350+ let sel = wrap ? node.optimized.optimized.join('') + `:is(${rule})` : rule;
1933019351 if (rule.includes('&')) {
1933119352 // @ts-ignore
1933219353 rule = replaceCompound(rule, node.optimized.optimized[0]);
0 commit comments