diff --git a/analyze-scope.js b/analyze-scope.js index df37a54..cfec9f5 100644 --- a/analyze-scope.js +++ b/analyze-scope.js @@ -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); } diff --git a/tests/fixtures/scope-analysis/class-implements.ts b/tests/fixtures/scope-analysis/class-implements.ts new file mode 100644 index 0000000..8da64a0 --- /dev/null +++ b/tests/fixtures/scope-analysis/class-implements.ts @@ -0,0 +1,3 @@ +class Foo implements Component, {}>, Component2 { + +} diff --git a/tests/lib/__snapshots__/scope-analysis.js.snap b/tests/lib/__snapshots__/scope-analysis.js.snap index 13475ef..2ae68e0 100644 --- a/tests/lib/__snapshots__/scope-analysis.js.snap +++ b/tests/lib/__snapshots__/scope-analysis.js.snap @@ -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, diff --git a/visitor-keys.js b/visitor-keys.js index 568baa7..4beead8 100644 --- a/visitor-keys.js +++ b/visitor-keys.js @@ -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"],