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

Fix: visiting typeParameters in expressions #565

Merged
merged 2 commits into from
Nov 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
42 changes: 42 additions & 0 deletions analyze-scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,20 @@ class Referencer extends OriginalReferencer {
super.visitClass(node);
}

/**
* Visit typeParameters.
* @param {*} node The node to visit.
* @returns {void}
*/
visitTypeParameters(node) {
if (node.typeParameters) {
const upperTypeMode = this.typeMode;
this.typeMode = true;
this.visit(node.typeParameters);
this.typeMode = upperTypeMode;
}
}

/**
* Override.
* Don't create the reference object in the type mode.
Expand Down Expand Up @@ -286,6 +300,34 @@ class Referencer extends OriginalReferencer {
this.typeMode = upperTypeMode;
}

/**
* Visit new expression.
* @param {NewExpression} node The NewExpression node to visit.
* @returns {void}
*/
NewExpression(node) {
this.visitTypeParameters(node);
this.visit(node.callee);
if (node.arguments) {
node.arguments.forEach(this.visit, this);
}
}

/**
* Override.
* Visit call expression.
* @param {CallExpression} node The CallExpression node to visit.
* @returns {void}
*/
CallExpression(node) {
this.visitTypeParameters(node);

this.visit(node.callee);
if (node.arguments) {
node.arguments.forEach(this.visit, this);
}
}

/**
* Define the variable of this function declaration only once.
* Because to avoid confusion of `no-redeclare` rule by overloading.
Expand Down
5 changes: 5 additions & 0 deletions tests/fixtures/scope-analysis/expression-type-parameters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const a, b, c, d, e, f

new foo<Bar>(a, b, c);

baz<Bar>(d, e, f);
Loading