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

Commit 8ff0ad1

Browse files
armano2platinumazure
authored andcommitted
Fix: missing implements in classes (#562)
1 parent cc92044 commit 8ff0ad1

File tree

4 files changed

+152
-6
lines changed

4 files changed

+152
-6
lines changed

analyze-scope.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -210,18 +210,21 @@ class Referencer extends OriginalReferencer {
210210
/**
211211
* Override.
212212
* Visit decorators.
213-
* @param {ClassDeclaration|ClassExpression} node The class node to visit.
213+
* @param {ClassDeclaration|ClassExpression|TSAbstractClassDeclaration} node The class node to visit.
214214
* @returns {void}
215215
*/
216216
visitClass(node) {
217217
this.visitDecorators(node.decorators);
218218

219+
const upperTypeMode = this.typeMode;
220+
this.typeMode = true;
219221
if (node.superTypeParameters) {
220-
const upperTypeMode = this.typeMode;
221-
this.typeMode = true;
222222
this.visit(node.superTypeParameters);
223-
this.typeMode = upperTypeMode;
224223
}
224+
if (node.implements) {
225+
this.visit(node.implements);
226+
}
227+
this.typeMode = upperTypeMode;
225228

226229
super.visitClass(node);
227230
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Foo<Nullable> implements Component<Nullable<SomeOther>, {}>, Component2 {
2+
3+
}

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

+140
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,146 @@ Object {
273273
}
274274
`;
275275

276+
exports[`TypeScript scope analysis tests/fixtures/scope-analysis/class-implements.ts 1`] = `
277+
Object {
278+
"$id": 3,
279+
"block": Object {
280+
"range": Array [
281+
0,
282+
83,
283+
],
284+
"type": "Program",
285+
},
286+
"childScopes": Array [
287+
Object {
288+
"$id": 2,
289+
"block": Object {
290+
"range": Array [
291+
0,
292+
82,
293+
],
294+
"type": "ClassDeclaration",
295+
},
296+
"childScopes": Array [],
297+
"functionExpressionScope": false,
298+
"isStrict": true,
299+
"references": Array [],
300+
"throughReferences": Array [],
301+
"type": "class",
302+
"upperScope": Object {
303+
"$ref": 3,
304+
},
305+
"variableMap": Object {
306+
"Foo": Object {
307+
"$ref": 1,
308+
},
309+
},
310+
"variableScope": Object {
311+
"$ref": 3,
312+
},
313+
"variables": Array [
314+
Object {
315+
"$id": 1,
316+
"defs": Array [
317+
Object {
318+
"name": Object {
319+
"name": "Foo",
320+
"range": Array [
321+
6,
322+
9,
323+
],
324+
"type": "Identifier",
325+
},
326+
"node": Object {
327+
"range": Array [
328+
0,
329+
82,
330+
],
331+
"type": "ClassDeclaration",
332+
},
333+
"parent": undefined,
334+
"type": "ClassName",
335+
},
336+
],
337+
"eslintUsed": undefined,
338+
"identifiers": Array [
339+
Object {
340+
"name": "Foo",
341+
"range": Array [
342+
6,
343+
9,
344+
],
345+
"type": "Identifier",
346+
},
347+
],
348+
"name": "Foo",
349+
"references": Array [],
350+
"scope": Object {
351+
"$ref": 2,
352+
},
353+
},
354+
],
355+
},
356+
],
357+
"functionExpressionScope": false,
358+
"isStrict": false,
359+
"references": Array [],
360+
"throughReferences": Array [],
361+
"type": "global",
362+
"upperScope": null,
363+
"variableMap": Object {
364+
"Foo": Object {
365+
"$ref": 0,
366+
},
367+
},
368+
"variableScope": Object {
369+
"$ref": 3,
370+
},
371+
"variables": Array [
372+
Object {
373+
"$id": 0,
374+
"defs": Array [
375+
Object {
376+
"name": Object {
377+
"name": "Foo",
378+
"range": Array [
379+
6,
380+
9,
381+
],
382+
"type": "Identifier",
383+
},
384+
"node": Object {
385+
"range": Array [
386+
0,
387+
82,
388+
],
389+
"type": "ClassDeclaration",
390+
},
391+
"parent": null,
392+
"type": "ClassName",
393+
},
394+
],
395+
"eslintUsed": undefined,
396+
"identifiers": Array [
397+
Object {
398+
"name": "Foo",
399+
"range": Array [
400+
6,
401+
9,
402+
],
403+
"type": "Identifier",
404+
},
405+
],
406+
"name": "Foo",
407+
"references": Array [],
408+
"scope": Object {
409+
"$ref": 3,
410+
},
411+
},
412+
],
413+
}
414+
`;
415+
276416
exports[`TypeScript scope analysis tests/fixtures/scope-analysis/class-properties.ts 1`] = `
277417
Object {
278418
"$id": 8,

visitor-keys.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ module.exports = Evk.unionWith({
1212
// Additional Properties.
1313
ArrayPattern: ["elements", "typeAnnotation"],
1414
ArrowFunctionExpression: ["typeParameters", "params", "returnType", "body"],
15-
ClassDeclaration: ["decorators", "id", "typeParameters", "superClass", "superTypeParameters", "body"],
16-
ClassExpression: ["decorators", "id", "typeParameters", "superClass", "superTypeParameters", "body"],
15+
ClassDeclaration: ["decorators", "id", "typeParameters", "superClass", "superTypeParameters", "implements", "body"],
16+
ClassExpression: ["decorators", "id", "typeParameters", "superClass", "superTypeParameters", "implements", "body"],
1717
FunctionDeclaration: ["id", "typeParameters", "params", "returnType", "body"],
1818
FunctionExpression: ["id", "typeParameters", "params", "returnType", "body"],
1919
Identifier: ["decorators", "typeAnnotation"],

0 commit comments

Comments
 (0)