Skip to content

Commit

Permalink
Fix handlers[node.type] is not a function error in for...in loops. (#…
Browse files Browse the repository at this point in the history
…232)

When `for (a[0] in b)` is found, buble threw an error.
This commit fixes the error and adds a test.
  • Loading branch information
luiscubal authored and mourner committed Dec 13, 2019
1 parent 5195f3f commit 616732e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/program/types/ForInStatement.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class ForInStatement extends LoopStatement {
super.transpile(code, transforms);

const maybePattern = hasDeclaration ? this.left.declarations[0].id : this.left;
if (maybePattern.type !== 'Identifier') {
if (maybePattern.type !== 'Identifier' && maybePattern.type !== 'MemberExpression') {
this.destructurePattern(code, maybePattern, hasDeclaration);
}
}
Expand Down
12 changes: 12 additions & 0 deletions test/samples/for-statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,17 @@ module.exports = [
};
for (;idx < sw.tabs.length;) loop( );`
},

{
description: 'for in with member expression',
input: `
for (a[0] in a) {
}
`,
output: `
for (a[0] in a) {
}
`
}
];

0 comments on commit 616732e

Please sign in to comment.