@master/eslint-plugin-css 2.0.0-rc.5 → 2.0.0-rc.51
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/README.md +2 -2
- package/dist/configs/base.cjs +11 -0
- package/dist/configs/base.d.ts +3 -0
- package/dist/configs/base.mjs +9 -0
- package/dist/configs/legacy.cjs +17 -0
- package/dist/configs/legacy.d.ts +3 -0
- package/dist/configs/legacy.mjs +15 -0
- package/dist/configs/recommended.cjs +14 -0
- package/dist/configs/recommended.d.ts +2 -13
- package/dist/configs/recommended.mjs +12 -1
- package/dist/create-rule.cjs +8 -0
- package/dist/create-rule.d.ts +3 -0
- package/dist/create-rule.mjs +6 -0
- package/dist/functions/filter-collision-classes.cjs +29 -0
- package/dist/functions/filter-collision-classes.d.ts +2 -0
- package/dist/functions/filter-collision-classes.mjs +27 -0
- package/dist/index.cjs +19 -0
- package/dist/index.d.ts +19 -1
- package/dist/index.mjs +17 -1
- package/dist/plugin.cjs +26 -0
- package/dist/plugin.d.ts +2 -2
- package/dist/plugin.mjs +23 -1
- package/dist/rules/class-collision.cjs +70 -0
- package/dist/rules/class-collision.d.ts +1 -2
- package/dist/rules/class-collision.mjs +68 -1
- package/dist/rules/class-order.cjs +175 -0
- package/dist/rules/class-order.d.ts +1 -2
- package/dist/rules/class-order.mjs +173 -1
- package/dist/rules/class-validation.cjs +71 -0
- package/dist/rules/class-validation.d.ts +1 -2
- package/dist/rules/class-validation.mjs +69 -1
- package/dist/settings-schema.cjs +35 -0
- package/dist/settings-schema.d.ts +3 -0
- package/dist/settings-schema.mjs +33 -0
- package/dist/settings.cjs +16 -0
- package/dist/settings.d.ts +10 -2
- package/dist/settings.mjs +14 -1
- package/dist/utils/define-visitors.cjs +92 -0
- package/dist/utils/define-visitors.d.ts +6 -4
- package/dist/utils/define-visitors.mjs +90 -1
- package/dist/utils/extract-classnames-from-value.cjs +34 -0
- package/dist/utils/extract-classnames-from-value.mjs +32 -1
- package/dist/utils/extract-range-from-node.cjs +18 -0
- package/dist/utils/extract-range-from-node.mjs +16 -1
- package/dist/utils/extract-value-from-node.cjs +23 -0
- package/dist/utils/extract-value-from-node.mjs +21 -1
- package/dist/utils/find-loc.cjs +51 -0
- package/dist/utils/find-loc.d.ts +1 -1
- package/dist/utils/find-loc.mjs +49 -1
- package/dist/utils/get-template-element-body.cjs +12 -0
- package/dist/utils/get-template-element-body.mjs +10 -1
- package/dist/utils/get-template-element-prefix.cjs +11 -0
- package/dist/utils/get-template-element-prefix.mjs +9 -1
- package/dist/utils/get-template-element-suffix.cjs +10 -0
- package/dist/utils/get-template-element-suffix.mjs +8 -1
- package/dist/utils/index-of-all.cjs +12 -0
- package/dist/utils/index-of-all.d.ts +1 -0
- package/dist/utils/index-of-all.mjs +10 -0
- package/dist/utils/parse-node-recursive.cjs +129 -0
- package/dist/utils/parse-node-recursive.d.ts +2 -2
- package/dist/utils/parse-node-recursive.mjs +127 -1
- package/dist/utils/resolve-context.cjs +36 -0
- package/dist/utils/resolve-context.d.ts +11 -2
- package/dist/utils/resolve-context.mjs +34 -1
- package/package.json +1 -1
- package/dist/configs/config.d.ts +0 -13
- package/dist/configs/config.js +0 -1
- package/dist/configs/config.mjs +0 -1
- package/dist/configs/flat.d.ts +0 -16
- package/dist/configs/flat.js +0 -1
- package/dist/configs/flat.mjs +0 -1
- package/dist/configs/recommended.js +0 -1
- package/dist/index.js +0 -1
- package/dist/plugin.js +0 -1
- package/dist/rules/class-collision.js +0 -1
- package/dist/rules/class-order.js +0 -1
- package/dist/rules/class-validation.js +0 -1
- package/dist/settings.js +0 -1
- package/dist/utils/are-declarations-equal.d.ts +0 -1
- package/dist/utils/are-declarations-equal.js +0 -1
- package/dist/utils/are-declarations-equal.mjs +0 -1
- package/dist/utils/define-visitors.js +0 -1
- package/dist/utils/extract-classnames-from-value.js +0 -1
- package/dist/utils/extract-range-from-node.js +0 -1
- package/dist/utils/extract-value-from-node.js +0 -1
- package/dist/utils/find-loc.js +0 -1
- package/dist/utils/get-mastercss.d.ts +0 -2
- package/dist/utils/get-mastercss.js +0 -1
- package/dist/utils/get-mastercss.mjs +0 -1
- package/dist/utils/get-template-element-body.js +0 -1
- package/dist/utils/get-template-element-prefix.js +0 -1
- package/dist/utils/get-template-element-suffix.js +0 -1
- package/dist/utils/parse-node-recursive.js +0 -1
- package/dist/utils/reorder-valid-classes-action.d.ts +0 -3
- package/dist/utils/reorder-valid-classes-action.js +0 -1
- package/dist/utils/reorder-valid-classes-action.mjs +0 -1
- package/dist/utils/resolve-context.js +0 -1
- package/dist/utils/valid-rules-action.d.ts +0 -3
- package/dist/utils/valid-rules-action.js +0 -1
- package/dist/utils/valid-rules-action.mjs +0 -1
- package/dist/utils/validate-action.d.ts +0 -3
- package/dist/utils/validate-action.js +0 -1
- package/dist/utils/validate-action.mjs +0 -1
- package/dist/utils/workers/reorder-valid-classes.d.ts +0 -2
- package/dist/utils/workers/reorder-valid-classes.js +0 -1
- package/dist/utils/workers/reorder-valid-classes.mjs +0 -1
- package/dist/utils/workers/valid-rules.d.ts +0 -2
- package/dist/utils/workers/valid-rules.js +0 -1
- package/dist/utils/workers/valid-rules.mjs +0 -1
- package/dist/utils/workers/validate.d.ts +0 -5
- package/dist/utils/workers/validate.js +0 -1
- package/dist/utils/workers/validate.mjs +0 -1
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function defineVisitors({ context, settings }, visitNode) {
|
|
4
|
+
const classAttributeRegex = new RegExp(`^(?:${settings.classAttributes.join('|')})$`);
|
|
5
|
+
const classFunctionsRegex = new RegExp(`^(?:${settings.classFunctions.join('|')})`);
|
|
6
|
+
const classDeclarationsRegex = new RegExp(`^(?:${settings.classDeclarations.join('|')})$`);
|
|
7
|
+
const isFnNode = (node)=>{
|
|
8
|
+
let calleeName = '';
|
|
9
|
+
const calleeNode = node.callee || node.tag;
|
|
10
|
+
if (calleeNode.type === 'Identifier') {
|
|
11
|
+
calleeName = calleeNode.name;
|
|
12
|
+
}
|
|
13
|
+
if (calleeNode.type === 'MemberExpression') {
|
|
14
|
+
calleeName = `${calleeNode.object.name}.${calleeNode.property.name}`;
|
|
15
|
+
}
|
|
16
|
+
return classFunctionsRegex.test(calleeName);
|
|
17
|
+
};
|
|
18
|
+
const CallExpression = function(node) {
|
|
19
|
+
if (!isFnNode(node)) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
node.arguments.forEach((arg)=>{
|
|
23
|
+
visitNode(node, arg);
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
const scriptVisitor = {
|
|
27
|
+
CallExpression,
|
|
28
|
+
JSXAttribute: function(node) {
|
|
29
|
+
if (!node.name || !classAttributeRegex.test(node.name.name)) return;
|
|
30
|
+
if (node.value && node.value.type === 'Literal') {
|
|
31
|
+
visitNode(node);
|
|
32
|
+
} else if (node.value && node.value.type === 'JSXExpressionContainer') {
|
|
33
|
+
visitNode(node, node.value.expression);
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
SvelteAttribute: function(node) {
|
|
37
|
+
if (!node.key?.name || !classAttributeRegex.test(node.key.name)) return;
|
|
38
|
+
for (const eachValue of node.value){
|
|
39
|
+
visitNode(node, eachValue);
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
TextAttribute: function(node) {
|
|
43
|
+
if (!node.name || !classAttributeRegex.test(node.name)) return;
|
|
44
|
+
visitNode(node);
|
|
45
|
+
},
|
|
46
|
+
TaggedTemplateExpression: function(node) {
|
|
47
|
+
if (isFnNode(node)) {
|
|
48
|
+
visitNode(node, node.quasi);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
VariableDeclaration: function(node) {
|
|
53
|
+
node.declarations.forEach((decl)=>{
|
|
54
|
+
if (decl.id.type === 'Identifier' && classDeclarationsRegex.test(decl.id.name)) {
|
|
55
|
+
visitNode(node, decl.init);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
ObjectExpression: function(node) {
|
|
60
|
+
node.properties.forEach((prop)=>{
|
|
61
|
+
if (prop.type === 'Property' && prop.key.type === 'Identifier' && classDeclarationsRegex.test(prop.key.name)) {
|
|
62
|
+
visitNode(node, prop.value);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const templateBodyVisitor = {
|
|
68
|
+
CallExpression,
|
|
69
|
+
VAttribute: function(node) {
|
|
70
|
+
if (node.value && node.value.type === 'VLiteral') {
|
|
71
|
+
visitNode(node);
|
|
72
|
+
} else if (node.value && node.value.type === 'VExpressionContainer' && node.value.expression?.type === 'ArrayExpression') {
|
|
73
|
+
node.value.expression.elements.forEach((arg)=>{
|
|
74
|
+
visitNode(node, arg);
|
|
75
|
+
});
|
|
76
|
+
} else if (node.value && node.value.type === 'VExpressionContainer' && node.value.expression?.type === 'ObjectExpression') {
|
|
77
|
+
node.value.expression.properties.forEach((prop)=>{
|
|
78
|
+
visitNode(node, prop);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
// @ts-expect-error defineTemplateBodyVisitor
|
|
84
|
+
if (context.sourceCode.parserServices == null || context.sourceCode.parserServices.defineTemplateBodyVisitor == null) {
|
|
85
|
+
return scriptVisitor;
|
|
86
|
+
} else {
|
|
87
|
+
// @ts-expect-error defineTemplateBodyVisitor
|
|
88
|
+
return context.sourceCode.parserServices.defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
module.exports = defineVisitors;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
import type { RuleContext, RuleListener } from '@typescript-eslint/utils/ts-eslint';
|
|
3
|
+
import { Settings } from '../settings';
|
|
2
4
|
export default function defineVisitors({ context, settings }: {
|
|
3
|
-
context:
|
|
4
|
-
settings:
|
|
5
|
-
}, visitNode: any):
|
|
5
|
+
context: RuleContext<any, any[]>;
|
|
6
|
+
settings: Settings;
|
|
7
|
+
}, visitNode: (node: TSESTree.Node, args?: any) => void): RuleListener;
|
|
@@ -1 +1,90 @@
|
|
|
1
|
-
function
|
|
1
|
+
function defineVisitors({ context, settings }, visitNode) {
|
|
2
|
+
const classAttributeRegex = new RegExp(`^(?:${settings.classAttributes.join('|')})$`);
|
|
3
|
+
const classFunctionsRegex = new RegExp(`^(?:${settings.classFunctions.join('|')})`);
|
|
4
|
+
const classDeclarationsRegex = new RegExp(`^(?:${settings.classDeclarations.join('|')})$`);
|
|
5
|
+
const isFnNode = (node)=>{
|
|
6
|
+
let calleeName = '';
|
|
7
|
+
const calleeNode = node.callee || node.tag;
|
|
8
|
+
if (calleeNode.type === 'Identifier') {
|
|
9
|
+
calleeName = calleeNode.name;
|
|
10
|
+
}
|
|
11
|
+
if (calleeNode.type === 'MemberExpression') {
|
|
12
|
+
calleeName = `${calleeNode.object.name}.${calleeNode.property.name}`;
|
|
13
|
+
}
|
|
14
|
+
return classFunctionsRegex.test(calleeName);
|
|
15
|
+
};
|
|
16
|
+
const CallExpression = function(node) {
|
|
17
|
+
if (!isFnNode(node)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
node.arguments.forEach((arg)=>{
|
|
21
|
+
visitNode(node, arg);
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
const scriptVisitor = {
|
|
25
|
+
CallExpression,
|
|
26
|
+
JSXAttribute: function(node) {
|
|
27
|
+
if (!node.name || !classAttributeRegex.test(node.name.name)) return;
|
|
28
|
+
if (node.value && node.value.type === 'Literal') {
|
|
29
|
+
visitNode(node);
|
|
30
|
+
} else if (node.value && node.value.type === 'JSXExpressionContainer') {
|
|
31
|
+
visitNode(node, node.value.expression);
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
SvelteAttribute: function(node) {
|
|
35
|
+
if (!node.key?.name || !classAttributeRegex.test(node.key.name)) return;
|
|
36
|
+
for (const eachValue of node.value){
|
|
37
|
+
visitNode(node, eachValue);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
TextAttribute: function(node) {
|
|
41
|
+
if (!node.name || !classAttributeRegex.test(node.name)) return;
|
|
42
|
+
visitNode(node);
|
|
43
|
+
},
|
|
44
|
+
TaggedTemplateExpression: function(node) {
|
|
45
|
+
if (isFnNode(node)) {
|
|
46
|
+
visitNode(node, node.quasi);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
VariableDeclaration: function(node) {
|
|
51
|
+
node.declarations.forEach((decl)=>{
|
|
52
|
+
if (decl.id.type === 'Identifier' && classDeclarationsRegex.test(decl.id.name)) {
|
|
53
|
+
visitNode(node, decl.init);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
ObjectExpression: function(node) {
|
|
58
|
+
node.properties.forEach((prop)=>{
|
|
59
|
+
if (prop.type === 'Property' && prop.key.type === 'Identifier' && classDeclarationsRegex.test(prop.key.name)) {
|
|
60
|
+
visitNode(node, prop.value);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const templateBodyVisitor = {
|
|
66
|
+
CallExpression,
|
|
67
|
+
VAttribute: function(node) {
|
|
68
|
+
if (node.value && node.value.type === 'VLiteral') {
|
|
69
|
+
visitNode(node);
|
|
70
|
+
} else if (node.value && node.value.type === 'VExpressionContainer' && node.value.expression?.type === 'ArrayExpression') {
|
|
71
|
+
node.value.expression.elements.forEach((arg)=>{
|
|
72
|
+
visitNode(node, arg);
|
|
73
|
+
});
|
|
74
|
+
} else if (node.value && node.value.type === 'VExpressionContainer' && node.value.expression?.type === 'ObjectExpression') {
|
|
75
|
+
node.value.expression.properties.forEach((prop)=>{
|
|
76
|
+
visitNode(node, prop);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
// @ts-expect-error defineTemplateBodyVisitor
|
|
82
|
+
if (context.sourceCode.parserServices == null || context.sourceCode.parserServices.defineTemplateBodyVisitor == null) {
|
|
83
|
+
return scriptVisitor;
|
|
84
|
+
} else {
|
|
85
|
+
// @ts-expect-error defineTemplateBodyVisitor
|
|
86
|
+
return context.sourceCode.parserServices.defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { defineVisitors as default };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const separatorRegEx = /([\t\n\f\r ]+)/;
|
|
4
|
+
function extractClassnamesFromValue(classStr) {
|
|
5
|
+
if (typeof classStr !== 'string') {
|
|
6
|
+
return {
|
|
7
|
+
classNames: [],
|
|
8
|
+
whitespaces: [],
|
|
9
|
+
headSpace: false,
|
|
10
|
+
tailSpace: false
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
const parts = classStr.split(separatorRegEx);
|
|
14
|
+
if (parts[0] === '') {
|
|
15
|
+
parts.shift();
|
|
16
|
+
}
|
|
17
|
+
if (parts[parts.length - 1] === '') {
|
|
18
|
+
parts.pop();
|
|
19
|
+
}
|
|
20
|
+
const headSpace = separatorRegEx.test(parts[0]);
|
|
21
|
+
const tailSpace = separatorRegEx.test(parts[parts.length - 1]);
|
|
22
|
+
const isClass = (_, i)=>headSpace ? i % 2 !== 0 : i % 2 === 0;
|
|
23
|
+
const isNotClass = (_, i)=>headSpace ? i % 2 === 0 : i % 2 !== 0;
|
|
24
|
+
const classNames = parts.filter(isClass);
|
|
25
|
+
const whitespaces = parts.filter(isNotClass);
|
|
26
|
+
return {
|
|
27
|
+
classNames: classNames,
|
|
28
|
+
whitespaces: whitespaces,
|
|
29
|
+
headSpace: headSpace,
|
|
30
|
+
tailSpace: tailSpace
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
module.exports = extractClassnamesFromValue;
|
|
@@ -1 +1,32 @@
|
|
|
1
|
-
const
|
|
1
|
+
const separatorRegEx = /([\t\n\f\r ]+)/;
|
|
2
|
+
function extractClassnamesFromValue(classStr) {
|
|
3
|
+
if (typeof classStr !== 'string') {
|
|
4
|
+
return {
|
|
5
|
+
classNames: [],
|
|
6
|
+
whitespaces: [],
|
|
7
|
+
headSpace: false,
|
|
8
|
+
tailSpace: false
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
const parts = classStr.split(separatorRegEx);
|
|
12
|
+
if (parts[0] === '') {
|
|
13
|
+
parts.shift();
|
|
14
|
+
}
|
|
15
|
+
if (parts[parts.length - 1] === '') {
|
|
16
|
+
parts.pop();
|
|
17
|
+
}
|
|
18
|
+
const headSpace = separatorRegEx.test(parts[0]);
|
|
19
|
+
const tailSpace = separatorRegEx.test(parts[parts.length - 1]);
|
|
20
|
+
const isClass = (_, i)=>headSpace ? i % 2 !== 0 : i % 2 === 0;
|
|
21
|
+
const isNotClass = (_, i)=>headSpace ? i % 2 === 0 : i % 2 !== 0;
|
|
22
|
+
const classNames = parts.filter(isClass);
|
|
23
|
+
const whitespaces = parts.filter(isNotClass);
|
|
24
|
+
return {
|
|
25
|
+
classNames: classNames,
|
|
26
|
+
whitespaces: whitespaces,
|
|
27
|
+
headSpace: headSpace,
|
|
28
|
+
tailSpace: tailSpace
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { extractClassnamesFromValue as default };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function extractRangeFromNode(node) {
|
|
4
|
+
if (node.type === 'TextAttribute' && node.name === 'class') {
|
|
5
|
+
return [
|
|
6
|
+
node.valueSpan.fullStart.offset,
|
|
7
|
+
node.valueSpan.end.offset
|
|
8
|
+
];
|
|
9
|
+
}
|
|
10
|
+
switch(node.value.type){
|
|
11
|
+
case 'JSXExpressionContainer':
|
|
12
|
+
return node.value.expression.range;
|
|
13
|
+
default:
|
|
14
|
+
return node.value.range;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = extractRangeFromNode;
|
|
@@ -1 +1,16 @@
|
|
|
1
|
-
function
|
|
1
|
+
function extractRangeFromNode(node) {
|
|
2
|
+
if (node.type === 'TextAttribute' && node.name === 'class') {
|
|
3
|
+
return [
|
|
4
|
+
node.valueSpan.fullStart.offset,
|
|
5
|
+
node.valueSpan.end.offset
|
|
6
|
+
];
|
|
7
|
+
}
|
|
8
|
+
switch(node.value.type){
|
|
9
|
+
case 'JSXExpressionContainer':
|
|
10
|
+
return node.value.expression.range;
|
|
11
|
+
default:
|
|
12
|
+
return node.value.range;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { extractRangeFromNode as default };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function extractValueFromNode(node) {
|
|
4
|
+
if (node.type === 'TextAttribute' && node.name === 'class') {
|
|
5
|
+
return node.value;
|
|
6
|
+
}
|
|
7
|
+
switch(node.value.type){
|
|
8
|
+
case 'JSXExpressionContainer':
|
|
9
|
+
return node.value.expression.value;
|
|
10
|
+
case 'VExpressionContainer':
|
|
11
|
+
switch(node.value.expression.type){
|
|
12
|
+
case 'ArrayExpression':
|
|
13
|
+
return node.value.expression.elements;
|
|
14
|
+
case 'ObjectExpression':
|
|
15
|
+
return node.value.expression.properties;
|
|
16
|
+
}
|
|
17
|
+
return node.value.expression.value;
|
|
18
|
+
default:
|
|
19
|
+
return node.value.value;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = extractValueFromNode;
|
|
@@ -1 +1,21 @@
|
|
|
1
|
-
function
|
|
1
|
+
function extractValueFromNode(node) {
|
|
2
|
+
if (node.type === 'TextAttribute' && node.name === 'class') {
|
|
3
|
+
return node.value;
|
|
4
|
+
}
|
|
5
|
+
switch(node.value.type){
|
|
6
|
+
case 'JSXExpressionContainer':
|
|
7
|
+
return node.value.expression.value;
|
|
8
|
+
case 'VExpressionContainer':
|
|
9
|
+
switch(node.value.expression.type){
|
|
10
|
+
case 'ArrayExpression':
|
|
11
|
+
return node.value.expression.elements;
|
|
12
|
+
case 'ObjectExpression':
|
|
13
|
+
return node.value.expression.properties;
|
|
14
|
+
}
|
|
15
|
+
return node.value.expression.value;
|
|
16
|
+
default:
|
|
17
|
+
return node.value.value;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { extractValueFromNode as default };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var indexOfAll = require('./index-of-all.cjs');
|
|
4
|
+
|
|
5
|
+
function findLoc(text, lines, startLine, startColumn, endLine, endColumn) {
|
|
6
|
+
const targetLines = text.match(/.+(?:\r\n|\n)?/g);
|
|
7
|
+
let checkingTargetLine = 0;
|
|
8
|
+
let resultStart = null;
|
|
9
|
+
let checking = false;
|
|
10
|
+
for(let i = startLine; i <= endLine; i++){
|
|
11
|
+
const sourceCodeLine = lines[i - 1];
|
|
12
|
+
const content = targetLines[checkingTargetLine].replace(/\r\n|\n/, '');
|
|
13
|
+
const indexes = indexOfAll.indexOfAll(sourceCodeLine, content);
|
|
14
|
+
if (indexes.length > 0) {
|
|
15
|
+
for (const index of indexes){
|
|
16
|
+
if (i === startLine && index < startColumn || i === endLine && index > endColumn) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (index !== 0 && sourceCodeLine[index - 1].match(/\w/) || index + content.length < sourceCodeLine.length && sourceCodeLine[index + content.length].match(/\w/)) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (checkingTargetLine === 0) {
|
|
23
|
+
resultStart = {
|
|
24
|
+
line: i,
|
|
25
|
+
column: index
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
if (checkingTargetLine === targetLines.length - 1) {
|
|
29
|
+
return {
|
|
30
|
+
start: resultStart,
|
|
31
|
+
end: {
|
|
32
|
+
line: i,
|
|
33
|
+
column: index + text.length
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
checking = true;
|
|
38
|
+
checkingTargetLine++;
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
if (checking) {
|
|
42
|
+
checking = false;
|
|
43
|
+
checkingTargetLine = 0;
|
|
44
|
+
resultStart = null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
module.exports = findLoc;
|
package/dist/utils/find-loc.d.ts
CHANGED
package/dist/utils/find-loc.mjs
CHANGED
|
@@ -1 +1,49 @@
|
|
|
1
|
-
|
|
1
|
+
import { indexOfAll } from './index-of-all.mjs';
|
|
2
|
+
|
|
3
|
+
function findLoc(text, lines, startLine, startColumn, endLine, endColumn) {
|
|
4
|
+
const targetLines = text.match(/.+(?:\r\n|\n)?/g);
|
|
5
|
+
let checkingTargetLine = 0;
|
|
6
|
+
let resultStart = null;
|
|
7
|
+
let checking = false;
|
|
8
|
+
for(let i = startLine; i <= endLine; i++){
|
|
9
|
+
const sourceCodeLine = lines[i - 1];
|
|
10
|
+
const content = targetLines[checkingTargetLine].replace(/\r\n|\n/, '');
|
|
11
|
+
const indexes = indexOfAll(sourceCodeLine, content);
|
|
12
|
+
if (indexes.length > 0) {
|
|
13
|
+
for (const index of indexes){
|
|
14
|
+
if (i === startLine && index < startColumn || i === endLine && index > endColumn) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
if (index !== 0 && sourceCodeLine[index - 1].match(/\w/) || index + content.length < sourceCodeLine.length && sourceCodeLine[index + content.length].match(/\w/)) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (checkingTargetLine === 0) {
|
|
21
|
+
resultStart = {
|
|
22
|
+
line: i,
|
|
23
|
+
column: index
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
if (checkingTargetLine === targetLines.length - 1) {
|
|
27
|
+
return {
|
|
28
|
+
start: resultStart,
|
|
29
|
+
end: {
|
|
30
|
+
line: i,
|
|
31
|
+
column: index + text.length
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
checking = true;
|
|
36
|
+
checkingTargetLine++;
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
if (checking) {
|
|
40
|
+
checking = false;
|
|
41
|
+
checkingTargetLine = 0;
|
|
42
|
+
resultStart = null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { findLoc as default };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function getTemplateElementBody(text, prefix, suffix) {
|
|
4
|
+
let arr = text.split(prefix);
|
|
5
|
+
arr.shift();
|
|
6
|
+
const body = arr.join(prefix);
|
|
7
|
+
arr = body.split(suffix);
|
|
8
|
+
arr.pop();
|
|
9
|
+
return arr.join(suffix);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
module.exports = getTemplateElementBody;
|
|
@@ -1 +1,10 @@
|
|
|
1
|
-
function
|
|
1
|
+
function getTemplateElementBody(text, prefix, suffix) {
|
|
2
|
+
let arr = text.split(prefix);
|
|
3
|
+
arr.shift();
|
|
4
|
+
const body = arr.join(prefix);
|
|
5
|
+
arr = body.split(suffix);
|
|
6
|
+
arr.pop();
|
|
7
|
+
return arr.join(suffix);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { getTemplateElementBody as default };
|
|
@@ -1 +1,9 @@
|
|
|
1
|
-
function
|
|
1
|
+
function getTemplateElementPrefix(text, raw) {
|
|
2
|
+
const idx = text.indexOf(raw);
|
|
3
|
+
if (idx === 0) {
|
|
4
|
+
return '';
|
|
5
|
+
}
|
|
6
|
+
return text.split(raw).shift();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { getTemplateElementPrefix as default };
|
|
@@ -1 +1,8 @@
|
|
|
1
|
-
function
|
|
1
|
+
function getTemplateElementSuffix(text, raw) {
|
|
2
|
+
if (text.indexOf(raw) === -1) {
|
|
3
|
+
return '';
|
|
4
|
+
}
|
|
5
|
+
return text.split(raw).pop();
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export { getTemplateElementSuffix as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function indexOfAll(arr: any[] | string, value: any): number[];
|