Add option to block-scoping to slow on throw code (#5236)

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).
This commit is contained in:
Ben Alpert
2017-02-06 10:50:56 -08:00
committed by Henry Zhu
parent 6ee7bf6df5
commit ff8a10e52f
9 changed files with 69 additions and 0 deletions

View File

@@ -360,6 +360,12 @@ class BlockScoping {
}
wrapClosure() {
if (this.file.opts.throwIfClosureRequired) {
throw this.blockPath.buildCodeFrameError(
"Compiling let/const in this block would add a closure " +
"(throwIfClosureRequired)."
);
}
const block = this.block;
const outsideRefs = this.outsideLetReferences;