Skip to content

Commit

Permalink
Evaluate arguments in function's scope
Browse files Browse the repository at this point in the history
  • Loading branch information
ooflorent committed May 25, 2018
1 parent 55ce143 commit f22fffd
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions lib/Parser.js
Expand Up @@ -1030,23 +1030,28 @@ class Parser extends Tapable {
}

walkForInStatement(statement) {
if (statement.left.type === "VariableDeclaration")
if (statement.left.type === "VariableDeclaration") {
this.walkVariableDeclaration(statement.left);
else this.walkPattern(statement.left);
} else {
this.walkPattern(statement.left);
}
this.walkExpression(statement.right);
this.walkStatement(statement.body);
}

prewalkForOfStatement(statement) {
if (statement.left.type === "VariableDeclaration")
if (statement.left.type === "VariableDeclaration") {
this.prewalkVariableDeclaration(statement.left);
}
this.prewalkStatement(statement.body);
}

walkForOfStatement(statement) {
if (statement.left.type === "VariableDeclaration")
if (statement.left.type === "VariableDeclaration") {
this.walkVariableDeclaration(statement.left);
else this.walkPattern(statement.left);
} else {
this.walkPattern(statement.left);
}
this.walkExpression(statement.right);
this.walkStatement(statement.body);
}
Expand All @@ -1062,8 +1067,10 @@ class Parser extends Tapable {
walkFunctionDeclaration(statement) {
const wasTopLevel = this.scope.topLevelScope;
this.scope.topLevelScope = false;
for (const param of statement.params) this.walkPattern(param);
this.inScope(statement.params, () => {
for (const param of statement.params) {
this.walkPattern(param);
}
if (statement.body.type === "BlockStatement") {
this.detectStrictMode(statement.body.body);
this.prewalkStatement(statement.body);
Expand Down Expand Up @@ -1355,13 +1362,10 @@ class Parser extends Tapable {
}

walkExpressions(expressions) {
for (
let expressionsIndex = 0, len = expressions.length;
expressionsIndex < len;
expressionsIndex++
) {
const expression = expressions[expressionsIndex];
if (expression) this.walkExpression(expression);
for (const expression of expressions) {
if (expression) {
this.walkExpression(expression);
}
}
}

Expand Down Expand Up @@ -1469,8 +1473,10 @@ class Parser extends Tapable {
walkFunctionExpression(expression) {
const wasTopLevel = this.scope.topLevelScope;
this.scope.topLevelScope = false;
for (const param of expression.params) this.walkPattern(param);
this.inScope(expression.params, () => {
for (const param of expression.params) {
this.walkPattern(param);
}
if (expression.body.type === "BlockStatement") {
this.detectStrictMode(expression.body.body);
this.prewalkStatement(expression.body);
Expand All @@ -1483,8 +1489,10 @@ class Parser extends Tapable {
}

walkArrowFunctionExpression(expression) {
for (const param of expression.params) this.walkPattern(param);
this.inScope(expression.params, () => {
for (const param of expression.params) {
this.walkPattern(param);
}
if (expression.body.type === "BlockStatement") {
this.detectStrictMode(expression.body.body);
this.prewalkStatement(expression.body);
Expand Down Expand Up @@ -1640,7 +1648,9 @@ class Parser extends Tapable {
if (functionExpression.body.type === "BlockStatement") {
this.prewalkStatement(functionExpression.body);
this.walkStatement(functionExpression.body);
} else this.walkExpression(functionExpression.body);
} else {
this.walkExpression(functionExpression.body);
}
});
this.scope.topLevelScope = wasTopLevel;
}
Expand Down Expand Up @@ -1743,13 +1753,7 @@ class Parser extends Tapable {

this.scope.renames.set("this", null);

for (
let paramIndex = 0, len = params.length;
paramIndex < len;
paramIndex++
) {
const param = params[paramIndex];

for (const param of params) {
if (typeof param !== "string") {
this.enterPattern(param, param => {
this.scope.renames.set(param, null);
Expand Down

0 comments on commit f22fffd

Please sign in to comment.