40 Commits

Author SHA1 Message Date
Henry Zhu
413aa79711 v7.0.0-beta.33 2017-12-01 09:27:57 -05:00
Henry Zhu
5761eb0bb4 add readme entry for for-of assumeArray, use it (#6942) 2017-11-30 17:40:23 -06:00
Brian Ng
d8bbaaae0a Split exportExtensions into exportDefault and exportNamespace plugins… (#6920)
* Split exportExtensions into two plugins in babylon
* rename proposal-export-default to proposal-export-default-from
* rename proposal-export-namespace to proposal-export-namespace-from
2017-11-30 17:46:36 -05:00
Brian Ng
0a3c2a0c4c
Fix babylon test 2017-11-24 09:15:17 -06:00
Martin McKeaveney
6d820a2757 removing expression field from ArrowFunctionExpression (#6836) 2017-11-23 22:12:13 +01:00
Gidi Meir Morris
edbf5d33dc Fix "Better error messaging for unexpected tokens #6715" (#6875) 2017-11-22 15:31:03 -06:00
Nicolò Ribaudo
464df13c69 Allow yielding an arrow function withour parens around the param (#6877) 2017-11-22 15:28:37 -06:00
Sven SAULEAU
bb89364813
Merge pull request #6727 from babel/feat-use-charcode-constants
[Babylon] Use char codes contants
2017-11-16 10:35:42 +01:00
Sven SAULEAU
57e2c45cbe
chore: upgrade charcode 2017-11-16 09:57:20 +01:00
Raja Sekar
63397d0aad Better error message for super when not using an object method (#6754) 2017-11-15 21:29:46 -06:00
Brian Ng
0f2ab2fe20
Fix some reserved type handling and declare class with multiple extends (#6725) 2017-11-15 16:16:15 -06:00
Sven SAULEAU
4c584ae341
chore: upgrade and fix charcodes 2017-11-15 19:53:30 +01:00
Nicolò Ribaudo
9ae23639ad
Parse async arrows with flow type parameters (#6802)
Fixes #6712
2017-11-14 16:24:14 +01:00
Sven SAULEAU
186f04a3e9
feat: use charcodes in JSX plugin 2017-11-13 13:15:32 +01:00
Henry Zhu
4e6cd298c7 v7.0.0-beta.32 2017-11-12 08:32:53 -05:00
Sven SAULEAU
097ff40001
feat: more charCodes 2017-11-11 18:08:43 +01:00
Logan Smyth
432a9b5092
Allow sourceType:unambiguous as a way to tell Babylon to guess the type. (#6789)
* Allow sourceType:unambiguous as a way to tell Babylon to guess the type.

* Update some docs.
2017-11-10 15:00:06 -08:00
Sven SAULEAU
b79e3c0e99
fix: minor changes 2017-11-09 18:07:10 +01:00
Sven SAULEAU
88c1b4ef1c
feat: more charcodes 2017-11-09 17:13:36 +01:00
Sven SAULEAU
6b417a8ecb
chore: bump charcode plugin 2017-11-08 16:56:25 +01:00
Sven SAULEAU
cd8a869a18
fix: remove unwanted change 2017-11-08 13:20:11 +01:00
Sven SAULEAU
f3f005c67e
feat: use charcode AOT transform 2017-11-07 19:16:04 +01:00
Sven SAULEAU
7dfa79f4c8
Merge branch 'master' into feat-use-charcode-constants 2017-11-07 18:09:52 +01:00
Sven SAULEAU
3e34162092
chore: bump charcode 2017-11-07 18:07:38 +01: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
Henry Zhu
f76ac0b197 v7.0.0-beta.31 2017-11-03 16:03:01 -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
Sven SAULEAU
b93800d3cb
fix: use charcode package 2017-11-03 09:52:45 +01:00
Sven SAULEAU
233e60c765
Merge branch 'master' into feat-use-charcode-constants 2017-11-03 08:52:54 +01:00
Sven SAULEAU
72a90cb63d
feat: more charcodes 2017-11-03 08:51:48 +01:00
Sven SAULEAU
b51ac5e60a
feat: sort by value
Vim 🖤
2017-11-03 08:27:03 +01:00
Sven SAULEAU
8b206b2c3b
feat: generate charCodes
Vim 🖤
2017-11-02 20:13:44 +01:00
Sven SAULEAU
a2ed843636
feat: add more charCodes 2017-11-02 18:14:29 +01:00
Sven SAULEAU
b95810f4b4
refactor: switch to individual exports 2017-11-02 17:57:58 +01:00
Raja Sekar
2d0211a085 Fix parsing arrow with existential return type (#6726) 2017-11-02 10:56:27 -05:00
Sven SAULEAU
abb4850709
refactor: use charCodes 2017-11-02 16:40:08 +01:00
Sven SAULEAU
459e289d63
feat: setup constants 2017-11-02 09:10:26 +01:00
Daniel Tschinder
3b540e3f5a
Integrate babylon into babel workflow 2017-11-01 23:26:51 +01:00
Daniel Tschinder
2d378d076e
Move babylon into monorepo 2017-11-01 16:16:48 +01:00