Skip to content

Commit

Permalink
init rhs of for-in loop head with correct scope - fixes #1480
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Aug 11, 2017
1 parent d0392e9 commit 7a2a8d2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/ast/nodes/ForInStatement.js
Expand Up @@ -6,18 +6,18 @@ import { STRING } from '../values.js';
export default class ForInStatement extends Statement {
initialiseChildren () {
this.left.initialise( this.scope );
this.right.initialise( this.scope );
this.right.initialise( this.scope.parent );
this.body.initialiseAndReplaceScope ?
this.body.initialiseAndReplaceScope( this.scope ) :
this.body.initialise( this.scope );
assignTo( this.left, this.scope, STRING );
}

initialiseScope ( parentScope ) {
this.scope = new Scope( {
this.scope = new Scope({
parent: parentScope,
isBlockScope: true,
isLexicalBoundary: false
} );
});
}
}
3 changes: 3 additions & 0 deletions test/function/samples/for-loop-head-dependencies/_config.js
@@ -0,0 +1,3 @@
module.exports = {
description: 'uses parent scope for right-hand-side in for-in statement (#1480)'
};
12 changes: 12 additions & 0 deletions test/function/samples/for-loop-head-dependencies/main.js
@@ -0,0 +1,12 @@
function foo() {
return ['x'];
}

const result = [];

for (let i in foo()) {
const foo = i;
result.push(foo);
}

assert.deepEqual(result, [0]);

0 comments on commit 7a2a8d2

Please sign in to comment.