From 660d764390a65a3ff54d6e93fd801d4f9138c7da Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Wed, 18 Mar 2015 23:31:11 +1100 Subject: [PATCH] remove loop check when aliasing breaks, continues etc - fixes #1051 --- .../transformers/es6/block-scoping.js | 4 ---- .../es6-block-scoping/issue-1051/actual.js | 14 ++++++++++++ .../es6-block-scoping/issue-1051/expected.js | 22 +++++++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/transformation/es6-block-scoping/issue-1051/actual.js create mode 100644 test/fixtures/transformation/es6-block-scoping/issue-1051/expected.js diff --git a/src/babel/transformation/transformers/es6/block-scoping.js b/src/babel/transformation/transformers/es6/block-scoping.js index 79eb0380c7..fadcd43544 100644 --- a/src/babel/transformation/transformers/es6/block-scoping.js +++ b/src/babel/transformation/transformers/es6/block-scoping.js @@ -527,10 +527,6 @@ class BlockScoping { } if (has.hasBreakContinue) { - if (!loop) { - throw new Error("Aren't in a loop and we're trying to reassign breaks and continues, something is going wrong here."); - } - for (var key in has.map) { cases.push(t.switchCase(t.literal(key), [has.map[key]])); } diff --git a/test/fixtures/transformation/es6-block-scoping/issue-1051/actual.js b/test/fixtures/transformation/es6-block-scoping/issue-1051/actual.js new file mode 100644 index 0000000000..88d3593f2a --- /dev/null +++ b/test/fixtures/transformation/es6-block-scoping/issue-1051/actual.js @@ -0,0 +1,14 @@ +foo.func1 = function() { + if (cond1) { + for (;;) { + if (cond2) { + function func2() {} + function func3() {} + func4(function() { + func2(); + }); + break; + } + } + } +}; diff --git a/test/fixtures/transformation/es6-block-scoping/issue-1051/expected.js b/test/fixtures/transformation/es6-block-scoping/issue-1051/expected.js new file mode 100644 index 0000000000..099a69bb6a --- /dev/null +++ b/test/fixtures/transformation/es6-block-scoping/issue-1051/expected.js @@ -0,0 +1,22 @@ +"use strict"; + +foo.func1 = function () { + if (cond1) { + for (;;) { + if (cond2) { + var _ret = (function () { + var func2 = function () {}; + + var func3 = function () {}; + + func4(function () { + func2(); + }); + return "break"; + })(); + + if (_ret === "break") break; + } + } + } +};