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

Commit

Permalink
Fix: visiting typeParameters in expressions (#565)
Browse files Browse the repository at this point in the history
* Fix: missing typeParameters in expressions

* ignoreEval is always set to true, than we can ignore this case
  • Loading branch information
armano2 authored and platinumazure committed Nov 28, 2018
1 parent c19e479 commit 83dbabb
Show file tree
Hide file tree
Showing 4 changed files with 550 additions and 0 deletions.
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

0 comments on commit 83dbabb

Please sign in to comment.