Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to block-scoping to slow on throw code
The let/const plugin can add closures where you don't expect them. This is undesirable in some perf-sensitive projects (ex: React). I added an option that throws whenever the plugin adds a function (as opposed to simply renaming variables when converting to var).
- Loading branch information
1 parent
a97be35
commit 53e694c
Showing
9 changed files
with
69 additions
and
0 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
6 changes: 6 additions & 0 deletions
6
...orm-es2015-block-scoping/test/fixtures/throwIfClosureRequired/for-const-closure/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,6 @@ | ||
for (let i = 0; i < 5; i++) { | ||
const l = i; | ||
setTimeout(function() { | ||
console.log(l); | ||
}, 1); | ||
} |
3 changes: 3 additions & 0 deletions
3
...-es2015-block-scoping/test/fixtures/throwIfClosureRequired/for-const-closure/options.json
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,3 @@ | ||
{ | ||
"throws": "Compiling let/const in this block would add a closure (throwIfClosureRequired)." | ||
} |
3 changes: 3 additions & 0 deletions
3
...in-transform-es2015-block-scoping/test/fixtures/throwIfClosureRequired/function/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,3 @@ | ||
function test() { | ||
let foo = "bar"; | ||
} |
3 changes: 3 additions & 0 deletions
3
...-transform-es2015-block-scoping/test/fixtures/throwIfClosureRequired/function/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,3 @@ | ||
function test() { | ||
var foo = "bar"; | ||
} |
3 changes: 3 additions & 0 deletions
3
...l-plugin-transform-es2015-block-scoping/test/fixtures/throwIfClosureRequired/options.json
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,3 @@ | ||
{ | ||
"plugins": [["transform-es2015-block-scoping", { "throwIfClosureRequired": true }], "syntax-jsx", "transform-react-jsx", "transform-es2015-block-scoped-functions", "transform-es2015-arrow-functions"] | ||
} |
16 changes: 16 additions & 0 deletions
16
...transform-es2015-block-scoping/test/fixtures/throwIfClosureRequired/superswitch/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,16 @@ | ||
function foo() { | ||
switch (2) { | ||
case 0: { | ||
if (true) { | ||
return; | ||
} | ||
|
||
const stuff = new Map(); | ||
const data = 0; | ||
stuff.forEach(() => { | ||
const d = data; | ||
}); | ||
break; | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...nsform-es2015-block-scoping/test/fixtures/throwIfClosureRequired/superswitch/options.json
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,3 @@ | ||
{ | ||
"throws": "Compiling let/const in this block would add a closure (throwIfClosureRequired)." | ||
} |