10890 Commits

Author SHA1 Message Date
Logan Smyth
6fe7f77eb4
Merge pull request #6778 from loganfsmyth/use-peerdep
Use the peerDep to load types/template/traverse in plugins
2017-11-08 23:05:08 -08:00
Logan Smyth
e0fc5e974d
Merge pull request #6777 from loganfsmyth/options-simplified
Add an official 'state.filename' and be more explicit about option passing.
2017-11-08 23:00:44 -08:00
Logan Smyth
d5643d27f4 Remove unused dependency. 2017-11-08 17:38:55 -08:00
Logan Smyth
4d7d4605b6 Centralize parserOpts and generatorOpts normalization. 2017-11-08 17:06:01 -08:00
Logan Smyth
39119f88e7 Pass explicit options list to babel-code-frame 2017-11-08 17:00:02 -08:00
Logan Smyth
6684986372 Expose an official API to access the current filename. 2017-11-08 16:48:25 -08:00
Logan Smyth
82513465ee Pass an explicit whitelist of options down into babel-generator. 2017-11-08 16:41:33 -08:00
Diogo Franco
81811bf1b9 Fix transform-arrow-functions in { spec: true } shadowing (#6760)
* Fix transform-arrow-functions in { spec: true } shadowing

The function name matching the variable declaration name could
shadow the actual function object inside the generated function,
leading to invalid behavior due to holding a reference to the
original unbound function.

* Combine it with transform-function-name just to be sure in spec: false

* Revert "Fix transform-arrow-functions in { spec: true } shadowing"

This reverts commit 1cafe2561d0b0ddd181b956a85eb074621da12e8.

* Much simpler version of the above fix

* Missing fixture updates

* Avoid using rest/spread to make the tests pass on node 4

* ...actually update _all_ the fixtures
2017-11-08 17:21:30 -05:00
Brian Ng
c440f045f5
Update preset-env README with removing core-js stubs change [skip ci] 2017-11-07 08:48:50 -06:00
Brian Ng
ef47d8b1be Remove core-js/regenerator-runtime stubs (#6755) 2017-11-07 08:23:38 -05:00
Logan Smyth
b19b66d94b Use peerDep rather than plugin param for common APIs. 2017-11-06 11:32:47 -08:00
Daniel Tschinder
7dbed2170e Move typscript test copy script to scripts folder and run once (#6749) 2017-11-06 09:46:49 -06:00
Daniel Tschinder
cc66495a95
Unify eslint/prettier config (#6747)
* Unify eslint/prettier config

Use a prettier config file and correctly configure trailing commas

Enable curly in babylon as in all other packages.

* Add experimental and codemods
2017-11-06 14:19:59 +01:00
Benedikt Meurer
de72ce6ce7 Changed for..in loops to iterating through Object.keys, so only own properties gets processed (#6748)
* Properly guard for..in loops with Object#hasOwnProperty.

I noticed that babylon spends a lot of time in what we call *slow mode*
`for..in` when running in Node (on V8), and the reason for that is that
the version distributed on npm is build with *loose mode*, which turns
methods on the prototype into enumerable properties. Let's look at a
simplified example of the `State` class from `src/tokenizer/state.js`:

```js
class State {
  constructor() { this.x = 1; }

  clone() {
    var state = new State();
    for (var key in this) {
      var val = this[key];
      state[key] = val;
    }
    return state;
  }
}
```

According to the specification the `State.prototype.clone` method is
non-enumerable. However when transpiling this with loose mode, we get
the following output:

```js
var State = (function() {
  function State() { this.x = 1; }

  State.prototype.clone = function clone() {
    var state = new State();
    for (var key in this) {
      var val = this[key];
      state[key] = val;
    }
    return state;
  }

  return State;
})();
```

So all of a sudden the `State.prototype.clone` method is enumerable.
This means that the `for..in` loop inside of that method enumerates
`x` and `clone` for `key`, whereas originally it was supposed to only
enumerate `x`. This in turn means that the shape of the result of a
call to `clone` will be different than the shape of a state that is
created via the `State` constructor. You can check this in `d8` using
the `--allow-natives-syntax` flag and this simple test driver:

```js
const s = new State;
%DebugPrint(s);
%DebugPrint(s.clone());
```

Using either the class version or the transpiled version we see:

```
$ out/Release/d8 --allow-natives-syntax state-original.js
0x2a9d7970d329 <State map = 0x2a9d40b0c751>
0x2a9d7970d3c1 <State map = 0x2a9d40b0c751>
$ out/Release/d8 --allow-natives-syntax state-loose.js
0x3729ee30d1b9 <State map = 0x3729af90c701>
0x3729ee30d251 <State map = 0x3729af90c7a1>
```

So as you can see, the transpiled version (using *loose mode*) produces
a different shape for the result of `clone`, whereas the original
version is fine. This pollutes all sites which use either a state
created from the `State` constructor or returned from the `clone`
method. The original one has only the `x` property in either case,
whereas in the transpiled version the result of `clone` has properties
`x` and `clone` on the instance.

To mitigate this effect, it's best to guard the `for..in` loops with
`Object.prototype.hasOwnProperty` calls, such that the actual body of
the loop only deals with own properties and not with properties from the
prototype chain. This change does exactly that for the two affected
`clone` functions.

In addition to the performance hit because of the unnecessary
polymorphism, there's also the performance hit because of the *slow
mode* `for..in` itself, which has to collect the properties from the
instance plus the prototype. Ideally the prototype properties shouldn't
be enumerable to avoid this whole set of problems. I see a couple of
possible solutions:

1. Distribute the original ES2015 version via npm.
2. Don't use loose mode, so that `Object.defineProperty` is used
   instead, correctly passing `enumerable:false`.
3. Globally change loose mode in Babel to generate the correct and
   fast `Object.defineProperty` instead.

I'd personally prefer a combination of 1. and 3. here, but I'm aware
that distributing the ES2015 code might not be an option yet. So the
mitigation of properly guarding the `for..in` here should already help.
But it'd be nice to have a discussion on using `Object.defineProperty`
in general, as I imagine that this could easily bite other applications
as well and this performance cliff is completely unobvious to
developers.

* Switch to Object.keys and Array.prototype.forEach.
2017-11-06 13:23:20 +01:00
Brian Ng
d81cca3b5f Add additional support for loose mode in helper-module-transforms (#6742) 2017-11-05 20:54:14 -05:00
Henry Zhu
e8a33165ff
Publish to the latest dist tag [skip ci] (#6738)
- This is because with scoped packages the `latest` package was the first publish we did
- This happens to be beta.4..
- So in this case we should publish whatever version as latest anyway
2017-11-04 01:02:26 -04:00
Henry Zhu
f76ac0b197 v7.0.0-beta.31 v7.0.0-beta.31 2017-11-03 16:03:01 -04:00
Henry Zhu
f5b6e69214 Change version to beta.30 since babylon was already at that version [skip ci] 2017-11-03 15:56:41 -04:00
Henry Zhu
efdc32fec5
Run with loose, exclude typeof in standalone (#6736) 2017-11-03 15:42:37 -04:00
Henry Zhu
1196ec1e38
add loose/useBuiltIns option to stage presets, use it, opt babylon build (#6733)
* add loose, useBuiltIns options to presets + use loose class properties

* whitelist helpers for babylon

* use transform-for-of-as-array in babylon
2017-11-03 14:22:06 -04:00
Artem Yavorsky
9cf017b2ca Fix global reference for use-built-ins plugin (#6478)
* Consider instance type for polyfills.

* Add test cases for evaluated objects.

* preset-env fixtures: babel-polyfill -> @babel/polyfill

* Split up fixtures with evaluated variables.
2017-11-03 11:22:11 -04:00
Clement Hoang
1a7194a22f Add JSX Fragment syntax support (#6552)
* Add JSX Fragments to babel-types

* Support JSX fragments in the transform-react-jsx plugin

* Add tests JSX fragments

* Update helper-builder and transform plugin documentations for jsx fragment

* Add generator for jsx fragments

* Add test for jsx fragment generator

* Split jsx transform example into normal and fragment examples

* Remove unnecessary fields from ElementState in babel-helper-builder-react-jsx

* inline [skip ci]
2017-11-03 10:43:48 -04:00
Logan Smyth
9e2828322e
Merge pull request #6556 from loganfsmyth/early-validation
Strictly validate Babel's options to centralize Flow refinement of datatype
2017-11-02 16:24:36 -07:00
MICHAEL JACKSON
ce53c7668a Fix unpkg link (#6730) [skip ci] 2017-11-02 13:36:05 -04:00
Raja Sekar
2d0211a085 Fix parsing arrow with existential return type (#6726) 2017-11-02 10:56:27 -05:00
Daniel Tschinder
3b540e3f5a
Integrate babylon into babel workflow 2017-11-01 23:26:51 +01:00
Daniel Tschinder
52537410ef Merge histories of babylon and babel 2017-11-01 16:17:41 +01:00
Daniel Tschinder
2d378d076e
Move babylon into monorepo 2017-11-01 16:16:48 +01:00
Daniel Tschinder
1b612148bf "yield" parsing inside function name and parameters (#689)
* Use parseFunctionParams to parse method parameters

* [funct] Set this.state.inGenerator before parsing the function name/params

This allows "yield" inside generator parameters to be actually
parsed as a yield expression

* [funct] Disallow yield in function parameters

* [arrow] "yield" can start an arrow function (e.g. "yield => {}")

* [arrow] Disallow YieldExpressions inside arrow parameters.

* [err msg] Disallow yield as fn name in strict mode using checkReservedWord.

So Babylon throws "yield is a reserved word" instead of
a custom "Binding yield in strict mode"

* [err msg] "X is reserved in strict mode" should have precedence over "X is reserved", since it is more specific.

This was observable if "checkKeywords" is true and the word is both a keyword and a reserved
word in strict mode

* Disallow "yield" as an identifier inside generators

* [tests] Add tests, update wrong esprima tests and enable disabled esprima tests

* [tests] Move uncategorized tests to es2015/yield

* [tests] Update test262 whitelist

* Fix regression introduced by 8c77073

* [tests] Update flow whitelist

* Fix flow errors
2017-11-01 16:05:18 +01:00
Logan Smyth
0b3182911a
Avoid node duplication to fix spread bug with import. (#6657) 2017-10-31 20:37:16 -07:00
Henry Zhu
dbff057b8c update lockfile [skip ci] 2017-10-31 21:26:54 -04:00
Logan Smyth
d31c2c1470
Merge pull request #6655 from loganfsmyth/more-peerdeps
Use peerDeps in register and babel-node, add missing peerDependencies, and declare devDependencies
2017-10-31 18:10:55 -07:00
Logan Smyth
2d7685bdeb Explicitly declare devDependency to satisfy peerDep on babel-core. 2017-10-31 17:00:55 -07:00
Logan Smyth
ffad34e1a6 Remove unused @babel/types dependency. 2017-10-31 17:00:45 -07:00
Logan Smyth
8c95145c14 Use peerDependency for @babel register/node/cli. 2017-10-31 17:00:41 -07:00
Logan Smyth
948f741067 Add missing peerDependencies. 2017-10-31 16:57:56 -07:00
Henry Zhu
0e2a249746
Update to beta.5 with scoped packages 👻 (#6654)
* Update to beta.5 with scoped packages

* update to released version

* allow node 9 [skip ci]
2017-10-31 19:55:54 -04:00
Brian Ng
29a4aea27b Update parsing flow type/typeof imports (#773)
* Remove extranneous backticks from type/typeof error message

* Add isLookaheadContextual util

* Update parsing flow type/typeof imports
2017-10-31 17:09:39 +01:00
Nicolò Ribaudo
cd050e1405 Parse parameters inside function's env (#652)
* Parse parameters inside function context

* Add test for new.target inside parameters
2017-10-31 16:31:35 +01:00
M Behzad
fee7de2c1d white lists getter and setter acceseors for having stage-2 decorators (#766)
- adds `get` and `set` kind in addition to `method` to the list of allowed class members for having a decorator,
- adds tests for this two cases (decorator + set and decorator + get)
2017-10-31 16:13:04 +01:00
Henry Zhu
690d6465d8 v7.0.0-beta.5 v7.0.0-beta.5 2017-10-30 16:55:46 -04:00
Henry Zhu
bede73122d
fixup places that aren not scoped [skip ci] (#6646) 2017-10-30 16:47:13 -04:00
Mateusz Burzyński
a1c7449a92 Fixed incorrect static class field initialization order (#6530) 2017-10-30 16:32:45 -04:00
Henry Zhu
624f00f23c
Fix peerDep to ^ for beta only (#6644) 2017-10-30 16:24:42 -04:00
Henry Zhu
38f984f956 v7.0.0-beta.4 v7.0.0-beta.4 2017-10-30 14:33:56 -04:00
Henry Zhu
acfe99a4bc remove deprecated lerna command [skip ci] 2017-10-30 14:27:41 -04:00
Henry Zhu
96c380899b update types [skip ci] 2017-10-30 12:35:08 -04:00
Henry Zhu
397953c32d update lock [skip ci] 2017-10-30 12:21:20 -04:00
Benedikt Meurer
00342452e2 Fix OOB string character access in Printer#_maybeAddParen. (#6589)
* Fix OOB string character access in Printer#_maybeAddParen.

The `_maybeAddParen` method of the `Printer` class does

```js
const chaPost = str[i + 1]
```

without checking that `i + 1` is still within the bounds of `str`. It
seems like this triggers fairly often that the `str[i + 1]` access is
out of bounds. The first out of bounds access will turn the KeyedLoadIC
(in case of V8) into *MEGAMORPHIC* state, which is significantly slower
for strings (there's a fix in flight for V8 to mitigate the cost a bit
in that case). Even worse than that, the out of bounds access also
pollutes the later comparisons, namely

```js
chaPost === "/"
```

and

```js
chaPost === "*"
```

which are now no longer monomorphic on strings, since `chaPost` was
sometimes `undefined`.

This is a non-breaking performance fix, which improves babel execution
on the [web-tooling-benchmark](github.com/v8/web-tooling-benchmark)
workload by around 6-9%.

* Restructure and optimize the code a bit.
2017-10-30 09:16:44 -04:00
Daniel Tschinder
86abc16b37
Fix decorators2 to support export @decorator class A {} (#767)
* Fix decorators2 to support `export @decorator class A {}`

* change to better error message

Also ensure that null/undefined options get default value
2017-10-29 12:20:15 +01:00