From 42f1801cdc9e26b271ab8ad7f8399669118ff34b Mon Sep 17 00:00:00 2001 From: Armano Date: Sun, 16 Dec 2018 02:14:19 +0100 Subject: [PATCH 1/2] Fix: Allow to visit typeParameters in VariableDeclarator --- tests/fixtures/scope-analysis/type-generic.ts | 1 + .../lib/__snapshots__/scope-analysis.js.snap | 25 +++++++++++++++++++ visitor-keys.js | 2 ++ 3 files changed, 28 insertions(+) create mode 100644 tests/fixtures/scope-analysis/type-generic.ts diff --git a/tests/fixtures/scope-analysis/type-generic.ts b/tests/fixtures/scope-analysis/type-generic.ts new file mode 100644 index 0000000..b26722a --- /dev/null +++ b/tests/fixtures/scope-analysis/type-generic.ts @@ -0,0 +1 @@ +type foo = Foo diff --git a/tests/lib/__snapshots__/scope-analysis.js.snap b/tests/lib/__snapshots__/scope-analysis.js.snap index 6316b14..35a5ec2 100644 --- a/tests/lib/__snapshots__/scope-analysis.js.snap +++ b/tests/lib/__snapshots__/scope-analysis.js.snap @@ -5690,6 +5690,31 @@ Object { } `; +exports[`TypeScript scope analysis tests/fixtures/scope-analysis/type-generic.ts 1`] = ` +Object { + "$id": 0, + "block": Object { + "range": Array [ + 0, + 21, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object {}, + "variableScope": Object { + "$ref": 0, + }, + "variables": Array [], +} +`; + exports[`TypeScript scope analysis tests/fixtures/scope-analysis/typeof.ts 1`] = ` Object { "$id": 3, diff --git a/visitor-keys.js b/visitor-keys.js index 40a5e49..3ec6ee9 100644 --- a/visitor-keys.js +++ b/visitor-keys.js @@ -21,6 +21,8 @@ module.exports = Evk.unionWith({ ObjectPattern: ["properties", "typeAnnotation"], NewExpression: ["callee", "typeParameters", "arguments"], CallExpression: ["callee", "typeParameters", "arguments"], + // typeParameters are preset only when kind='type' + VariableDeclarator: ["id", "typeParameters", "init"], // Additional Nodes. ClassProperty: ["decorators", "key", "typeAnnotation", "value"], From 33acafac54038916d0d4a543775a9a201b317e91 Mon Sep 17 00:00:00 2001 From: Armano Date: Sun, 16 Dec 2018 14:57:43 +0100 Subject: [PATCH 2/2] chore: fix typo --- visitor-keys.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/visitor-keys.js b/visitor-keys.js index 3ec6ee9..8bc199d 100644 --- a/visitor-keys.js +++ b/visitor-keys.js @@ -21,7 +21,7 @@ module.exports = Evk.unionWith({ ObjectPattern: ["properties", "typeAnnotation"], NewExpression: ["callee", "typeParameters", "arguments"], CallExpression: ["callee", "typeParameters", "arguments"], - // typeParameters are preset only when kind='type' + // typeParameters are present only when kind='type' VariableDeclarator: ["id", "typeParameters", "init"], // Additional Nodes.