Skip to content

Commit

Permalink
Fix bind order in for-loops, resolves #2337 (#2338)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jul 18, 2018
1 parent 9c60723 commit be58bce
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/ast/nodes/ForInStatement.ts
Expand Up @@ -20,8 +20,10 @@ export default class ForInStatement extends StatementBase {
body: StatementNode;

bind() {
super.bind();
this.left.bind();
this.left.deoptimizePath(EMPTY_PATH);
this.right.bind();
this.body.bind();
}

createScope(parentScope: Scope) {
Expand Down
4 changes: 3 additions & 1 deletion src/ast/nodes/ForOfStatement.ts
Expand Up @@ -21,8 +21,10 @@ export default class ForOfStatement extends StatementBase {
await: boolean;

bind() {
super.bind();
this.left.bind();
this.left.deoptimizePath(EMPTY_PATH);
this.right.bind();
this.body.bind();
}

createScope(parentScope: Scope) {
Expand Down
3 changes: 3 additions & 0 deletions test/function/samples/for-of-with-in-operator/_config.js
@@ -0,0 +1,3 @@
module.exports = {
description: 'handles using the in operator in the iterator of a for-of loop (#2337)'
};
5 changes: 5 additions & 0 deletions test/function/samples/for-of-with-in-operator/main.js
@@ -0,0 +1,5 @@
for (const foo of [{}]) {
if ('x' in foo) {
throw new Error('There should be no x');
}
}

0 comments on commit be58bce

Please sign in to comment.