@@ -3,6 +3,11 @@ var escapeStringRegexp = require('escape-string-regexp');
33var isPieceAlwaysAncestorSelector = require ( './is-piece-always-ancestor-selector' ) ;
44var generateDirectDescendantPiecesFromSelector = require ( './generate-direct-descendant-pieces-from-selector' ) ;
55
6+ var RE_AT_RULE_SCOPE_PIECE = ( / ^ @ .* / ) ;
7+ // This will match pseudo selectors that have a base part
8+ // ex. .foo:hover
9+ // It will NOT match `:root`
10+ var RE_PSEUDO_SELECTOR = ( / ( [ ^ \s ] + ) ( (?: : | : : ) .* ?) (?: \s + | $ ) / ) ;
611
712
813function getScopeMatchResults ( nodeScopeList , scopeNodeScopeList ) {
@@ -12,7 +17,20 @@ function getScopeMatchResults(nodeScopeList, scopeNodeScopeList) {
1217 // Check each comma separated piece of the complex selector
1318 var doesMatchScope = scopeNodeScopeList . some ( function ( scopeNodeScopePieces ) {
1419 return nodeScopeList . some ( function ( nodeScopePieces ) {
20+ // Because we only care about the scopeNodeScope matching to the nodeScope
21+ // Remove the pseudo selectors from the nodeScope so it can match a broader version
22+ // ex. `.foo:hover` can resolve variables from `.foo`
23+ nodeScopePieces = nodeScopePieces
24+ . map ( function ( descendantPiece ) {
25+ // If not an at-rule piece, remove the pseudo selector part `@media (max-width: 300px)`
26+ if ( ! RE_AT_RULE_SCOPE_PIECE . test ( descendantPiece ) ) {
27+ return descendantPiece . replace ( new RegExp ( RE_PSEUDO_SELECTOR . source , 'g' ) , function ( whole , baseSelector , pseudo ) {
28+ return baseSelector ;
29+ } ) ;
30+ }
1531
32+ return descendantPiece ;
33+ } ) ;
1634
1735 currentPieceOffset = null ;
1836 var wasEveryPieceFound = true ;
0 commit comments