@@ -28,6 +28,14 @@ function eachMapItemDependencyOfDecl(variablesUsedList, map, decl, cb) {
28
28
var innerMostAtRuleSelector = varDeclScopeList [ 0 ] . slice ( - 1 ) [ 0 ] ;
29
29
var nodeToSpliceParentOnto = findNodeAncestorWithSelector ( innerMostAtRuleSelector , decl . parent ) ;
30
30
31
+ // attept to add a specific root scope if necessary
32
+ if ( mapItem . isRootSpecific ) {
33
+ const varDeclRootRule = mapItem . parent
34
+ const nodeToSpliceParentOnto = findNodeAncestorWithSelector ( mapItem . parent . selector , decl . parent )
35
+
36
+ mimicDecl = cloneSpliceParentOntoNodeWhen ( decl , varDeclRootRule , ( ancestor ) => ancestor === nodeToSpliceParentOnto )
37
+ }
38
+
31
39
// Splice on where the selector starts matching the selector inside at-rule
32
40
// See: `test/fixtures/cascade-on-nested-rules.css`
33
41
var varDeclAtRule = mapItem . parent . parent ;
@@ -41,6 +49,12 @@ function eachMapItemDependencyOfDecl(variablesUsedList, map, decl, cb) {
41
49
//console.log(generateScopeList(mapItem.parent, true));
42
50
//console.log('amd isNodeUnderScope', isNodeUnderScope(mimicDecl.parent, mapItem.parent), mapItem.decl.value);
43
51
}
52
+ else if ( mapItem . isRootSpecific ) {
53
+ const varDeclRootRule = mapItem . parent
54
+ const nodeToSpliceParentOnto = findNodeAncestorWithSelector ( mapItem . parent . selector , decl . parent )
55
+
56
+ mimicDecl = cloneSpliceParentOntoNodeWhen ( decl , varDeclRootRule , ( ancestor ) => ancestor === nodeToSpliceParentOnto )
57
+ }
44
58
// TODO: use regex from `isUnderScope`
45
59
else if ( isUnderScope . RE_PSEUDO_SELECTOR . test ( mapItem . parent . selector ) ) {
46
60
// Create a detached clone
@@ -115,6 +129,9 @@ function resolveDecl(decl, map, /*optional*/shouldPreserve, /*optional*/preserve
115
129
// Add the rule to the atRule
116
130
atRuleNode . append ( ruleClone ) ;
117
131
132
+ if ( mapItem . isRootSpecific ) {
133
+ ruleClone . selector = [ mapItem . parent . selector , ruleClone . selector ] . filter ( item => Boolean ( item ) ) . join ( ' ' ) ;
134
+ }
118
135
119
136
// Since that atRuleNode can be nested in other atRules, we need to make the appropriate structure
120
137
var parentAtRuleNode = atRuleNode ;
@@ -137,8 +154,13 @@ function resolveDecl(decl, map, /*optional*/shouldPreserve, /*optional*/preserve
137
154
138
155
// Save referance of previous atRuleStructure
139
156
previousAtRuleNode = parentAtRuleNode
140
- }
141
- else {
157
+ } else if ( mapItem . isRootSpecific ) {
158
+ ruleClone . selector = [ mapItem . parent . selector , mimicDecl . parent . selector ] . filter ( item => Boolean ( item ) ) . join ( ' ' ) ;
159
+
160
+ // Put the first atRuleStructure after the declaration's rule,
161
+ // and after that, put them right after the previous one
162
+ decl . parent . parent . insertAfter ( preserveAtRulesOrder && previousAtRuleNode || decl . parent , ruleClone ) ;
163
+ } else {
142
164
ruleClone . selector = mimicDecl . parent . selector ;
143
165
144
166
// Put the first atRuleStructure after the declaration's rule,
0 commit comments