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

Commit 1b9195a

Browse files
committed
Upgrade: typescript-estree to 12.0.0 and add new tests
1 parent 3b40d25 commit 1b9195a

File tree

6 files changed

+76
-28
lines changed

6 files changed

+76
-28
lines changed

analyze-scope.js

+15-16
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,24 @@ class Referencer extends OriginalReferencer {
346346
* @returns {void}
347347
*/
348348
TSInterfaceDeclaration(node) {
349+
this.visitTypeNodes(node);
350+
}
351+
352+
/**
353+
* Visit type assertion.
354+
* @param {TSTypeAssertion} node The TSTypeAssertion node to visit.
355+
* @returns {void}
356+
*/
357+
TSTypeAssertion(node) {
349358
if (this.typeMode) {
350-
this.visitChildren(node);
359+
this.visit(node.typeAnnotation);
351360
} else {
352361
this.typeMode = true;
353-
this.visitChildren(node);
362+
this.visit(node.typeAnnotation);
354363
this.typeMode = false;
355364
}
365+
366+
this.visit(node.expression);
356367
}
357368

358369
/**
@@ -378,13 +389,7 @@ class Referencer extends OriginalReferencer {
378389
* @returns {void}
379390
*/
380391
TSTypeAnnotation(node) {
381-
if (this.typeMode) {
382-
this.visitChildren(node);
383-
} else {
384-
this.typeMode = true;
385-
this.visitChildren(node);
386-
this.typeMode = false;
387-
}
392+
this.visitTypeNodes(node);
388393
}
389394

390395
/**
@@ -393,13 +398,7 @@ class Referencer extends OriginalReferencer {
393398
* @returns {void}
394399
*/
395400
TSTypeParameterDeclaration(node) {
396-
if (this.typeMode) {
397-
this.visitChildren(node);
398-
} else {
399-
this.typeMode = true;
400-
this.visitChildren(node);
401-
this.typeMode = false;
402-
}
401+
this.visitTypeNodes(node);
403402
}
404403

405404
/**

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": "9.0.0"
49+
"typescript-estree": "12.0.0"
5050
},
5151
"devDependencies": {
5252
"eslint": "^4.19.1",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export as namespace a;

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

+49-2
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/export-as-namespace.ts 1`] = `
3400+
Object {
3401+
"$id": 1,
3402+
"block": Object {
3403+
"range": Array [
3404+
0,
3405+
23,
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+
20,
3422+
21,
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-as.ts 1`] = `
34003447
Object {
34013448
"$id": 1,
@@ -5677,7 +5724,7 @@ Object {
56775724
21,
56785725
26,
56795726
],
5680-
"type": "TSTypeAssertionExpression",
5727+
"type": "TSTypeAssertion",
56815728
},
56825729
},
56835730
Object {
@@ -5949,7 +5996,7 @@ Object {
59495996
27,
59505997
40,
59515998
],
5952-
"type": "TSTypeAssertionExpression",
5999+
"type": "TSTypeAssertion",
59536000
},
59546001
},
59556002
Object {

tests/lib/__snapshots__/typescript.js.snap

+5-6
Original file line numberDiff line numberDiff line change
@@ -31746,8 +31746,7 @@ Object {
3174631746
245,
3174731747
265,
3174831748
],
31749-
"type": "TSConstructSignature",
31750-
"typeAnnotation": Object {
31749+
"returnType": Object {
3175131750
"loc": Object {
3175231751
"end": Object {
3175331752
"column": 23,
@@ -31781,6 +31780,7 @@ Object {
3178131780
"type": "TSStringKeyword",
3178231781
},
3178331782
},
31783+
"type": "TSConstructSignatureDeclaration",
3178431784
},
3178531785
Object {
3178631786
"loc": Object {
@@ -31836,8 +31836,7 @@ Object {
3183631836
270,
3183731837
293,
3183831838
],
31839-
"type": "TSConstructSignature",
31840-
"typeAnnotation": Object {
31839+
"returnType": Object {
3184131840
"loc": Object {
3184231841
"end": Object {
3184331842
"column": 26,
@@ -31871,6 +31870,7 @@ Object {
3187131870
"type": "TSStringKeyword",
3187231871
},
3187331872
},
31873+
"type": "TSConstructSignatureDeclaration",
3187431874
"typeParameters": Object {
3187531875
"loc": Object {
3187631876
"end": Object {
@@ -34095,8 +34095,7 @@ Object {
3409534095
21,
3409634096
47,
3409734097
],
34098-
"type": "TSConstructSignature",
34099-
"typeAnnotation": null,
34098+
"type": "TSConstructSignatureDeclaration",
3410034099
},
3410134100
],
3410234101
"loc": Object {

visitor-keys.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ module.exports = Evk.unionWith({
3636
TSAsyncKeyword: [],
3737
TSBigIntKeyword: [],
3838
TSBooleanKeyword: [],
39-
TSCallSignature: ["typeParameters", "parameters", "typeAnnotation"],
39+
TSCallSignatureDeclaration: ["typeParameters", "params", "returnType"],
4040
TSConditionalType: ["checkType", "extendsType", "trueType", "falseType"],
41-
TSConstructSignature: ["typeParameters", "params", "typeAnnotation"],
41+
TSConstructSignatureDeclaration: ["typeParameters", "params", "returnType"],
4242
TSConstructorType: ["typeAnnotation", "parameters"],
4343
TSDeclareKeyword: [],
4444
TSEmptyBodyDeclareFunction: ["id", "typeParameters", "params", "returnType"],
@@ -64,6 +64,7 @@ module.exports = Evk.unionWith({
6464
TSMethodSignature: ["typeAnnotation", "typeParameters", "key", "params"],
6565
TSModuleBlock: ["body"],
6666
TSModuleDeclaration: ["id", "body"],
67+
TSNamespaceExportDeclaration: ["id"],
6768
TSNamespaceFunctionDeclaration: [],
6869
TSNonNullExpression: ["expression"],
6970
TSNeverKeyword: [],
@@ -86,8 +87,9 @@ module.exports = Evk.unionWith({
8687
TSSymbolKeyword: [],
8788
TSThisType: [],
8889
TSTupleType: ["elementTypes"],
89-
TSTypeAnnotation: ["typeAnnotation"],
9090
TSTypeAliasDeclaration: ["id", "typeParameters", "typeAnnotation"],
91+
TSTypeAnnotation: ["typeAnnotation"],
92+
TSTypeAssertion: ["typeAnnotation", "expression"],
9193
TSTypeLiteral: ["members"],
9294
TSTypeOperator: ["typeAnnotation"],
9395
TSTypeParameter: ["constraint", "default"],

0 commit comments

Comments
 (0)