@@ -34,12 +34,34 @@ var resolveValue = function(decl, map, /*optional*/ignorePseudoScope, /*internal
34
34
var resultantValue = toString ( decl . value ) ;
35
35
var warnings = [ ] ;
36
36
37
-
38
37
// Match all variables first so we can later on if there are circular dependencies
39
38
var variablesUsedInValue = [ ] ;
40
- while ( ( matchingVarDecl = RE_VAR_FUNC_G . exec ( resultantValue ) ) ) {
41
- variablesUsedInValue . push ( matchingVarDecl [ 1 ] ) ;
39
+ // Create a temporary variable, storing resultantValue variable value
40
+ var resultantValueTemp = resultantValue ;
41
+ // Use balanced lib to find var() declarations and store variable names
42
+ while ( ( matchingVarDecl = balanced ( 'var(' , ')' , resultantValueTemp ) ) ) {
43
+ // Split at the comma to find variable name and fallback value
44
+ // There may be other commas in the values so this isn't necessarily just 2 pieces
45
+ var variableFallbackSplitPieces = matchingVarDecl . body . split ( ',' ) ;
46
+
47
+ // Get variable name and fallback, filtering empty items
48
+ var variableName = variableFallbackSplitPieces [ 0 ] . trim ( ) ;
49
+
50
+ // Push found variable to variables used array
51
+ variablesUsedInValue . push ( variableName ) ;
52
+
53
+ // Replace variable name (first occurence only) from result, to avoid circular loop
54
+ resultantValueTemp = ( matchingVarDecl . pre || '' ) + matchingVarDecl . body . replace ( variableName , '' ) + ( matchingVarDecl . post || '' ) ;
42
55
}
56
+ // clear temporary variable
57
+ resultantValueTemp = undefined ;
58
+
59
+ // Old strategy to find used variable names in declaration value, using RegExp
60
+ // TODO: remove unused block
61
+ // while ((matchingVarDecl = RE_VAR_FUNC_G.exec(resultantValue))) {
62
+ // variablesUsedInValue.push(matchingVarDecl[1]);
63
+ // }
64
+
43
65
// Remove duplicates from array
44
66
variablesUsedInValue = variablesUsedInValue . filter ( filterDistinct ) ;
45
67
0 commit comments