1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

Fix #4020: No need for break; after a switch case that throws (#4538)

This commit is contained in:
Geoffrey Booth 2017-05-06 01:38:20 -07:00 committed by GitHub
parent b28e398396
commit 22d0cc1012
2 changed files with 2 additions and 2 deletions

View file

@ -4014,7 +4014,7 @@
break; break;
} }
expr = this.lastNonComment(block.expressions); expr = this.lastNonComment(block.expressions);
if (expr instanceof Return || (expr instanceof Literal && expr.jumps() && expr.value !== 'debugger')) { if (expr instanceof Return || expr instanceof Throw || (expr instanceof Literal && expr.jumps() && expr.value !== 'debugger')) {
continue; continue;
} }
fragments.push(cond.makeCode(idt2 + 'break;\n')); fragments.push(cond.makeCode(idt2 + 'break;\n'));

View file

@ -3000,7 +3000,7 @@ exports.Switch = class Switch extends Base
fragments = fragments.concat body, @makeCode('\n') if (body = block.compileToFragments o, LEVEL_TOP).length > 0 fragments = fragments.concat body, @makeCode('\n') if (body = block.compileToFragments o, LEVEL_TOP).length > 0
break if i is @cases.length - 1 and not @otherwise break if i is @cases.length - 1 and not @otherwise
expr = @lastNonComment block.expressions expr = @lastNonComment block.expressions
continue if expr instanceof Return or (expr instanceof Literal and expr.jumps() and expr.value isnt 'debugger') continue if expr instanceof Return or expr instanceof Throw or (expr instanceof Literal and expr.jumps() and expr.value isnt 'debugger')
fragments.push cond.makeCode(idt2 + 'break;\n') fragments.push cond.makeCode(idt2 + 'break;\n')
if @otherwise and @otherwise.expressions.length if @otherwise and @otherwise.expressions.length
fragments.push @makeCode(idt1 + "default:\n"), (@otherwise.compileToFragments o, LEVEL_TOP)..., @makeCode("\n") fragments.push @makeCode(idt1 + "default:\n"), (@otherwise.compileToFragments o, LEVEL_TOP)..., @makeCode("\n")