@eslint-react/var 1.23.0 → 1.23.1-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +36 -21
- package/dist/index.d.ts +36 -21
- package/dist/index.js +70 -73
- package/dist/index.mjs +70 -73
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -45,7 +45,10 @@ type Construction = Data.TaggedEnum<{
|
|
|
45
45
|
node: TSESTree.NewExpression;
|
|
46
46
|
usage: O.Option<TSESTree.Node>;
|
|
47
47
|
};
|
|
48
|
-
None: {
|
|
48
|
+
None: {
|
|
49
|
+
node: TSESTree.Node;
|
|
50
|
+
usage: O.Option<TSESTree.Node>;
|
|
51
|
+
};
|
|
49
52
|
ObjectExpression: {
|
|
50
53
|
node: TSESTree.ObjectExpression;
|
|
51
54
|
usage: O.Option<TSESTree.Node>;
|
|
@@ -56,6 +59,11 @@ type Construction = Data.TaggedEnum<{
|
|
|
56
59
|
};
|
|
57
60
|
}>;
|
|
58
61
|
declare const Construction: {
|
|
62
|
+
readonly None: Data.Case.Constructor<{
|
|
63
|
+
readonly _tag: "None";
|
|
64
|
+
readonly node: TSESTree.Node;
|
|
65
|
+
readonly usage: O.Option<TSESTree.Node>;
|
|
66
|
+
}, "_tag">;
|
|
59
67
|
readonly Array: Data.Case.Constructor<{
|
|
60
68
|
readonly _tag: "Array";
|
|
61
69
|
readonly node: TSESTree.ArrayExpression;
|
|
@@ -106,9 +114,6 @@ declare const Construction: {
|
|
|
106
114
|
readonly node: TSESTree.NewExpression;
|
|
107
115
|
readonly usage: O.Option<TSESTree.Node>;
|
|
108
116
|
}, "_tag">;
|
|
109
|
-
readonly None: Data.Case.Constructor<{
|
|
110
|
-
readonly _tag: "None";
|
|
111
|
-
}, "_tag">;
|
|
112
117
|
readonly ObjectExpression: Data.Case.Constructor<{
|
|
113
118
|
readonly _tag: "ObjectExpression";
|
|
114
119
|
readonly node: TSESTree.ObjectExpression;
|
|
@@ -119,7 +124,13 @@ declare const Construction: {
|
|
|
119
124
|
readonly node: TSESTree.Literal;
|
|
120
125
|
readonly usage: O.Option<TSESTree.Node>;
|
|
121
126
|
}, "_tag">;
|
|
122
|
-
readonly $is: <Tag extends "Array" | "AssignmentExpression" | "AssignmentPattern" | "CallExpression" | "ClassExpression" | "FunctionDeclaration" | "FunctionExpression" | "JSXElement" | "JSXFragment" | "NewExpression" | "
|
|
127
|
+
readonly $is: <Tag extends "None" | "Array" | "AssignmentExpression" | "AssignmentPattern" | "CallExpression" | "ClassExpression" | "FunctionDeclaration" | "FunctionExpression" | "JSXElement" | "JSXFragment" | "NewExpression" | "ObjectExpression" | "RegExpLiteral">(tag: Tag) => (u: unknown) => u is Extract<{
|
|
128
|
+
readonly _tag: "None";
|
|
129
|
+
readonly node: TSESTree.Node;
|
|
130
|
+
readonly usage: O.Option<TSESTree.Node>;
|
|
131
|
+
}, {
|
|
132
|
+
readonly _tag: Tag;
|
|
133
|
+
}> | Extract<{
|
|
123
134
|
readonly _tag: "Array";
|
|
124
135
|
readonly node: TSESTree.ArrayExpression;
|
|
125
136
|
readonly usage: O.Option<TSESTree.Node>;
|
|
@@ -179,10 +190,6 @@ declare const Construction: {
|
|
|
179
190
|
readonly usage: O.Option<TSESTree.Node>;
|
|
180
191
|
}, {
|
|
181
192
|
readonly _tag: Tag;
|
|
182
|
-
}> | Extract<{
|
|
183
|
-
readonly _tag: "None";
|
|
184
|
-
}, {
|
|
185
|
-
readonly _tag: Tag;
|
|
186
193
|
}> | Extract<{
|
|
187
194
|
readonly _tag: "ObjectExpression";
|
|
188
195
|
readonly node: TSESTree.ObjectExpression;
|
|
@@ -198,6 +205,11 @@ declare const Construction: {
|
|
|
198
205
|
}>;
|
|
199
206
|
readonly $match: {
|
|
200
207
|
<Cases extends {
|
|
208
|
+
readonly None: (args: {
|
|
209
|
+
readonly _tag: "None";
|
|
210
|
+
readonly node: TSESTree.Node;
|
|
211
|
+
readonly usage: O.Option<TSESTree.Node>;
|
|
212
|
+
}) => any;
|
|
201
213
|
readonly Array: (args: {
|
|
202
214
|
readonly _tag: "Array";
|
|
203
215
|
readonly node: TSESTree.ArrayExpression;
|
|
@@ -248,9 +260,6 @@ declare const Construction: {
|
|
|
248
260
|
readonly node: TSESTree.NewExpression;
|
|
249
261
|
readonly usage: O.Option<TSESTree.Node>;
|
|
250
262
|
}) => any;
|
|
251
|
-
readonly None: (args: {
|
|
252
|
-
readonly _tag: "None";
|
|
253
|
-
}) => any;
|
|
254
263
|
readonly ObjectExpression: (args: {
|
|
255
264
|
readonly _tag: "ObjectExpression";
|
|
256
265
|
readonly node: TSESTree.ObjectExpression;
|
|
@@ -262,6 +271,10 @@ declare const Construction: {
|
|
|
262
271
|
readonly usage: O.Option<TSESTree.Node>;
|
|
263
272
|
}) => any;
|
|
264
273
|
}>(cases: Cases): (value: {
|
|
274
|
+
readonly _tag: "None";
|
|
275
|
+
readonly node: TSESTree.Node;
|
|
276
|
+
readonly usage: O.Option<TSESTree.Node>;
|
|
277
|
+
} | {
|
|
265
278
|
readonly _tag: "Array";
|
|
266
279
|
readonly node: TSESTree.ArrayExpression;
|
|
267
280
|
readonly usage: O.Option<TSESTree.Node>;
|
|
@@ -301,8 +314,6 @@ declare const Construction: {
|
|
|
301
314
|
readonly _tag: "NewExpression";
|
|
302
315
|
readonly node: TSESTree.NewExpression;
|
|
303
316
|
readonly usage: O.Option<TSESTree.Node>;
|
|
304
|
-
} | {
|
|
305
|
-
readonly _tag: "None";
|
|
306
317
|
} | {
|
|
307
318
|
readonly _tag: "ObjectExpression";
|
|
308
319
|
readonly node: TSESTree.ObjectExpression;
|
|
@@ -311,8 +322,13 @@ declare const Construction: {
|
|
|
311
322
|
readonly _tag: "RegExpLiteral";
|
|
312
323
|
readonly node: TSESTree.Literal;
|
|
313
324
|
readonly usage: O.Option<TSESTree.Node>;
|
|
314
|
-
}) => effect_Unify.Unify<ReturnType<Cases["Array" | "AssignmentExpression" | "AssignmentPattern" | "CallExpression" | "ClassExpression" | "FunctionDeclaration" | "FunctionExpression" | "JSXElement" | "JSXFragment" | "NewExpression" | "
|
|
325
|
+
}) => effect_Unify.Unify<ReturnType<Cases["None" | "Array" | "AssignmentExpression" | "AssignmentPattern" | "CallExpression" | "ClassExpression" | "FunctionDeclaration" | "FunctionExpression" | "JSXElement" | "JSXFragment" | "NewExpression" | "ObjectExpression" | "RegExpLiteral"]>>;
|
|
315
326
|
<Cases extends {
|
|
327
|
+
readonly None: (args: {
|
|
328
|
+
readonly _tag: "None";
|
|
329
|
+
readonly node: TSESTree.Node;
|
|
330
|
+
readonly usage: O.Option<TSESTree.Node>;
|
|
331
|
+
}) => any;
|
|
316
332
|
readonly Array: (args: {
|
|
317
333
|
readonly _tag: "Array";
|
|
318
334
|
readonly node: TSESTree.ArrayExpression;
|
|
@@ -363,9 +379,6 @@ declare const Construction: {
|
|
|
363
379
|
readonly node: TSESTree.NewExpression;
|
|
364
380
|
readonly usage: O.Option<TSESTree.Node>;
|
|
365
381
|
}) => any;
|
|
366
|
-
readonly None: (args: {
|
|
367
|
-
readonly _tag: "None";
|
|
368
|
-
}) => any;
|
|
369
382
|
readonly ObjectExpression: (args: {
|
|
370
383
|
readonly _tag: "ObjectExpression";
|
|
371
384
|
readonly node: TSESTree.ObjectExpression;
|
|
@@ -377,6 +390,10 @@ declare const Construction: {
|
|
|
377
390
|
readonly usage: O.Option<TSESTree.Node>;
|
|
378
391
|
}) => any;
|
|
379
392
|
}>(value: {
|
|
393
|
+
readonly _tag: "None";
|
|
394
|
+
readonly node: TSESTree.Node;
|
|
395
|
+
readonly usage: O.Option<TSESTree.Node>;
|
|
396
|
+
} | {
|
|
380
397
|
readonly _tag: "Array";
|
|
381
398
|
readonly node: TSESTree.ArrayExpression;
|
|
382
399
|
readonly usage: O.Option<TSESTree.Node>;
|
|
@@ -416,8 +433,6 @@ declare const Construction: {
|
|
|
416
433
|
readonly _tag: "NewExpression";
|
|
417
434
|
readonly node: TSESTree.NewExpression;
|
|
418
435
|
readonly usage: O.Option<TSESTree.Node>;
|
|
419
|
-
} | {
|
|
420
|
-
readonly _tag: "None";
|
|
421
436
|
} | {
|
|
422
437
|
readonly _tag: "ObjectExpression";
|
|
423
438
|
readonly node: TSESTree.ObjectExpression;
|
|
@@ -426,7 +441,7 @@ declare const Construction: {
|
|
|
426
441
|
readonly _tag: "RegExpLiteral";
|
|
427
442
|
readonly node: TSESTree.Literal;
|
|
428
443
|
readonly usage: O.Option<TSESTree.Node>;
|
|
429
|
-
}, cases: Cases): effect_Unify.Unify<ReturnType<Cases["Array" | "AssignmentExpression" | "AssignmentPattern" | "CallExpression" | "ClassExpression" | "FunctionDeclaration" | "FunctionExpression" | "JSXElement" | "JSXFragment" | "NewExpression" | "
|
|
444
|
+
}, cases: Cases): effect_Unify.Unify<ReturnType<Cases["None" | "Array" | "AssignmentExpression" | "AssignmentPattern" | "CallExpression" | "ClassExpression" | "FunctionDeclaration" | "FunctionExpression" | "JSXElement" | "JSXFragment" | "NewExpression" | "ObjectExpression" | "RegExpLiteral"]>>;
|
|
430
445
|
};
|
|
431
446
|
};
|
|
432
447
|
type ConstructionHint = bigint;
|
package/dist/index.d.ts
CHANGED
|
@@ -45,7 +45,10 @@ type Construction = Data.TaggedEnum<{
|
|
|
45
45
|
node: TSESTree.NewExpression;
|
|
46
46
|
usage: O.Option<TSESTree.Node>;
|
|
47
47
|
};
|
|
48
|
-
None: {
|
|
48
|
+
None: {
|
|
49
|
+
node: TSESTree.Node;
|
|
50
|
+
usage: O.Option<TSESTree.Node>;
|
|
51
|
+
};
|
|
49
52
|
ObjectExpression: {
|
|
50
53
|
node: TSESTree.ObjectExpression;
|
|
51
54
|
usage: O.Option<TSESTree.Node>;
|
|
@@ -56,6 +59,11 @@ type Construction = Data.TaggedEnum<{
|
|
|
56
59
|
};
|
|
57
60
|
}>;
|
|
58
61
|
declare const Construction: {
|
|
62
|
+
readonly None: Data.Case.Constructor<{
|
|
63
|
+
readonly _tag: "None";
|
|
64
|
+
readonly node: TSESTree.Node;
|
|
65
|
+
readonly usage: O.Option<TSESTree.Node>;
|
|
66
|
+
}, "_tag">;
|
|
59
67
|
readonly Array: Data.Case.Constructor<{
|
|
60
68
|
readonly _tag: "Array";
|
|
61
69
|
readonly node: TSESTree.ArrayExpression;
|
|
@@ -106,9 +114,6 @@ declare const Construction: {
|
|
|
106
114
|
readonly node: TSESTree.NewExpression;
|
|
107
115
|
readonly usage: O.Option<TSESTree.Node>;
|
|
108
116
|
}, "_tag">;
|
|
109
|
-
readonly None: Data.Case.Constructor<{
|
|
110
|
-
readonly _tag: "None";
|
|
111
|
-
}, "_tag">;
|
|
112
117
|
readonly ObjectExpression: Data.Case.Constructor<{
|
|
113
118
|
readonly _tag: "ObjectExpression";
|
|
114
119
|
readonly node: TSESTree.ObjectExpression;
|
|
@@ -119,7 +124,13 @@ declare const Construction: {
|
|
|
119
124
|
readonly node: TSESTree.Literal;
|
|
120
125
|
readonly usage: O.Option<TSESTree.Node>;
|
|
121
126
|
}, "_tag">;
|
|
122
|
-
readonly $is: <Tag extends "Array" | "AssignmentExpression" | "AssignmentPattern" | "CallExpression" | "ClassExpression" | "FunctionDeclaration" | "FunctionExpression" | "JSXElement" | "JSXFragment" | "NewExpression" | "
|
|
127
|
+
readonly $is: <Tag extends "None" | "Array" | "AssignmentExpression" | "AssignmentPattern" | "CallExpression" | "ClassExpression" | "FunctionDeclaration" | "FunctionExpression" | "JSXElement" | "JSXFragment" | "NewExpression" | "ObjectExpression" | "RegExpLiteral">(tag: Tag) => (u: unknown) => u is Extract<{
|
|
128
|
+
readonly _tag: "None";
|
|
129
|
+
readonly node: TSESTree.Node;
|
|
130
|
+
readonly usage: O.Option<TSESTree.Node>;
|
|
131
|
+
}, {
|
|
132
|
+
readonly _tag: Tag;
|
|
133
|
+
}> | Extract<{
|
|
123
134
|
readonly _tag: "Array";
|
|
124
135
|
readonly node: TSESTree.ArrayExpression;
|
|
125
136
|
readonly usage: O.Option<TSESTree.Node>;
|
|
@@ -179,10 +190,6 @@ declare const Construction: {
|
|
|
179
190
|
readonly usage: O.Option<TSESTree.Node>;
|
|
180
191
|
}, {
|
|
181
192
|
readonly _tag: Tag;
|
|
182
|
-
}> | Extract<{
|
|
183
|
-
readonly _tag: "None";
|
|
184
|
-
}, {
|
|
185
|
-
readonly _tag: Tag;
|
|
186
193
|
}> | Extract<{
|
|
187
194
|
readonly _tag: "ObjectExpression";
|
|
188
195
|
readonly node: TSESTree.ObjectExpression;
|
|
@@ -198,6 +205,11 @@ declare const Construction: {
|
|
|
198
205
|
}>;
|
|
199
206
|
readonly $match: {
|
|
200
207
|
<Cases extends {
|
|
208
|
+
readonly None: (args: {
|
|
209
|
+
readonly _tag: "None";
|
|
210
|
+
readonly node: TSESTree.Node;
|
|
211
|
+
readonly usage: O.Option<TSESTree.Node>;
|
|
212
|
+
}) => any;
|
|
201
213
|
readonly Array: (args: {
|
|
202
214
|
readonly _tag: "Array";
|
|
203
215
|
readonly node: TSESTree.ArrayExpression;
|
|
@@ -248,9 +260,6 @@ declare const Construction: {
|
|
|
248
260
|
readonly node: TSESTree.NewExpression;
|
|
249
261
|
readonly usage: O.Option<TSESTree.Node>;
|
|
250
262
|
}) => any;
|
|
251
|
-
readonly None: (args: {
|
|
252
|
-
readonly _tag: "None";
|
|
253
|
-
}) => any;
|
|
254
263
|
readonly ObjectExpression: (args: {
|
|
255
264
|
readonly _tag: "ObjectExpression";
|
|
256
265
|
readonly node: TSESTree.ObjectExpression;
|
|
@@ -262,6 +271,10 @@ declare const Construction: {
|
|
|
262
271
|
readonly usage: O.Option<TSESTree.Node>;
|
|
263
272
|
}) => any;
|
|
264
273
|
}>(cases: Cases): (value: {
|
|
274
|
+
readonly _tag: "None";
|
|
275
|
+
readonly node: TSESTree.Node;
|
|
276
|
+
readonly usage: O.Option<TSESTree.Node>;
|
|
277
|
+
} | {
|
|
265
278
|
readonly _tag: "Array";
|
|
266
279
|
readonly node: TSESTree.ArrayExpression;
|
|
267
280
|
readonly usage: O.Option<TSESTree.Node>;
|
|
@@ -301,8 +314,6 @@ declare const Construction: {
|
|
|
301
314
|
readonly _tag: "NewExpression";
|
|
302
315
|
readonly node: TSESTree.NewExpression;
|
|
303
316
|
readonly usage: O.Option<TSESTree.Node>;
|
|
304
|
-
} | {
|
|
305
|
-
readonly _tag: "None";
|
|
306
317
|
} | {
|
|
307
318
|
readonly _tag: "ObjectExpression";
|
|
308
319
|
readonly node: TSESTree.ObjectExpression;
|
|
@@ -311,8 +322,13 @@ declare const Construction: {
|
|
|
311
322
|
readonly _tag: "RegExpLiteral";
|
|
312
323
|
readonly node: TSESTree.Literal;
|
|
313
324
|
readonly usage: O.Option<TSESTree.Node>;
|
|
314
|
-
}) => effect_Unify.Unify<ReturnType<Cases["Array" | "AssignmentExpression" | "AssignmentPattern" | "CallExpression" | "ClassExpression" | "FunctionDeclaration" | "FunctionExpression" | "JSXElement" | "JSXFragment" | "NewExpression" | "
|
|
325
|
+
}) => effect_Unify.Unify<ReturnType<Cases["None" | "Array" | "AssignmentExpression" | "AssignmentPattern" | "CallExpression" | "ClassExpression" | "FunctionDeclaration" | "FunctionExpression" | "JSXElement" | "JSXFragment" | "NewExpression" | "ObjectExpression" | "RegExpLiteral"]>>;
|
|
315
326
|
<Cases extends {
|
|
327
|
+
readonly None: (args: {
|
|
328
|
+
readonly _tag: "None";
|
|
329
|
+
readonly node: TSESTree.Node;
|
|
330
|
+
readonly usage: O.Option<TSESTree.Node>;
|
|
331
|
+
}) => any;
|
|
316
332
|
readonly Array: (args: {
|
|
317
333
|
readonly _tag: "Array";
|
|
318
334
|
readonly node: TSESTree.ArrayExpression;
|
|
@@ -363,9 +379,6 @@ declare const Construction: {
|
|
|
363
379
|
readonly node: TSESTree.NewExpression;
|
|
364
380
|
readonly usage: O.Option<TSESTree.Node>;
|
|
365
381
|
}) => any;
|
|
366
|
-
readonly None: (args: {
|
|
367
|
-
readonly _tag: "None";
|
|
368
|
-
}) => any;
|
|
369
382
|
readonly ObjectExpression: (args: {
|
|
370
383
|
readonly _tag: "ObjectExpression";
|
|
371
384
|
readonly node: TSESTree.ObjectExpression;
|
|
@@ -377,6 +390,10 @@ declare const Construction: {
|
|
|
377
390
|
readonly usage: O.Option<TSESTree.Node>;
|
|
378
391
|
}) => any;
|
|
379
392
|
}>(value: {
|
|
393
|
+
readonly _tag: "None";
|
|
394
|
+
readonly node: TSESTree.Node;
|
|
395
|
+
readonly usage: O.Option<TSESTree.Node>;
|
|
396
|
+
} | {
|
|
380
397
|
readonly _tag: "Array";
|
|
381
398
|
readonly node: TSESTree.ArrayExpression;
|
|
382
399
|
readonly usage: O.Option<TSESTree.Node>;
|
|
@@ -416,8 +433,6 @@ declare const Construction: {
|
|
|
416
433
|
readonly _tag: "NewExpression";
|
|
417
434
|
readonly node: TSESTree.NewExpression;
|
|
418
435
|
readonly usage: O.Option<TSESTree.Node>;
|
|
419
|
-
} | {
|
|
420
|
-
readonly _tag: "None";
|
|
421
436
|
} | {
|
|
422
437
|
readonly _tag: "ObjectExpression";
|
|
423
438
|
readonly node: TSESTree.ObjectExpression;
|
|
@@ -426,7 +441,7 @@ declare const Construction: {
|
|
|
426
441
|
readonly _tag: "RegExpLiteral";
|
|
427
442
|
readonly node: TSESTree.Literal;
|
|
428
443
|
readonly usage: O.Option<TSESTree.Node>;
|
|
429
|
-
}, cases: Cases): effect_Unify.Unify<ReturnType<Cases["Array" | "AssignmentExpression" | "AssignmentPattern" | "CallExpression" | "ClassExpression" | "FunctionDeclaration" | "FunctionExpression" | "JSXElement" | "JSXFragment" | "NewExpression" | "
|
|
444
|
+
}, cases: Cases): effect_Unify.Unify<ReturnType<Cases["None" | "Array" | "AssignmentExpression" | "AssignmentPattern" | "CallExpression" | "ClassExpression" | "FunctionDeclaration" | "FunctionExpression" | "JSXElement" | "JSXFragment" | "NewExpression" | "ObjectExpression" | "RegExpLiteral"]>>;
|
|
430
445
|
};
|
|
431
446
|
};
|
|
432
447
|
type ConstructionHint = bigint;
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var AST2 = require('@eslint-react/ast');
|
|
4
4
|
var eff = require('@eslint-react/eff');
|
|
5
|
-
var scopeManager = require('@typescript-eslint/scope-manager');
|
|
6
5
|
var types = require('@typescript-eslint/types');
|
|
7
6
|
var tsPattern = require('ts-pattern');
|
|
7
|
+
var scopeManager = require('@typescript-eslint/scope-manager');
|
|
8
8
|
var ASTUtils = require('@typescript-eslint/utils/ast-utils');
|
|
9
9
|
|
|
10
10
|
function _interopNamespace(e) {
|
|
@@ -25,9 +25,33 @@ function _interopNamespace(e) {
|
|
|
25
25
|
return Object.freeze(n);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
var
|
|
28
|
+
var AST2__namespace = /*#__PURE__*/_interopNamespace(AST2);
|
|
29
29
|
var ASTUtils__namespace = /*#__PURE__*/_interopNamespace(ASTUtils);
|
|
30
30
|
|
|
31
|
+
// src/construction.ts
|
|
32
|
+
function getVariableNode(at) {
|
|
33
|
+
return (variable) => {
|
|
34
|
+
return eff.F.pipe(
|
|
35
|
+
eff.O.some(variable),
|
|
36
|
+
eff.O.flatMapNullable((v) => v.defs.at(at)),
|
|
37
|
+
eff.O.flatMapNullable((def) => {
|
|
38
|
+
switch (true) {
|
|
39
|
+
case (def.type === scopeManager.DefinitionType.FunctionName && def.node.type === types.AST_NODE_TYPES.FunctionDeclaration):
|
|
40
|
+
return def.node;
|
|
41
|
+
case (def.type === scopeManager.DefinitionType.ClassName && def.node.type === types.AST_NODE_TYPES.ClassDeclaration):
|
|
42
|
+
return def.node;
|
|
43
|
+
case (def.type === scopeManager.DefinitionType.Parameter && AST2__namespace.isFunction(def.node)):
|
|
44
|
+
return def.node;
|
|
45
|
+
case ("init" in def.node && def.node.init && !("declarations" in def.node.init)):
|
|
46
|
+
return def.node.init;
|
|
47
|
+
default:
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
31
55
|
// src/construction.ts
|
|
32
56
|
var Construction = eff.Data.taggedEnum();
|
|
33
57
|
var ConstructionHint = {
|
|
@@ -36,84 +60,79 @@ var ConstructionHint = {
|
|
|
36
60
|
};
|
|
37
61
|
function inspectConstruction(node, initialScope, hint = ConstructionHint.None) {
|
|
38
62
|
const detect = (node2) => {
|
|
39
|
-
return tsPattern.match(node2).when(
|
|
63
|
+
return tsPattern.match(node2).when(AST2__namespace.is(types.AST_NODE_TYPES.ArrayExpression), (node3) => Construction.Array({ node: node3, usage: eff.O.none() })).when(AST2__namespace.is(types.AST_NODE_TYPES.ObjectExpression), (node3) => Construction.ObjectExpression({ node: node3, usage: eff.O.none() })).when(AST2__namespace.is(types.AST_NODE_TYPES.ClassExpression), (node3) => Construction.ClassExpression({ node: node3, usage: eff.O.none() })).when(AST2__namespace.is(types.AST_NODE_TYPES.JSXElement), (node3) => Construction.JSXElement({ node: node3, usage: eff.O.none() })).when(AST2__namespace.is(types.AST_NODE_TYPES.JSXFragment), (node3) => Construction.JSXFragment({ node: node3, usage: eff.O.none() })).when(AST2__namespace.is(types.AST_NODE_TYPES.CallExpression), (node3) => {
|
|
40
64
|
if (hint & ConstructionHint.StrictCallExpression) {
|
|
41
65
|
return Construction.CallExpression({ node: node3, usage: eff.O.none() });
|
|
42
66
|
}
|
|
43
|
-
return Construction.None();
|
|
44
|
-
}).when(
|
|
45
|
-
|
|
67
|
+
return Construction.None({ node: node3, usage: eff.O.none() });
|
|
68
|
+
}).when(AST2__namespace.is(types.AST_NODE_TYPES.NewExpression), (node3) => Construction.NewExpression({ node: node3, usage: eff.O.none() })).when(
|
|
69
|
+
AST2__namespace.isOneOf([
|
|
46
70
|
types.AST_NODE_TYPES.FunctionExpression,
|
|
47
71
|
types.AST_NODE_TYPES.ArrowFunctionExpression
|
|
48
72
|
]),
|
|
49
73
|
(node3) => {
|
|
50
74
|
return Construction.FunctionExpression({ node: node3, usage: eff.O.none() });
|
|
51
75
|
}
|
|
52
|
-
).when(
|
|
53
|
-
if (!("object" in node3)) return Construction.None();
|
|
76
|
+
).when(AST2__namespace.is(types.AST_NODE_TYPES.MemberExpression), (node3) => {
|
|
77
|
+
if (!("object" in node3)) return Construction.None({ node: node3, usage: eff.O.none() });
|
|
54
78
|
const object = detect(node3.object);
|
|
55
79
|
if (object._tag === "None") return object;
|
|
56
80
|
return {
|
|
57
81
|
...object,
|
|
58
82
|
usage: eff.O.some(node3.object)
|
|
59
83
|
};
|
|
60
|
-
}).when(
|
|
61
|
-
if (!("right" in node3)) return Construction.None();
|
|
84
|
+
}).when(AST2__namespace.is(types.AST_NODE_TYPES.AssignmentExpression), (node3) => {
|
|
85
|
+
if (!("right" in node3)) return Construction.None({ node: node3, usage: eff.O.none() });
|
|
62
86
|
const right = detect(node3.right);
|
|
63
87
|
if (right._tag === "None") return right;
|
|
64
88
|
return Construction.AssignmentExpression({
|
|
65
89
|
node: right.node,
|
|
66
90
|
usage: eff.O.some(node3)
|
|
67
91
|
});
|
|
68
|
-
}).when(
|
|
69
|
-
if (!("right" in node3)) return Construction.None();
|
|
92
|
+
}).when(AST2__namespace.is(types.AST_NODE_TYPES.AssignmentPattern), (node3) => {
|
|
93
|
+
if (!("right" in node3)) return Construction.None({ node: node3, usage: eff.O.none() });
|
|
70
94
|
const right = detect(node3.right);
|
|
71
95
|
if (right._tag === "None") return right;
|
|
72
96
|
return Construction.AssignmentPattern({
|
|
73
97
|
node: right.node,
|
|
74
98
|
usage: eff.O.some(node3)
|
|
75
99
|
});
|
|
76
|
-
}).when(
|
|
77
|
-
if (!("left" in node3 && "right" in node3)) return Construction.None();
|
|
100
|
+
}).when(AST2__namespace.is(types.AST_NODE_TYPES.LogicalExpression), (node3) => {
|
|
101
|
+
if (!("left" in node3 && "right" in node3)) return Construction.None({ node: node3, usage: eff.O.none() });
|
|
78
102
|
const left = detect(node3.left);
|
|
79
103
|
if (left._tag !== "None") return left;
|
|
80
104
|
return detect(node3.right);
|
|
81
|
-
}).when(
|
|
105
|
+
}).when(AST2__namespace.is(types.AST_NODE_TYPES.ConditionalExpression), (node3) => {
|
|
82
106
|
if (!("consequent" in node3 && "alternate" in node3 && !eff.isNullable(node3.alternate))) {
|
|
83
|
-
return Construction.None();
|
|
107
|
+
return Construction.None({ node: node3, usage: eff.O.none() });
|
|
84
108
|
}
|
|
85
109
|
const consequent = detect(node3.consequent);
|
|
86
|
-
if (consequent._tag !== "None") return Construction.None();
|
|
110
|
+
if (consequent._tag !== "None") return Construction.None({ node: node3, usage: eff.O.none() });
|
|
87
111
|
return detect(node3.alternate);
|
|
88
|
-
}).when(
|
|
89
|
-
if (!("name" in node3 && eff.isString(node3.name))) return Construction.None();
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (!("init" in latestDef.node) || latestDef.node.init === null) {
|
|
103
|
-
return Construction.None();
|
|
104
|
-
}
|
|
105
|
-
return detect(latestDef.node.init);
|
|
106
|
-
}).when(AST__namespace.is(types.AST_NODE_TYPES.Literal), (node3) => {
|
|
112
|
+
}).when(AST2__namespace.is(types.AST_NODE_TYPES.Identifier), (node3) => {
|
|
113
|
+
if (!("name" in node3 && eff.isString(node3.name))) return Construction.None({ node: node3, usage: eff.O.none() });
|
|
114
|
+
const construction = eff.F.pipe(
|
|
115
|
+
eff.O.fromNullable(initialScope.set.get(node3.name)),
|
|
116
|
+
eff.O.flatMap(getVariableNode(-1)),
|
|
117
|
+
eff.O.map(detect),
|
|
118
|
+
eff.O.filter(eff.not(Construction.$is("None")))
|
|
119
|
+
);
|
|
120
|
+
if (eff.O.isNone(construction)) return Construction.None({ node: node3, usage: eff.O.none() });
|
|
121
|
+
return {
|
|
122
|
+
...construction.value,
|
|
123
|
+
usage: eff.O.some(node3)
|
|
124
|
+
};
|
|
125
|
+
}).when(AST2__namespace.is(types.AST_NODE_TYPES.Literal), (node3) => {
|
|
107
126
|
if ("regex" in node3) {
|
|
108
127
|
return Construction.RegExpLiteral({ node: node3, usage: eff.O.none() });
|
|
109
128
|
}
|
|
110
|
-
return Construction.None();
|
|
111
|
-
}).when(
|
|
129
|
+
return Construction.None({ node: node3, usage: eff.O.none() });
|
|
130
|
+
}).when(AST2__namespace.isTypeExpression, () => {
|
|
112
131
|
if (!("expression" in node2) || !eff.isObject(node2.expression)) {
|
|
113
|
-
return Construction.None();
|
|
132
|
+
return Construction.None({ node: node2, usage: eff.O.none() });
|
|
114
133
|
}
|
|
115
134
|
return detect(node2.expression);
|
|
116
|
-
}).otherwise(() => Construction.None());
|
|
135
|
+
}).otherwise(() => Construction.None({ node: node2, usage: eff.O.none() }));
|
|
117
136
|
};
|
|
118
137
|
return detect(node);
|
|
119
138
|
}
|
|
@@ -151,28 +170,6 @@ function getVariableDeclaratorID(node, prev) {
|
|
|
151
170
|
return getVariableDeclaratorID(node.parent, node);
|
|
152
171
|
}
|
|
153
172
|
}
|
|
154
|
-
function getVariableNode(at) {
|
|
155
|
-
return (variable) => {
|
|
156
|
-
return eff.F.pipe(
|
|
157
|
-
eff.O.some(variable),
|
|
158
|
-
eff.O.flatMapNullable((v) => v.defs.at(at)),
|
|
159
|
-
eff.O.flatMapNullable((def) => {
|
|
160
|
-
switch (true) {
|
|
161
|
-
case (def.type === scopeManager.DefinitionType.FunctionName && def.node.type === types.AST_NODE_TYPES.FunctionDeclaration):
|
|
162
|
-
return def.node;
|
|
163
|
-
case (def.type === scopeManager.DefinitionType.ClassName && def.node.type === types.AST_NODE_TYPES.ClassDeclaration):
|
|
164
|
-
return def.node;
|
|
165
|
-
case (def.type === scopeManager.DefinitionType.Parameter && AST__namespace.isFunction(def.node)):
|
|
166
|
-
return def.node;
|
|
167
|
-
case ("init" in def.node && def.node.init && !("declarations" in def.node.init)):
|
|
168
|
-
return def.node.init;
|
|
169
|
-
default:
|
|
170
|
-
return null;
|
|
171
|
-
}
|
|
172
|
-
})
|
|
173
|
-
);
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
173
|
function getVariables(initialScope) {
|
|
177
174
|
let scope = initialScope;
|
|
178
175
|
const variables = [...scope.variables];
|
|
@@ -197,7 +194,7 @@ function isInitializedFromSource(name, source, initialScope) {
|
|
|
197
194
|
return eff.F.pipe(
|
|
198
195
|
getRequireExpressionArguments(init),
|
|
199
196
|
eff.O.flatMapNullable((args) => args[0]),
|
|
200
|
-
eff.O.filter(
|
|
197
|
+
eff.O.filter(AST2__namespace.isStringLiteral),
|
|
201
198
|
// check for: `require('source')` or `require('source/...')`
|
|
202
199
|
eff.O.exists((arg) => arg.value === source || arg.value.startsWith(`${source}/`))
|
|
203
200
|
);
|
|
@@ -247,25 +244,25 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
247
244
|
const aDefParentParent = eff.O.flatMapNullable(aDef, (d) => d.parent?.parent);
|
|
248
245
|
const bDefParentParent = eff.O.flatMapNullable(bDef, (d) => d.parent?.parent);
|
|
249
246
|
switch (true) {
|
|
250
|
-
case (eff.O.exists(aVarNodeParent,
|
|
247
|
+
case (eff.O.exists(aVarNodeParent, AST2__namespace.is(types.AST_NODE_TYPES.CallExpression)) && eff.O.exists(bVarNodeParent, AST2__namespace.is(types.AST_NODE_TYPES.CallExpression)) && eff.O.exists(aVarNode, AST2__namespace.isFunction) && eff.O.exists(bVarNode, AST2__namespace.isFunction)): {
|
|
251
248
|
const hasSameCallee = eff.F.pipe(
|
|
252
249
|
eff.O.Do,
|
|
253
250
|
eff.O.bind("aCallee", () => eff.O.map(aVarNodeParent, (n) => n.callee)),
|
|
254
251
|
eff.O.bind("bCallee", () => eff.O.map(bVarNodeParent, (n) => n.callee)),
|
|
255
|
-
eff.O.exists(({ aCallee, bCallee }) =>
|
|
252
|
+
eff.O.exists(({ aCallee, bCallee }) => AST2__namespace.isNodeEqual(aCallee, bCallee))
|
|
256
253
|
);
|
|
257
254
|
if (!hasSameCallee) return false;
|
|
258
255
|
return eff.F.pipe(
|
|
259
256
|
eff.O.Do,
|
|
260
257
|
eff.O.bind("aParams", () => eff.O.map(aVarNode, (n) => n.params)),
|
|
261
258
|
eff.O.bind("bParams", () => eff.O.map(bVarNode, (n) => n.params)),
|
|
262
|
-
eff.O.let("aPos", ({ aParams }) => aParams.findIndex(
|
|
263
|
-
eff.O.let("bPos", ({ bParams }) => bParams.findIndex(
|
|
259
|
+
eff.O.let("aPos", ({ aParams }) => aParams.findIndex(AST2__namespace.isNodeEqual(a))),
|
|
260
|
+
eff.O.let("bPos", ({ bParams }) => bParams.findIndex(AST2__namespace.isNodeEqual(b))),
|
|
264
261
|
eff.O.filter(({ aPos, bPos }) => aPos !== -1 && bPos !== -1),
|
|
265
262
|
eff.O.exists(({ aPos, bPos }) => aPos === bPos)
|
|
266
263
|
);
|
|
267
264
|
}
|
|
268
|
-
case (eff.O.exists(aDefParentParent,
|
|
265
|
+
case (eff.O.exists(aDefParentParent, AST2__namespace.is(types.AST_NODE_TYPES.ForOfStatement)) && eff.O.exists(bDefParentParent, AST2__namespace.is(types.AST_NODE_TYPES.ForOfStatement))): {
|
|
269
266
|
return eff.F.pipe(
|
|
270
267
|
eff.O.Do,
|
|
271
268
|
eff.O.bind("aLeft", () => eff.O.map(aDefParentParent, (d) => d.left)),
|
|
@@ -273,7 +270,7 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
273
270
|
eff.O.filter(({ aLeft, bLeft }) => aLeft.type === bLeft.type),
|
|
274
271
|
eff.O.bind("aRight", () => eff.O.map(aDefParentParent, (d) => d.right)),
|
|
275
272
|
eff.O.bind("bRight", () => eff.O.map(bDefParentParent, (d) => d.right)),
|
|
276
|
-
eff.O.exists(({ aRight, bRight }) =>
|
|
273
|
+
eff.O.exists(({ aRight, bRight }) => AST2__namespace.isNodeEqual(aRight, bRight))
|
|
277
274
|
);
|
|
278
275
|
}
|
|
279
276
|
default: {
|
|
@@ -282,14 +279,14 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
282
279
|
}
|
|
283
280
|
}
|
|
284
281
|
case (a.type === types.AST_NODE_TYPES.MemberExpression && b.type === types.AST_NODE_TYPES.MemberExpression): {
|
|
285
|
-
return
|
|
282
|
+
return AST2__namespace.isNodeEqual(a.property, b.property) && isNodeValueEqual(a.object, b.object, initialScopes);
|
|
286
283
|
}
|
|
287
284
|
case (a.type === types.AST_NODE_TYPES.ThisExpression && b.type === types.AST_NODE_TYPES.ThisExpression): {
|
|
288
285
|
if (aScope.block === bScope.block) return true;
|
|
289
286
|
return eff.F.pipe(
|
|
290
287
|
eff.O.Do,
|
|
291
|
-
eff.O.bind("aFunction", () =>
|
|
292
|
-
eff.O.bind("bFunction", () =>
|
|
288
|
+
eff.O.bind("aFunction", () => AST2__namespace.traverseUp(a, AST2__namespace.isOneOf(thisBlockTypes))),
|
|
289
|
+
eff.O.bind("bFunction", () => AST2__namespace.traverseUp(b, AST2__namespace.isOneOf(thisBlockTypes))),
|
|
293
290
|
eff.O.exists(({ aFunction, bFunction }) => aFunction === bFunction)
|
|
294
291
|
);
|
|
295
292
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,34 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { Data, F, O, Equal, isNullable, isString, isObject } from '@eslint-react/eff';
|
|
3
|
-
import { DefinitionType, ScopeType } from '@typescript-eslint/scope-manager';
|
|
1
|
+
import * as AST2 from '@eslint-react/ast';
|
|
2
|
+
import { Data, F, O, Equal, isNullable, isString, not, isObject } from '@eslint-react/eff';
|
|
4
3
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
5
4
|
import { isMatching, match } from 'ts-pattern';
|
|
5
|
+
import { DefinitionType, ScopeType } from '@typescript-eslint/scope-manager';
|
|
6
6
|
import * as ASTUtils from '@typescript-eslint/utils/ast-utils';
|
|
7
7
|
|
|
8
|
+
// src/construction.ts
|
|
9
|
+
function getVariableNode(at) {
|
|
10
|
+
return (variable) => {
|
|
11
|
+
return F.pipe(
|
|
12
|
+
O.some(variable),
|
|
13
|
+
O.flatMapNullable((v) => v.defs.at(at)),
|
|
14
|
+
O.flatMapNullable((def) => {
|
|
15
|
+
switch (true) {
|
|
16
|
+
case (def.type === DefinitionType.FunctionName && def.node.type === AST_NODE_TYPES.FunctionDeclaration):
|
|
17
|
+
return def.node;
|
|
18
|
+
case (def.type === DefinitionType.ClassName && def.node.type === AST_NODE_TYPES.ClassDeclaration):
|
|
19
|
+
return def.node;
|
|
20
|
+
case (def.type === DefinitionType.Parameter && AST2.isFunction(def.node)):
|
|
21
|
+
return def.node;
|
|
22
|
+
case ("init" in def.node && def.node.init && !("declarations" in def.node.init)):
|
|
23
|
+
return def.node.init;
|
|
24
|
+
default:
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
8
32
|
// src/construction.ts
|
|
9
33
|
var Construction = Data.taggedEnum();
|
|
10
34
|
var ConstructionHint = {
|
|
@@ -13,84 +37,79 @@ var ConstructionHint = {
|
|
|
13
37
|
};
|
|
14
38
|
function inspectConstruction(node, initialScope, hint = ConstructionHint.None) {
|
|
15
39
|
const detect = (node2) => {
|
|
16
|
-
return match(node2).when(
|
|
40
|
+
return match(node2).when(AST2.is(AST_NODE_TYPES.ArrayExpression), (node3) => Construction.Array({ node: node3, usage: O.none() })).when(AST2.is(AST_NODE_TYPES.ObjectExpression), (node3) => Construction.ObjectExpression({ node: node3, usage: O.none() })).when(AST2.is(AST_NODE_TYPES.ClassExpression), (node3) => Construction.ClassExpression({ node: node3, usage: O.none() })).when(AST2.is(AST_NODE_TYPES.JSXElement), (node3) => Construction.JSXElement({ node: node3, usage: O.none() })).when(AST2.is(AST_NODE_TYPES.JSXFragment), (node3) => Construction.JSXFragment({ node: node3, usage: O.none() })).when(AST2.is(AST_NODE_TYPES.CallExpression), (node3) => {
|
|
17
41
|
if (hint & ConstructionHint.StrictCallExpression) {
|
|
18
42
|
return Construction.CallExpression({ node: node3, usage: O.none() });
|
|
19
43
|
}
|
|
20
|
-
return Construction.None();
|
|
21
|
-
}).when(
|
|
22
|
-
|
|
44
|
+
return Construction.None({ node: node3, usage: O.none() });
|
|
45
|
+
}).when(AST2.is(AST_NODE_TYPES.NewExpression), (node3) => Construction.NewExpression({ node: node3, usage: O.none() })).when(
|
|
46
|
+
AST2.isOneOf([
|
|
23
47
|
AST_NODE_TYPES.FunctionExpression,
|
|
24
48
|
AST_NODE_TYPES.ArrowFunctionExpression
|
|
25
49
|
]),
|
|
26
50
|
(node3) => {
|
|
27
51
|
return Construction.FunctionExpression({ node: node3, usage: O.none() });
|
|
28
52
|
}
|
|
29
|
-
).when(
|
|
30
|
-
if (!("object" in node3)) return Construction.None();
|
|
53
|
+
).when(AST2.is(AST_NODE_TYPES.MemberExpression), (node3) => {
|
|
54
|
+
if (!("object" in node3)) return Construction.None({ node: node3, usage: O.none() });
|
|
31
55
|
const object = detect(node3.object);
|
|
32
56
|
if (object._tag === "None") return object;
|
|
33
57
|
return {
|
|
34
58
|
...object,
|
|
35
59
|
usage: O.some(node3.object)
|
|
36
60
|
};
|
|
37
|
-
}).when(
|
|
38
|
-
if (!("right" in node3)) return Construction.None();
|
|
61
|
+
}).when(AST2.is(AST_NODE_TYPES.AssignmentExpression), (node3) => {
|
|
62
|
+
if (!("right" in node3)) return Construction.None({ node: node3, usage: O.none() });
|
|
39
63
|
const right = detect(node3.right);
|
|
40
64
|
if (right._tag === "None") return right;
|
|
41
65
|
return Construction.AssignmentExpression({
|
|
42
66
|
node: right.node,
|
|
43
67
|
usage: O.some(node3)
|
|
44
68
|
});
|
|
45
|
-
}).when(
|
|
46
|
-
if (!("right" in node3)) return Construction.None();
|
|
69
|
+
}).when(AST2.is(AST_NODE_TYPES.AssignmentPattern), (node3) => {
|
|
70
|
+
if (!("right" in node3)) return Construction.None({ node: node3, usage: O.none() });
|
|
47
71
|
const right = detect(node3.right);
|
|
48
72
|
if (right._tag === "None") return right;
|
|
49
73
|
return Construction.AssignmentPattern({
|
|
50
74
|
node: right.node,
|
|
51
75
|
usage: O.some(node3)
|
|
52
76
|
});
|
|
53
|
-
}).when(
|
|
54
|
-
if (!("left" in node3 && "right" in node3)) return Construction.None();
|
|
77
|
+
}).when(AST2.is(AST_NODE_TYPES.LogicalExpression), (node3) => {
|
|
78
|
+
if (!("left" in node3 && "right" in node3)) return Construction.None({ node: node3, usage: O.none() });
|
|
55
79
|
const left = detect(node3.left);
|
|
56
80
|
if (left._tag !== "None") return left;
|
|
57
81
|
return detect(node3.right);
|
|
58
|
-
}).when(
|
|
82
|
+
}).when(AST2.is(AST_NODE_TYPES.ConditionalExpression), (node3) => {
|
|
59
83
|
if (!("consequent" in node3 && "alternate" in node3 && !isNullable(node3.alternate))) {
|
|
60
|
-
return Construction.None();
|
|
84
|
+
return Construction.None({ node: node3, usage: O.none() });
|
|
61
85
|
}
|
|
62
86
|
const consequent = detect(node3.consequent);
|
|
63
|
-
if (consequent._tag !== "None") return Construction.None();
|
|
87
|
+
if (consequent._tag !== "None") return Construction.None({ node: node3, usage: O.none() });
|
|
64
88
|
return detect(node3.alternate);
|
|
65
|
-
}).when(
|
|
66
|
-
if (!("name" in node3 && isString(node3.name))) return Construction.None();
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (!("init" in latestDef.node) || latestDef.node.init === null) {
|
|
80
|
-
return Construction.None();
|
|
81
|
-
}
|
|
82
|
-
return detect(latestDef.node.init);
|
|
83
|
-
}).when(AST.is(AST_NODE_TYPES.Literal), (node3) => {
|
|
89
|
+
}).when(AST2.is(AST_NODE_TYPES.Identifier), (node3) => {
|
|
90
|
+
if (!("name" in node3 && isString(node3.name))) return Construction.None({ node: node3, usage: O.none() });
|
|
91
|
+
const construction = F.pipe(
|
|
92
|
+
O.fromNullable(initialScope.set.get(node3.name)),
|
|
93
|
+
O.flatMap(getVariableNode(-1)),
|
|
94
|
+
O.map(detect),
|
|
95
|
+
O.filter(not(Construction.$is("None")))
|
|
96
|
+
);
|
|
97
|
+
if (O.isNone(construction)) return Construction.None({ node: node3, usage: O.none() });
|
|
98
|
+
return {
|
|
99
|
+
...construction.value,
|
|
100
|
+
usage: O.some(node3)
|
|
101
|
+
};
|
|
102
|
+
}).when(AST2.is(AST_NODE_TYPES.Literal), (node3) => {
|
|
84
103
|
if ("regex" in node3) {
|
|
85
104
|
return Construction.RegExpLiteral({ node: node3, usage: O.none() });
|
|
86
105
|
}
|
|
87
|
-
return Construction.None();
|
|
88
|
-
}).when(
|
|
106
|
+
return Construction.None({ node: node3, usage: O.none() });
|
|
107
|
+
}).when(AST2.isTypeExpression, () => {
|
|
89
108
|
if (!("expression" in node2) || !isObject(node2.expression)) {
|
|
90
|
-
return Construction.None();
|
|
109
|
+
return Construction.None({ node: node2, usage: O.none() });
|
|
91
110
|
}
|
|
92
111
|
return detect(node2.expression);
|
|
93
|
-
}).otherwise(() => Construction.None());
|
|
112
|
+
}).otherwise(() => Construction.None({ node: node2, usage: O.none() }));
|
|
94
113
|
};
|
|
95
114
|
return detect(node);
|
|
96
115
|
}
|
|
@@ -128,28 +147,6 @@ function getVariableDeclaratorID(node, prev) {
|
|
|
128
147
|
return getVariableDeclaratorID(node.parent, node);
|
|
129
148
|
}
|
|
130
149
|
}
|
|
131
|
-
function getVariableNode(at) {
|
|
132
|
-
return (variable) => {
|
|
133
|
-
return F.pipe(
|
|
134
|
-
O.some(variable),
|
|
135
|
-
O.flatMapNullable((v) => v.defs.at(at)),
|
|
136
|
-
O.flatMapNullable((def) => {
|
|
137
|
-
switch (true) {
|
|
138
|
-
case (def.type === DefinitionType.FunctionName && def.node.type === AST_NODE_TYPES.FunctionDeclaration):
|
|
139
|
-
return def.node;
|
|
140
|
-
case (def.type === DefinitionType.ClassName && def.node.type === AST_NODE_TYPES.ClassDeclaration):
|
|
141
|
-
return def.node;
|
|
142
|
-
case (def.type === DefinitionType.Parameter && AST.isFunction(def.node)):
|
|
143
|
-
return def.node;
|
|
144
|
-
case ("init" in def.node && def.node.init && !("declarations" in def.node.init)):
|
|
145
|
-
return def.node.init;
|
|
146
|
-
default:
|
|
147
|
-
return null;
|
|
148
|
-
}
|
|
149
|
-
})
|
|
150
|
-
);
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
150
|
function getVariables(initialScope) {
|
|
154
151
|
let scope = initialScope;
|
|
155
152
|
const variables = [...scope.variables];
|
|
@@ -174,7 +171,7 @@ function isInitializedFromSource(name, source, initialScope) {
|
|
|
174
171
|
return F.pipe(
|
|
175
172
|
getRequireExpressionArguments(init),
|
|
176
173
|
O.flatMapNullable((args) => args[0]),
|
|
177
|
-
O.filter(
|
|
174
|
+
O.filter(AST2.isStringLiteral),
|
|
178
175
|
// check for: `require('source')` or `require('source/...')`
|
|
179
176
|
O.exists((arg) => arg.value === source || arg.value.startsWith(`${source}/`))
|
|
180
177
|
);
|
|
@@ -224,25 +221,25 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
224
221
|
const aDefParentParent = O.flatMapNullable(aDef, (d) => d.parent?.parent);
|
|
225
222
|
const bDefParentParent = O.flatMapNullable(bDef, (d) => d.parent?.parent);
|
|
226
223
|
switch (true) {
|
|
227
|
-
case (O.exists(aVarNodeParent,
|
|
224
|
+
case (O.exists(aVarNodeParent, AST2.is(AST_NODE_TYPES.CallExpression)) && O.exists(bVarNodeParent, AST2.is(AST_NODE_TYPES.CallExpression)) && O.exists(aVarNode, AST2.isFunction) && O.exists(bVarNode, AST2.isFunction)): {
|
|
228
225
|
const hasSameCallee = F.pipe(
|
|
229
226
|
O.Do,
|
|
230
227
|
O.bind("aCallee", () => O.map(aVarNodeParent, (n) => n.callee)),
|
|
231
228
|
O.bind("bCallee", () => O.map(bVarNodeParent, (n) => n.callee)),
|
|
232
|
-
O.exists(({ aCallee, bCallee }) =>
|
|
229
|
+
O.exists(({ aCallee, bCallee }) => AST2.isNodeEqual(aCallee, bCallee))
|
|
233
230
|
);
|
|
234
231
|
if (!hasSameCallee) return false;
|
|
235
232
|
return F.pipe(
|
|
236
233
|
O.Do,
|
|
237
234
|
O.bind("aParams", () => O.map(aVarNode, (n) => n.params)),
|
|
238
235
|
O.bind("bParams", () => O.map(bVarNode, (n) => n.params)),
|
|
239
|
-
O.let("aPos", ({ aParams }) => aParams.findIndex(
|
|
240
|
-
O.let("bPos", ({ bParams }) => bParams.findIndex(
|
|
236
|
+
O.let("aPos", ({ aParams }) => aParams.findIndex(AST2.isNodeEqual(a))),
|
|
237
|
+
O.let("bPos", ({ bParams }) => bParams.findIndex(AST2.isNodeEqual(b))),
|
|
241
238
|
O.filter(({ aPos, bPos }) => aPos !== -1 && bPos !== -1),
|
|
242
239
|
O.exists(({ aPos, bPos }) => aPos === bPos)
|
|
243
240
|
);
|
|
244
241
|
}
|
|
245
|
-
case (O.exists(aDefParentParent,
|
|
242
|
+
case (O.exists(aDefParentParent, AST2.is(AST_NODE_TYPES.ForOfStatement)) && O.exists(bDefParentParent, AST2.is(AST_NODE_TYPES.ForOfStatement))): {
|
|
246
243
|
return F.pipe(
|
|
247
244
|
O.Do,
|
|
248
245
|
O.bind("aLeft", () => O.map(aDefParentParent, (d) => d.left)),
|
|
@@ -250,7 +247,7 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
250
247
|
O.filter(({ aLeft, bLeft }) => aLeft.type === bLeft.type),
|
|
251
248
|
O.bind("aRight", () => O.map(aDefParentParent, (d) => d.right)),
|
|
252
249
|
O.bind("bRight", () => O.map(bDefParentParent, (d) => d.right)),
|
|
253
|
-
O.exists(({ aRight, bRight }) =>
|
|
250
|
+
O.exists(({ aRight, bRight }) => AST2.isNodeEqual(aRight, bRight))
|
|
254
251
|
);
|
|
255
252
|
}
|
|
256
253
|
default: {
|
|
@@ -259,14 +256,14 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
259
256
|
}
|
|
260
257
|
}
|
|
261
258
|
case (a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression): {
|
|
262
|
-
return
|
|
259
|
+
return AST2.isNodeEqual(a.property, b.property) && isNodeValueEqual(a.object, b.object, initialScopes);
|
|
263
260
|
}
|
|
264
261
|
case (a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression): {
|
|
265
262
|
if (aScope.block === bScope.block) return true;
|
|
266
263
|
return F.pipe(
|
|
267
264
|
O.Do,
|
|
268
|
-
O.bind("aFunction", () =>
|
|
269
|
-
O.bind("bFunction", () =>
|
|
265
|
+
O.bind("aFunction", () => AST2.traverseUp(a, AST2.isOneOf(thisBlockTypes))),
|
|
266
|
+
O.bind("bFunction", () => AST2.traverseUp(b, AST2.isOneOf(thisBlockTypes))),
|
|
270
267
|
O.exists(({ aFunction, bFunction }) => aFunction === bFunction)
|
|
271
268
|
);
|
|
272
269
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/var",
|
|
3
|
-
"version": "1.23.0",
|
|
3
|
+
"version": "1.23.1-next.0",
|
|
4
4
|
"description": "ESLint React's TSESTree AST utility module for static analysis of variables",
|
|
5
5
|
"homepage": "https://github.com/rEl1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"@typescript-eslint/utils": "^8.19.0",
|
|
39
39
|
"string-ts": "^2.2.0",
|
|
40
40
|
"ts-pattern": "^5.6.0",
|
|
41
|
-
"@eslint-react/ast": "1.23.0",
|
|
42
|
-
"@eslint-react/eff": "1.23.0",
|
|
43
|
-
"@eslint-react/types": "1.23.0"
|
|
41
|
+
"@eslint-react/ast": "1.23.1-next.0",
|
|
42
|
+
"@eslint-react/eff": "1.23.1-next.0",
|
|
43
|
+
"@eslint-react/types": "1.23.1-next.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"tsup": "^8.3.5",
|