Skip to content

Commit

Permalink
Merge pull request #834 from null-a/fix-790
Browse files Browse the repository at this point in the history
Fix top level use of `else if`
  • Loading branch information
stuhlmueller committed Apr 21, 2017
2 parents 83adc18 + 31c4a45 commit 02fa610
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function returnify(nodes) {
return build.ifStatement(
test,
build.blockStatement(returnify(consequent.body)),
alternate === null ? null : build.blockStatement(returnify(alternate.body)));
alternate === null ? null : build.blockStatement(returnify([alternate])));
}),
clause(Syntax.ReturnStatement, function(argument) {
return build.returnStatement(argument);
Expand Down
22 changes: 21 additions & 1 deletion tests/test-transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,27 @@ var tests = {
' };' +
'};' +
'foo(10);'),
expected: 1 }
expected: 1 },

{ name: 'testTopLevelIf1',
code: 'if (true) { 1 }',
expected: 1
},

{ name: 'testTopLevelIf2',
code: 'if (false) { 1 } else { 2 }',
expected: 2
},

{ name: 'testTopLevelIf3',
code: 'if (false) { 1 } else if (true) { 2 }',
expected: 2
},

{ name: 'testTopLevelIf4',
code: 'if (false) { 1 } else if (false) { 2 } else { 3 }',
expected: 3
}

],

Expand Down

0 comments on commit 02fa610

Please sign in to comment.