Skip to content

Commit 0e95947

Browse files
committed
chore: improve performance of check
1 parent e601ca3 commit 0e95947

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/base/VariableResolver.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,23 @@ export class BaseVariableResolver {
274274

275275
const reversedVariables = [ ...scopeVariables, ...parentsScopeVariables ].reverse();
276276

277+
const seenNames = new Set();
278+
277279
return reversedVariables.filter(variable => {
278280

279281
// if external variable, keep
280282
if (variable.provider.find(extractor => extractor !== this._baseExtractor)) {
281283
return true;
282284
}
283285

284-
// if not external, keep only if first of its name
285-
return reversedVariables.find(v => v.name === variable.name) === variable;
286+
// if not external, keep only the first occurrence of each name
287+
if (!seenNames.has(variable.name)) {
288+
seenNames.add(variable.name);
289+
290+
return true;
291+
}
292+
293+
return false;
286294
});
287295
}
288296
}

0 commit comments

Comments
 (0)