@@ -1018,13 +1018,10 @@ function indexInsideNonIifeRange(
10181018// opacity to EXACTLY zero. The declaration regex is boundary-anchored so
10191019// `opacity: 0.98` never matches; it ends at `;` or end of input, which also
10201020// catches a final declaration without a trailing semicolon.
1021- function collectCssOpacityZeroSelectors (
1021+ function cssRuleSubjects (
10221022 styles : LintContext [ "styles" ] ,
1023- tags : OpenTag [ ] ,
1024- ) : Set < string > {
1025- const selectors = new Set < string > ( ) ;
1026- const opacityExactlyZero = / o p a c i t y \s * : \s * 0 (?: \. 0 + ) ? \s * (?: ; | $ ) / ;
1027-
1023+ ) : Array < { declarations : string [ ] ; subjects : string [ ] } > {
1024+ const rules : Array < { declarations : string [ ] ; subjects : string [ ] } > = [ ] ;
10281025 for ( const style of styles ) {
10291026 let root : postcss . Root ;
10301027 try {
@@ -1033,13 +1030,26 @@ function collectCssOpacityZeroSelectors(
10331030 continue ;
10341031 }
10351032 root . walkRules ( ( rule ) => {
1036- if ( ! rule . nodes . some ( ( node ) => opacityExactlyZero . test ( node . toString ( ) ) ) ) return ;
1037- for ( const selector of rule . selectors ) {
1038- const subject = / [ # . ] [ a - z A - Z 0 - 9 _ - ] + $ / . exec ( selector . trim ( ) ) ;
1039- if ( subject ) selectors . add ( subject [ 0 ] ) ;
1040- }
1033+ const subjects = rule . selectors . flatMap (
1034+ ( selector ) => / [ # . ] [ a - z A - Z 0 - 9 _ - ] + $ / . exec ( selector . trim ( ) ) ?. [ 0 ] ?? [ ] ,
1035+ ) ;
1036+ if ( subjects . length ) rules . push ( { declarations : rule . nodes . map ( String ) , subjects } ) ;
10411037 } ) ;
10421038 }
1039+ return rules ;
1040+ }
1041+
1042+ function collectCssOpacityZeroSelectors (
1043+ styles : LintContext [ "styles" ] ,
1044+ tags : OpenTag [ ] ,
1045+ ) : Set < string > {
1046+ const selectors = new Set < string > ( ) ;
1047+ const opacityExactlyZero = / o p a c i t y \s * : \s * 0 (?: \. 0 + ) ? \s * (?: ; | $ ) / ;
1048+
1049+ for ( const { declarations, subjects } of cssRuleSubjects ( styles ) ) {
1050+ if ( ! declarations . some ( ( declaration ) => opacityExactlyZero . test ( declaration ) ) ) continue ;
1051+ for ( const subject of subjects ) selectors . add ( subject ) ;
1052+ }
10431053
10441054 for ( const tag of tags ) {
10451055 const inlineStyle = readAttr ( tag . raw , "style" ) ;
@@ -1327,17 +1337,13 @@ export const gsapRules: LintRule<LintContext>[] = [
13271337 const cssScaleSelectors = new Map < string , string > ( ) ;
13281338
13291339 // Check <style> blocks for transform rules
1330- for ( const style of styles ) {
1331- for ( const [ , selector , body ] of style . content . matchAll (
1332- / ( [ # . ] [ a - z A - Z 0 - 9 _ - ] + ) \s * \{ ( [ ^ } ] + ) \} / g,
1333- ) ) {
1334- const tMatch = body ?. match ( / t r a n s f o r m \s * : \s * ( [ ^ ; ] + ) / ) ;
1335- if ( ! tMatch || ! tMatch [ 1 ] ) continue ;
1336- const transformVal = tMatch [ 1 ] . trim ( ) ;
1337- if ( / t r a n s l a t e / i. test ( transformVal ) )
1338- cssTranslateSelectors . set ( ( selector ?? "" ) . trim ( ) , transformVal ) ;
1339- if ( / s c a l e / i. test ( transformVal ) )
1340- cssScaleSelectors . set ( ( selector ?? "" ) . trim ( ) , transformVal ) ;
1340+ for ( const { declarations, subjects } of cssRuleSubjects ( styles ) ) {
1341+ const tMatch = declarations . join ( ";" ) . match ( / t r a n s f o r m \s * : \s * ( [ ^ ; ] + ) / ) ;
1342+ if ( ! tMatch || ! tMatch [ 1 ] ) continue ;
1343+ const transformVal = tMatch [ 1 ] . trim ( ) ;
1344+ for ( const subject of subjects ) {
1345+ if ( / t r a n s l a t e / i. test ( transformVal ) ) cssTranslateSelectors . set ( subject , transformVal ) ;
1346+ if ( / s c a l e / i. test ( transformVal ) ) cssScaleSelectors . set ( subject , transformVal ) ;
13411347 }
13421348 }
13431349
0 commit comments