* Remove whitespace generation and rely on default printing
Changes to printing:
* Add newline after last empty SwitchCase
* Add newlines around block comments if they are non-flow comments or contain newlines
* Fix a few more fixtures
* Handle arrow function processing via shared API rather than default plugin.
* Fix a few small PR comments.
* Preserve existing spec arrow 'this' rewrites, and support spec in subclass constructors.
When you write
```
for (const x of l) {
setTimeout(() => x);
}
```
we need to add a closure because the variable is meant to be block-scoped and recreated each time the block runs. We do this.
However, we also add the closure when no loop is present. This isn't necessary, because if no loop is present then each piece of code runs at most once. I changed the transform to only add a closure if a variable is referenced from within a loop.
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).
* Add failing test of function parameter bindings in a catch block.
This test can be run in isolation via the following command:
TEST_GREP='block-scoping.*function in catch' make test-only
This test fails because BlockScoping#getLetReferences accidentally
considers the parameters of the function declaration as let bindings in
the catch scope. When the name of the catch parameter is the same as one
of the function's parameter names, the function declaration will be
unnecessarily wrapped to isolate its parameters from the outer scope.
While the extra wrapping may not seem harmful in this case, this behavior
is a symptom of a deeper problem that causes very subtle bugs in transform
code involving catch parameters and function declarations. This test case
was just the simplest example I could find to demonstrate the problem.
I have a proposed fix for this problem that I will push as soon as the
tests fail for this commit.
* Make BlockScoping#getLetReferences ignore function parameters.
When block scoped variables caused the block to be wrapped in a closure, the variable `bindings` remained in parent function scope, which caused the JSX element to be hoisted out of the closure.