49 Commits

Author SHA1 Message Date
Mauro Bringolf
b83e0ec7b0 2nd try: Add loose option for es2015-parameters transformation (#5943)
* Import changes to parameters package from previous branch

* Refactor plugin option access via state
2017-07-12 17:36:44 -04:00
Buu Nguyen
8decefe8bc Fix bug incorrect dereferencing rest argument (#5810)
* Fix bug incorrect dereferencing rest argument

* Fix pure path

* Minor refactor
2017-07-11 23:26:57 -04:00
Daniel Tschinder
b3372a572d Remove whitespace generation (#5833)
* 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
2017-06-27 21:57:02 -05:00
Justin Ridgewell
5387d9f903 Merge pull request #5721 from Qantas94Heavy/rest-parameters-5656
Fix optimisation of shadowed rest parameters
2017-06-13 13:57:53 -04:00
Henry Zhu
123dce5fcd Hardcode to double quotes, indent to 2 spaces (#5824) 2017-06-05 22:14:37 -05:00
Karl Cheng
0667160b11 Fix optimisation of shadowed rest parameters
The arguments of a function would be unnecessarily copied if there was
a nested function that had a parameter with the same identifier as the
rest parameter for the outer function. This checks the scope of the
parameter is correct before deoptimising.

Fixes: https://github.com/babel/babel/issues/5656
Refs: https://github.com/babel/babel/issues/2091
2017-05-16 22:39:13 +10:00
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
Sergey Rubanov
292c3ca206 Refactor test packages to use ES modules instead of CJS (#5138) 2017-01-16 11:25:04 -05:00
Henry Zhu
bfe4faa0d9 fix tests 2016-12-16 11:50:57 -05:00
Justin Ridgewell
852348d700 Fix default parameter - rest parameter edge case (#3572)
When the rest parameter shared the same name as a default identifier
for a param, the loop would be hoisted outside the function!

```js
var a = 1;

for (var _len = arguments.length, a = Array(_len > 1 ? _len - 1 : 0),
_key = 1; _key < _len; _key++) {
  a[_key - 1] = arguments[_key];
}

function foo2() {
  var b = arguments.length <= 0 || arguments[0] === undefined ? a :
arguments[0];

  assert.equal(b, 1);
}
foo2(undefined, 2);
```

And if you tried to reference any index or `#length`, it’d blow up and
refuse to transpile.
2016-12-16 10:53:52 -05:00
Brian Ng
dfe896dd54 Avoid unnecessary +0 in transform-es2015-parameters (#4738) 2016-10-17 17:09:55 +02:00
Moti Zilberman
9fc51d6292 Consolidate contiguous var declarations in destructuring transform (#4690)
* Consolidate contiguous var declarations in destructuring transform

Fixes #3081.

* Simplify var node coalescing in es2015-destructuring

* Revert "Simplify var node coalescing in es2015-destructuring"

This reverts commit 15cb373f0726f68225f7080a7ae206a63af174ee.

* More careful condition for var coalescing in es2015-destructuring
2016-10-14 11:51:22 -04:00
Dan Harper
33eb56ab09 fix error when constructor default arg refers to own static property or self (#4666)
(closes #4253)
(closes #4442)
2016-10-05 17:52:42 -04:00
Moti Zilberman
0366d1ad19 Handle side effects correctly in rest params index expressions (#4348) (#4674) 2016-10-05 21:59:41 +02:00
Moti Zilberman
12d2673038 Add test for rest params name collision with top-level name (#4333) (#4673) 2016-10-05 10:15:04 -04:00
Daniel Tschinder
16716ea3de Fix rest parameters with flow type casting (#4636)
Do not skip TypeCastExpressions when finding referenced identifiers as the
type cast contains valid non flow code that we need to visit.
2016-10-01 12:58:14 -04:00
Justin Ridgewell
c2ed9de7fb Flip default parameter template (#4515)
* Flip default parameter template

YMMV, I saved ~10b on a 2kb library. Not noticeable at the small scale, by why not do it anyway?

I've (unscientifically) found that flipping the default parameter conditional yields better gzip results. I think this is due to the slightly longer string it can now repeatedly match:

```js
// old
var param = arguments.length <= 0 || void 0 === arguments[0] ? null : arguments[0]
--------------------------------------------------------------^

// new
var param = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : null
------------------------------------------------------------------------^
```

Though it's entirely likely gzip will also choose up to the index of the arguments if you many default parameters at different indexes.

* Update tests
2016-09-25 14:05:53 -07:00
Daniel Tschinder
590ad4d24f Replace phabricator tickets with github ones in code comments (#4519) 2016-09-17 22:50:02 -04:00
Daniel Tschinder
10cd6519d8 Fix class inheritance in IE <=10 (T3041) (#3527)
* Fix class inheritance in IE9 & IE10 (T3041)

Internet Explorer 9&10 do not support __proto__ at all, don't have
Object.setPrototypeOf(), but have Object.getPrototypeOf().

Because of this setting the prototype is not possible, which makes the
babelHelpers.inherits() function to set __proto__ although not supported.

Afterwards Object.getPrototypeOf() is used, but this one is not
respecting the "custom" property __proto__ that we set.

The solution is to check for __proto__ first and afterwards fallback to
Object.getPrototypeOf().

* Do the same logic in babel-helper-replace-supers

* Fix tests

* Extract creation of prototype nodes to small helper
2016-08-23 15:08:44 -04:00
Justin Ridgewell
823ffbd87c Fix error in rest parameter length optimization (#3573)
If there aren’t enough arguments to get to the offset index, we would
return an negative length.
2016-07-12 21:12:45 -04:00
Logan Smyth
231f27f170 Fix non-unique 'ref' binding name - fixes T7468 2016-06-28 19:16:44 -07:00
Jay Phelps
330071e59d also visit ClassProperty's for rest param deopt check, fixes #T7311 (#3481) 2016-05-13 17:18:14 -04:00
Jesse McCarthy
8419be1afc Add postfix update expression fixtures.
(Failing.)
2016-02-25 17:11:19 -05:00
Jesse McCarthy
5f98d22b6d Add for-of fixture.
(Failing.)
2016-02-25 17:11:19 -05:00
Jesse McCarthy
1c304965e7 Add rest loop position optimization fixture.
(Failing.)

With destructuring assignment to an element.

This makes the function ineligible for `arguments` optimization, while
remaining eligible for loop position optimization.
2016-02-25 17:11:19 -05:00
Victor Felder
183fbab967 Fix some rest optimization errors.
Commit message edited by @jmm.
2016-02-25 17:11:19 -05:00
Jesse McCarthy
6ca07974c9 Add array destruct w/o [rest[0]] on RHS fixture.
(Failing.)
2016-02-25 17:11:19 -05:00
Jesse McCarthy
0be3a58dd2 Add expected fixtures for new actuals.
(Failing.)
2016-02-25 17:11:18 -05:00
Ben Newman
a82bf11e2a Add rest deoptimization fixtures.
(Failing.)

Commit message edited by @jmm.
2016-02-25 17:11:18 -05:00
Jesse McCarthy
3b8c5b7620 Merge pull request #3249 from jmm/rest-assign-el
Fix assignment to rest param element AST error.

Fix T6932.
2016-02-19 08:47:17 -05:00
Erik
27a132a9cb Add test for T3077 (Incorrect rest operator behavior for async arrow functions) 2016-02-09 13:13:28 -05:00
Jesse McCarthy
49728be8b6 Test for no-opt of assign to rest param element.
That is, do not attempt to optimize assignments as opposed to reads.

(Failing.)
2016-01-14 13:21:40 -05:00
Jesse McCarthy
857675c99c Add fixtures to exercise shadow conditional. 2016-01-13 17:37:29 -05:00
Jesse McCarthy
41066f55ea Add fixtures for deopt due to arguments. 2016-01-13 17:37:23 -05:00
Amjad Masad
59ea034df2 Support expressions in rest arg access
The current implementation assumes a numeric literal although it just
checks the base type.
2016-01-06 17:07:05 -08:00
kpdecker
28280be3ed Add failing tests case for 6.4 rest.length issue 2016-01-06 17:34:43 -06:00
Fabio M. Costa
699868ed2a [fix][babel-plugin-transform-es2015-parameters] arguments.length optimization bugfix 2015-12-28 21:56:49 -08:00
Amjad Masad
0d8e5a9e86 Fix over-parenthesizing of function expressions 2015-12-24 14:55:51 -08:00
Sebastian McKenzie
1fa24b1efd rename babel-plugin-external-helpers-2 to babel-plugin-external-helpers 2015-12-24 03:54:40 +00:00
Amjad Masad
090e8b18ea Merge pull request #3191 from vhf/destructuring-rest-args-initialization-order
Order of arguments initialization - fixes T6809
2015-12-22 20:51:20 -08:00
Victor Felder
28adaa49b2 Order of arguments initialization - fixes T6809
When using a default param + some destructuring param + a rest param, the
initialization order of the destructured arguments was incorrect due to the
presence of the rest parameter.
2015-12-21 02:53:36 +01:00
Victor Felder
f472670503 Add test case for regression possibly introduced by #2833 2015-12-21 02:42:01 +01:00
Victor Felder
6cc0538d2f Safely transform all usages of rest arguments 2015-12-18 11:30:48 +01:00
Victor Felder
2dea8b2352 Safely transform multiple rest arguments 2015-12-18 11:30:48 +01:00
Victor Felder
3dfb4eb8c6 Simplify rest transformation 2015-12-18 11:30:48 +01:00
Fabio M. Costa
3868d36e31 [babel-plugin-transform-es2015-parameters] more oportunities for optimisations 2015-12-17 10:50:56 -08:00
Victor Felder
306b5db1ef Have es2015 rest transform safely use arguments 2015-11-19 12:47:55 +01:00
Amjad Masad
ed4a5fb811 get rid of _let 2015-11-11 10:42:55 -08:00
Sebastian McKenzie
15969a0904 move all plugin tests out of babel-core and into their appropriate folders 2015-11-08 23:04:10 -08:00