@eslint-react/var 1.17.4-next.3 → 1.17.4-next.5
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 +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +28 -14
- package/dist/index.mjs +27 -15
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -452,6 +452,8 @@ declare function getChidScopes(scope: Scope, prev?: readonly Scope[]): readonly
|
|
|
452
452
|
|
|
453
453
|
declare function getScope(node: TSESTree.Node, scopeManager: ScopeManager): _typescript_eslint_scope_manager.Scope | null;
|
|
454
454
|
|
|
455
|
+
declare function getStaticValue(node: TSESTree.Node, initialScope: Scope): O.Option<unknown>;
|
|
456
|
+
|
|
455
457
|
declare function getVariableDeclaratorID(node: TSESTree.Node, prev?: TSESTree.Node): O.Option<TSESTree.BindingName | TSESTree.Expression>;
|
|
456
458
|
|
|
457
459
|
/**
|
|
@@ -491,6 +493,9 @@ declare function isInitializedFromSource(name: string, source: string, initialSc
|
|
|
491
493
|
* @param initialScopes initial scopes of the two nodes
|
|
492
494
|
* @returns `true` if node value equal
|
|
493
495
|
*/
|
|
494
|
-
declare function isNodeValueEqual(a: TSESTree.Node, b: TSESTree.Node, initialScopes: [
|
|
496
|
+
declare function isNodeValueEqual(a: TSESTree.Node, b: TSESTree.Node, initialScopes: [
|
|
497
|
+
aScope: Scope,
|
|
498
|
+
bScope: Scope
|
|
499
|
+
]): boolean;
|
|
495
500
|
|
|
496
|
-
export { Construction, ConstructionHint, findVariable, getChidScopes, getScope, getVariableDeclaratorID, getVariableDef, getVariableNode, getVariables, inspectConstruction, isInitializedFromSource, isNodeValueEqual };
|
|
501
|
+
export { Construction, ConstructionHint, findVariable, getChidScopes, getScope, getStaticValue, getVariableDeclaratorID, getVariableDef, getVariableNode, getVariables, inspectConstruction, isInitializedFromSource, isNodeValueEqual };
|
package/dist/index.d.ts
CHANGED
|
@@ -452,6 +452,8 @@ declare function getChidScopes(scope: Scope, prev?: readonly Scope[]): readonly
|
|
|
452
452
|
|
|
453
453
|
declare function getScope(node: TSESTree.Node, scopeManager: ScopeManager): _typescript_eslint_scope_manager.Scope | null;
|
|
454
454
|
|
|
455
|
+
declare function getStaticValue(node: TSESTree.Node, initialScope: Scope): O.Option<unknown>;
|
|
456
|
+
|
|
455
457
|
declare function getVariableDeclaratorID(node: TSESTree.Node, prev?: TSESTree.Node): O.Option<TSESTree.BindingName | TSESTree.Expression>;
|
|
456
458
|
|
|
457
459
|
/**
|
|
@@ -491,6 +493,9 @@ declare function isInitializedFromSource(name: string, source: string, initialSc
|
|
|
491
493
|
* @param initialScopes initial scopes of the two nodes
|
|
492
494
|
* @returns `true` if node value equal
|
|
493
495
|
*/
|
|
494
|
-
declare function isNodeValueEqual(a: TSESTree.Node, b: TSESTree.Node, initialScopes: [
|
|
496
|
+
declare function isNodeValueEqual(a: TSESTree.Node, b: TSESTree.Node, initialScopes: [
|
|
497
|
+
aScope: Scope,
|
|
498
|
+
bScope: Scope
|
|
499
|
+
]): boolean;
|
|
495
500
|
|
|
496
|
-
export { Construction, ConstructionHint, findVariable, getChidScopes, getScope, getVariableDeclaratorID, getVariableDef, getVariableNode, getVariables, inspectConstruction, isInitializedFromSource, isNodeValueEqual };
|
|
501
|
+
export { Construction, ConstructionHint, findVariable, getChidScopes, getScope, getStaticValue, getVariableDeclaratorID, getVariableDef, getVariableNode, getVariables, inspectConstruction, isInitializedFromSource, isNodeValueEqual };
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ var tools = require('@eslint-react/tools');
|
|
|
5
5
|
var scopeManager = require('@typescript-eslint/scope-manager');
|
|
6
6
|
var types = require('@typescript-eslint/types');
|
|
7
7
|
var tsPattern = require('ts-pattern');
|
|
8
|
-
var
|
|
8
|
+
var ASTUtils = require('@typescript-eslint/utils/ast-utils');
|
|
9
9
|
|
|
10
10
|
function _interopNamespace(e) {
|
|
11
11
|
if (e && e.__esModule) return e;
|
|
@@ -26,6 +26,7 @@ function _interopNamespace(e) {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
var AST__namespace = /*#__PURE__*/_interopNamespace(AST);
|
|
29
|
+
var ASTUtils__namespace = /*#__PURE__*/_interopNamespace(ASTUtils);
|
|
29
30
|
|
|
30
31
|
// src/construction.ts
|
|
31
32
|
var Construction = tools.Data.taggedEnum();
|
|
@@ -122,8 +123,8 @@ function inspectConstruction(node, initialScope, hint = ConstructionHint.None) {
|
|
|
122
123
|
};
|
|
123
124
|
return detect(node);
|
|
124
125
|
}
|
|
125
|
-
var
|
|
126
|
-
return tools.O.fromNullable(
|
|
126
|
+
var findVariable2 = tools.F.dual(2, (nameOrNode, initialScope) => {
|
|
127
|
+
return tools.O.fromNullable(ASTUtils__namespace.findVariable(initialScope, nameOrNode));
|
|
127
128
|
});
|
|
128
129
|
|
|
129
130
|
// src/get-child-scopes.ts
|
|
@@ -138,6 +139,12 @@ function getScope(node, scopeManager) {
|
|
|
138
139
|
if (parent) return getScope(parent, scopeManager);
|
|
139
140
|
return null;
|
|
140
141
|
}
|
|
142
|
+
function getStaticValue2(node, initialScope) {
|
|
143
|
+
return tools.F.pipe(
|
|
144
|
+
tools.O.fromNullable(ASTUtils__namespace.getStaticValue(node, initialScope)),
|
|
145
|
+
tools.O.map((v) => v.value)
|
|
146
|
+
);
|
|
147
|
+
}
|
|
141
148
|
function getVariableDeclaratorID(node, prev) {
|
|
142
149
|
switch (true) {
|
|
143
150
|
case (node.type === types.AST_NODE_TYPES.VariableDeclarator && node.init === prev):
|
|
@@ -187,7 +194,7 @@ function getVariables(initialScope) {
|
|
|
187
194
|
return variables.reverse();
|
|
188
195
|
}
|
|
189
196
|
function isInitializedFromSource(name, source, initialScope) {
|
|
190
|
-
const maybeLatestDef = tools.O.flatMapNullable(
|
|
197
|
+
const maybeLatestDef = tools.O.flatMapNullable(findVariable2(name, initialScope), (v) => v.defs.at(-1));
|
|
191
198
|
if (tools.O.isNone(maybeLatestDef)) return false;
|
|
192
199
|
const latestDef = maybeLatestDef.value;
|
|
193
200
|
const { node, parent } = latestDef;
|
|
@@ -236,8 +243,8 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
236
243
|
return a.value.cooked === b.value.cooked;
|
|
237
244
|
}
|
|
238
245
|
case (a.type === types.AST_NODE_TYPES.Identifier && b.type === types.AST_NODE_TYPES.Identifier): {
|
|
239
|
-
const aVar =
|
|
240
|
-
const bVar =
|
|
246
|
+
const aVar = findVariable2(a, aScope);
|
|
247
|
+
const bVar = findVariable2(b, bScope);
|
|
241
248
|
const aVarNode = tools.O.flatMap(aVar, getVariableNode(0));
|
|
242
249
|
const bVarNode = tools.O.flatMap(bVar, getVariableNode(0));
|
|
243
250
|
const aVarNodeParent = tools.O.flatMapNullable(aVarNode, (n) => n.parent);
|
|
@@ -277,7 +284,7 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
277
284
|
);
|
|
278
285
|
}
|
|
279
286
|
default: {
|
|
280
|
-
return tools.O.isSome(aVar) && tools.O.isSome(bVar) && aVar
|
|
287
|
+
return tools.O.isSome(aVar) && tools.O.isSome(bVar) && tools.Equal.equals(aVar, bVar);
|
|
281
288
|
}
|
|
282
289
|
}
|
|
283
290
|
}
|
|
@@ -286,23 +293,30 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
286
293
|
}
|
|
287
294
|
case (a.type === types.AST_NODE_TYPES.ThisExpression && b.type === types.AST_NODE_TYPES.ThisExpression): {
|
|
288
295
|
if (aScope.block === bScope.block) return true;
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
296
|
+
return tools.F.pipe(
|
|
297
|
+
tools.O.Do,
|
|
298
|
+
tools.O.bind("aFunction", () => AST__namespace.traverseUp(a, AST__namespace.isOneOf(thisBlockTypes))),
|
|
299
|
+
tools.O.bind("bFunction", () => AST__namespace.traverseUp(b, AST__namespace.isOneOf(thisBlockTypes))),
|
|
300
|
+
tools.O.exists(({ aFunction, bFunction }) => aFunction === bFunction)
|
|
301
|
+
);
|
|
292
302
|
}
|
|
293
303
|
default: {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
304
|
+
return tools.F.pipe(
|
|
305
|
+
tools.O.Do,
|
|
306
|
+
tools.O.bind("aStatic", () => getStaticValue2(a, aScope)),
|
|
307
|
+
tools.O.bind("bStatic", () => getStaticValue2(b, bScope)),
|
|
308
|
+
tools.O.exists(({ aStatic, bStatic }) => aStatic === bStatic)
|
|
309
|
+
);
|
|
297
310
|
}
|
|
298
311
|
}
|
|
299
312
|
}
|
|
300
313
|
|
|
301
314
|
exports.Construction = Construction;
|
|
302
315
|
exports.ConstructionHint = ConstructionHint;
|
|
303
|
-
exports.findVariable =
|
|
316
|
+
exports.findVariable = findVariable2;
|
|
304
317
|
exports.getChidScopes = getChidScopes;
|
|
305
318
|
exports.getScope = getScope;
|
|
319
|
+
exports.getStaticValue = getStaticValue2;
|
|
306
320
|
exports.getVariableDeclaratorID = getVariableDeclaratorID;
|
|
307
321
|
exports.getVariableDef = getVariableDef;
|
|
308
322
|
exports.getVariableNode = getVariableNode;
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as AST from '@eslint-react/ast';
|
|
2
|
-
import { Data, F, O, isString, isNullable, isObject } from '@eslint-react/tools';
|
|
2
|
+
import { Data, F, O, isString, Equal, isNullable, isObject } from '@eslint-react/tools';
|
|
3
3
|
import { DefinitionType, ScopeType } from '@typescript-eslint/scope-manager';
|
|
4
4
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
5
5
|
import { match, isMatching } from 'ts-pattern';
|
|
6
|
-
import
|
|
6
|
+
import * as ASTUtils from '@typescript-eslint/utils/ast-utils';
|
|
7
7
|
|
|
8
8
|
// src/construction.ts
|
|
9
9
|
var Construction = Data.taggedEnum();
|
|
@@ -100,8 +100,8 @@ function inspectConstruction(node, initialScope, hint = ConstructionHint.None) {
|
|
|
100
100
|
};
|
|
101
101
|
return detect(node);
|
|
102
102
|
}
|
|
103
|
-
var
|
|
104
|
-
return O.fromNullable(findVariable
|
|
103
|
+
var findVariable2 = F.dual(2, (nameOrNode, initialScope) => {
|
|
104
|
+
return O.fromNullable(ASTUtils.findVariable(initialScope, nameOrNode));
|
|
105
105
|
});
|
|
106
106
|
|
|
107
107
|
// src/get-child-scopes.ts
|
|
@@ -116,6 +116,12 @@ function getScope(node, scopeManager) {
|
|
|
116
116
|
if (parent) return getScope(parent, scopeManager);
|
|
117
117
|
return null;
|
|
118
118
|
}
|
|
119
|
+
function getStaticValue2(node, initialScope) {
|
|
120
|
+
return F.pipe(
|
|
121
|
+
O.fromNullable(ASTUtils.getStaticValue(node, initialScope)),
|
|
122
|
+
O.map((v) => v.value)
|
|
123
|
+
);
|
|
124
|
+
}
|
|
119
125
|
function getVariableDeclaratorID(node, prev) {
|
|
120
126
|
switch (true) {
|
|
121
127
|
case (node.type === AST_NODE_TYPES.VariableDeclarator && node.init === prev):
|
|
@@ -165,7 +171,7 @@ function getVariables(initialScope) {
|
|
|
165
171
|
return variables.reverse();
|
|
166
172
|
}
|
|
167
173
|
function isInitializedFromSource(name, source, initialScope) {
|
|
168
|
-
const maybeLatestDef = O.flatMapNullable(
|
|
174
|
+
const maybeLatestDef = O.flatMapNullable(findVariable2(name, initialScope), (v) => v.defs.at(-1));
|
|
169
175
|
if (O.isNone(maybeLatestDef)) return false;
|
|
170
176
|
const latestDef = maybeLatestDef.value;
|
|
171
177
|
const { node, parent } = latestDef;
|
|
@@ -214,8 +220,8 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
214
220
|
return a.value.cooked === b.value.cooked;
|
|
215
221
|
}
|
|
216
222
|
case (a.type === AST_NODE_TYPES.Identifier && b.type === AST_NODE_TYPES.Identifier): {
|
|
217
|
-
const aVar =
|
|
218
|
-
const bVar =
|
|
223
|
+
const aVar = findVariable2(a, aScope);
|
|
224
|
+
const bVar = findVariable2(b, bScope);
|
|
219
225
|
const aVarNode = O.flatMap(aVar, getVariableNode(0));
|
|
220
226
|
const bVarNode = O.flatMap(bVar, getVariableNode(0));
|
|
221
227
|
const aVarNodeParent = O.flatMapNullable(aVarNode, (n) => n.parent);
|
|
@@ -255,7 +261,7 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
255
261
|
);
|
|
256
262
|
}
|
|
257
263
|
default: {
|
|
258
|
-
return O.isSome(aVar) && O.isSome(bVar) && aVar
|
|
264
|
+
return O.isSome(aVar) && O.isSome(bVar) && Equal.equals(aVar, bVar);
|
|
259
265
|
}
|
|
260
266
|
}
|
|
261
267
|
}
|
|
@@ -264,16 +270,22 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
264
270
|
}
|
|
265
271
|
case (a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression): {
|
|
266
272
|
if (aScope.block === bScope.block) return true;
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
273
|
+
return F.pipe(
|
|
274
|
+
O.Do,
|
|
275
|
+
O.bind("aFunction", () => AST.traverseUp(a, AST.isOneOf(thisBlockTypes))),
|
|
276
|
+
O.bind("bFunction", () => AST.traverseUp(b, AST.isOneOf(thisBlockTypes))),
|
|
277
|
+
O.exists(({ aFunction, bFunction }) => aFunction === bFunction)
|
|
278
|
+
);
|
|
270
279
|
}
|
|
271
280
|
default: {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
281
|
+
return F.pipe(
|
|
282
|
+
O.Do,
|
|
283
|
+
O.bind("aStatic", () => getStaticValue2(a, aScope)),
|
|
284
|
+
O.bind("bStatic", () => getStaticValue2(b, bScope)),
|
|
285
|
+
O.exists(({ aStatic, bStatic }) => aStatic === bStatic)
|
|
286
|
+
);
|
|
275
287
|
}
|
|
276
288
|
}
|
|
277
289
|
}
|
|
278
290
|
|
|
279
|
-
export { Construction, ConstructionHint, findVariable, getChidScopes, getScope, getVariableDeclaratorID, getVariableDef, getVariableNode, getVariables, inspectConstruction, isInitializedFromSource, isNodeValueEqual };
|
|
291
|
+
export { Construction, ConstructionHint, findVariable2 as findVariable, getChidScopes, getScope, getStaticValue2 as getStaticValue, getVariableDeclaratorID, getVariableDef, getVariableNode, getVariables, inspectConstruction, isInitializedFromSource, isNodeValueEqual };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/var",
|
|
3
|
-
"version": "1.17.4-next.
|
|
3
|
+
"version": "1.17.4-next.5",
|
|
4
4
|
"description": "TSESTree AST utility module for static analysis of variables",
|
|
5
5
|
"homepage": "https://github.com/rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"@typescript-eslint/types": "^8.17.0",
|
|
40
40
|
"@typescript-eslint/utils": "^8.17.0",
|
|
41
41
|
"ts-pattern": "^5.5.0",
|
|
42
|
-
"@eslint-react/ast": "1.17.4-next.
|
|
43
|
-
"@eslint-react/tools": "1.17.4-next.
|
|
44
|
-
"@eslint-react/types": "1.17.4-next.
|
|
42
|
+
"@eslint-react/ast": "1.17.4-next.5",
|
|
43
|
+
"@eslint-react/tools": "1.17.4-next.5",
|
|
44
|
+
"@eslint-react/types": "1.17.4-next.5"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"string-ts": "^2.2.0",
|