@typescript-eslint/type-utils 8.35.2-alpha.8 → 8.36.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.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { TSESTree } from '@typescript-eslint/types';
|
|
1
2
|
import type * as ts from 'typescript';
|
|
2
3
|
/**
|
|
3
4
|
* Describes specific types or values declared in local files.
|
|
@@ -127,4 +128,6 @@ export declare const typeOrValueSpecifiersSchema: {
|
|
|
127
128
|
};
|
|
128
129
|
export declare function typeMatchesSpecifier(type: ts.Type, specifier: TypeOrValueSpecifier, program: ts.Program): boolean;
|
|
129
130
|
export declare const typeMatchesSomeSpecifier: (type: ts.Type, specifiers: TypeOrValueSpecifier[] | undefined, program: ts.Program) => boolean;
|
|
131
|
+
export declare function valueMatchesSpecifier(node: TSESTree.Node, specifier: TypeOrValueSpecifier, program: ts.Program, type: ts.Type): boolean;
|
|
132
|
+
export declare const valueMatchesSomeSpecifier: (node: TSESTree.Node, specifiers: TypeOrValueSpecifier[] | undefined, program: ts.Program, type: ts.Type) => boolean;
|
|
130
133
|
//# sourceMappingURL=TypeOrValueSpecifier.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeOrValueSpecifier.d.ts","sourceRoot":"","sources":["../src/TypeOrValueSpecifier.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TypeOrValueSpecifier.d.ts","sourceRoot":"","sources":["../src/TypeOrValueSpecifier.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEzD,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAUtC;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAExB;;OAEG;IACH,IAAI,CAAC,E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Star) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.typeMatchesSomeSpecifier = exports.typeOrValueSpecifiersSchema = void 0;
|
|
36
|
+
exports.valueMatchesSomeSpecifier = exports.typeMatchesSomeSpecifier = exports.typeOrValueSpecifiersSchema = void 0;
|
|
37
37
|
exports.typeMatchesSpecifier = typeMatchesSpecifier;
|
|
38
|
+
exports.valueMatchesSpecifier = valueMatchesSpecifier;
|
|
39
|
+
const types_1 = require("@typescript-eslint/types");
|
|
38
40
|
const tsutils = __importStar(require("ts-api-utils"));
|
|
39
41
|
const specifierNameMatches_1 = require("./typeOrValueSpecifiers/specifierNameMatches");
|
|
40
42
|
const typeDeclaredInFile_1 = require("./typeOrValueSpecifiers/typeDeclaredInFile");
|
|
@@ -170,3 +172,38 @@ function typeMatchesSpecifier(type, specifier, program) {
|
|
|
170
172
|
}
|
|
171
173
|
const typeMatchesSomeSpecifier = (type, specifiers = [], program) => specifiers.some(specifier => typeMatchesSpecifier(type, specifier, program));
|
|
172
174
|
exports.typeMatchesSomeSpecifier = typeMatchesSomeSpecifier;
|
|
175
|
+
const getSpecifierNames = (specifierName) => {
|
|
176
|
+
return typeof specifierName === 'string' ? [specifierName] : specifierName;
|
|
177
|
+
};
|
|
178
|
+
const getStaticName = (node) => {
|
|
179
|
+
if (node.type === types_1.AST_NODE_TYPES.Identifier ||
|
|
180
|
+
node.type === types_1.AST_NODE_TYPES.JSXIdentifier ||
|
|
181
|
+
node.type === types_1.AST_NODE_TYPES.PrivateIdentifier) {
|
|
182
|
+
return node.name;
|
|
183
|
+
}
|
|
184
|
+
if (node.type === types_1.AST_NODE_TYPES.Literal && typeof node.value === 'string') {
|
|
185
|
+
return node.value;
|
|
186
|
+
}
|
|
187
|
+
return undefined;
|
|
188
|
+
};
|
|
189
|
+
function valueMatchesSpecifier(node, specifier, program, type) {
|
|
190
|
+
const staticName = getStaticName(node);
|
|
191
|
+
if (!staticName) {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
if (typeof specifier === 'string') {
|
|
195
|
+
return specifier === staticName;
|
|
196
|
+
}
|
|
197
|
+
if (!getSpecifierNames(specifier.name).includes(staticName)) {
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
if (specifier.from === 'package') {
|
|
201
|
+
const symbol = type.getSymbol() ?? type.aliasSymbol;
|
|
202
|
+
const declarations = symbol?.getDeclarations() ?? [];
|
|
203
|
+
const declarationFiles = declarations.map(declaration => declaration.getSourceFile());
|
|
204
|
+
return (0, typeDeclaredInPackageDeclarationFile_1.typeDeclaredInPackageDeclarationFile)(specifier.package, declarations, declarationFiles, program);
|
|
205
|
+
}
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
const valueMatchesSomeSpecifier = (node, specifiers = [], program, type) => specifiers.some(specifier => valueMatchesSpecifier(node, specifier, program, type));
|
|
209
|
+
exports.valueMatchesSomeSpecifier = valueMatchesSomeSpecifier;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typescript-eslint/type-utils",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.36.0",
|
|
4
4
|
"description": "Type utilities for working with TypeScript + ESLint together",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"typecheck": "yarn run -BT nx typecheck"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@typescript-eslint/typescript-estree": "8.
|
|
48
|
-
"@typescript-eslint/utils": "8.
|
|
47
|
+
"@typescript-eslint/typescript-estree": "8.36.0",
|
|
48
|
+
"@typescript-eslint/utils": "8.36.0",
|
|
49
49
|
"debug": "^4.3.4",
|
|
50
50
|
"ts-api-utils": "^2.1.0"
|
|
51
51
|
},
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"typescript": ">=4.8.4 <5.9.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@typescript-eslint/parser": "8.
|
|
57
|
+
"@typescript-eslint/parser": "8.36.0",
|
|
58
58
|
"@vitest/coverage-v8": "^3.1.3",
|
|
59
59
|
"ajv": "^6.12.6",
|
|
60
60
|
"eslint": "*",
|