@eslint-react/ast 2.0.0-next.146 → 2.0.0-next.147

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