@@ -6022,6 +6022,18 @@ const _prefixedSelectorName = (name) => {
60226022 return _prefixedSelectorNames . get ( name ) ;
60236023} ;
60246024
6025+ // A selector prelude part split at its `(`: a functional pseudo prints as one
6026+ // token (`dir(rtl)`), so its name is matched and rewritten apart from the
6027+ // argument that carries over unchanged. A bare pseudo has no `(`.
6028+ /**
6029+ * @param {string } part a printed prelude token
6030+ * @returns {string } its name, without any `(argument)`
6031+ */
6032+ const _selectorPartName = ( part ) => {
6033+ const paren = part . indexOf ( "(" ) ;
6034+ return paren === - 1 ? part : part . slice ( 0 , paren ) ;
6035+ } ;
6036+
60256037/**
60266038 * A qualified rule prefixed against the target when its selector is a single
60276039 * prefixable pseudo (`::placeholder`): a copy with the pseudo's engine spelling
@@ -6050,17 +6062,24 @@ const _prefixQualifiedRule = (path, ruleText, parts, soft, body, writer) => {
60506062 if (
60516063 i !== 0 &&
60526064 parts [ i - 1 ] === ":" &&
6053- ( PREFIXED_SELECTORS . has ( parts [ i ] . toLowerCase ( ) ) ||
6054- _prefixedSelectorName ( parts [ i ] . toLowerCase ( ) ) !== undefined )
6065+ ( PREFIXED_SELECTORS . has ( _selectorPartName ( parts [ i ] ) . toLowerCase ( ) ) ||
6066+ _prefixedSelectorName ( _selectorPartName ( parts [ i ] ) . toLowerCase ( ) ) !==
6067+ undefined )
60556068 ) {
60566069 if ( nameIndex !== - 1 ) return ruleText ;
60576070 nameIndex = i ;
60586071 }
60596072 }
60606073 if ( nameIndex === - 1 ) return ruleText ;
6061- const found = _prefixedSelectorName ( parts [ nameIndex ] . toLowerCase ( ) ) ;
6062- const base = found === undefined ? parts [ nameIndex ] . toLowerCase ( ) : found [ 0 ] ;
6063- const signature = `s${ _join ( [ ...parts . slice ( 0 , nameIndex ) , base , ...parts . slice ( nameIndex + 1 ) ] , false , _TRIM_COMBINATORS ) } ` ;
6074+ // A functional pseudo (`dir(rtl)`) keeps its argument; only the name is
6075+ // matched and swapped, and the argument is part of the sibling signature so
6076+ // `:dir(rtl)` and `:dir(ltr)` stay distinct.
6077+ const raw = parts [ nameIndex ] ;
6078+ const nameOnly = _selectorPartName ( raw ) . toLowerCase ( ) ;
6079+ const args = raw . slice ( _selectorPartName ( raw ) . length ) ;
6080+ const found = _prefixedSelectorName ( nameOnly ) ;
6081+ const base = found === undefined ? nameOnly : found [ 0 ] ;
6082+ const signature = `s${ _join ( [ ...parts . slice ( 0 , nameIndex ) , base + args , ...parts . slice ( nameIndex + 1 ) ] , false , _TRIM_COMBINATORS ) } ` ;
60646083 /**
60656084 * @param {string } name the pseudo's spelling to print with
60666085 * @returns {string } the rule with that pseudo
@@ -6090,7 +6109,7 @@ const _prefixQualifiedRule = (path, ruleText, parts, soft, body, writer) => {
60906109 // of this signature, so a later one that overrides an earlier keeps its
60916110 // prefixed twin winning too.
60926111 if ( seen . has ( `${ signature } \0${ prefix } ` ) ) continue ;
6093- out += withName ( prefix + base ) ;
6112+ out += withName ( prefix + base + args ) ;
60946113 }
60956114 return out + ruleText ;
60966115} ;
@@ -8716,7 +8735,7 @@ const _printAttributeSelector = (path, children, writer) => {
87168735 * @param {CssPath } path the accessor positioned on the rule
87178736 * @param {PrintContext } writer the print context
87188737 * @param {boolean } minify whether printing minified
8719- * @param {string[]= } outParts filled with the prelude's tokens, for the prefixer
8738+ * @param {string[]= } outParts filled with the prelude's tokens, for prefixing
87208739 * @returns {string } the rule's prelude text
87218740 */
87228741const _rulePrelude = ( path , writer , minify , outParts ) => {
@@ -9109,7 +9128,7 @@ const printer = (path, writer) => {
91099128 }
91109129 case T_AT_RULE :
91119130 case T_QUALIFIED_RULE : {
9112- // The prefixer reads the prelude's tokens, not its joined text.
9131+ // Prefixing reads the prelude's tokens, not its joined text.
91139132 const preludeParts =
91149133 minify && _seenPrefixRules !== null
91159134 ? /** @type {string[] } */ ( [ ] )
@@ -9284,8 +9303,11 @@ const printer = (path, writer) => {
92849303 const text = `${ prelude } ${ soft } {${ body } ${ nl } }` ;
92859304 // Prefix copies turn one rule into several, so a rewritten rule is not
92869305 // offered for joining — its text no longer describes a single block.
9306+ // Top-level only: `_seenPrefixRules` has no nesting key, so a nested
9307+ // `@keyframes` / pseudo must not add or drop against a same-named
9308+ // top-level twin in another scope. Declarations are prefixed above.
92879309 const out =
9288- minify && _seenPrefixRules !== null
9310+ minify && _seenPrefixRules !== null && path . parent === null
92899311 ? path . type ( ) === T_AT_RULE
92909312 ? _prefixAtRule ( path , text , prelude , writer )
92919313 : _prefixQualifiedRule (
0 commit comments