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

Fix: missing visitor-keys #554

Merged
merged 3 commits into from
Nov 20, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions analyze-scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,12 @@ class Referencer extends OriginalReferencer {
* @returns {void}
*/
Identifier(node) {
this.visitDecorators(node.decorators);

if (!this.typeMode) {
super.Identifier(node);
}

this.visit(node.typeAnnotation);
}

Expand Down
4 changes: 4 additions & 0 deletions tests/fixtures/scope-analysis/identifier-decorators.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export class Test {
constructor(@Decorator config) {
}
}
7 changes: 7 additions & 0 deletions tests/fixtures/scope-analysis/interface-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
interface C<T = any> {

}

interface R<T extends C> {
foo: C
}
274 changes: 274 additions & 0 deletions tests/lib/__snapshots__/scope-analysis.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2927,6 +2927,255 @@ Object {
}
`;

exports[`TypeScript scope analysis tests/fixtures/scope-analysis/identifier-decorators.ts 1`] = `
Object {
"$id": 7,
"block": Object {
"range": Array [
0,
65,
],
"type": "Program",
},
"childScopes": Array [
Object {
"$id": 6,
"block": Object {
"range": Array [
0,
65,
],
"type": "Program",
},
"childScopes": Array [
Object {
"$id": 5,
"block": Object {
"range": Array [
7,
64,
],
"type": "ClassDeclaration",
},
"childScopes": Array [
Object {
"$id": 4,
"block": Object {
"range": Array [
35,
62,
],
"type": "FunctionExpression",
},
"childScopes": Array [],
"functionExpressionScope": false,
"isStrict": true,
"references": Array [],
armano2 marked this conversation as resolved.
Show resolved Hide resolved
"throughReferences": Array [],
"type": "function",
"upperScope": Object {
"$ref": 5,
},
"variableMap": Object {
"arguments": Object {
"$ref": 2,
},
"config": Object {
"$ref": 3,
},
},
"variableScope": Object {
"$ref": 4,
},
"variables": Array [
Object {
"$id": 2,
"defs": Array [],
"eslintUsed": undefined,
"identifiers": Array [],
"name": "arguments",
"references": Array [],
"scope": Object {
"$ref": 4,
},
},
Object {
"$id": 3,
"defs": Array [
Object {
"name": Object {
"name": "config",
"range": Array [
47,
53,
],
"type": "Identifier",
},
"node": Object {
"range": Array [
35,
62,
],
"type": "FunctionExpression",
},
"parent": null,
"type": "Parameter",
},
],
"eslintUsed": undefined,
"identifiers": Array [
Object {
"name": "config",
"range": Array [
47,
53,
],
"type": "Identifier",
},
],
"name": "config",
"references": Array [],
"scope": Object {
"$ref": 4,
},
},
],
},
],
"functionExpressionScope": false,
"isStrict": true,
"references": Array [],
"throughReferences": Array [],
"type": "class",
"upperScope": Object {
"$ref": 6,
},
"variableMap": Object {
"Test": Object {
"$ref": 1,
},
},
"variableScope": Object {
"$ref": 6,
},
"variables": Array [
Object {
"$id": 1,
"defs": Array [
Object {
"name": Object {
"name": "Test",
"range": Array [
13,
17,
],
"type": "Identifier",
},
"node": Object {
"range": Array [
7,
64,
],
"type": "ClassDeclaration",
},
"parent": undefined,
"type": "ClassName",
},
],
"eslintUsed": undefined,
"identifiers": Array [
Object {
"name": "Test",
"range": Array [
13,
17,
],
"type": "Identifier",
},
],
"name": "Test",
"references": Array [],
"scope": Object {
"$ref": 5,
},
},
],
},
],
"functionExpressionScope": false,
"isStrict": true,
"references": Array [],
"throughReferences": Array [],
"type": "module",
"upperScope": Object {
"$ref": 7,
},
"variableMap": Object {
"Test": Object {
"$ref": 0,
},
},
"variableScope": Object {
"$ref": 6,
},
"variables": Array [
Object {
"$id": 0,
"defs": Array [
Object {
"name": Object {
"name": "Test",
"range": Array [
13,
17,
],
"type": "Identifier",
},
"node": Object {
"range": Array [
7,
64,
],
"type": "ClassDeclaration",
},
"parent": null,
"type": "ClassName",
},
],
"eslintUsed": undefined,
"identifiers": Array [
Object {
"name": "Test",
"range": Array [
13,
17,
],
"type": "Identifier",
},
],
"name": "Test",
"references": Array [],
"scope": Object {
"$ref": 6,
},
},
],
},
],
"functionExpressionScope": false,
"isStrict": false,
"references": Array [],
"throughReferences": Array [],
"type": "global",
"upperScope": null,
"variableMap": Object {},
"variableScope": Object {
"$ref": 7,
},
"variables": Array [],
}
`;

exports[`TypeScript scope analysis tests/fixtures/scope-analysis/ignore-type-only-stuff.ts 1`] = `
Object {
"$id": 1,
Expand Down Expand Up @@ -3003,6 +3252,31 @@ Object {
}
`;

exports[`TypeScript scope analysis tests/fixtures/scope-analysis/interface-type.ts 1`] = `
Object {
"$id": 0,
"block": Object {
"range": Array [
0,
67,
],
"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/method-overload.ts 1`] = `
Object {
"$id": 10,
Expand Down
6 changes: 3 additions & 3 deletions visitor-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = Evk.unionWith({
ClassExpression: ["decorators", "id", "typeParameters", "superClass", "body"],
FunctionDeclaration: ["id", "typeParameters", "params", "returnType", "body"],
FunctionExpression: ["id", "typeParameters", "params", "returnType", "body"],
Identifier: ["typeAnnotation"],
Identifier: ["decorators", "typeAnnotation"],
MethodDefinition: ["decorators", "key", "value"],
ObjectPattern: ["properties", "typeAnnotation"],

Expand Down Expand Up @@ -46,9 +46,9 @@ module.exports = Evk.unionWith({
TSLiteralType: ["literal"],
TSIndexSignature: ["typeAnnotation", "index"],
TSInterfaceBody: ["body"],
TSInterfaceDeclaration: ["body", "id", "heritage"],
TSInterfaceDeclaration: ["body", "id", "heritage", "typeParameters"],
mysticatea marked this conversation as resolved.
Show resolved Hide resolved
TSInterfaceHeritage: ["id", "typeParameters"],
TSFunctionType: ["typeAnnotation"],
TSFunctionType: ["parameters", "typeAnnotation"],
TSMethodSignature: ["typeAnnotation", "typeParameters", "key", "params"],
TSModuleBlock: ["body"],
TSModuleDeclaration: ["id", "body"],
Expand Down