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 PathHoister ignored member references on "this", causing it
to potentially hoist an expression above its function scope.
This patch tells the hoister to watch for "this", and if seen,
mark the nearest non-arrow function scope as the upper limit
for hoistng.
This fixes#4397 and is an alternative to #4787.
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).
* checks if babel is installed globally and displays correct cli message - fixes#5228
* recommend local installation and fix lint errors
* uses babel-cli vs babel
* switch back to babel
* use process.cwd() to determine if globally executed
* checks for /node_module/.bin/babel
* compare execPath and module execution path to determine global or local installation
* Move the babel/cli.js into a 'src' so the 'const's are compiled Node < 6.
* avoid duplicating impure initializers in object rest destructuring
* reuse existing VariableDeclarations in object rest destructuring, to fix two issues:
1. inserting an additional VariableDeclaration after the current one may change order of operations, which is unsafe if a future VariableDeclarator refers to a destructured variable.
2. The entire VariableDeclaration is removed when all properties are rest properties, indiscriminately removing other variables