eslint-plugin-vue-scoped-css 2.3.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/styles/context/vue-components/find-vue.js +9 -0
- package/dist/styles/context/vue-components/index.js +3 -3
- package/dist/styles/selectors/query/attribute-tracker.js +3 -18
- package/dist/styles/selectors/query/index.js +11 -26
- package/dist/styles/selectors/query/reference-expression.js +43 -0
- package/dist/styles/template/index.js +1 -1
- package/package.json +5 -5
|
@@ -37,7 +37,12 @@ function getVueComponentObject(node) {
|
|
|
37
37
|
}
|
|
38
38
|
return null;
|
|
39
39
|
}
|
|
40
|
+
const vueComponentCache = new WeakMap();
|
|
40
41
|
function findVueComponent(context) {
|
|
42
|
+
const cached = vueComponentCache.get(context);
|
|
43
|
+
if (cached !== undefined && cached.cachedAt > Date.now() - 1000) {
|
|
44
|
+
return cached.component;
|
|
45
|
+
}
|
|
41
46
|
const sourceCode = context.getSourceCode();
|
|
42
47
|
const componentComments = sourceCode
|
|
43
48
|
.getAllComments()
|
|
@@ -77,6 +82,10 @@ function findVueComponent(context) {
|
|
|
77
82
|
leaveNode() {
|
|
78
83
|
},
|
|
79
84
|
});
|
|
85
|
+
vueComponentCache.set(context, {
|
|
86
|
+
component: result,
|
|
87
|
+
cachedAt: Date.now(),
|
|
88
|
+
});
|
|
80
89
|
return result;
|
|
81
90
|
}
|
|
82
91
|
exports.default = findVueComponent;
|
|
@@ -17,7 +17,7 @@ class VueComponentContext {
|
|
|
17
17
|
}
|
|
18
18
|
findVueComponentProperty(name) {
|
|
19
19
|
const properties = this.properties ||
|
|
20
|
-
(this.properties =
|
|
20
|
+
(this.properties = extractVueComponentProperties(this.node, this.context));
|
|
21
21
|
if (properties[UNKNOWN]) {
|
|
22
22
|
return null;
|
|
23
23
|
}
|
|
@@ -48,7 +48,7 @@ function createVueComponentContext(context) {
|
|
|
48
48
|
return new VueComponentContext(node, context);
|
|
49
49
|
}
|
|
50
50
|
exports.createVueComponentContext = createVueComponentContext;
|
|
51
|
-
function
|
|
51
|
+
function extractVueComponentProperties(vueNode, context) {
|
|
52
52
|
const result = {
|
|
53
53
|
data: {},
|
|
54
54
|
computed: {},
|
|
@@ -129,7 +129,7 @@ function extractVueComponentComputed(computedNode, context) {
|
|
|
129
129
|
continue;
|
|
130
130
|
}
|
|
131
131
|
const values = computed[keyName] || (computed[keyName] = []);
|
|
132
|
-
const
|
|
132
|
+
const value = p.value;
|
|
133
133
|
let func = value;
|
|
134
134
|
if (value.type === "ObjectExpression") {
|
|
135
135
|
const get = value.properties
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const context_1 = require("../../context");
|
|
3
|
+
exports.getAttributeValueNodes = void 0;
|
|
5
4
|
const templates_1 = require("../../../utils/templates");
|
|
5
|
+
const reference_expression_1 = require("./reference-expression");
|
|
6
6
|
function getAttributeValueNodes(element, name, context) {
|
|
7
7
|
const results = [];
|
|
8
8
|
const { startTag } = element;
|
|
@@ -35,7 +35,7 @@ function getAttributeValueNodes(element, name, context) {
|
|
|
35
35
|
if (expression == null) {
|
|
36
36
|
continue;
|
|
37
37
|
}
|
|
38
|
-
const expressions = getReferenceExpressions(expression, context);
|
|
38
|
+
const expressions = (0, reference_expression_1.getReferenceExpressions)(expression, context);
|
|
39
39
|
if (!expressions) {
|
|
40
40
|
return null;
|
|
41
41
|
}
|
|
@@ -47,18 +47,3 @@ function getAttributeValueNodes(element, name, context) {
|
|
|
47
47
|
return results;
|
|
48
48
|
}
|
|
49
49
|
exports.getAttributeValueNodes = getAttributeValueNodes;
|
|
50
|
-
function getReferenceExpressions(expression, context) {
|
|
51
|
-
if (expression.type !== "Identifier") {
|
|
52
|
-
return [expression];
|
|
53
|
-
}
|
|
54
|
-
const vueComponent = (0, context_1.getVueComponentContext)(context);
|
|
55
|
-
if (!vueComponent) {
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
const props = vueComponent.findVueComponentProperty(expression.name);
|
|
59
|
-
if (props == null) {
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
return props;
|
|
63
|
-
}
|
|
64
|
-
exports.getReferenceExpressions = getReferenceExpressions;
|
|
@@ -9,6 +9,7 @@ const nodes_1 = require("../../utils/nodes");
|
|
|
9
9
|
const template_1 = require("../../template");
|
|
10
10
|
const templates_1 = require("../../../utils/templates");
|
|
11
11
|
const style_1 = require("../../context/style");
|
|
12
|
+
const reference_expression_1 = require("./reference-expression");
|
|
12
13
|
const TRANSITION_CLASS_BASES = [
|
|
13
14
|
"enter",
|
|
14
15
|
"enter-from",
|
|
@@ -562,30 +563,20 @@ function matchClassNameExpression(expression, className, document) {
|
|
|
562
563
|
}
|
|
563
564
|
function matchClassNameForArrayExpression(expression, className, document) {
|
|
564
565
|
for (const e of expression.elements) {
|
|
565
|
-
if (e.type === "
|
|
566
|
-
if (withinTemplate(e, document)) {
|
|
567
|
-
const expressions = (0, attribute_tracker_1.getReferenceExpressions)(e, document.context);
|
|
568
|
-
if (expressions) {
|
|
569
|
-
for (const e2 of expressions) {
|
|
570
|
-
if (matchClassNameExpression(e2, className, document)) {
|
|
571
|
-
return true;
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
else {
|
|
577
|
-
if (matchClassNameExpression(e, className, document)) {
|
|
578
|
-
return true;
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
else if (e.type === "SpreadElement") {
|
|
566
|
+
if (e.type === "SpreadElement") {
|
|
583
567
|
if (matchClassNameExpression(e.argument, className, document)) {
|
|
584
568
|
return true;
|
|
585
569
|
}
|
|
586
570
|
}
|
|
587
|
-
else
|
|
588
|
-
|
|
571
|
+
else {
|
|
572
|
+
const expressions = (0, reference_expression_1.getReferenceExpressions)(e, document.context);
|
|
573
|
+
if (expressions) {
|
|
574
|
+
for (const e2 of expressions) {
|
|
575
|
+
if (matchClassNameExpression(e2, className, document)) {
|
|
576
|
+
return true;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
589
580
|
}
|
|
590
581
|
}
|
|
591
582
|
return false;
|
|
@@ -629,12 +620,6 @@ function includesClassName(value, className) {
|
|
|
629
620
|
}
|
|
630
621
|
return value.divide(/\s+/u).some((s) => className.match(s));
|
|
631
622
|
}
|
|
632
|
-
function withinTemplate(expr, document) {
|
|
633
|
-
var _a;
|
|
634
|
-
const templateBody = document.context.getSourceCode().ast.templateBody;
|
|
635
|
-
const templateRange = (_a = templateBody === null || templateBody === void 0 ? void 0 : templateBody.range) !== null && _a !== void 0 ? _a : [0, 0];
|
|
636
|
-
return templateRange[0] <= expr.range[0] && expr.range[1] <= templateRange[1];
|
|
637
|
-
}
|
|
638
623
|
function* iterateUnique(gen) {
|
|
639
624
|
const found = new Set();
|
|
640
625
|
for (const e of gen()) {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getReferenceExpressions = void 0;
|
|
4
|
+
const context_1 = require("../../context");
|
|
5
|
+
function getReferenceExpressions(expression, context) {
|
|
6
|
+
var _a, _b, _c, _d;
|
|
7
|
+
if (expression.type === "ConditionalExpression") {
|
|
8
|
+
const { consequent, alternate } = expression;
|
|
9
|
+
return [
|
|
10
|
+
...((_a = getReferenceExpressions(consequent, context)) !== null && _a !== void 0 ? _a : [consequent]),
|
|
11
|
+
...((_b = getReferenceExpressions(alternate, context)) !== null && _b !== void 0 ? _b : [alternate]),
|
|
12
|
+
];
|
|
13
|
+
}
|
|
14
|
+
if (expression.type === "LogicalExpression") {
|
|
15
|
+
const { left, right } = expression;
|
|
16
|
+
return [
|
|
17
|
+
...((_c = getReferenceExpressions(left, context)) !== null && _c !== void 0 ? _c : [left]),
|
|
18
|
+
...((_d = getReferenceExpressions(right, context)) !== null && _d !== void 0 ? _d : [right]),
|
|
19
|
+
];
|
|
20
|
+
}
|
|
21
|
+
if (expression.type !== "Identifier") {
|
|
22
|
+
return [expression];
|
|
23
|
+
}
|
|
24
|
+
if (!withinTemplate(expression, context)) {
|
|
25
|
+
return [expression];
|
|
26
|
+
}
|
|
27
|
+
const vueComponent = (0, context_1.getVueComponentContext)(context);
|
|
28
|
+
if (!vueComponent) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const props = vueComponent.findVueComponentProperty(expression.name);
|
|
32
|
+
if (props == null) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return props;
|
|
36
|
+
}
|
|
37
|
+
exports.getReferenceExpressions = getReferenceExpressions;
|
|
38
|
+
function withinTemplate(expr, context) {
|
|
39
|
+
var _a;
|
|
40
|
+
const templateBody = context.getSourceCode().ast.templateBody;
|
|
41
|
+
const templateRange = (_a = templateBody === null || templateBody === void 0 ? void 0 : templateBody.range) !== null && _a !== void 0 ? _a : [0, 0];
|
|
42
|
+
return templateRange[0] <= expr.range[0] && expr.range[1] <= templateRange[1];
|
|
43
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-vue-scoped-css",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"description": "ESLint plugin for Scoped CSS in Vue.js",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -82,12 +82,12 @@
|
|
|
82
82
|
"raw-loader": "^4.0.1",
|
|
83
83
|
"rimraf": "^3.0.2",
|
|
84
84
|
"semver": "^7.3.2",
|
|
85
|
-
"stylelint": "^
|
|
85
|
+
"stylelint": "^15.0.0",
|
|
86
86
|
"stylelint-config-recommended-vue": "^1.1.0",
|
|
87
|
-
"stylelint-config-standard": "^
|
|
88
|
-
"stylelint-stylus": "^0.
|
|
87
|
+
"stylelint-config-standard": "^33.0.0",
|
|
88
|
+
"stylelint-stylus": "^0.18.0",
|
|
89
89
|
"ts-node": "^10.9.1",
|
|
90
|
-
"typescript": "^
|
|
90
|
+
"typescript": "^5.0.0",
|
|
91
91
|
"vue-eslint-editor": "^1.1.0",
|
|
92
92
|
"vue-eslint-parser": "^9.0.0",
|
|
93
93
|
"vuepress": "^1.8.2"
|