36 Commits

Author SHA1 Message Date
Brian Ng
e4b35f680d
Run prettier 2017-06-27 12:15:00 -05:00
Peeyush Kushwaha
72d83acc07 Properly convert continue statements in switch
Ignore just non-label break statements in a switch, and allow continue
statments and lablled break statements.

Fixes #5725
2017-05-25 13:49:29 +05:30
Logan Smyth
14584c218c Kill the "shadow-functions.js" internal plugin in favor of an explicit helper (#5677)
* 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.
2017-05-05 13:27:18 -07:00
Brian Ng
8a82cc060a Run new lint rules (#5413) 2017-03-04 10:46:01 -05:00
Ben Alpert
14d3c2e256 Avoid adding unnecessary closure for block scoping (#5246)
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.
2017-02-13 13:46:00 -08:00
Ben Alpert
ff8a10e52f 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).
2017-02-06 13:50:56 -05:00
Logan Smyth
b845f2b69d Re-enable the max-len ESLint rule. (#5265) 2017-02-04 11:07:15 -05:00
Henry Zhu
672adba9a1 enable prefer const (#5113) 2017-01-14 09:48:52 -05:00
Henry Zhu
670ee996c8 Merge pull request #4940 from appden/fix-react-constant-elements
Fix React constant element bugs
2016-12-16 15:29:05 -05:00
Ben Newman
26b4e0909e Add (and fix) failing test of function parameter bindings in a catch block (#4880)
* 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.
2016-12-08 10:16:48 -05:00
Scott Kyle
5a9509205b Fix constant elements hoisted out of block (#4419)
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.
2016-12-03 19:54:53 -08:00
Moti Zilberman
7a7704fea0 Fix block scoping transform for declarations in labeled statements (#4669)
* Fix block scoping transform for declarations in labeled statements (#4122)

* DRY block-scoping
2016-10-05 21:47:21 +02:00
Ryan Biwer
23ea626241 Fix block scope remapping (fixes T7525) (#3662) 2016-09-01 10:48:32 -04:00
Adam Leventhal
0d1e1ee10c incorrect handling of returns nested in switch cases (#3618) 2016-08-18 10:14:07 -04:00
Logan Smyth
5ddce1372b Fix an issue with the switch handing from PR #3490. 2016-06-11 00:17:36 -07:00
Logan Smyth
61b3a6314b Merge pull request #3490 from jayphelps/T7324
create new lexical env inside switch statement blocks, fixes #T7324
2016-05-30 14:42:29 -07:00
Jordan Klassen
dc1f40540d Upgrade to lodash 4 (#3315)
* Upgrade to lodash 4

* Fix incorrect require in babel-runtime/scripts

* Replace cloneDeep with cloneDeepWith where applicable
2016-05-13 17:15:14 -04:00
Jay Phelps
4166e5148e create new lexical env inside switch statement blocks, fixes #T7324 2016-04-29 23:54:41 -07:00
Amjad Masad
07d2c15e99 quotes 2016-03-09 13:34:06 -08:00
Amjad Masad
3dd80a6b14 Update updateScopeInfo method to use moveBindingTo 2016-03-09 13:28:45 -08:00
Amjad Masad
8b4b02a5fb [hotfix T7197] Use scope.moveBindingTo
I had deleted the binding and created a new one. I naively thought that
the analysis will automatically run again. But now discovered the method
I actually want to use: `scope.moveBindingTo` which moves the binding
and all the correct analysis. The only thing that was left to do is to
update `binding.kind` which I did manually.
2016-03-09 13:24:20 -08:00
Amjad Masad
3bebc3a7ca lint 2016-03-07 18:26:51 -08:00
Amjad Masad
77c7cc5363 Rework scope info updating in block-scoping transform
I previously tried an approach to scope bindings from var to scope but
it didn't catch all cases. This is evident in this bug:

https://phabricator.babeljs.io/T2892

Where even after transforming a const to a var we still get an error
that it's read-only.

This approach will go through and delete every existing let and const
binding and creates a new one with the kind "var"
2016-03-07 18:19:10 -08:00
Amjad Masad
3667527d04 Revert "Remove flow"
This reverts commit 2827ff6b01dcce69e9d3c0402e96b52b3a2a47ee.
2016-03-03 14:49:20 -08:00
Amjad Masad
47782a6170 Merge pull request #3389 from babel/block-binding-actual
Update scope binding info after transforming block-scoped bindings
2016-03-02 18:51:26 -08:00
Sam Goldman
2827ff6b01 Remove flow 2016-03-01 22:33:30 -08:00
Amjad Masad
30bb38c4bb Update scope binding info after transforming block-scoped bindings
When convert a const, let or any other block-bound binding to a var we
forget to update the scope info. This confuses other transforms that may
come after this as to which scope does the binding belongs to.

This also uncovered an issue where duplicate block-scoped bindings were allowed
to co-exist.
2016-03-01 17:03:06 -08:00
Sebastian McKenzie
5b89849f43 Switch to klint, fix some lint rules 2016-02-14 23:25:14 +00:00
Andrew Schmadel
307d5c5a0d rename scope bindings during block scope transform 2016-02-10 11:44:16 -05:00
Amjad Masad
0711fa67b4 ensure block 2015-11-11 10:42:55 -08:00
Amjad Masad
8891ed38b8 cleanup 2015-11-11 10:42:55 -08:00
Amjad Masad
ed4a5fb811 get rid of _let 2015-11-11 10:42:55 -08:00
Amjad Masad
aa8b96bf38 Support consts in block-scoping transform 2015-11-11 10:42:55 -08:00
Sebastian McKenzie
e62a00df50 rename NumberLiteral to NumericLiteral and RegexLiteral to RegExpLiteral 2015-11-03 01:19:35 +00:00
Sebastian McKenzie
ae7d5367f1 6.0.0
I'm extremely stupid and didn't commit as I go. To anyone reading this
I'm extremely sorry. A lot of these changes are very broad and I plan on
releasing Babel 6.0.0 today live on stage at Ember Camp London so I'm
afraid I couldn't wait. If you're ever in London I'll buy you a beer
(or assorted beverage!) to make up for it, also I'll kiss your feet and
give you a back massage, maybe.
2015-10-29 17:51:24 +00:00
Sebastian McKenzie
9969224a93 add more plugins, rename some 2015-09-15 06:12:46 +01:00