Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Commit 3b40d25

Browse files
committed
Upgrade: typescript-estree to 9.0.0 and add new tests
1 parent 34adb5d commit 3b40d25

File tree

6 files changed

+114
-6
lines changed

6 files changed

+114
-6
lines changed

analyze-scope.js

+29-4
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,23 @@ class Referencer extends OriginalReferencer {
355355
}
356356
}
357357

358+
/**
359+
* Visit as expression.
360+
* @param {TSAsExpression} node The TSAsExpression node to visit.
361+
* @returns {void}
362+
*/
363+
TSAsExpression(node) {
364+
this.visit(node.expression);
365+
366+
if (this.typeMode) {
367+
this.visit(node.typeAnnotation);
368+
} else {
369+
this.typeMode = true;
370+
this.visit(node.typeAnnotation);
371+
this.typeMode = false;
372+
}
373+
}
374+
358375
/**
359376
* Switch to the type mode and visit child nodes to find `typeof x` expression in type declarations.
360377
* @param {TSTypeAnnotation} node The TSTypeAnnotation node to visit.
@@ -400,6 +417,14 @@ class Referencer extends OriginalReferencer {
400417
}
401418
}
402419

420+
/**
421+
* @param {TSInferType} node The TSInferType node to visit.
422+
* @returns {void}
423+
*/
424+
TSInferType(node) {
425+
this.visitTypeNodes(node);
426+
}
427+
403428
/**
404429
* @param {TSTypeReference} node The TSTypeReference node to visit.
405430
* @returns {void}
@@ -659,11 +684,11 @@ class Referencer extends OriginalReferencer {
659684
* @returns {void}
660685
*/
661686
TSImportEqualsDeclaration(node) {
662-
const { name, moduleReference } = node;
663-
if (name && name.type === "Identifier") {
687+
const { id, moduleReference } = node;
688+
if (id && id.type === "Identifier") {
664689
this.currentScope().__define(
665-
name,
666-
new Definition("ImportBinding", name, node, null, null, null)
690+
id,
691+
new Definition("ImportBinding", id, node, null, null, null)
667692
);
668693
}
669694
this.visit(moduleReference);

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"dependencies": {
4747
"eslint-scope": "^4.0.0",
4848
"eslint-visitor-keys": "^1.0.0",
49-
"typescript-estree": "8.1.0"
49+
"typescript-estree": "9.0.0"
5050
},
5151
"devDependencies": {
5252
"eslint": "^4.19.1",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(a as number as any) = 42;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type Unpacked<T> =
2+
T extends (infer U)[] ? U :
3+
T extends infer U ? U :
4+
T extends Promise<infer U> ? U :
5+
T;

tests/lib/__snapshots__/scope-analysis.js.snap

+72
Original file line numberDiff line numberDiff line change
@@ -3396,6 +3396,53 @@ Object {
33963396
}
33973397
`;
33983398

3399+
exports[`TypeScript scope analysis tests/fixtures/scope-analysis/expression-as.ts 1`] = `
3400+
Object {
3401+
"$id": 1,
3402+
"block": Object {
3403+
"range": Array [
3404+
0,
3405+
27,
3406+
],
3407+
"type": "Program",
3408+
},
3409+
"childScopes": Array [],
3410+
"functionExpressionScope": false,
3411+
"isStrict": false,
3412+
"references": Array [
3413+
Object {
3414+
"$id": 0,
3415+
"from": Object {
3416+
"$ref": 1,
3417+
},
3418+
"identifier": Object {
3419+
"name": "a",
3420+
"range": Array [
3421+
1,
3422+
2,
3423+
],
3424+
"type": "Identifier",
3425+
},
3426+
"kind": "r",
3427+
"resolved": null,
3428+
"writeExpr": undefined,
3429+
},
3430+
],
3431+
"throughReferences": Array [
3432+
Object {
3433+
"$ref": 0,
3434+
},
3435+
],
3436+
"type": "global",
3437+
"upperScope": null,
3438+
"variableMap": Object {},
3439+
"variableScope": Object {
3440+
"$ref": 1,
3441+
},
3442+
"variables": Array [],
3443+
}
3444+
`;
3445+
33993446
exports[`TypeScript scope analysis tests/fixtures/scope-analysis/expression-type-parameters.ts 1`] = `
34003447
Object {
34013448
"$id": 14,
@@ -7339,6 +7386,31 @@ Object {
73397386
}
73407387
`;
73417388

7389+
exports[`TypeScript scope analysis tests/fixtures/scope-analysis/types-infer.ts 1`] = `
7390+
Object {
7391+
"$id": 0,
7392+
"block": Object {
7393+
"range": Array [
7394+
0,
7395+
147,
7396+
],
7397+
"type": "Program",
7398+
},
7399+
"childScopes": Array [],
7400+
"functionExpressionScope": false,
7401+
"isStrict": false,
7402+
"references": Array [],
7403+
"throughReferences": Array [],
7404+
"type": "global",
7405+
"upperScope": null,
7406+
"variableMap": Object {},
7407+
"variableScope": Object {
7408+
"$ref": 0,
7409+
},
7410+
"variables": Array [],
7411+
}
7412+
`;
7413+
73427414
exports[`TypeScript scope analysis tests/fixtures/scope-analysis/types-intersection-type.src.ts 1`] = `
73437415
Object {
73447416
"$id": 0,

visitor-keys.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ module.exports = Evk.unionWith({
3232
TSAbstractMethodDefinition: ["key", "value"],
3333
TSAnyKeyword: [],
3434
TSArrayType: ["elementType"],
35+
TSAsExpression: ["expression", "typeAnnotation"],
3536
TSAsyncKeyword: [],
37+
TSBigIntKeyword: [],
3638
TSBooleanKeyword: [],
3739
TSCallSignature: ["typeParameters", "parameters", "typeAnnotation"],
3840
TSConditionalType: ["checkType", "extendsType", "trueType", "falseType"],
@@ -48,14 +50,15 @@ module.exports = Evk.unionWith({
4850
TSExportKeyword: [],
4951
TSExternalModuleReference: ["expression"],
5052
TSImportType: ["parameter", "qualifier", "typeParameters"],
53+
TSInferType: ["typeParameter"],
5154
TSLiteralType: ["literal"],
5255
TSIntersectionType: ["types"],
5356
TSIndexedAccessType: ["indexType", "objectType"],
5457
TSIndexSignature: ["typeAnnotation", "index"],
5558
TSInterfaceBody: ["body"],
5659
TSInterfaceDeclaration: ["id", "typeParameters", "heritage", "body"],
5760
TSInterfaceHeritage: ["id", "typeParameters"],
58-
TSImportEqualsDeclaration: ["name", "moduleReference"],
61+
TSImportEqualsDeclaration: ["id", "moduleReference"],
5962
TSFunctionType: ["parameters", "typeAnnotation"],
6063
TSMappedType: ["typeParameter"],
6164
TSMethodSignature: ["typeAnnotation", "typeParameters", "key", "params"],
@@ -81,6 +84,7 @@ module.exports = Evk.unionWith({
8184
TSStaticKeyword: [],
8285
TSStringKeyword: [],
8386
TSSymbolKeyword: [],
87+
TSThisType: [],
8488
TSTupleType: ["elementTypes"],
8589
TSTypeAnnotation: ["typeAnnotation"],
8690
TSTypeAliasDeclaration: ["id", "typeParameters", "typeAnnotation"],
@@ -94,5 +98,6 @@ module.exports = Evk.unionWith({
9498
TSTypeQuery: ["exprName"],
9599
TSUnionType: ["types"],
96100
TSUndefinedKeyword: [],
101+
TSUnknownKeyword: [],
97102
TSVoidKeyword: []
98103
});

0 commit comments

Comments
 (0)