@master/eslint-plugin-css 2.0.0-rc.2 → 2.0.0-rc.21

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.
Files changed (120) hide show
  1. package/README.md +1 -1
  2. package/dist/configs/config.cjs +16 -0
  3. package/dist/configs/config.mjs +14 -1
  4. package/dist/configs/flat.cjs +13 -0
  5. package/dist/configs/flat.d.ts +10 -1
  6. package/dist/configs/flat.mjs +11 -1
  7. package/dist/configs/recommended.cjs +12 -0
  8. package/dist/configs/recommended.mjs +10 -1
  9. package/dist/create-rule.cjs +7 -0
  10. package/dist/create-rule.d.ts +3 -0
  11. package/dist/create-rule.mjs +5 -0
  12. package/dist/functions/get-css.cjs +16 -0
  13. package/dist/functions/get-css.d.ts +1 -0
  14. package/dist/functions/get-css.mjs +14 -0
  15. package/dist/functions/reorder-valid-classes.cjs +9 -0
  16. package/dist/functions/reorder-valid-classes.d.ts +3 -0
  17. package/dist/functions/reorder-valid-classes.mjs +11 -0
  18. package/dist/functions/reorder-valid-classes.worker.cjs +15 -0
  19. package/dist/functions/reorder-valid-classes.worker.d.ts +1 -0
  20. package/dist/functions/reorder-valid-classes.worker.mjs +13 -0
  21. package/dist/functions/valid-rules.cjs +9 -0
  22. package/dist/functions/valid-rules.d.ts +3 -0
  23. package/dist/functions/valid-rules.mjs +11 -0
  24. package/dist/functions/valid-rules.worker.cjs +24 -0
  25. package/dist/functions/valid-rules.worker.d.ts +6 -0
  26. package/dist/functions/valid-rules.worker.mjs +22 -0
  27. package/dist/functions/validate.cjs +9 -0
  28. package/dist/functions/validate.d.ts +3 -0
  29. package/dist/functions/validate.mjs +11 -0
  30. package/dist/functions/validate.worker.cjs +15 -0
  31. package/dist/functions/validate.worker.d.ts +5 -0
  32. package/dist/functions/validate.worker.mjs +13 -0
  33. package/dist/index.cjs +17 -0
  34. package/dist/index.d.ts +57 -1
  35. package/dist/index.mjs +15 -1
  36. package/dist/plugin.cjs +18 -0
  37. package/dist/plugin.d.ts +10 -2
  38. package/dist/plugin.mjs +16 -1
  39. package/dist/rules/class-collision.cjs +107 -0
  40. package/dist/rules/class-collision.d.ts +1 -2
  41. package/dist/rules/class-collision.mjs +105 -1
  42. package/dist/rules/class-order.cjs +198 -0
  43. package/dist/rules/class-order.d.ts +1 -2
  44. package/dist/rules/class-order.mjs +196 -1
  45. package/dist/rules/class-validation.cjs +94 -0
  46. package/dist/rules/class-validation.d.ts +1 -2
  47. package/dist/rules/class-validation.mjs +92 -1
  48. package/dist/settings.cjs +13 -0
  49. package/dist/settings.d.ts +6 -0
  50. package/dist/settings.mjs +11 -1
  51. package/dist/utils/are-declarations-equal.cjs +21 -0
  52. package/dist/utils/are-declarations-equal.mjs +19 -1
  53. package/dist/utils/are-vendor-prefix-selectors-equal.cjs +14 -0
  54. package/dist/utils/are-vendor-prefix-selectors-equal.d.ts +1 -0
  55. package/dist/utils/are-vendor-prefix-selectors-equal.mjs +12 -0
  56. package/dist/utils/define-visitors.cjs +76 -0
  57. package/dist/utils/define-visitors.d.ts +8 -5
  58. package/dist/utils/define-visitors.mjs +74 -1
  59. package/dist/utils/extract-classnames-from-value.cjs +34 -0
  60. package/dist/utils/extract-classnames-from-value.mjs +32 -1
  61. package/dist/utils/extract-range-from-node.cjs +18 -0
  62. package/dist/utils/extract-range-from-node.mjs +16 -1
  63. package/dist/utils/extract-value-from-node.cjs +23 -0
  64. package/dist/utils/extract-value-from-node.mjs +21 -1
  65. package/dist/utils/find-loc.cjs +40 -0
  66. package/dist/utils/find-loc.mjs +38 -1
  67. package/dist/utils/get-template-element-body.cjs +12 -0
  68. package/dist/utils/get-template-element-body.mjs +10 -1
  69. package/dist/utils/get-template-element-prefix.cjs +11 -0
  70. package/dist/utils/get-template-element-prefix.mjs +9 -1
  71. package/dist/utils/get-template-element-suffix.cjs +10 -0
  72. package/dist/utils/get-template-element-suffix.mjs +8 -1
  73. package/dist/utils/parse-node-recursive.cjs +122 -0
  74. package/dist/utils/parse-node-recursive.d.ts +2 -2
  75. package/dist/utils/parse-node-recursive.mjs +120 -1
  76. package/dist/utils/resolve-context.cjs +13 -0
  77. package/dist/utils/resolve-context.d.ts +8 -2
  78. package/dist/utils/resolve-context.mjs +11 -1
  79. package/package.json +1 -1
  80. package/dist/configs/config.js +0 -1
  81. package/dist/configs/flat.js +0 -1
  82. package/dist/configs/recommended.js +0 -1
  83. package/dist/index.js +0 -1
  84. package/dist/plugin.js +0 -1
  85. package/dist/rules/class-collision.js +0 -1
  86. package/dist/rules/class-order.js +0 -1
  87. package/dist/rules/class-validation.js +0 -1
  88. package/dist/settings.js +0 -1
  89. package/dist/utils/are-declarations-equal.js +0 -1
  90. package/dist/utils/define-visitors.js +0 -1
  91. package/dist/utils/extract-classnames-from-value.js +0 -1
  92. package/dist/utils/extract-range-from-node.js +0 -1
  93. package/dist/utils/extract-value-from-node.js +0 -1
  94. package/dist/utils/find-loc.js +0 -1
  95. package/dist/utils/get-mastercss.d.ts +0 -2
  96. package/dist/utils/get-mastercss.js +0 -1
  97. package/dist/utils/get-mastercss.mjs +0 -1
  98. package/dist/utils/get-template-element-body.js +0 -1
  99. package/dist/utils/get-template-element-prefix.js +0 -1
  100. package/dist/utils/get-template-element-suffix.js +0 -1
  101. package/dist/utils/parse-node-recursive.js +0 -1
  102. package/dist/utils/reorder-valid-classes-action.d.ts +0 -3
  103. package/dist/utils/reorder-valid-classes-action.js +0 -1
  104. package/dist/utils/reorder-valid-classes-action.mjs +0 -1
  105. package/dist/utils/resolve-context.js +0 -1
  106. package/dist/utils/valid-rules-action.d.ts +0 -3
  107. package/dist/utils/valid-rules-action.js +0 -1
  108. package/dist/utils/valid-rules-action.mjs +0 -1
  109. package/dist/utils/validate-action.d.ts +0 -3
  110. package/dist/utils/validate-action.js +0 -1
  111. package/dist/utils/validate-action.mjs +0 -1
  112. package/dist/utils/workers/reorder-valid-classes.d.ts +0 -2
  113. package/dist/utils/workers/reorder-valid-classes.js +0 -1
  114. package/dist/utils/workers/reorder-valid-classes.mjs +0 -1
  115. package/dist/utils/workers/valid-rules.d.ts +0 -2
  116. package/dist/utils/workers/valid-rules.js +0 -1
  117. package/dist/utils/workers/valid-rules.mjs +0 -1
  118. package/dist/utils/workers/validate.d.ts +0 -5
  119. package/dist/utils/workers/validate.js +0 -1
  120. package/dist/utils/workers/validate.mjs +0 -1
@@ -1 +1,92 @@
1
- import u from"../utils/define-visitors.mjs";import y from"../utils/resolve-context.mjs";import l from"../utils/find-loc.mjs";import{parseNodeRecursive as C}from"../utils/parse-node-recursive.mjs";import w from"../utils/validate-action.mjs";var b={meta:{docs:{description:"Detect syntax errors early when writing classes",category:"Stylistic Issues",recommended:!1,url:"https://rc.css.master.co/docs/code-linting#syntax-error-checks"},messages:{invalidClass:"{{message}}",disallowUnknownClass:"{{message}}"},fixable:null,schema:[{type:"object",properties:{calleeMatching:{type:"string"},classMatching:{type:"string"},ignoredKeys:{type:"array",items:{type:"string",minLength:0},uniqueItems:!0},config:{type:["string","object"]}}}]},create:function(e){const{options:c,settings:o}=y(e);return u({context:e,settings:o},(d,m=null)=>{C(d,m,(g,r)=>{const t=e.sourceCode.lines,i=r.loc.start.line,n=r.loc.end.line;for(const s of g){const{isMasterCSS:f,errors:a}=w(s,o.config);if(a.length>0)for(const p of a)f?e.report({loc:l(s,t,i,n),messageId:"invalidClass",data:{message:p.message+"."}}):c.disallowUnknownClass&&e.report({loc:l(s,t,i,n),messageId:"disallowUnknownClass",data:{message:`"${s}" is not a valid or known class.`}})}},!1,!1,o.ignoredKeys,e)})}};export{b as default};
1
+ import defineVisitors from '../utils/define-visitors.mjs';
2
+ import resolveContext from '../utils/resolve-context.mjs';
3
+ import findLoc from '../utils/find-loc.mjs';
4
+ import { parseNodeRecursive } from '../utils/parse-node-recursive.mjs';
5
+ import validate from '../functions/validate.mjs';
6
+ import createRule from '../create-rule.mjs';
7
+
8
+ var classValidation = createRule({
9
+ name: 'syntax-error-checks',
10
+ meta: {
11
+ type: 'problem',
12
+ docs: {
13
+ description: 'Detect syntax errors early when writing classes',
14
+ recommended: 'recommended'
15
+ },
16
+ messages: {
17
+ invalidClass: '{{message}}',
18
+ disallowUnknownClass: '{{message}}'
19
+ },
20
+ fixable: null,
21
+ schema: [
22
+ {
23
+ type: 'object',
24
+ properties: {
25
+ calleeMatching: {
26
+ type: 'string'
27
+ },
28
+ classMatching: {
29
+ type: 'string'
30
+ },
31
+ ignoredKeys: {
32
+ type: 'array',
33
+ items: {
34
+ type: 'string',
35
+ minLength: 0
36
+ },
37
+ uniqueItems: true
38
+ },
39
+ config: {
40
+ type: [
41
+ 'string',
42
+ 'object'
43
+ ]
44
+ }
45
+ }
46
+ }
47
+ ]
48
+ },
49
+ defaultOptions: [],
50
+ create: function(context) {
51
+ const { options, settings } = resolveContext(context);
52
+ const visitNode = (node, arg = null)=>{
53
+ parseNodeRecursive(node, arg, (classNames, node)=>{
54
+ const sourceCode = context.sourceCode;
55
+ const sourceCodeLines = sourceCode.lines;
56
+ const nodeStartLine = node.loc.start.line;
57
+ const nodeEndLine = node.loc.end.line;
58
+ for (const className of classNames){
59
+ const { isMasterCSS, errors } = validate(className, settings.config);
60
+ if (errors.length > 0) {
61
+ for (const error of errors){
62
+ if (isMasterCSS) {
63
+ context.report({
64
+ loc: findLoc(className, sourceCodeLines, nodeStartLine, nodeEndLine),
65
+ messageId: 'invalidClass',
66
+ data: {
67
+ message: error.message + '.'
68
+ }
69
+ });
70
+ } else if (options.disallowUnknownClass) {
71
+ context.report({
72
+ loc: findLoc(className, sourceCodeLines, nodeStartLine, nodeEndLine),
73
+ messageId: 'disallowUnknownClass',
74
+ data: {
75
+ message: `"${className}" is not a valid or known class.`
76
+ }
77
+ });
78
+ }
79
+ }
80
+ }
81
+ }
82
+ }, false, false, settings.ignoredKeys, context);
83
+ };
84
+ return defineVisitors({
85
+ context,
86
+ settings,
87
+ options
88
+ }, visitNode);
89
+ }
90
+ });
91
+
92
+ export { classValidation as default };
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ const settings = {
4
+ calleeMatching: '^(classnames|clsx|ctl|cva|cv|classVariant|styled(?:\\.\\w+)?)',
5
+ classMatching: '^class(Name)?$',
6
+ ignoredKeys: [
7
+ 'compoundVariants',
8
+ 'defaultVariants'
9
+ ],
10
+ config: 'master.css'
11
+ };
12
+
13
+ module.exports = settings;
@@ -5,3 +5,9 @@ declare const settings: {
5
5
  config: string;
6
6
  };
7
7
  export default settings;
8
+ export interface Settings {
9
+ calleeMatching: string;
10
+ classMatching: string;
11
+ ignoredKeys: string[];
12
+ config: string | object;
13
+ }
package/dist/settings.mjs CHANGED
@@ -1 +1,11 @@
1
- const s={calleeMatching:"^(classnames|clsx|ctl|cva|cv|classVariant|styled(?:\\.\\w+)?)",classMatching:"^class(Name)?$",ignoredKeys:["compoundVariants","defaultVariants"],config:"master.css.*"};var a=s;export{a as default};
1
+ const settings = {
2
+ calleeMatching: '^(classnames|clsx|ctl|cva|cv|classVariant|styled(?:\\.\\w+)?)',
3
+ classMatching: '^class(Name)?$',
4
+ ignoredKeys: [
5
+ 'compoundVariants',
6
+ 'defaultVariants'
7
+ ],
8
+ config: 'master.css'
9
+ };
10
+
11
+ export { settings as default };
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ function areDeclarationsEqual(aDeclarations, bDeclarations) {
4
+ // 获取对象A和B的所有属性名
5
+ const aKeys = Object.keys(aDeclarations);
6
+ const bKeys = Object.keys(bDeclarations);
7
+ // 如果属性数量不相等,返回false
8
+ if (aKeys.length !== bKeys.length) {
9
+ return false;
10
+ }
11
+ // 检查对象A的属性是否都存在于对象B中
12
+ for (const key of aKeys){
13
+ if (!Object.prototype.hasOwnProperty.call(bDeclarations, key)) {
14
+ return false;
15
+ }
16
+ }
17
+ // 如果所有属性都匹配,返回true
18
+ return true;
19
+ }
20
+
21
+ module.exports = areDeclarationsEqual;
@@ -1 +1,19 @@
1
- function s(r,e){const t=Object.keys(r),n=Object.keys(e);if(t.length!==n.length)return!1;for(const o of t)if(!Object.prototype.hasOwnProperty.call(e,o))return!1;return!0}export{s as default};
1
+ function areDeclarationsEqual(aDeclarations, bDeclarations) {
2
+ // 获取对象A和B的所有属性名
3
+ const aKeys = Object.keys(aDeclarations);
4
+ const bKeys = Object.keys(bDeclarations);
5
+ // 如果属性数量不相等,返回false
6
+ if (aKeys.length !== bKeys.length) {
7
+ return false;
8
+ }
9
+ // 检查对象A的属性是否都存在于对象B中
10
+ for (const key of aKeys){
11
+ if (!Object.prototype.hasOwnProperty.call(bDeclarations, key)) {
12
+ return false;
13
+ }
14
+ }
15
+ // 如果所有属性都匹配,返回true
16
+ return true;
17
+ }
18
+
19
+ export { areDeclarationsEqual as default };
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ function areVendorPrefixSelectorsEqual(aVendorPrefixSelectors, bVendorPrefixSelectors) {
4
+ const aKeys = Object.keys(aVendorPrefixSelectors);
5
+ if (aKeys.length !== Object.keys(bVendorPrefixSelectors).length) return false;
6
+ return aKeys.every((eachAKey)=>{
7
+ if (!Object.prototype.hasOwnProperty.call(bVendorPrefixSelectors, eachAKey)) return false;
8
+ const aValues = aVendorPrefixSelectors[eachAKey];
9
+ const bValues = bVendorPrefixSelectors[eachAKey];
10
+ return aValues.length === bValues.length && aValues.every((eachAValue)=>bValues.includes(eachAValue));
11
+ });
12
+ }
13
+
14
+ module.exports = areVendorPrefixSelectorsEqual;
@@ -0,0 +1 @@
1
+ export default function areVendorPrefixSelectorsEqual(aVendorPrefixSelectors: any, bVendorPrefixSelectors: any): boolean;
@@ -0,0 +1,12 @@
1
+ function areVendorPrefixSelectorsEqual(aVendorPrefixSelectors, bVendorPrefixSelectors) {
2
+ const aKeys = Object.keys(aVendorPrefixSelectors);
3
+ if (aKeys.length !== Object.keys(bVendorPrefixSelectors).length) return false;
4
+ return aKeys.every((eachAKey)=>{
5
+ if (!Object.prototype.hasOwnProperty.call(bVendorPrefixSelectors, eachAKey)) return false;
6
+ const aValues = aVendorPrefixSelectors[eachAKey];
7
+ const bValues = bVendorPrefixSelectors[eachAKey];
8
+ return aValues.length === bValues.length && aValues.every((eachAValue)=>bValues.includes(eachAValue));
9
+ });
10
+ }
11
+
12
+ export { areVendorPrefixSelectorsEqual as default };
@@ -0,0 +1,76 @@
1
+ 'use strict';
2
+
3
+ function defineVisitors({ context, settings, options }, visitNode) {
4
+ const isFnNode = (node)=>{
5
+ let calleeName = '';
6
+ const calleeNode = node.callee || node.tag;
7
+ if (calleeNode.type === 'Identifier') {
8
+ calleeName = calleeNode.name;
9
+ }
10
+ if (calleeNode.type === 'MemberExpression') {
11
+ calleeName = `${calleeNode.object.name}.${calleeNode.property.name}`;
12
+ }
13
+ return new RegExp(settings.calleeMatching).test(calleeName);
14
+ };
15
+ const CallExpression = function(node) {
16
+ if (!isFnNode(node)) {
17
+ return;
18
+ }
19
+ node.arguments.forEach((arg)=>{
20
+ visitNode(node, arg);
21
+ });
22
+ };
23
+ const classMatchingRegex = new RegExp(settings.classMatching);
24
+ const scriptVisitor = {
25
+ CallExpression,
26
+ JSXAttribute: function(node) {
27
+ if (!node.name || !classMatchingRegex.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 || !classMatchingRegex.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 || !classMatchingRegex.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
+ };
51
+ const templateBodyVisitor = {
52
+ CallExpression,
53
+ VAttribute: function(node) {
54
+ if (node.value && node.value.type === 'VLiteral') {
55
+ visitNode(node);
56
+ } else if (node.value && node.value.type === 'VExpressionContainer' && node.value.expression.type === 'ArrayExpression') {
57
+ node.value.expression.elements.forEach((arg)=>{
58
+ visitNode(node, arg);
59
+ });
60
+ } else if (node.value && node.value.type === 'VExpressionContainer' && node.value.expression.type === 'ObjectExpression') {
61
+ node.value.expression.properties.forEach((prop)=>{
62
+ visitNode(node, prop);
63
+ });
64
+ }
65
+ }
66
+ };
67
+ // @ts-expect-error defineTemplateBodyVisitor
68
+ if (context.sourceCode.parserServices == null || context.sourceCode.parserServices.defineTemplateBodyVisitor == null) {
69
+ return scriptVisitor;
70
+ } else {
71
+ // @ts-expect-error defineTemplateBodyVisitor
72
+ return context.sourceCode.parserServices.defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor);
73
+ }
74
+ }
75
+
76
+ module.exports = defineVisitors;
@@ -1,5 +1,8 @@
1
- import { Rule } from 'eslint';
2
- export default function defineVisitors({ context, settings }: {
3
- context: Rule.RuleContext;
4
- settings: any;
5
- }, visitNode: any): any;
1
+ import { TSESTree } from '@typescript-eslint/utils';
2
+ import type { RuleContext, RuleListener } from '@typescript-eslint/utils/ts-eslint';
3
+ import { Settings } from '../settings';
4
+ export default function defineVisitors({ context, settings, options }: {
5
+ context: RuleContext<any, any[]>;
6
+ settings: Settings;
7
+ options: any;
8
+ }, visitNode: (node: TSESTree.Node, args?: any) => void): RuleListener;
@@ -1 +1,74 @@
1
- function f({context:a,settings:l},r){const n=e=>{let t="";const s=e.callee||e.tag;return s.type==="Identifier"&&(t=s.name),s.type==="MemberExpression"&&(t=`${s.object.name}.${s.property.name}`),new RegExp(l.calleeMatching).test(t)},u=function(e){n(e)&&e.arguments.forEach(t=>{r(e,t)})},i=new RegExp(l.classMatching),p={CallExpression:u,JSXAttribute:function(e){!e.name||!i.test(e.name.name)||(e.value&&e.value.type==="Literal"?r(e):e.value&&e.value.type==="JSXExpressionContainer"&&r(e,e.value.expression))},SvelteAttribute:function(e){if(!(!e.key?.name||!i.test(e.key.name)))for(const t of e.value)r(e,t)},TextAttribute:function(e){!e.name||!i.test(e.name)||r(e)},TaggedTemplateExpression:function(e){if(n(e)){r(e,e.quasi);return}}},c={CallExpression:u,VAttribute:function(e){e.value&&e.value.type==="VLiteral"?r(e):e.value&&e.value.type==="VExpressionContainer"&&e.value.expression.type==="ArrayExpression"?e.value.expression.elements.forEach(t=>{r(e,t)}):e.value&&e.value.type==="VExpressionContainer"&&e.value.expression.type==="ObjectExpression"&&e.value.expression.properties.forEach(t=>{r(e,t)})}};return a.sourceCode.parserServices==null||a.sourceCode.parserServices.defineTemplateBodyVisitor==null?p:a.sourceCode.parserServices.defineTemplateBodyVisitor(c,p)}export{f as default};
1
+ function defineVisitors({ context, settings, options }, visitNode) {
2
+ const isFnNode = (node)=>{
3
+ let calleeName = '';
4
+ const calleeNode = node.callee || node.tag;
5
+ if (calleeNode.type === 'Identifier') {
6
+ calleeName = calleeNode.name;
7
+ }
8
+ if (calleeNode.type === 'MemberExpression') {
9
+ calleeName = `${calleeNode.object.name}.${calleeNode.property.name}`;
10
+ }
11
+ return new RegExp(settings.calleeMatching).test(calleeName);
12
+ };
13
+ const CallExpression = function(node) {
14
+ if (!isFnNode(node)) {
15
+ return;
16
+ }
17
+ node.arguments.forEach((arg)=>{
18
+ visitNode(node, arg);
19
+ });
20
+ };
21
+ const classMatchingRegex = new RegExp(settings.classMatching);
22
+ const scriptVisitor = {
23
+ CallExpression,
24
+ JSXAttribute: function(node) {
25
+ if (!node.name || !classMatchingRegex.test(node.name.name)) return;
26
+ if (node.value && node.value.type === 'Literal') {
27
+ visitNode(node);
28
+ } else if (node.value && node.value.type === 'JSXExpressionContainer') {
29
+ visitNode(node, node.value.expression);
30
+ }
31
+ },
32
+ SvelteAttribute: function(node) {
33
+ if (!node.key?.name || !classMatchingRegex.test(node.key.name)) return;
34
+ for (const eachValue of node.value){
35
+ visitNode(node, eachValue);
36
+ }
37
+ },
38
+ TextAttribute: function(node) {
39
+ if (!node.name || !classMatchingRegex.test(node.name)) return;
40
+ visitNode(node);
41
+ },
42
+ TaggedTemplateExpression: function(node) {
43
+ if (isFnNode(node)) {
44
+ visitNode(node, node.quasi);
45
+ return;
46
+ }
47
+ }
48
+ };
49
+ const templateBodyVisitor = {
50
+ CallExpression,
51
+ VAttribute: function(node) {
52
+ if (node.value && node.value.type === 'VLiteral') {
53
+ visitNode(node);
54
+ } else if (node.value && node.value.type === 'VExpressionContainer' && node.value.expression.type === 'ArrayExpression') {
55
+ node.value.expression.elements.forEach((arg)=>{
56
+ visitNode(node, arg);
57
+ });
58
+ } else if (node.value && node.value.type === 'VExpressionContainer' && node.value.expression.type === 'ObjectExpression') {
59
+ node.value.expression.properties.forEach((prop)=>{
60
+ visitNode(node, prop);
61
+ });
62
+ }
63
+ }
64
+ };
65
+ // @ts-expect-error defineTemplateBodyVisitor
66
+ if (context.sourceCode.parserServices == null || context.sourceCode.parserServices.defineTemplateBodyVisitor == null) {
67
+ return scriptVisitor;
68
+ } else {
69
+ // @ts-expect-error defineTemplateBodyVisitor
70
+ return context.sourceCode.parserServices.defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor);
71
+ }
72
+ }
73
+
74
+ 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 a=/([\t\n\f\r ]+)/;function f(c){if(typeof c!="string")return{classNames:[],whitespaces:[],headSpace:!1,tailSpace:!1};const s=c.split(a);s[0]===""&&s.shift(),s[s.length-1]===""&&s.pop();const t=a.test(s[0]),l=a.test(s[s.length-1]),n=(r,e)=>t?e%2!==0:e%2===0,p=(r,e)=>t?e%2===0:e%2!==0,i=s.filter(n),o=s.filter(p);return{classNames:i,whitespaces:o,headSpace:t,tailSpace:l}}export{f as default};
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 t(e){if(e.type==="TextAttribute"&&e.name==="class")return[e.valueSpan.fullStart.offset,e.valueSpan.end.offset];switch(e.value.type){case"JSXExpressionContainer":return e.value.expression.range;default:return e.value.range}}export{t as default};
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 r(e){if(e.type==="TextAttribute"&&e.name==="class")return e.value;switch(e.value.type){case"JSXExpressionContainer":return e.value.expression.value;case"VExpressionContainer":switch(e.value.expression.type){case"ArrayExpression":return e.value.expression.elements;case"ObjectExpression":return e.value.expression.properties}return e.value.expression.value;default:return e.value.value}}export{r as default};
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,40 @@
1
+ 'use strict';
2
+
3
+ function findLoc(text, lines, startLine, endLine) {
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 index = sourceCodeLine.indexOf(targetLines[checkingTargetLine].replace(/\r\n|\n/, ''));
11
+ if (index !== -1) {
12
+ if (checkingTargetLine === 0) {
13
+ resultStart = {
14
+ line: i,
15
+ column: index
16
+ };
17
+ }
18
+ if (checkingTargetLine === targetLines.length - 1) {
19
+ return {
20
+ start: resultStart,
21
+ end: {
22
+ line: i,
23
+ column: index + text.length
24
+ }
25
+ };
26
+ }
27
+ checking = true;
28
+ checkingTargetLine++;
29
+ } else {
30
+ if (checking) {
31
+ checking = false;
32
+ checkingTargetLine = 0;
33
+ resultStart = null;
34
+ }
35
+ }
36
+ }
37
+ return null;
38
+ }
39
+
40
+ module.exports = findLoc;
@@ -1 +1,38 @@
1
- function s(r,o,u,f){const c=r.match(/.+(?:\r\n|\n)?/g);let e=0,l=null,t=!1;for(let n=u;n<=f;n++){const i=o[n-1].indexOf(c[e].replace(/\r\n|\n/,""));if(i!==-1){if(e===0&&(l={line:n,column:i}),e===c.length-1)return{start:l,end:{line:n,column:i+r.length}};t=!0,e++}else t&&(t=!1,e=0,l=null)}return null}export{s as default};
1
+ function findLoc(text, lines, startLine, endLine) {
2
+ const targetLines = text.match(/.+(?:\r\n|\n)?/g);
3
+ let checkingTargetLine = 0;
4
+ let resultStart = null;
5
+ let checking = false;
6
+ for(let i = startLine; i <= endLine; i++){
7
+ const sourceCodeLine = lines[i - 1];
8
+ const index = sourceCodeLine.indexOf(targetLines[checkingTargetLine].replace(/\r\n|\n/, ''));
9
+ if (index !== -1) {
10
+ if (checkingTargetLine === 0) {
11
+ resultStart = {
12
+ line: i,
13
+ column: index
14
+ };
15
+ }
16
+ if (checkingTargetLine === targetLines.length - 1) {
17
+ return {
18
+ start: resultStart,
19
+ end: {
20
+ line: i,
21
+ column: index + text.length
22
+ }
23
+ };
24
+ }
25
+ checking = true;
26
+ checkingTargetLine++;
27
+ } else {
28
+ if (checking) {
29
+ checking = false;
30
+ checkingTargetLine = 0;
31
+ resultStart = null;
32
+ }
33
+ }
34
+ }
35
+ return null;
36
+ }
37
+
38
+ 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 l(n,o,e){let t=n.split(o);return t.shift(),t=t.join(o).split(e),t.pop(),t.join(e)}export{l as default};
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 };
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ function getTemplateElementPrefix(text, raw) {
4
+ const idx = text.indexOf(raw);
5
+ if (idx === 0) {
6
+ return '';
7
+ }
8
+ return text.split(raw).shift();
9
+ }
10
+
11
+ module.exports = getTemplateElementPrefix;