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

Commit

Permalink
Fix: missing implements in classes (#562)
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 authored and platinumazure committed Nov 28, 2018
1 parent cc92044 commit 8ff0ad1
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 6 deletions.
11 changes: 7 additions & 4 deletions analyze-scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,21 @@ class Referencer extends OriginalReferencer {
/**
* Override.
* Visit decorators.
* @param {ClassDeclaration|ClassExpression} node The class node to visit.
* @param {ClassDeclaration|ClassExpression|TSAbstractClassDeclaration} node The class node to visit.
* @returns {void}
*/
visitClass(node) {
this.visitDecorators(node.decorators);

const upperTypeMode = this.typeMode;
this.typeMode = true;
if (node.superTypeParameters) {
const upperTypeMode = this.typeMode;
this.typeMode = true;
this.visit(node.superTypeParameters);
this.typeMode = upperTypeMode;
}
if (node.implements) {
this.visit(node.implements);
}
this.typeMode = upperTypeMode;

super.visitClass(node);
}
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/scope-analysis/class-implements.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Foo<Nullable> implements Component<Nullable<SomeOther>, {}>, Component2 {

}
140 changes: 140 additions & 0 deletions tests/lib/__snapshots__/scope-analysis.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,146 @@ Object {
}
`;

exports[`TypeScript scope analysis tests/fixtures/scope-analysis/class-implements.ts 1`] = `
Object {
"$id": 3,
"block": Object {
"range": Array [
0,
83,
],
"type": "Program",
},
"childScopes": Array [
Object {
"$id": 2,
"block": Object {
"range": Array [
0,
82,
],
"type": "ClassDeclaration",
},
"childScopes": Array [],
"functionExpressionScope": false,
"isStrict": true,
"references": Array [],
"throughReferences": Array [],
"type": "class",
"upperScope": Object {
"$ref": 3,
},
"variableMap": Object {
"Foo": Object {
"$ref": 1,
},
},
"variableScope": Object {
"$ref": 3,
},
"variables": Array [
Object {
"$id": 1,
"defs": Array [
Object {
"name": Object {
"name": "Foo",
"range": Array [
6,
9,
],
"type": "Identifier",
},
"node": Object {
"range": Array [
0,
82,
],
"type": "ClassDeclaration",
},
"parent": undefined,
"type": "ClassName",
},
],
"eslintUsed": undefined,
"identifiers": Array [
Object {
"name": "Foo",
"range": Array [
6,
9,
],
"type": "Identifier",
},
],
"name": "Foo",
"references": Array [],
"scope": Object {
"$ref": 2,
},
},
],
},
],
"functionExpressionScope": false,
"isStrict": false,
"references": Array [],
"throughReferences": Array [],
"type": "global",
"upperScope": null,
"variableMap": Object {
"Foo": Object {
"$ref": 0,
},
},
"variableScope": Object {
"$ref": 3,
},
"variables": Array [
Object {
"$id": 0,
"defs": Array [
Object {
"name": Object {
"name": "Foo",
"range": Array [
6,
9,
],
"type": "Identifier",
},
"node": Object {
"range": Array [
0,
82,
],
"type": "ClassDeclaration",
},
"parent": null,
"type": "ClassName",
},
],
"eslintUsed": undefined,
"identifiers": Array [
Object {
"name": "Foo",
"range": Array [
6,
9,
],
"type": "Identifier",
},
],
"name": "Foo",
"references": Array [],
"scope": Object {
"$ref": 3,
},
},
],
}
`;

exports[`TypeScript scope analysis tests/fixtures/scope-analysis/class-properties.ts 1`] = `
Object {
"$id": 8,
Expand Down
4 changes: 2 additions & 2 deletions visitor-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ module.exports = Evk.unionWith({
// Additional Properties.
ArrayPattern: ["elements", "typeAnnotation"],
ArrowFunctionExpression: ["typeParameters", "params", "returnType", "body"],
ClassDeclaration: ["decorators", "id", "typeParameters", "superClass", "superTypeParameters", "body"],
ClassExpression: ["decorators", "id", "typeParameters", "superClass", "superTypeParameters", "body"],
ClassDeclaration: ["decorators", "id", "typeParameters", "superClass", "superTypeParameters", "implements", "body"],
ClassExpression: ["decorators", "id", "typeParameters", "superClass", "superTypeParameters", "implements", "body"],
FunctionDeclaration: ["id", "typeParameters", "params", "returnType", "body"],
FunctionExpression: ["id", "typeParameters", "params", "returnType", "body"],
Identifier: ["decorators", "typeAnnotation"],
Expand Down

0 comments on commit 8ff0ad1

Please sign in to comment.