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.
* Initial estree support for ClassMethod
* Handle literals for estree
* Fix regex
* correct output of regexp and regenerate test
* Add tests for validation stuff with estree plugin
* Parse Properties correctly
This also refactors how babylon parses obj properties in general
so that this logic can be more easily extended.
* Run all throws-tests a second time with estree plugin
* Fix all throw tests
* Remove rebase conflict
* Correctly set kind
This ensures state.inMethod gets propagated correctly
* Add computed: false to methods with ident async
* Implement directive field on Directives
* Test invalid directives
* more tests
* [Flow] Function predicate declaration
The accepted syntax for function declarations is extended to allow
the following predicate declaration:
FunctionReturnType :=
Type
Predicate
Type Predicate
Predicate :=
%checks
%checks ( ConditionalExpression )
* [Flow] Minor tweaks and more examples to function predicates
* [Flow] Clean-up and better message for function predicates
* [Flow] Adding abstract function predicate example
* [Flow] Rearranging the `predicate` field to ease babel generator.
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.