* Redeclaring a variable counts as a modification.
Fixes#6217.
* Remove "existing" logic from Binding.
Was added in #5745, but no longer triggered since 6536e605a.
* Fix bad Scope#parent caching
Now, we traverse the path until we find a parent scope.
Fixes#6057.
* Fix bad merge
* Remove cached data
* I need to stop using Github editor
* Fix infinite loops due to scopable paths being moved up
* for-of: IteratorClose spec compatibility.
See #3:
https://tc39.github.io/ecma262/#sec-iteratorclose
* Update spec fixtures for for-of.
* Fix IteratorClose case for remap-async-to-generator.
* Fix IteratorClose case for async-generator-function test output.
* Modify few tests according to iteratorClose fix.
* Fix iteratorClose for helpers.slicedToArray also.
* Update iteratorClose fixture for commonjs.
* Don't merge test options.
Particularly, I don't want `lodash/merge` to merge my specific plugins
with the general test plugins. It led to odd behavior where I could
enable a loose transform in my specific test, just to have it overridden
by the test fixture's general options.
* Need options
So, I was reading the new Flow type strictness and noticed
https://flow.org/blog/2017/05/07/Strict-Function-Call-Arity/
Specifically, I wondered whether the `sum_all` example would copy the
arguments into an array, then loop over. Sadly, it does.
```js
function sum_all(...rest) {
let ret = 0;
for (let i = 0; i < rest.length; i++) { ret += rest[i]; }
return ret;
}
// output
function sum_all() {
var ret = 0;
for (var _len = arguments.length, rest = Array(_len), _key = 0; _key < _len; _key++) {
rest[_key] = arguments[_key];
}
for (var i = 0; i < rest.length; i++) { ret += rest[i]; }
return ret;
}
```
But then I noticed if I changed `let i = 0` to `let i: number = 0`, it
worked directly on `arguments`. That lead me down a rabbit hole to
`Path#_guessExecutionStatusRelativeTo`. When tracing through, the last
comparison made no sense to me. It was trying to find the index of
`"init"` in a list of `["declarations"]` and `"body"` in `["directives",
"body"]`. Red flags and such.
But it makes sense when you're trying to compare the visitor order of
the common ancestor path. Then we're trying to find `"init"` in a list
of `["init", "test", "update", "body"]`. Oh, and there's `"body"` in
there too! And now we know the `ForStatement`'s `init` is executed
before the `body`.
* add transform-class-properties to stage 3, set spec mode to default
* update readme with examples; use `buildUndefinedNode()`; change behavior to always define both static and nonstatic class properties regardless of spec/loose mode; update tests
* 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
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
* 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.
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.
* 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
* 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
* 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
(Failing.)
With destructuring assignment to an element.
This makes the function ineligible for `arguments` optimization, while
remaining eligible for loop position optimization.