Skip to content

Commit d21b706

Browse files
committed
Fix: missing typeParameters in expressions
1 parent 491ebca commit d21b706

File tree

4 files changed

+557
-0
lines changed

4 files changed

+557
-0
lines changed

analyze-scope.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,20 @@ class Referencer extends OriginalReferencer {
218218
super.visitClass(node);
219219
}
220220

221+
/**
222+
* Visit typeParameters.
223+
* @param {*} node The node to visit.
224+
* @returns {void}
225+
*/
226+
visitTypeParameters(node) {
227+
if (node.typeParameters) {
228+
const upperTypeMode = this.typeMode;
229+
this.typeMode = true;
230+
this.visit(node.typeParameters);
231+
this.typeMode = upperTypeMode;
232+
}
233+
}
234+
221235
/**
222236
* Override.
223237
* Don't create the reference object in the type mode.
@@ -286,6 +300,41 @@ class Referencer extends OriginalReferencer {
286300
this.typeMode = upperTypeMode;
287301
}
288302

303+
/**
304+
* Visit new expression.
305+
* @param {NewExpression} node The NewExpression node to visit.
306+
* @returns {void}
307+
*/
308+
NewExpression(node) {
309+
this.visitTypeParameters(node);
310+
this.visit(node.callee);
311+
if (node.arguments) {
312+
node.arguments.forEach(this.visit, this);
313+
}
314+
}
315+
316+
/**
317+
* Override.
318+
* Visit call expression.
319+
* @param {CallExpression} node The CallExpression node to visit.
320+
* @returns {void}
321+
*/
322+
CallExpression(node) {
323+
this.visitTypeParameters(node);
324+
325+
// Check this is direct call to eval
326+
if (!this.scopeManager.__ignoreEval() && node.callee.type === "Identifier" && node.callee.name === "eval") {
327+
328+
// NOTE: This should be `variableScope`. Since direct eval call always creates Lexical environment and
329+
// let / const should be enclosed into it. Only VariableDeclaration affects on the caller's environment.
330+
this.currentScope().variableScope.__detectEval();
331+
}
332+
this.visit(node.callee);
333+
if (node.arguments) {
334+
node.arguments.forEach(this.visit, this);
335+
}
336+
}
337+
289338
/**
290339
* Define the variable of this function declaration only once.
291340
* Because to avoid confusion of `no-redeclare` rule by overloading.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const a, b, c, d, e, f
2+
3+
new foo<Bar>(a, b, c);
4+
5+
baz<Bar>(d, e, f);

0 commit comments

Comments
 (0)