52 Commits

Author SHA1 Message Date
Mateusz Burzyński
d8b7bc39af Fixed loose option of transform-es2015-parameters handling only Assig… (#6274) 2017-09-22 19:39:39 -04:00
Pranav Prakash
e98bb3dc60 Use new Array instead of Array for V8 optimization (#6250)
* Use new Array instead of Array for V8 optimization

* fix spacing [skip ci]

* Remove extraneous use strict clauses
2017-09-18 14:14:46 -04:00
Brian Ng
9dd65c809f
fixes 2017-08-03 22:27:30 -05:00
Logan Smyth
d86ae2fb84
Remove _blockHoist usage from param processing. 2017-08-03 20:56:50 -05:00
Logan Smyth
8e19a5b057
Update param scope values when expanding parameters. 2017-08-03 20:56:24 -05:00
Logan Smyth
95882d4e5a
Rewrite param processing to be more clearly defined. 2017-08-03 20:56:08 -05:00
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
Brian Ng
e4b35f680d
Run prettier 2017-06-27 12:15:00 -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
Brian Ng
8a82cc060a Run new lint rules (#5413) 2017-03-04 10:46:01 -05:00
Logan Smyth
b845f2b69d Re-enable the max-len ESLint rule. (#5265) 2017-02-04 11:07:15 -05:00
Brian Ng
8c35b320d3 Bump eslint-config-babel and fix lint (#5129) 2017-01-17 10:51:16 +01:00
Henry Zhu
672adba9a1 enable prefer const (#5113) 2017-01-14 09:48:52 -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
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
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
Justin Ridgewell
9a6890c92f Default parameters cleanup (#3574)
* Remove buildDefaultParamAssign

This seems to have been
[added](https://github.com/babel/babel/commit/4b85b05839017ab2abc03ba2d1
e875a63f002890) in v5.5.4 to address
[#1690](https://phabricator.babeljs.io/T1690). It [became
“dead”](https://github.com/babel/babel/blob/v6.0.0/packages/babel-core/t
est/fixtures/transformation/es6.parameters/default-before-last/expected.
js) (as far as I can tell) in the [v6.0.0
commit](https://github.com/babel/babel/commit/ae7d5367f1c3d438667242d692
5db024f875fccd).

Either way, this code is never executed.

- `pushDefNode` is only called when the param is a default param.
- `buildDefaultParamAssign` (which is inside `pushDefNode`) only runs
of the param index is less than or equals to the lastNonDefaultParam.
AKA, is this param before any non-defaulting params.

Which is a contradiction.

* Small optimization

No need to check if we need an iife if we already know we need one.
2016-07-18 11:03:59 -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
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
49e30f49bc Fix rest optimization errors. 2016-02-25 18:42:52 -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
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
Sebastian McKenzie
5b89849f43 Switch to klint, fix some lint rules 2016-02-14 23:25:14 +00:00
Jesse McCarthy
19937573a6 Fix assignment to rest param element. 2016-01-14 13:21:47 -05:00
Jesse McCarthy
b17965ab8b Improve comments. 2016-01-13 17:24:06 -05:00
Jesse McCarthy
059d7123db Remove unnecessary else. 2016-01-13 17:24:06 -05:00
Jesse McCarthy
e4044062c3 Remove unnecessary length check & nesting. 2016-01-13 17:24:06 -05:00
Jesse McCarthy
4c69f1cda5 Replace func expr with arrow. 2016-01-13 17:24:06 -05:00
Jesse McCarthy
afd98ebd2a Remove unnecessary literal return value. 2016-01-13 17:24:06 -05:00
Jesse McCarthy
bcfa58a6a2 Remove unnecessary intermediate var. 2016-01-13 17:24:06 -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
Fabio M. Costa
699868ed2a [fix][babel-plugin-transform-es2015-parameters] arguments.length optimization bugfix 2015-12-28 21:56:49 -08: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
27f2918abb Minor refactoring 2015-12-21 10:43:59 +01: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
5d414a2323 Handle case where optimisation concist of only replacing rest param id with args 2015-12-18 17:43:00 +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
9a97d92217 T2965: Patterns as rest parameter operands are not valid, therefore this relic should go 2015-11-19 13:50:12 +01:00
Victor Felder
a510e7325b Factor out optimiseCandidate to reduce nesting & complexity 2015-11-19 13:47:07 +01:00
Victor Felder
306b5db1ef Have es2015 rest transform safely use arguments 2015-11-19 12:47:55 +01:00
Sebastian McKenzie
e62a00df50 rename NumberLiteral to NumericLiteral and RegexLiteral to RegExpLiteral 2015-11-03 01:19:35 +00:00
Sebastian McKenzie
5c7f88a5fb fix parameters after defaults in arrow functions refering to the wrong arguments - fixes #2682 2015-10-30 17:39:57 +00:00