@eslint-react/ast 1.52.9 → 1.52.10-beta.1
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/index.d.mts +50 -97
- package/dist/index.d.ts +50 -97
- package/dist/index.js +520 -460
- package/dist/index.mjs +498 -459
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,523 +1,583 @@
|
|
|
1
|
-
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
2
22
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
23
|
+
//#endregion
|
|
24
|
+
const __typescript_eslint_types = __toESM(require("@typescript-eslint/types"));
|
|
25
|
+
const __eslint_react_eff = __toESM(require("@eslint-react/eff"));
|
|
26
|
+
const __typescript_eslint_utils = __toESM(require("@typescript-eslint/utils"));
|
|
27
|
+
const __typescript_eslint_typescript_estree = __toESM(require("@typescript-eslint/typescript-estree"));
|
|
28
|
+
const string_ts = __toESM(require("string-ts"));
|
|
8
29
|
|
|
9
|
-
|
|
30
|
+
//#region src/ast-array-method.ts
|
|
10
31
|
function isArrayFromCall(node, loose = true) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
32
|
+
if (node.type !== __typescript_eslint_types.AST_NODE_TYPES.CallExpression) return false;
|
|
33
|
+
if (node.callee.type !== __typescript_eslint_types.AST_NODE_TYPES.MemberExpression) return false;
|
|
34
|
+
if (node.callee.property.type !== __typescript_eslint_types.AST_NODE_TYPES.Identifier) return false;
|
|
35
|
+
const name = node.callee.property.name;
|
|
36
|
+
return name === "from" || loose && name.startsWith("from");
|
|
16
37
|
}
|
|
17
38
|
function isArrayMapCall(node, loose = true) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
39
|
+
if (node.type !== __typescript_eslint_types.AST_NODE_TYPES.CallExpression) return false;
|
|
40
|
+
if (node.callee.type !== __typescript_eslint_types.AST_NODE_TYPES.MemberExpression) return false;
|
|
41
|
+
if (node.callee.property.type !== __typescript_eslint_types.AST_NODE_TYPES.Identifier) return false;
|
|
42
|
+
const name = node.callee.property.name;
|
|
43
|
+
return name === "map" || loose && name.endsWith("Map");
|
|
23
44
|
}
|
|
24
45
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/ast-array-method-callback.ts
|
|
48
|
+
const indexParamPosition = new Map([
|
|
49
|
+
["every", 1],
|
|
50
|
+
["filter", 1],
|
|
51
|
+
["find", 1],
|
|
52
|
+
["findIndex", 1],
|
|
53
|
+
["findLast", 1],
|
|
54
|
+
["findLastIndex", 1],
|
|
55
|
+
["flatMap", 1],
|
|
56
|
+
["forEach", 1],
|
|
57
|
+
["map", 1],
|
|
58
|
+
["reduce", 2],
|
|
59
|
+
["reduceRight", 2],
|
|
60
|
+
["some", 1]
|
|
39
61
|
]);
|
|
40
62
|
function getArrayMethodCallbackIndexParamPosition(methodName) {
|
|
41
|
-
|
|
63
|
+
return indexParamPosition.get(methodName) ?? -1;
|
|
42
64
|
}
|
|
65
|
+
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/ast-class-id.ts
|
|
68
|
+
/**
|
|
69
|
+
* Gets class identifier from ClassDeclaration or ClassExpression
|
|
70
|
+
* @param node The AST node to check
|
|
71
|
+
* @returns class identifier or null
|
|
72
|
+
*/
|
|
43
73
|
function getClassId(node) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
return eff.unit;
|
|
74
|
+
if (node.id != null) return node.id;
|
|
75
|
+
if (node.parent.type === __typescript_eslint_types.AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === __typescript_eslint_types.AST_NODE_TYPES.Identifier) return node.parent.id;
|
|
76
|
+
return __eslint_react_eff.unit;
|
|
49
77
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
types.AST_NODE_TYPES.FunctionDeclaration,
|
|
60
|
-
types.AST_NODE_TYPES.FunctionExpression,
|
|
61
|
-
types.AST_NODE_TYPES.TSCallSignatureDeclaration,
|
|
62
|
-
types.AST_NODE_TYPES.TSConstructSignatureDeclaration,
|
|
63
|
-
types.AST_NODE_TYPES.TSDeclareFunction,
|
|
64
|
-
types.AST_NODE_TYPES.TSEmptyBodyFunctionExpression,
|
|
65
|
-
types.AST_NODE_TYPES.TSFunctionType,
|
|
66
|
-
types.AST_NODE_TYPES.TSMethodSignature
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/ast-is.ts
|
|
81
|
+
const is = __typescript_eslint_utils.ASTUtils.isNodeOfType;
|
|
82
|
+
const isOneOf = __typescript_eslint_utils.ASTUtils.isNodeOfTypes;
|
|
83
|
+
const isFunction = isOneOf([
|
|
84
|
+
__typescript_eslint_types.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
85
|
+
__typescript_eslint_types.AST_NODE_TYPES.FunctionDeclaration,
|
|
86
|
+
__typescript_eslint_types.AST_NODE_TYPES.FunctionExpression
|
|
67
87
|
]);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
88
|
+
const isFunctionType = isOneOf([
|
|
89
|
+
__typescript_eslint_types.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
90
|
+
__typescript_eslint_types.AST_NODE_TYPES.FunctionDeclaration,
|
|
91
|
+
__typescript_eslint_types.AST_NODE_TYPES.FunctionExpression,
|
|
92
|
+
__typescript_eslint_types.AST_NODE_TYPES.TSCallSignatureDeclaration,
|
|
93
|
+
__typescript_eslint_types.AST_NODE_TYPES.TSConstructSignatureDeclaration,
|
|
94
|
+
__typescript_eslint_types.AST_NODE_TYPES.TSDeclareFunction,
|
|
95
|
+
__typescript_eslint_types.AST_NODE_TYPES.TSEmptyBodyFunctionExpression,
|
|
96
|
+
__typescript_eslint_types.AST_NODE_TYPES.TSFunctionType,
|
|
97
|
+
__typescript_eslint_types.AST_NODE_TYPES.TSMethodSignature
|
|
72
98
|
]);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
99
|
+
const isClass = isOneOf([__typescript_eslint_types.AST_NODE_TYPES.ClassDeclaration, __typescript_eslint_types.AST_NODE_TYPES.ClassExpression]);
|
|
100
|
+
const isMethodOrProperty = isOneOf([__typescript_eslint_types.AST_NODE_TYPES.PropertyDefinition, __typescript_eslint_types.AST_NODE_TYPES.MethodDefinition]);
|
|
101
|
+
const isProperty = isOneOf([
|
|
102
|
+
__typescript_eslint_types.AST_NODE_TYPES.PropertyDefinition,
|
|
103
|
+
__typescript_eslint_types.AST_NODE_TYPES.TSIndexSignature,
|
|
104
|
+
__typescript_eslint_types.AST_NODE_TYPES.TSParameterProperty,
|
|
105
|
+
__typescript_eslint_types.AST_NODE_TYPES.TSPropertySignature
|
|
78
106
|
]);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
107
|
+
const isJSXElement = is(__typescript_eslint_types.AST_NODE_TYPES.JSXElement);
|
|
108
|
+
const isJSXFragment = is(__typescript_eslint_types.AST_NODE_TYPES.JSXFragment);
|
|
109
|
+
const isJSXTagNameExpression = isOneOf([
|
|
110
|
+
__typescript_eslint_types.AST_NODE_TYPES.JSXIdentifier,
|
|
111
|
+
__typescript_eslint_types.AST_NODE_TYPES.JSXMemberExpression,
|
|
112
|
+
__typescript_eslint_types.AST_NODE_TYPES.JSXNamespacedName
|
|
85
113
|
]);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
114
|
+
const isJSX = isOneOf([
|
|
115
|
+
__typescript_eslint_types.AST_NODE_TYPES.JSXAttribute,
|
|
116
|
+
__typescript_eslint_types.AST_NODE_TYPES.JSXClosingElement,
|
|
117
|
+
__typescript_eslint_types.AST_NODE_TYPES.JSXClosingFragment,
|
|
118
|
+
__typescript_eslint_types.AST_NODE_TYPES.JSXElement,
|
|
119
|
+
__typescript_eslint_types.AST_NODE_TYPES.JSXEmptyExpression,
|
|
120
|
+
__typescript_eslint_types.AST_NODE_TYPES.JSXExpressionContainer,
|
|
121
|
+
__typescript_eslint_types.AST_NODE_TYPES.JSXFragment,
|
|
122
|
+
__typescript_eslint_types.AST_NODE_TYPES.JSXIdentifier,
|
|
123
|
+
__typescript_eslint_types.AST_NODE_TYPES.JSXMemberExpression,
|
|
124
|
+
__typescript_eslint_types.AST_NODE_TYPES.JSXNamespacedName,
|
|
125
|
+
__typescript_eslint_types.AST_NODE_TYPES.JSXOpeningElement,
|
|
126
|
+
__typescript_eslint_types.AST_NODE_TYPES.JSXOpeningFragment,
|
|
127
|
+
__typescript_eslint_types.AST_NODE_TYPES.JSXSpreadAttribute,
|
|
128
|
+
__typescript_eslint_types.AST_NODE_TYPES.JSXSpreadChild,
|
|
129
|
+
__typescript_eslint_types.AST_NODE_TYPES.JSXText
|
|
102
130
|
]);
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
131
|
+
const isLoop = isOneOf([
|
|
132
|
+
__typescript_eslint_types.AST_NODE_TYPES.DoWhileStatement,
|
|
133
|
+
__typescript_eslint_types.AST_NODE_TYPES.ForInStatement,
|
|
134
|
+
__typescript_eslint_types.AST_NODE_TYPES.ForOfStatement,
|
|
135
|
+
__typescript_eslint_types.AST_NODE_TYPES.ForStatement,
|
|
136
|
+
__typescript_eslint_types.AST_NODE_TYPES.WhileStatement
|
|
109
137
|
]);
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
138
|
+
const isTypeExpression = isOneOf([
|
|
139
|
+
__typescript_eslint_types.AST_NODE_TYPES.TSAsExpression,
|
|
140
|
+
__typescript_eslint_types.AST_NODE_TYPES.TSTypeAssertion,
|
|
141
|
+
__typescript_eslint_types.AST_NODE_TYPES.TSNonNullExpression,
|
|
142
|
+
__typescript_eslint_types.AST_NODE_TYPES.TSSatisfiesExpression,
|
|
143
|
+
__typescript_eslint_types.AST_NODE_TYPES.TSInstantiationExpression
|
|
116
144
|
]);
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
145
|
+
const isTypeAssertionExpression = isOneOf([
|
|
146
|
+
__typescript_eslint_types.AST_NODE_TYPES.TSAsExpression,
|
|
147
|
+
__typescript_eslint_types.AST_NODE_TYPES.TSTypeAssertion,
|
|
148
|
+
__typescript_eslint_types.AST_NODE_TYPES.TSNonNullExpression,
|
|
149
|
+
__typescript_eslint_types.AST_NODE_TYPES.TSSatisfiesExpression
|
|
122
150
|
]);
|
|
123
151
|
|
|
124
|
-
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region src/ast-expression.ts
|
|
154
|
+
/**
|
|
155
|
+
* Recursively get the inner expression until it's not a TypeExpression
|
|
156
|
+
* @param node - The node to get the expression from
|
|
157
|
+
* @returns The inner expression
|
|
158
|
+
*/
|
|
125
159
|
function getJSExpression(node) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
return node;
|
|
160
|
+
if (isTypeExpression(node)) return getJSExpression(node.expression);
|
|
161
|
+
return node;
|
|
130
162
|
}
|
|
131
163
|
function isThisExpression(node) {
|
|
132
|
-
|
|
164
|
+
return getJSExpression(node).type === __typescript_eslint_types.AST_NODE_TYPES.ThisExpression;
|
|
133
165
|
}
|
|
166
|
+
|
|
167
|
+
//#endregion
|
|
168
|
+
//#region src/ast-function-id.ts
|
|
134
169
|
function getFunctionId(node) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
// {MaybeComponent: () => {}}
|
|
146
|
-
// {MaybeComponent() {}}
|
|
147
|
-
case (node.parent.type === types.AST_NODE_TYPES.Property && node.parent.value === node && !node.parent.computed && node.parent.key.type === types.AST_NODE_TYPES.Identifier):
|
|
148
|
-
return node.parent.key;
|
|
149
|
-
// class {MaybeComponent = () => {}}
|
|
150
|
-
// class {MaybeComponent() {}}
|
|
151
|
-
case (isMethodOrProperty(node.parent) && node.parent.value === node && node.parent.key.type === types.AST_NODE_TYPES.Identifier):
|
|
152
|
-
return node.parent.key;
|
|
153
|
-
// Follow spec convention for `IsAnonymousFunctionDefinition()` usage.
|
|
154
|
-
//
|
|
155
|
-
// const {MaybeComponent = () => {}} = {};
|
|
156
|
-
// ({MaybeComponent = () => {}} = {});
|
|
157
|
-
case (node.parent.type === types.AST_NODE_TYPES.AssignmentPattern && node.parent.right === node && node.parent.left.type === types.AST_NODE_TYPES.Identifier):
|
|
158
|
-
return node.parent.left;
|
|
159
|
-
// const MaybeComponent = (() => {})!;
|
|
160
|
-
// const MaybeComponent = (() => {}) as FunctionComponent;
|
|
161
|
-
// const MaybeComponent = (() => {}) satisfies FunctionComponent;
|
|
162
|
-
case isTypeAssertionExpression(node.parent):
|
|
163
|
-
return getFunctionId(node.parent);
|
|
164
|
-
}
|
|
165
|
-
return eff.unit;
|
|
170
|
+
switch (true) {
|
|
171
|
+
case "id" in node && node.id != null: return node.id;
|
|
172
|
+
case node.parent.type === __typescript_eslint_types.AST_NODE_TYPES.VariableDeclarator && node.parent.init === node && node.parent.id.type === __typescript_eslint_types.AST_NODE_TYPES.Identifier: return node.parent.id;
|
|
173
|
+
case node.parent.type === __typescript_eslint_types.AST_NODE_TYPES.AssignmentExpression && node.parent.right === node && node.parent.operator === "=" && node.parent.left.type === __typescript_eslint_types.AST_NODE_TYPES.Identifier: return node.parent.left;
|
|
174
|
+
case node.parent.type === __typescript_eslint_types.AST_NODE_TYPES.Property && node.parent.value === node && !node.parent.computed && node.parent.key.type === __typescript_eslint_types.AST_NODE_TYPES.Identifier: return node.parent.key;
|
|
175
|
+
case isMethodOrProperty(node.parent) && node.parent.value === node && node.parent.key.type === __typescript_eslint_types.AST_NODE_TYPES.Identifier: return node.parent.key;
|
|
176
|
+
case node.parent.type === __typescript_eslint_types.AST_NODE_TYPES.AssignmentPattern && node.parent.right === node && node.parent.left.type === __typescript_eslint_types.AST_NODE_TYPES.Identifier: return node.parent.left;
|
|
177
|
+
case isTypeAssertionExpression(node.parent): return getFunctionId(node.parent);
|
|
178
|
+
}
|
|
179
|
+
return __eslint_react_eff.unit;
|
|
166
180
|
}
|
|
181
|
+
|
|
182
|
+
//#endregion
|
|
183
|
+
//#region src/ast-function-init-path.ts
|
|
167
184
|
function getFunctionInitPath(node) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
185
|
+
if (node.type === __typescript_eslint_types.AST_NODE_TYPES.FunctionDeclaration) return [node];
|
|
186
|
+
const { parent } = node;
|
|
187
|
+
switch (true) {
|
|
188
|
+
case parent.type === __typescript_eslint_types.AST_NODE_TYPES.VariableDeclarator: return [
|
|
189
|
+
parent.parent,
|
|
190
|
+
parent,
|
|
191
|
+
node
|
|
192
|
+
];
|
|
193
|
+
case parent.type === __typescript_eslint_types.AST_NODE_TYPES.CallExpression && parent.parent.type === __typescript_eslint_types.AST_NODE_TYPES.VariableDeclarator: return [
|
|
194
|
+
parent.parent.parent,
|
|
195
|
+
parent.parent,
|
|
196
|
+
parent,
|
|
197
|
+
node
|
|
198
|
+
];
|
|
199
|
+
case parent.type === __typescript_eslint_types.AST_NODE_TYPES.CallExpression && parent.parent.type === __typescript_eslint_types.AST_NODE_TYPES.CallExpression && parent.parent.parent.type === __typescript_eslint_types.AST_NODE_TYPES.VariableDeclarator: return [
|
|
200
|
+
parent.parent.parent.parent,
|
|
201
|
+
parent.parent.parent,
|
|
202
|
+
parent.parent,
|
|
203
|
+
parent,
|
|
204
|
+
node
|
|
205
|
+
];
|
|
206
|
+
case parent.type === __typescript_eslint_types.AST_NODE_TYPES.Property && parent.parent.type === __typescript_eslint_types.AST_NODE_TYPES.ObjectExpression && parent.parent.parent.type === __typescript_eslint_types.AST_NODE_TYPES.VariableDeclarator: return [
|
|
207
|
+
parent.parent.parent.parent,
|
|
208
|
+
parent.parent.parent,
|
|
209
|
+
parent.parent,
|
|
210
|
+
parent,
|
|
211
|
+
node
|
|
212
|
+
];
|
|
213
|
+
case parent.type === __typescript_eslint_types.AST_NODE_TYPES.MethodDefinition && parent.parent.parent.type === __typescript_eslint_types.AST_NODE_TYPES.ClassDeclaration: return [
|
|
214
|
+
parent.parent.parent,
|
|
215
|
+
parent.parent,
|
|
216
|
+
parent,
|
|
217
|
+
node
|
|
218
|
+
];
|
|
219
|
+
case parent.type === __typescript_eslint_types.AST_NODE_TYPES.PropertyDefinition && parent.parent.parent.type === __typescript_eslint_types.AST_NODE_TYPES.ClassDeclaration: return [
|
|
220
|
+
parent.parent.parent,
|
|
221
|
+
parent.parent,
|
|
222
|
+
parent,
|
|
223
|
+
node
|
|
224
|
+
];
|
|
225
|
+
}
|
|
226
|
+
return __eslint_react_eff.unit;
|
|
187
227
|
}
|
|
188
228
|
function hasCallInFunctionInitPath(callName, initPath) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
return "name" in n.callee.property && n.callee.property.name === callName;
|
|
198
|
-
default:
|
|
199
|
-
return false;
|
|
200
|
-
}
|
|
201
|
-
});
|
|
229
|
+
return initPath.some((n) => {
|
|
230
|
+
if (n.type !== __typescript_eslint_types.AST_NODE_TYPES.CallExpression) return false;
|
|
231
|
+
switch (n.callee.type) {
|
|
232
|
+
case __typescript_eslint_types.AST_NODE_TYPES.Identifier: return n.callee.name === callName;
|
|
233
|
+
case __typescript_eslint_types.AST_NODE_TYPES.MemberExpression: return "name" in n.callee.property && n.callee.property.name === callName;
|
|
234
|
+
default: return false;
|
|
235
|
+
}
|
|
236
|
+
});
|
|
202
237
|
}
|
|
238
|
+
|
|
239
|
+
//#endregion
|
|
240
|
+
//#region src/ast-function-is.ts
|
|
203
241
|
function isEmptyFunction(node) {
|
|
204
|
-
|
|
242
|
+
return node.body.type === __typescript_eslint_types.AST_NODE_TYPES.BlockStatement && node.body.body.length === 0;
|
|
205
243
|
}
|
|
244
|
+
|
|
245
|
+
//#endregion
|
|
246
|
+
//#region src/ast-hierarchy.ts
|
|
206
247
|
function findParentNode(node, test) {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
return eff.unit;
|
|
248
|
+
if (node == null) return __eslint_react_eff.unit;
|
|
249
|
+
let parent = node.parent;
|
|
250
|
+
while (parent != null && parent.type !== __typescript_eslint_types.AST_NODE_TYPES.Program) {
|
|
251
|
+
if (test(parent)) return parent;
|
|
252
|
+
parent = parent.parent;
|
|
253
|
+
}
|
|
254
|
+
return __eslint_react_eff.unit;
|
|
216
255
|
}
|
|
256
|
+
/**
|
|
257
|
+
* Get all nested identifiers in a expression like node
|
|
258
|
+
* @param node The node to get the nested identifiers from
|
|
259
|
+
* @returns All nested identifiers
|
|
260
|
+
*/
|
|
217
261
|
function getNestedIdentifiers(node) {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}
|
|
278
|
-
return identifiers;
|
|
262
|
+
const identifiers = [];
|
|
263
|
+
if (node.type === __typescript_eslint_types.AST_NODE_TYPES.Identifier) identifiers.push(node);
|
|
264
|
+
if ("arguments" in node) {
|
|
265
|
+
const chunk = node.arguments.map(getNestedIdentifiers).flat(1);
|
|
266
|
+
identifiers.push(...chunk);
|
|
267
|
+
}
|
|
268
|
+
if ("elements" in node) {
|
|
269
|
+
const chunk = node.elements.filter((x) => x != null).map(getNestedIdentifiers).flat(1);
|
|
270
|
+
identifiers.push(...chunk);
|
|
271
|
+
}
|
|
272
|
+
if ("properties" in node) {
|
|
273
|
+
const chunk = node.properties.map(getNestedIdentifiers).flat(1);
|
|
274
|
+
identifiers.push(...chunk);
|
|
275
|
+
}
|
|
276
|
+
if ("expressions" in node) {
|
|
277
|
+
const chunk = node.expressions.map(getNestedIdentifiers).flat(1);
|
|
278
|
+
identifiers.push(...chunk);
|
|
279
|
+
}
|
|
280
|
+
if ("left" in node) {
|
|
281
|
+
const chunk = getNestedIdentifiers(node.left);
|
|
282
|
+
identifiers.push(...chunk);
|
|
283
|
+
}
|
|
284
|
+
if ("right" in node) {
|
|
285
|
+
const chunk = getNestedIdentifiers(node.right);
|
|
286
|
+
identifiers.push(...chunk);
|
|
287
|
+
}
|
|
288
|
+
if (node.type === __typescript_eslint_types.AST_NODE_TYPES.Property) {
|
|
289
|
+
const chunk = getNestedIdentifiers(node.value);
|
|
290
|
+
identifiers.push(...chunk);
|
|
291
|
+
}
|
|
292
|
+
if (node.type === __typescript_eslint_types.AST_NODE_TYPES.SpreadElement) {
|
|
293
|
+
const chunk = getNestedIdentifiers(node.argument);
|
|
294
|
+
identifiers.push(...chunk);
|
|
295
|
+
}
|
|
296
|
+
if (node.type === __typescript_eslint_types.AST_NODE_TYPES.MemberExpression) {
|
|
297
|
+
const chunk = getNestedIdentifiers(node.object);
|
|
298
|
+
identifiers.push(...chunk);
|
|
299
|
+
}
|
|
300
|
+
if (node.type === __typescript_eslint_types.AST_NODE_TYPES.UnaryExpression) {
|
|
301
|
+
const chunk = getNestedIdentifiers(node.argument);
|
|
302
|
+
identifiers.push(...chunk);
|
|
303
|
+
}
|
|
304
|
+
if (node.type === __typescript_eslint_types.AST_NODE_TYPES.ChainExpression) {
|
|
305
|
+
const chunk = getNestedIdentifiers(node.expression);
|
|
306
|
+
identifiers.push(...chunk);
|
|
307
|
+
}
|
|
308
|
+
if (node.type === __typescript_eslint_types.AST_NODE_TYPES.TSNonNullExpression) {
|
|
309
|
+
const chunk = getNestedIdentifiers(node.expression);
|
|
310
|
+
identifiers.push(...chunk);
|
|
311
|
+
}
|
|
312
|
+
if (node.type === __typescript_eslint_types.AST_NODE_TYPES.TSAsExpression) {
|
|
313
|
+
const chunk = getNestedIdentifiers(node.expression);
|
|
314
|
+
identifiers.push(...chunk);
|
|
315
|
+
}
|
|
316
|
+
if (node.type === __typescript_eslint_types.AST_NODE_TYPES.TSSatisfiesExpression) {
|
|
317
|
+
const chunk = getNestedIdentifiers(node.expression);
|
|
318
|
+
identifiers.push(...chunk);
|
|
319
|
+
}
|
|
320
|
+
return identifiers;
|
|
279
321
|
}
|
|
322
|
+
/**
|
|
323
|
+
* Gets the nested return statements in the node that are within the same function
|
|
324
|
+
* @param node The AST node
|
|
325
|
+
* @returns The nested return statements in the node
|
|
326
|
+
*/
|
|
280
327
|
function getNestedReturnStatements(node) {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
statements.push(node2);
|
|
293
|
-
}
|
|
294
|
-
});
|
|
295
|
-
return statements;
|
|
328
|
+
const statements = [];
|
|
329
|
+
const boundaryNode = isFunction(node) ? node : findParentNode(node, isFunction);
|
|
330
|
+
(0, __typescript_eslint_typescript_estree.simpleTraverse)(node, { enter(node$1) {
|
|
331
|
+
if (node$1.type !== __typescript_eslint_types.AST_NODE_TYPES.ReturnStatement) return;
|
|
332
|
+
const parentFunction = findParentNode(node$1, isFunction);
|
|
333
|
+
if (parentFunction !== boundaryNode) return;
|
|
334
|
+
statements.push(node$1);
|
|
335
|
+
} });
|
|
336
|
+
return statements;
|
|
296
337
|
}
|
|
338
|
+
/**
|
|
339
|
+
* Get all nested expressions of type T in an expression like node
|
|
340
|
+
* @param type The type of the expression to retrieve within the node
|
|
341
|
+
* @returns A partially applied function bound to a predicate of type T. The returned function can be called passing a
|
|
342
|
+
* node, and it will return an array of all nested expressions of type T.
|
|
343
|
+
*/
|
|
297
344
|
function getNestedExpressionsOfType(type) {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
return expressions;
|
|
378
|
-
};
|
|
345
|
+
const isNodeOfType = is(type);
|
|
346
|
+
return function(node) {
|
|
347
|
+
const boundGetNestedExpressionsOfType = getNestedExpressionsOfType(type);
|
|
348
|
+
const expressions = [];
|
|
349
|
+
if (isNodeOfType(node)) expressions.push(node);
|
|
350
|
+
if ("arguments" in node) {
|
|
351
|
+
const chunk = node.arguments.map(getNestedExpressionsOfType(type)).flat(1);
|
|
352
|
+
expressions.push(...chunk);
|
|
353
|
+
}
|
|
354
|
+
if ("expression" in node && node.expression !== true && node.expression !== false) {
|
|
355
|
+
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
356
|
+
expressions.push(...chunk);
|
|
357
|
+
}
|
|
358
|
+
if ("left" in node) {
|
|
359
|
+
const chunk = boundGetNestedExpressionsOfType(node.left);
|
|
360
|
+
expressions.push(...chunk);
|
|
361
|
+
}
|
|
362
|
+
if ("right" in node) {
|
|
363
|
+
const chunk = boundGetNestedExpressionsOfType(node.right);
|
|
364
|
+
expressions.push(...chunk);
|
|
365
|
+
}
|
|
366
|
+
if ("test" in node && node.test != null) {
|
|
367
|
+
const chunk = boundGetNestedExpressionsOfType(node.test);
|
|
368
|
+
expressions.push(...chunk);
|
|
369
|
+
}
|
|
370
|
+
if ("consequent" in node) {
|
|
371
|
+
const chunk = Array.isArray(node.consequent) ? node.consequent.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.consequent);
|
|
372
|
+
expressions.push(...chunk);
|
|
373
|
+
}
|
|
374
|
+
if ("alternate" in node && node.alternate != null) {
|
|
375
|
+
const chunk = Array.isArray(node.alternate) ? node.alternate.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.alternate);
|
|
376
|
+
expressions.push(...chunk);
|
|
377
|
+
}
|
|
378
|
+
if ("elements" in node) {
|
|
379
|
+
const chunk = node.elements.filter((x) => x != null).map(getNestedExpressionsOfType(type)).flat(1);
|
|
380
|
+
expressions.push(...chunk);
|
|
381
|
+
}
|
|
382
|
+
if ("properties" in node) {
|
|
383
|
+
const chunk = node.properties.map(boundGetNestedExpressionsOfType).flat(1);
|
|
384
|
+
expressions.push(...chunk);
|
|
385
|
+
}
|
|
386
|
+
if ("expressions" in node) {
|
|
387
|
+
const chunk = node.expressions.map(boundGetNestedExpressionsOfType).flat(1);
|
|
388
|
+
expressions.push(...chunk);
|
|
389
|
+
}
|
|
390
|
+
if (node.type === __typescript_eslint_types.AST_NODE_TYPES.Property) {
|
|
391
|
+
const chunk = boundGetNestedExpressionsOfType(node.value);
|
|
392
|
+
expressions.push(...chunk);
|
|
393
|
+
}
|
|
394
|
+
if (node.type === __typescript_eslint_types.AST_NODE_TYPES.SpreadElement) {
|
|
395
|
+
const chunk = boundGetNestedExpressionsOfType(node.argument);
|
|
396
|
+
expressions.push(...chunk);
|
|
397
|
+
}
|
|
398
|
+
if (node.type === __typescript_eslint_types.AST_NODE_TYPES.MemberExpression) {
|
|
399
|
+
const chunk = boundGetNestedExpressionsOfType(node.object);
|
|
400
|
+
expressions.push(...chunk);
|
|
401
|
+
}
|
|
402
|
+
if (node.type === __typescript_eslint_types.AST_NODE_TYPES.UnaryExpression) {
|
|
403
|
+
const chunk = boundGetNestedExpressionsOfType(node.argument);
|
|
404
|
+
expressions.push(...chunk);
|
|
405
|
+
}
|
|
406
|
+
if (node.type === __typescript_eslint_types.AST_NODE_TYPES.ChainExpression) {
|
|
407
|
+
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
408
|
+
expressions.push(...chunk);
|
|
409
|
+
}
|
|
410
|
+
if (node.type === __typescript_eslint_types.AST_NODE_TYPES.TSNonNullExpression) {
|
|
411
|
+
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
412
|
+
expressions.push(...chunk);
|
|
413
|
+
}
|
|
414
|
+
if (node.type === __typescript_eslint_types.AST_NODE_TYPES.TSAsExpression) {
|
|
415
|
+
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
416
|
+
expressions.push(...chunk);
|
|
417
|
+
}
|
|
418
|
+
if (node.type === __typescript_eslint_types.AST_NODE_TYPES.TSSatisfiesExpression) {
|
|
419
|
+
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
420
|
+
expressions.push(...chunk);
|
|
421
|
+
}
|
|
422
|
+
return expressions;
|
|
423
|
+
};
|
|
379
424
|
}
|
|
380
|
-
|
|
381
|
-
|
|
425
|
+
/**
|
|
426
|
+
* Get all nested new expressions in an expression like node
|
|
427
|
+
* @param node The node to get the nested new expressions from
|
|
428
|
+
* @returns All nested new expressions
|
|
429
|
+
*/
|
|
430
|
+
const getNestedNewExpressions = getNestedExpressionsOfType(__typescript_eslint_types.AST_NODE_TYPES.NewExpression);
|
|
431
|
+
/**
|
|
432
|
+
* Get all nested call expressions in a expression like node
|
|
433
|
+
* @param node The node to get the nested call expressions from
|
|
434
|
+
* @returns All nested call expressions
|
|
435
|
+
*/
|
|
436
|
+
const getNestedCallExpressions = getNestedExpressionsOfType(__typescript_eslint_types.AST_NODE_TYPES.CallExpression);
|
|
437
|
+
|
|
438
|
+
//#endregion
|
|
439
|
+
//#region src/ast-line.ts
|
|
440
|
+
/**
|
|
441
|
+
* Check if a node is multiline
|
|
442
|
+
* @param node The AST node to check
|
|
443
|
+
* @returns `true` if the node is multiline
|
|
444
|
+
*/
|
|
382
445
|
function isMultiLine(node) {
|
|
383
|
-
|
|
446
|
+
return node.loc.start.line !== node.loc.end.line;
|
|
384
447
|
}
|
|
448
|
+
/**
|
|
449
|
+
* Check if a node is a line break
|
|
450
|
+
* @param node The AST node to check
|
|
451
|
+
* @returns boolean
|
|
452
|
+
*/
|
|
385
453
|
function isLineBreak(node) {
|
|
386
|
-
|
|
454
|
+
return isOneOf([__typescript_eslint_types.AST_NODE_TYPES.Literal, __typescript_eslint_types.AST_NODE_TYPES.JSXText])(node) && typeof node.value === "string" && node.value.trim() === "" && isMultiLine(node);
|
|
387
455
|
}
|
|
456
|
+
|
|
457
|
+
//#endregion
|
|
458
|
+
//#region src/ast-literal-is.ts
|
|
388
459
|
function isLiteral(node, type) {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
case "regexp":
|
|
399
|
-
return "regex" in node;
|
|
400
|
-
case "string":
|
|
401
|
-
return typeof node.value === "string";
|
|
402
|
-
}
|
|
460
|
+
if (node.type !== __typescript_eslint_types.AST_NODE_TYPES.Literal) return false;
|
|
461
|
+
if (type == null) return true;
|
|
462
|
+
switch (type) {
|
|
463
|
+
case "boolean": return typeof node.value === "boolean";
|
|
464
|
+
case "null": return node.value === null;
|
|
465
|
+
case "number": return typeof node.value === "number";
|
|
466
|
+
case "regexp": return "regex" in node;
|
|
467
|
+
case "string": return typeof node.value === "string";
|
|
468
|
+
}
|
|
403
469
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
return false;
|
|
443
|
-
}
|
|
444
|
-
if (a.value == null || b.value == null) {
|
|
445
|
-
return a.value === b.value;
|
|
446
|
-
}
|
|
447
|
-
return isNodeEqual(a.value, b.value);
|
|
448
|
-
}
|
|
449
|
-
case (a.type === types.AST_NODE_TYPES.ThisExpression && b.type === types.AST_NODE_TYPES.ThisExpression):
|
|
450
|
-
return true;
|
|
451
|
-
default:
|
|
452
|
-
return false;
|
|
453
|
-
}
|
|
470
|
+
|
|
471
|
+
//#endregion
|
|
472
|
+
//#region src/ast-node-equal.ts
|
|
473
|
+
/**
|
|
474
|
+
* Determines whether node equals to another node
|
|
475
|
+
* @param a node to compare
|
|
476
|
+
* @param b node to compare
|
|
477
|
+
* @returns `true` if node equal
|
|
478
|
+
* @see https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/util/isNodeEqual.ts
|
|
479
|
+
*/
|
|
480
|
+
const isNodeEqual = (0, __eslint_react_eff.dual)(2, (a, b) => {
|
|
481
|
+
switch (true) {
|
|
482
|
+
case a === b: return true;
|
|
483
|
+
case a.type !== b.type: return false;
|
|
484
|
+
case a.type === __typescript_eslint_types.AST_NODE_TYPES.Literal && b.type === __typescript_eslint_types.AST_NODE_TYPES.Literal: return a.value === b.value;
|
|
485
|
+
case a.type === __typescript_eslint_types.AST_NODE_TYPES.TemplateElement && b.type === __typescript_eslint_types.AST_NODE_TYPES.TemplateElement: return a.value.raw === b.value.raw;
|
|
486
|
+
case a.type === __typescript_eslint_types.AST_NODE_TYPES.TemplateLiteral && b.type === __typescript_eslint_types.AST_NODE_TYPES.TemplateLiteral: {
|
|
487
|
+
if (a.quasis.length !== b.quasis.length || a.expressions.length !== b.expressions.length) return false;
|
|
488
|
+
let i = a.quasis.length;
|
|
489
|
+
while (i--) if (a.quasis[i]?.value.raw !== b.quasis[i]?.value.raw) return false;
|
|
490
|
+
i = a.expressions.length;
|
|
491
|
+
while (i--) {
|
|
492
|
+
const exprA = a.expressions[i];
|
|
493
|
+
const exprB = b.expressions[i];
|
|
494
|
+
if (!isNodeEqual(exprA, exprB)) return false;
|
|
495
|
+
}
|
|
496
|
+
return true;
|
|
497
|
+
}
|
|
498
|
+
case a.type === __typescript_eslint_types.AST_NODE_TYPES.Identifier && b.type === __typescript_eslint_types.AST_NODE_TYPES.Identifier: return a.name === b.name;
|
|
499
|
+
case a.type === __typescript_eslint_types.AST_NODE_TYPES.PrivateIdentifier && b.type === __typescript_eslint_types.AST_NODE_TYPES.PrivateIdentifier: return a.name === b.name;
|
|
500
|
+
case a.type === __typescript_eslint_types.AST_NODE_TYPES.MemberExpression && b.type === __typescript_eslint_types.AST_NODE_TYPES.MemberExpression: return isNodeEqual(a.property, b.property) && isNodeEqual(a.object, b.object);
|
|
501
|
+
case a.type === __typescript_eslint_types.AST_NODE_TYPES.JSXAttribute && b.type === __typescript_eslint_types.AST_NODE_TYPES.JSXAttribute:
|
|
502
|
+
if (a.name.name !== b.name.name) return false;
|
|
503
|
+
if (a.value == null || b.value == null) return a.value === b.value;
|
|
504
|
+
return isNodeEqual(a.value, b.value);
|
|
505
|
+
case a.type === __typescript_eslint_types.AST_NODE_TYPES.ThisExpression && b.type === __typescript_eslint_types.AST_NODE_TYPES.ThisExpression: return true;
|
|
506
|
+
default: return false;
|
|
507
|
+
}
|
|
454
508
|
});
|
|
509
|
+
|
|
510
|
+
//#endregion
|
|
511
|
+
//#region src/ast-process-env-node-env.ts
|
|
512
|
+
/**
|
|
513
|
+
* Check if the given node is a member expression that accesses `process.env.NODE_ENV`
|
|
514
|
+
* @param node The AST node
|
|
515
|
+
* @returns True if the node is a member expression that accesses `process.env.NODE_ENV`, false otherwise
|
|
516
|
+
*/
|
|
455
517
|
function isProcessEnvNodeEnv(node) {
|
|
456
|
-
|
|
518
|
+
return node != null && node.type === __typescript_eslint_types.AST_NODE_TYPES.MemberExpression && node.object.type === __typescript_eslint_types.AST_NODE_TYPES.MemberExpression && node.object.object.type === __typescript_eslint_types.AST_NODE_TYPES.Identifier && node.object.object.name === "process" && node.object.property.type === __typescript_eslint_types.AST_NODE_TYPES.Identifier && node.object.property.name === "env" && node.property.type === __typescript_eslint_types.AST_NODE_TYPES.Identifier && node.property.name === "NODE_ENV";
|
|
457
519
|
}
|
|
520
|
+
/**
|
|
521
|
+
* Check if the given node is a binary expression that compares `process.env.NODE_ENV` with a string literal
|
|
522
|
+
* @param node The AST node
|
|
523
|
+
* @param operator The operator used in the comparison
|
|
524
|
+
* @param value The string literal value to compare against
|
|
525
|
+
* @returns True if the node is a binary expression that compares `process.env.NODE_ENV` with the specified value, false otherwise
|
|
526
|
+
*/
|
|
458
527
|
function isProcessEnvNodeEnvCompare(node, operator, value) {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
if (isLiteral(node.left, "string") && isProcessEnvNodeEnv(node.right)) {
|
|
466
|
-
return node.left.value === value;
|
|
467
|
-
}
|
|
468
|
-
return false;
|
|
528
|
+
if (node == null) return false;
|
|
529
|
+
if (node.type !== __typescript_eslint_types.AST_NODE_TYPES.BinaryExpression) return false;
|
|
530
|
+
if (node.operator !== operator) return false;
|
|
531
|
+
if (isProcessEnvNodeEnv(node.left) && isLiteral(node.right, "string")) return node.right.value === value;
|
|
532
|
+
if (isLiteral(node.left, "string") && isProcessEnvNodeEnv(node.right)) return node.left.value === value;
|
|
533
|
+
return false;
|
|
469
534
|
}
|
|
535
|
+
|
|
536
|
+
//#endregion
|
|
537
|
+
//#region src/ast-property-name.ts
|
|
470
538
|
function getPropertyName(node) {
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
}
|
|
477
|
-
if (node.type === types.AST_NODE_TYPES.Literal) {
|
|
478
|
-
return String(node.value);
|
|
479
|
-
}
|
|
480
|
-
if (node.type === types.AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
|
|
481
|
-
return node.quasis[0]?.value.raw;
|
|
482
|
-
}
|
|
483
|
-
return eff.unit;
|
|
539
|
+
if (isTypeExpression(node)) return getPropertyName(getJSExpression(node));
|
|
540
|
+
if (node.type === __typescript_eslint_types.AST_NODE_TYPES.Identifier || node.type === __typescript_eslint_types.AST_NODE_TYPES.PrivateIdentifier) return node.name;
|
|
541
|
+
if (node.type === __typescript_eslint_types.AST_NODE_TYPES.Literal) return String(node.value);
|
|
542
|
+
if (node.type === __typescript_eslint_types.AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) return node.quasis[0]?.value.raw;
|
|
543
|
+
return __eslint_react_eff.unit;
|
|
484
544
|
}
|
|
545
|
+
|
|
546
|
+
//#endregion
|
|
547
|
+
//#region src/ast-to-string.ts
|
|
485
548
|
function getLiteralValueType(input) {
|
|
486
|
-
|
|
487
|
-
|
|
549
|
+
if (input === null) return "null";
|
|
550
|
+
return typeof input;
|
|
488
551
|
}
|
|
489
552
|
function toDelimiterCaseType(node, delimiter = " ") {
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
if (isJSX(node)) {
|
|
497
|
-
return `JSX ${stringTs.toLowerCase(stringTs.delimiterCase(stringTs.replace(node.type, "JSX", ""), delimiter))}`;
|
|
498
|
-
}
|
|
499
|
-
return stringTs.toLowerCase(stringTs.delimiterCase(node.type, delimiter));
|
|
553
|
+
if (node.type === __typescript_eslint_types.AST_NODE_TYPES.Literal) {
|
|
554
|
+
if ("regex" in node) return "RegExp literal";
|
|
555
|
+
return `${getLiteralValueType(node.value)} literal`;
|
|
556
|
+
}
|
|
557
|
+
if (isJSX(node)) return `JSX ${(0, string_ts.toLowerCase)((0, string_ts.delimiterCase)((0, string_ts.replace)(node.type, "JSX", ""), delimiter))}`;
|
|
558
|
+
return (0, string_ts.toLowerCase)((0, string_ts.delimiterCase)(node.type, delimiter));
|
|
500
559
|
}
|
|
560
|
+
/**
|
|
561
|
+
* Returns human readable node name for given AST node
|
|
562
|
+
* @param node AST node
|
|
563
|
+
* @param getText A function that returns the text of the node in the source code
|
|
564
|
+
* @returns Human readable node name
|
|
565
|
+
*/
|
|
501
566
|
function toString(node, getText) {
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
return node.value;
|
|
514
|
-
case types.AST_NODE_TYPES.Literal:
|
|
515
|
-
return node.raw;
|
|
516
|
-
default:
|
|
517
|
-
return getText(node);
|
|
518
|
-
}
|
|
567
|
+
switch (node.type) {
|
|
568
|
+
case __typescript_eslint_types.AST_NODE_TYPES.Identifier:
|
|
569
|
+
case __typescript_eslint_types.AST_NODE_TYPES.JSXIdentifier:
|
|
570
|
+
case __typescript_eslint_types.AST_NODE_TYPES.PrivateIdentifier: return node.name;
|
|
571
|
+
case __typescript_eslint_types.AST_NODE_TYPES.MemberExpression:
|
|
572
|
+
case __typescript_eslint_types.AST_NODE_TYPES.JSXMemberExpression: return `${toString(node.object, getText)}.${toString(node.property, getText)}`;
|
|
573
|
+
case __typescript_eslint_types.AST_NODE_TYPES.JSXNamespacedName: return `${node.namespace.name}:${node.name.name}`;
|
|
574
|
+
case __typescript_eslint_types.AST_NODE_TYPES.JSXText: return node.value;
|
|
575
|
+
case __typescript_eslint_types.AST_NODE_TYPES.Literal: return node.raw;
|
|
576
|
+
default: return getText(node);
|
|
577
|
+
}
|
|
519
578
|
}
|
|
520
579
|
|
|
580
|
+
//#endregion
|
|
521
581
|
exports.findParentNode = findParentNode;
|
|
522
582
|
exports.getArrayMethodCallbackIndexParamPosition = getArrayMethodCallbackIndexParamPosition;
|
|
523
583
|
exports.getClassId = getClassId;
|
|
@@ -556,4 +616,4 @@ exports.isThisExpression = isThisExpression;
|
|
|
556
616
|
exports.isTypeAssertionExpression = isTypeAssertionExpression;
|
|
557
617
|
exports.isTypeExpression = isTypeExpression;
|
|
558
618
|
exports.toDelimiterCaseType = toDelimiterCaseType;
|
|
559
|
-
exports.toString = toString;
|
|
619
|
+
exports.toString = toString;
|