@@ -30,40 +30,32 @@ var resolveValue = function(decl, map, /*optional*/ignorePseudoScope, /*internal
30
30
var debugIndent = _debugIsInternal ? '\t' : '' ;
31
31
32
32
var matchingVarDecl = undefined ;
33
- var RE_VAR_FUNC_G = new RegExp ( RE_VAR_FUNC . source , 'g' ) ;
34
33
var resultantValue = toString ( decl . value ) ;
35
34
var warnings = [ ] ;
36
35
37
36
// Match all variables first so we can later on if there are circular dependencies
38
- var variablesUsedInValue = [ ] ;
37
+ var variablesUsedInValueMap = { }
39
38
// Create a temporary variable, storing resultantValue variable value
40
- var resultantValueTemp = resultantValue ;
39
+ var remainingVariableValue = resultantValue ;
41
40
// Use balanced lib to find var() declarations and store variable names
42
- while ( ( matchingVarDecl = balanced ( 'var(' , ')' , resultantValueTemp ) ) ) {
41
+ while ( ( matchingVarDecl = balanced ( 'var(' , ')' , remainingVariableValue ) ) ) {
43
42
// Split at the comma to find variable name and fallback value
44
43
// There may be other commas in the values so this isn't necessarily just 2 pieces
45
44
var variableFallbackSplitPieces = matchingVarDecl . body . split ( ',' ) ;
46
45
47
46
// Get variable name and fallback, filtering empty items
48
47
var variableName = variableFallbackSplitPieces [ 0 ] . trim ( ) ;
49
48
50
- // Push found variable to variables used array
51
- variablesUsedInValue . push ( variableName ) ;
49
+ // add variable found in the object
50
+ variablesUsedInValueMap [ variableName ] = true ;
52
51
53
52
// Replace variable name (first occurence only) from result, to avoid circular loop
54
- resultantValueTemp = ( matchingVarDecl . pre || '' ) + matchingVarDecl . body . replace ( variableName , '' ) + ( matchingVarDecl . post || '' ) ;
53
+ remainingVariableValue = ( matchingVarDecl . pre || '' ) + matchingVarDecl . body . replace ( variableName , '' ) + ( matchingVarDecl . post || '' ) ;
55
54
}
56
55
// clear temporary variable
57
- resultantValueTemp = undefined ;
56
+ remainingVariableValue = undefined ;
58
57
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
-
65
- // Remove duplicates from array
66
- variablesUsedInValue = variablesUsedInValue . filter ( filterDistinct ) ;
58
+ var variablesUsedInValue = Object . keys ( variablesUsedInValueMap ) ;
67
59
68
60
//console.log(debugIndent, (_debugIsInternal ? '' : 'Try resolving'), generateScopeList(decl.parent, true), `ignorePseudoScope=${ignorePseudoScope}`, '------------------------');
69
61
0 commit comments