Skip to content

Commit ca24d60

Browse files
Small changes and code cleanup
1 parent b3b3fb0 commit ca24d60

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

lib/resolve-value.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,40 +30,32 @@ var resolveValue = function(decl, map, /*optional*/ignorePseudoScope, /*internal
3030
var debugIndent = _debugIsInternal ? '\t' : '';
3131

3232
var matchingVarDecl = undefined;
33-
var RE_VAR_FUNC_G = new RegExp(RE_VAR_FUNC.source, 'g');
3433
var resultantValue = toString(decl.value);
3534
var warnings = [];
3635

3736
// Match all variables first so we can later on if there are circular dependencies
38-
var variablesUsedInValue = [];
37+
var variablesUsedInValueMap = {}
3938
// Create a temporary variable, storing resultantValue variable value
40-
var resultantValueTemp = resultantValue;
39+
var remainingVariableValue = resultantValue;
4140
// Use balanced lib to find var() declarations and store variable names
42-
while ((matchingVarDecl = balanced('var(', ')', resultantValueTemp))) {
41+
while ((matchingVarDecl = balanced('var(', ')', remainingVariableValue))) {
4342
// Split at the comma to find variable name and fallback value
4443
// There may be other commas in the values so this isn't necessarily just 2 pieces
4544
var variableFallbackSplitPieces = matchingVarDecl.body.split(',');
4645

4746
// Get variable name and fallback, filtering empty items
4847
var variableName = variableFallbackSplitPieces[0].trim();
4948

50-
// Push found variable to variables used array
51-
variablesUsedInValue.push(variableName);
49+
// add variable found in the object
50+
variablesUsedInValueMap[variableName] = true;
5251

5352
// 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 || '');
5554
}
5655
// clear temporary variable
57-
resultantValueTemp = undefined;
56+
remainingVariableValue = undefined;
5857

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);
6759

6860
//console.log(debugIndent, (_debugIsInternal ? '' : 'Try resolving'), generateScopeList(decl.parent, true), `ignorePseudoScope=${ignorePseudoScope}`, '------------------------');
6961

0 commit comments

Comments
 (0)