-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5775 from peey/switch-continue
Switch continue
- Loading branch information
Showing
7 changed files
with
223 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...-plugin-transform-es2015-block-scoping/test/fixtures/general/switch-inside-loop/actual.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// it shouldn't break on a case-break statement | ||
var i; | ||
for (i = 0; i < 10; i++) { | ||
switch (i) { | ||
case 1: | ||
break; | ||
} | ||
|
||
const z = 3; // to force the plugin to convert to loop function call | ||
() => z; | ||
} | ||
|
||
assert.equal(i, 10); | ||
|
||
// it should continue on continue statements within switch | ||
var j = 0; | ||
for (i = 0; i < 10; i++) { | ||
switch (i) { | ||
case 0: | ||
continue; | ||
} | ||
j++; | ||
|
||
const z = 3; | ||
() => z; | ||
} | ||
|
||
assert.equal(j, 9); | ||
|
||
// it should work with loops nested within switch | ||
j = 0; | ||
for (i = 0; i < 10; i++) { | ||
switch (i) { | ||
case 0: | ||
for (var k = 0; k < 10; k++) { | ||
const z = 3; | ||
() => z; | ||
j++; | ||
break; | ||
} | ||
break; | ||
} | ||
|
||
const z = 3; | ||
() => z; | ||
} | ||
|
||
assert.equal(j, 1); |
48 changes: 48 additions & 0 deletions
48
...el-plugin-transform-es2015-block-scoping/test/fixtures/general/switch-inside-loop/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// it shouldn't break on a case-break statement | ||
var i; | ||
for (i = 0; i < 10; i++) { | ||
switch (i) { | ||
case 1: | ||
break; | ||
} | ||
|
||
const z = 3; // to force the plugin to convert to loop function call | ||
() => z; | ||
} | ||
|
||
assert.equal(i, 10); | ||
|
||
// it should continue on continue statements within switch | ||
var j = 0; | ||
for (i = 0; i < 10; i++) { | ||
switch (i) { | ||
case 0: | ||
continue; | ||
} | ||
j++; | ||
|
||
const z = 3; | ||
() => z; | ||
} | ||
|
||
assert.equal(j, 9); | ||
|
||
// it should work with loops nested within switch | ||
j = 0; | ||
for (i = 0; i < 10; i++) { | ||
switch (i) { | ||
case 0: | ||
for (var k = 0; k < 10; k++) { | ||
const z = 3; | ||
() => z; | ||
j++; | ||
break; | ||
} | ||
break; | ||
} | ||
|
||
const z = 3; | ||
() => z; | ||
} | ||
|
||
assert.equal(j, 1); |
81 changes: 81 additions & 0 deletions
81
...lugin-transform-es2015-block-scoping/test/fixtures/general/switch-inside-loop/expected.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// it shouldn't break on a case-break statement | ||
var i; | ||
|
||
var _loop = function () { | ||
switch (i) { | ||
case 1: | ||
break; | ||
} | ||
|
||
var z = 3; // to force the plugin to convert to loop function call | ||
(function () { | ||
return z; | ||
}); | ||
}; | ||
|
||
for (i = 0; i < 10; i++) { | ||
_loop(); | ||
} | ||
|
||
assert.equal(i, 10); | ||
|
||
// it should continue on continue statements within switch | ||
var j = 0; | ||
|
||
var _loop2 = function () { | ||
switch (i) { | ||
case 0: | ||
return "continue"; | ||
} | ||
j++; | ||
|
||
var z = 3; | ||
(function () { | ||
return z; | ||
}); | ||
}; | ||
|
||
for (i = 0; i < 10; i++) { | ||
var _ret = _loop2(); | ||
|
||
if (_ret === "continue") continue; | ||
} | ||
|
||
assert.equal(j, 9); | ||
|
||
// it should work with loops nested within switch | ||
j = 0; | ||
|
||
var _loop3 = function () { | ||
switch (i) { | ||
case 0: | ||
var _loop4 = function () { | ||
var z = 3; | ||
(function () { | ||
return z; | ||
}); | ||
j++; | ||
return "break"; | ||
}; | ||
|
||
for (k = 0; k < 10; k++) { | ||
var _ret2 = _loop4(); | ||
|
||
if (_ret2 === "break") break; | ||
} | ||
break; | ||
} | ||
|
||
var z = 3; | ||
(function () { | ||
return z; | ||
}); | ||
}; | ||
|
||
for (i = 0; i < 10; i++) { | ||
var k; | ||
|
||
_loop3(); | ||
} | ||
|
||
assert.equal(j, 1); |