Skip to content

Commit 0e015a7

Browse files
authored
perf: 72 times faster to check no-unused-selector (#285)
* 33 times faster to check no-unused-selector * add changeset
1 parent d078489 commit 0e015a7

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

.changeset/warm-cooks-shake.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-vue-scoped-css": patch
3+
---
4+
5+
Improve `no-unused-selector` performance

lib/styles/context/vue-components/find-vue.ts

+15
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ function getVueComponentObject(
5555
return null;
5656
}
5757

58+
const vueComponentCache = new WeakMap<
59+
RuleContext,
60+
{ component: AST.ESLintObjectExpression | null; cachedAt: number }
61+
>();
62+
5863
/**
5964
* Find Vue component of the current file.
6065
* @param {RuleContext} context The ESLint rule context object.
@@ -63,6 +68,11 @@ function getVueComponentObject(
6368
function findVueComponent(
6469
context: RuleContext
6570
): AST.ESLintObjectExpression | null {
71+
const cached = vueComponentCache.get(context);
72+
if (cached !== undefined && cached.cachedAt > Date.now() - 1000) {
73+
return cached.component;
74+
}
75+
6676
const sourceCode = context.getSourceCode();
6777
const componentComments = sourceCode
6878
.getAllComments()
@@ -118,6 +128,11 @@ function findVueComponent(
118128
// noop
119129
},
120130
});
131+
132+
vueComponentCache.set(context, {
133+
component: result,
134+
cachedAt: Date.now(),
135+
});
121136
return result;
122137
}
123138

0 commit comments

Comments
 (0)