Compare commits

...

59 Commits

Author SHA1 Message Date
Nicolò Ribaudo
4e1d6e7ff4 v7.1.6 2018-11-13 22:10:06 +01:00
Henry Zhu
efb71ea12b fix publish command [skip ci] (#8982) 2018-11-13 11:47:05 -08:00
Logan Smyth
cbbb3c7962 Ensure that the arrow nodes have a location before using them. (#9003) 2018-11-12 17:10:49 -08:00
Greg Bergé
4fcee1751a Fix cloneNode with typeAnnotation. (#8997)
Fixes #8996
2018-11-12 17:10:09 -08:00
Tien Pham
efa571a42c Update CHANGELOG.md (#9014) 2018-11-11 23:33:56 +01:00
Alican Çubukçuoğlu
bf8c4785f2 Fix "TypeError: comments is not iterable" (#8701) 2018-11-09 13:58:28 -08:00
Brian Ng
4f206b2416 prettier@1.15.1 (#9001) 2018-11-09 15:25:13 -06:00
Daniel Tschinder
504b331da4 Fix browser files to have the same API as the nodejs ones (#9004) 2018-11-09 13:11:46 -08:00
Daniel Tschinder
74f969b603 Update debug dependency (#8989) 2018-11-09 16:27:41 +01:00
Remi Liu
4dfd801887 [Types] fix generated TS/Flow comment types (#9007) 2018-11-09 09:03:53 -06:00
Daniel Tschinder
62233ed7c9 Update json5 to latest version (#8990) 2018-11-08 17:29:13 -08:00
ylemkimon
7b54ab620b preset-env: fix opera from esmodules target and Browserslist not used (#8555) 2018-11-08 10:29:49 -06:00
Daniel Tschinder
343f776ca5 Rename primitive types to reserved types (#8984) 2018-11-07 16:50:36 -06:00
Daniel Tschinder
756ded4d64 Remove definition of micromatch which was removed. (#8988) 2018-11-07 16:49:27 -06:00
Nicolò Ribaudo
b706e34fc8 [decorators] Correctly insert _initialize(this) after super(). (#8970)
* [decorators] Correctly insert `_initialize(this)` after `super()`.

This commit fixes to problem:
1) After `super();` statements, `_initialize(this)` was inserted without
   a trailing semicolon.
2) `(0, super())` causes an infinite recursion.

* Fix tests

* Add test
2018-11-06 21:58:09 -08:00
Daniel Tschinder
5d5cd8612f Fix several edge cases with context expression state (#8972)
* Fix several edge cases with context expression state

* Fix review comments

* Remove unused field
2018-11-06 19:37:24 -08:00
Henry Zhu
afe67a7035 v7.1.5 2018-11-06 17:21:22 -05:00
Nicolò Ribaudo
2fa1984635 Fix await in function name and parameters (#7727)
* Disallow await in function parameters

* Fix await as function name

* Update test whitelists
2018-11-06 08:30:06 +01:00
Retsam
2194842d11 Typescript: Validate tuple type element positions (#8828)
* feat: validate the positions of rest elements and optional elements in tuple types

Adds a validation step to the parser which raises syntax errors if a rest param is not at the end of a tuple, or if a mandatory param follows an optional parameter

* Fix spread after optional case; add test case
2018-11-05 23:19:34 -08:00
Daniel Tschinder
e3b2c1afff fix: Do not allow TypeCastExpressions w/o parens (#8956) 2018-11-05 15:34:24 -08:00
James Garbutt
b95cbc4a8e output aliased types in typescript declarations (#8629) 2018-11-05 23:58:57 +01:00
Nicolò Ribaudo
24c4901ff5 Remove Babylon plugins for features already merged to the ECMAScript spec (#8448)
These are now enabled by default:
- objectRestSpread (2018)
- asyncGenerators (2018)
- optionalCatchBInding (2019)
- jsonStrings (2019)

TODO (after this commit):
- [ ] Deprecate the `@babel/plugin-syntax-*` packages.
- [ ] Deprecate the `@babel/plugin-proposal-*` packages.
- [ ] Create the `@babel/plugin-transform-*` packages.
2018-11-05 23:48:06 +01:00
Daniel Tschinder
c125b1dd74 Update test262 commit, as old commit broke for some reason 2018-11-05 10:53:34 -08:00
Jordan Brown
f216a7b06f [flow] Add support for parsing _ as implicit instantiation in call/new (#8883)
* [flow] Add support for parsing  as implicit instantiation in call/new

* Update flow tests and fix underscore being a reserved type

* Rebase onto flow-test

* Fix flow commit hash
2018-11-05 10:45:40 -08:00
Logan Smyth
c6d2f45cab Resolve babel.config.js 'babelrcRoots' values relative to the config file. (#8910) 2018-11-05 08:51:27 -08:00
Daniel Tschinder
1d4d760ffc Update test262 to latest commit and enable mapping for features
Also added an automated check for new features which are not mapped or ignored
2018-11-04 18:49:53 +01:00
Nicolò Ribaudo
d35563ee1a Set correct methods name 2018-11-02 13:59:57 +01:00
Nicolò Ribaudo
38397ce11f Use toPropertyKey in the "decorate" helper
This commit also makes the "toPropertyKey" helper call @@toPrimitive
when needed.
2018-11-02 13:59:57 +01:00
Daniel Tschinder
cd81b079ee Allow function types in type params within arrow return types (#8954) 2018-11-01 09:10:46 -05:00
everdimension
e85faec47d Fix message when plugin of a wrong type is passed (#8950) 2018-10-31 14:34:26 -05:00
Byron Luk
0d9e77f559 rename colliding let bindings with for loop init (#8937)
* rename colliding let bindings with for loop init

* added complex test case to check if loop init collisions were handled correctly

* updated test files
2018-10-31 20:28:36 +01:00
Ben Mosher
c82750a48a edge incomplete support for arrow destructuring (babel #8349) (#8926) 2018-10-31 10:15:27 -05:00
Ryan Marsh
de80aefece fix single-arg async arrows when retainLines=true (#8868) 2018-10-30 06:49:11 +01:00
Jordan Brown
e4929e11f6 [flow] Explicit inexact objects with ... (#8884) 2018-10-29 15:09:17 -05:00
Brian Ng
d942d47e10 Update preset-env data (#8898) 2018-10-25 09:48:41 -05:00
Thiago Arrais
84e7884d9c Treat break inside block inside loop (#8914) 2018-10-25 09:46:36 -05:00
0xflotus
9d0dcedb2b fixed "source map" formatting in comment (#8878) [skip ci] 2018-10-20 00:51:46 +02:00
Byron Luk
b576bf4b41 fix typo in contributing guidelines (#8901) [skip ci] 2018-10-19 08:49:33 +02:00
Cyp
e541d6031a fix: Expression x === 'y' && '' should not evaluate to undefined. (#8880)
Fixes https://github.com/babel/minify/issues/908.
2018-10-16 21:25:49 +02:00
Sven Sauleau
5fa3628506 Merge pull request #8873 from vvyomjjain/patch-1
fixed an extra word
2018-10-14 18:53:17 +02:00
Vyom Jain
f71e4660d4 fixed an extra word
"visit join" doesn't sound right. Either there is a word missing or the word 'visit' may be removed.
2018-10-14 22:14:02 +05:30
Byron Luk
929567523c Fixes #8865 (#8866) 2018-10-12 09:28:15 -05:00
Henry Zhu
5080059138 v7.1.4 2018-10-11 13:32:18 -04:00
Henry Zhu
8ee857e268 v7.1.3 2018-10-11 11:52:19 -04:00
Brian Ng
6b8261bbb7 Bump Babel deps (#8770) 2018-10-10 13:55:02 -05:00
Brian Ng
ce1a6526e5 flow-bin@0.82.0 (#8832) 2018-10-10 12:29:23 -05:00
Kevin Thomas
842c164be5 Insertafter jsx fix (#8833)
* Add check for JSXElement

* Add test
2018-10-10 10:10:20 -06:00
Retsam
d2c75c2d38 fix: corrects handling of newline after async with paren-less arrow function (#8830)
If async is followed by a newline, then a paren-less arrow function should be parsed as two expressions
2018-10-09 23:25:31 +02:00
Retsam
3951acbff5 chore: add generated files for #8805 (#8826) 2018-10-08 12:29:33 -05:00
Retsam
08454ece46 Typescript - Tuples can include rest elements (#8805) 2018-10-08 11:32:31 -05:00
Tim von Oldenburg
4b8cb75b74 types: allow jsxEmptyExpression inside jsxExpressionContainer (#8791) 2018-10-07 23:31:03 -04:00
Guy Bedford
3fa4f53d0a System module format - fixes function hoisting failure case (#8820)
* failing test case

* fix function hoist bug
2018-10-07 23:30:02 -04:00
Bruno Macabeus
850bc1d3dd class private methods and properties: should not allow spaces between # and identifier (#8756) 2018-10-02 19:31:06 -07:00
Brian Ng
36d12b5969 Ensure destructuring's computed key handling matches object-rest-spread (#8793) 2018-10-02 20:46:08 -05:00
Brian Ng
2575312d1f Fix parsing of slash after class expression (#8804) 2018-10-02 20:45:53 -05:00
Retsam
a5b5ed928d Typescript - Tuple elements can be optional (#8720) 2018-10-02 11:29:51 -05:00
Nicolò Ribaudo
3c87401714 [decorators] [typescript] Parse type parameters (#8767)
* [decorators] [typescript] Parse type parameters

* Add test for invalid code
2018-10-01 22:04:19 +02:00
Matthew Robertson
07862e7272 Fix perf issue in typescript parser plugin (#8792) 2018-10-01 12:59:16 -05:00
Henry Zhu
ca89212b45 add changelog up to 7.1.2 [skip ci] 2018-09-28 18:28:43 -04:00
443 changed files with 11955 additions and 1254 deletions

View File

@@ -15,6 +15,287 @@ See [CHANGELOG - v4](/.github/CHANGELOG-v4.md), [CHANGELOG - v5](/.github/CHANGE
See [CHANGELOG - 6to5](/.github/CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
See [Babylon's CHANGELOG](packages/babylon/CHANGELOG.md) for the Babylon pre-7.0.0-beta.29 version changelog.
## 7.1.2 (2018-09-28)
Same as v7.1.1, except compiled against Node 6 instead of Node 8 by accident (e.g had `async functions`).
## v7.1.1 (2018-09-28)
> EDIT: had a publish issue here as well where it compiled against Node 8 instead of Node 6 so 7.1.2 will fix this.
> Also force publish `@babel/runtime` and `@babel/runtime-corejs2`. We need to fix the publishing around that since Lerna doesn't pickup the `@babel/helpers` changes as there is no "dependency"
#### :bug: Bug Fix
* `babel-generator`, `babel-parser`, `babel-types`
* [#8755](https://github.com/babel/babel/pull/8755) TypeScript: reserve `unknown` as TSUnknownKeyword. ([@g-plane](https://github.com/g-plane))
* `babel-plugin-transform-destructuring`
* [#8535](https://github.com/babel/babel/pull/8535) Do not unpack array patterns that update a referenced binding. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
* `babel-plugin-proposal-decorators`
* [#8742](https://github.com/babel/babel/pull/8742) [decorators] Support async and generator methods. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
* `babel-helpers`, `babel-plugin-proposal-decorators`
* [#8761](https://github.com/babel/babel/pull/8761) [decorators] Fields are enumerable. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
* `babel-generator`
* [#8751](https://github.com/babel/babel/pull/8751) Fix some missing parens cases with OptionalMemberExpression in generator. ([@existentialism](https://github.com/existentialism))
* [#8727](https://github.com/babel/babel/pull/8727) Handle throw expressions in generator. ([@existentialism](https://github.com/existentialism))
#### :house: Internal
* Other
* [#8780](https://github.com/babel/babel/pull/8780) Run test262 tests for exportNamespaceFrom. ([@existentialism](https://github.com/existentialism))
* `babel-helper-transform-fixture-test-runner`
* [#8768](https://github.com/babel/babel/pull/8768) Use babel-check-duplicated-nodes. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
## v7.1.0 (2018-09-17)
Check http://babeljs.io/blog/2018/09/17/7.1.0
#### :rocket: New Feature
* `babel-cli`, `babel-core`
* [#8660](https://github.com/babel/babel/pull/8660) Better support monorepos by allowing users to opt into automatically resolving 'root' with `rootMode: "upward"`.. ([@loganfsmyth](https://github.com/loganfsmyth))
* `babel-helper-transform-fixture-test-runner`
* [#7582](https://github.com/babel/babel/pull/7582) Allow regular plugins/presets resolution algorithm for packages outsi…. ([@Andarist](https://github.com/Andarist))
* `babel-helpers`, `babel-plugin-proposal-decorators`, `babel-plugin-syntax-decorators`
* [#7976](https://github.com/babel/babel/pull/7976) Add support for the new decorators proposal. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
* `babel-helpers`, `babel-plugin-proposal-class-properties`
* [#8205](https://github.com/babel/babel/pull/8205) Private Static Fields Features: Stage 3. ([@rricard](https://github.com/rricard))
#### :bug: Bug Fix
* `babel-parser`
* [#8698](https://github.com/babel/babel/pull/8698) Fix parsing of newline between 'async' and 'function'. ([@existentialism](https://github.com/existentialism))
* [#8677](https://github.com/babel/babel/pull/8677) Fix typescript parsing typed object shorthand methods. ([@existentialism](https://github.com/existentialism))
* `babel-plugin-transform-typescript`
* [#8682](https://github.com/babel/babel/pull/8682) Fix TSParameterProperty getting lost with transform-classes. ([@existentialism](https://github.com/existentialism))
* [#8695](https://github.com/babel/babel/pull/8695) Adjust TSParameterProperty handling to work with transform-parameters. ([@existentialism](https://github.com/existentialism))
* [#8666](https://github.com/babel/babel/pull/8666) Fix typescript import elision. ([@Retsam](https://github.com/Retsam))
* `babel-preset-env`
* [#8693](https://github.com/babel/babel/pull/8693) Fix es6.string.iterator mapping in babel-preset-env. ([@existentialism](https://github.com/existentialism))
* `babel-core`, `babel-plugin-proposal-class-properties`, `babel-plugin-proposal-decorators`, `babel-plugin-transform-runtime`
* [#8659](https://github.com/babel/babel/pull/8659) Fix version checks in .availableHelper and transform-runtime definitions.. ([@loganfsmyth](https://github.com/loganfsmyth))
* Other
* [#8627](https://github.com/babel/babel/pull/8627) ts generator: allow reserved keywords in interfaces. ([@43081j](https://github.com/43081j))
* `babel-plugin-transform-parameters`
* [#8414](https://github.com/babel/babel/pull/8414) Allow patterns as argument of RestElement. ([@microbouji](https://github.com/microbouji))
* `babel-core`, `babel-plugin-transform-runtime`
* [#8624](https://github.com/babel/babel/pull/8624) Verify 'sourceMap' option with hasOwnProperty, and verify string-typed 'version'. ([@loganfsmyth](https://github.com/loganfsmyth))
* `babel-helpers`, `babel-plugin-proposal-class-properties`
* [#8614](https://github.com/babel/babel/pull/8614) [static private] Unify loose handling of static and instance props. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
#### :nail_care: Polish
* `babel-plugin-transform-runtime`
* [#8581](https://github.com/babel/babel/pull/8581) Fix grammar in error message at @babel/plugin-transform-runtime. ([@tricknotes](https://github.com/tricknotes))
* `babel-parser`
* [#8576](https://github.com/babel/babel/pull/8576) More helpful errorr message for missing decoratorsBeforeExport in parser. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
#### :memo: Documentation
* [#8561](https://github.com/babel/babel/pull/8561) Added pronounciation of babel. ([@siddhant1](https://github.com/siddhant1))
#### :house: Internal
* `babel-core`
* [#8714](https://github.com/babel/babel/pull/8714) Fix Flow error with new versionRange test.. ([@loganfsmyth](https://github.com/loganfsmyth))
* Other
* [#8679](https://github.com/babel/babel/pull/8679) remove force publish, temp tag [skip ci]. ([@hzoo](https://github.com/hzoo))
* `babel-plugin-transform-runtime`
* [#8661](https://github.com/babel/babel/pull/8661) Makefile: run fix json on fix. ([@xtuc](https://github.com/xtuc))
* `babel-*`
* [#8658](https://github.com/babel/babel/pull/8658) Format fixture options.json with Prettier.. ([@loganfsmyth](https://github.com/loganfsmyth))
* `babel-parser`
* [#8630](https://github.com/babel/babel/pull/8630) Bump flow to 0.80 and fix sourceType error. ([@existentialism](https://github.com/existentialism))
* [#8610](https://github.com/babel/babel/pull/8610) types: missing `unambiguous` sourceType. ([@xtuc](https://github.com/xtuc))
* [#8170](https://github.com/babel/babel/pull/8170) @babel/parser: expose a TypeScript definition file from package. ([@AviVahl](https://github.com/AviVahl))
* `babel-*`
* [#8573](https://github.com/babel/babel/pull/8573) add access public to all packages [skip ci]. ([@hzoo](https://github.com/hzoo))
## v7.0.1 (2018-09-11)
Doing a quick patch regarding helpers versioning to prevent future issues: https://github.com/babel/babel/pull/8659
## v7.0.0 (2018-08-27)
No change from rc.4. Finally released as https://babeljs.io/blog/2018/08/27/7.0.0!
## v7.0.0-rc.4 (2018-08-27)
> Similar to removing proposals in `@babel/polyfill`, we are removing them in `transform-runtime`
#### :boom: Breaking Change
* `babel-plugin-transform-runtime`
* [#8547](https://github.com/babel/babel/pull/8547) Remove nonstandard functions and fake prototype methods from babel-runtime. ([@loganfsmyth](https://github.com/loganfsmyth))
* `babel-parser`
* [#8539](https://github.com/babel/babel/pull/8539) Update parser whitespace for clarity. ([@jridgewell](https://github.com/jridgewell))
#### :bug: Bug Fix
* `babel-register`
* [#8553](https://github.com/babel/babel/pull/8553) bump source-map-support. ([@hzoo](https://github.com/hzoo))
* `babel-core`
* [#8546](https://github.com/babel/babel/pull/8546) Default highlightCode:true for the parser highlighting.. ([@loganfsmyth](https://github.com/loganfsmyth))
#### :house: Internal
* Other
* [#8554](https://github.com/babel/babel/pull/8554) Lerna: remove exact [skip ci]. ([@hzoo](https://github.com/hzoo))
* `babel-parser`
* [#8540](https://github.com/babel/babel/pull/8540) Cleanup getLineInfo. ([@jridgewell](https://github.com/jridgewell))
* [#8541](https://github.com/babel/babel/pull/8541) Update to ES6 String methods. ([@jridgewell](https://github.com/jridgewell))
* [#8537](https://github.com/babel/babel/pull/8537) Flatten TokenType class hierarchy. ([@jridgewell](https://github.com/jridgewell))
* [#8539](https://github.com/babel/babel/pull/8539) Update parser whitespace for clarity. ([@jridgewell](https://github.com/jridgewell))
## v7.0.0-rc.3 (2018-08-24)
#### :boom: Breaking Change
* `babel-preset-env`
* [#8509](https://github.com/babel/babel/pull/8509) Add browserslist 4 support.. ([@yavorsky](https://github.com/yavorsky))
* `babel-plugin-transform-runtime`
* [#8518](https://github.com/babel/babel/pull/8518) Make 'useESModules' only toggle CJS vs ESM helpers when importing file is ESM.. ([@loganfsmyth](https://github.com/loganfsmyth))
#### :rocket: New Feature
* `babel-plugin-transform-runtime`
* [#8520](https://github.com/babel/babel/pull/8520) Expose opt-in useESModules:"auto" from transform-runtime to toggle based on 'supportsStaticESM'. ([@loganfsmyth](https://github.com/loganfsmyth))
#### :bug: Bug Fix
* `babel-helpers`, `babel-plugin-transform-classes`, `babel-preset-env`
* [#8501](https://github.com/babel/babel/pull/8501) [_wrapNativeSuper] Don't wrap non-native constructors. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
* `babel-generator`, `babel-traverse`, `babel-types`
* [#8478](https://github.com/babel/babel/pull/8478) Fix path.scope.rename() to not change break clauses. ([@rafeca](https://github.com/rafeca))
* `babel-plugin-proposal-object-rest-spread`
* [#8514](https://github.com/babel/babel/pull/8514) fix: object rest with default values bug. ([@jquense](https://github.com/jquense))
* `babel-traverse`
* [#8505](https://github.com/babel/babel/pull/8505) Rename exported functions where name conflicts with param.. ([@loganfsmyth](https://github.com/loganfsmyth))
#### :house: Internal
* `babel-plugin-transform-object-set-prototype-of-to-assign`
* [#8409](https://github.com/babel/babel/pull/8409) Add LICENSE file to published npm packages [skip ci]. ([@opichals](https://github.com/opichals))
* Other
* [#8504](https://github.com/babel/babel/pull/8504) Update Babel to rc.2. ([@hzoo](https://github.com/hzoo))
## v7.0.0-rc.2 (2018-08-21)
A notable change is the addition of https://github.com/babel/babel/pull/8485 which enables https://github.com/babel/babel-loader/pull/660 (automatically doing `modules: false` for `@babel/preset-env` when using `babel-loader`.
#### :boom: Breaking Change
* `babel-core`
* [#8470](https://github.com/babel/babel/pull/8470) Remove File#resolveModuleSource. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
* [#8473](https://github.com/babel/babel/pull/8473) Allow babel-plugin/preset prefix to not be a prefix, when used in a scope.. ([@loganfsmyth](https://github.com/loganfsmyth))
* `babel-core`, `babel-parser`, `babel-plugin-syntax-decorators`
* [#8465](https://github.com/babel/babel/pull/8465) Require decoratorsBeforeExport option for decorators. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
#### :rocket: New Feature
* `babel-preset-env`
* [#8500](https://github.com/babel/babel/pull/8500) Add missing es7.promise.finally polyfill when using useBuiltIns: usage. ([@jsnajdr](https://github.com/jsnajdr))
* `babel-cli`, `babel-core`, `babel-node`, `babel-preset-env`, `babel-register`
* [#8485](https://github.com/babel/babel/pull/8485) Allow preset-env to toggle module handling based on flags from the caller (like babel-loader). ([@loganfsmyth](https://github.com/loganfsmyth))
* `babel-core`
* [#8474](https://github.com/babel/babel/pull/8474) Preserve 'false'-options for disabled plugins/presets.. ([@loganfsmyth](https://github.com/loganfsmyth))
* [#8473](https://github.com/babel/babel/pull/8473) Allow babel-plugin/preset prefix to not be a prefix, when used in a scope.. ([@loganfsmyth](https://github.com/loganfsmyth))
* `babel-helper-transform-fixture-test-runner`, `babel-plugin-transform-runtime`
* [#8435](https://github.com/babel/babel/pull/8435) Allow transform-runtime to insert runtime references with absolute paths.. ([@loganfsmyth](https://github.com/loganfsmyth))
#### :bug: Bug Fix
* `babel-parser`
* [#8488](https://github.com/babel/babel/pull/8488) Fix trailingComments for FunctionExpression that is CallExpression arguments. ([@jiaxuan](https://github.com/jiaxuan))
* `babel-core`
* [#8493](https://github.com/babel/babel/pull/8493) Take top-level config source into consideration when processing nested env/overrides.. ([@loganfsmyth](https://github.com/loganfsmyth))
* `babel-helpers`, `babel-plugin-proposal-decorators`
* [#7429](https://github.com/babel/babel/pull/7429) Fix default descriptor setting for class properties with decorators. ([@yhpark](https://github.com/yhpark))
* `babel-plugin-transform-parameters`
* [#8479](https://github.com/babel/babel/pull/8479) Fixes setter paratemer default value. ([@nikolayemrikh](https://github.com/nikolayemrikh))
#### :nail_care: Polish
* `babel-core`
* [#8494](https://github.com/babel/babel/pull/8494) Cache individual programmatic descriptors along with the overall list.. ([@loganfsmyth](https://github.com/loganfsmyth))
* [#8493](https://github.com/babel/babel/pull/8493) Take top-level config source into consideration when processing nested env/overrides.. ([@loganfsmyth](https://github.com/loganfsmyth))
#### :house: Internal
* `babel-core`
* [#8493](https://github.com/babel/babel/pull/8493) Take top-level config source into consideration when processing nested env/overrides.. ([@loganfsmyth](https://github.com/loganfsmyth))
* `babel-plugin-transform-classes`
* [#8472](https://github.com/babel/babel/pull/8472) Remove unused file. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
## v7.0.0-rc.1 (2018-08-09)
Same as rc.0 but fixes the peerDep issue #8443. It's changed to just be ^7.0.0-0
## v7.0.0-rc.0 (2018-08-09)
> This had an issue with `peerDependencies` so please use `rc.1`.
Alright finally at the end 🙂. Shouldn't have anymore breaking changes and going to wait some time to fix bugs/regressions
> Summary: `@babel/polyfill` will not include proposal polyfills by default and fixed a regression.
#### :boom: Breaking Change
* `babel-polyfill`
* [#8440](https://github.com/babel/babel/pull/8440) remove proposals polyfills from default import [skip ci]. ([@hzoo](https://github.com/hzoo))
> Will add this to the upgrade guide/polyfill docs. I guess we could include a `babel-upgrade` for this too, not sure.
#### :bug: Bug Fix
* `babel-cli`
* [#8436](https://github.com/babel/babel/pull/8436) Require v1.1.0 so that correct filter params are passed.. ([@loganfsmyth](https://github.com/loganfsmyth))
## v7.0.0-beta.56 (2018-08-03)
- Separate `@babel/runtime`: should work for helpers alone and opt-into core-js if necessary.
- More details in http://babeljs.io/docs/en/next/babel-runtime, http://babeljs.io/docs/en/next/babel-plugin-transform-runtime (via https://github.com/babel/babel/pull/8266, https://github.com/babel/website/pull/1714)
- `babel-upgrade` issue: https://github.com/babel/babel-upgrade/issues/70
#### :boom: Breaking Change
* `babel-plugin-transform-regenerator`, `babel-plugin-transform-runtime`, `babel-runtime-corejs2`, `babel-runtime`
* [#8266](https://github.com/babel/babel/pull/8266) Split @babel/runtime into 2 modules via @babel/runtime-corejs2. ([@loganfsmyth](https://github.com/loganfsmyth))
* `babel-core`, `babel-helper-module-imports`, `babel-helpers`, `babel-plugin-external-helpers`, `babel-plugin-transform-runtime`
* [#8398](https://github.com/babel/babel/pull/8398) Only reference helpers from external/runtime helpers if they are known to be available.. ([@loganfsmyth](https://github.com/loganfsmyth))
#### :rocket: New Feature
* `babel-plugin-transform-regenerator`, `babel-plugin-transform-runtime`, `babel-runtime-corejs2`, `babel-runtime`
* [#8266](https://github.com/babel/babel/pull/8266) Split @babel/runtime into 2 modules via @babel/runtime-corejs2. ([@loganfsmyth](https://github.com/loganfsmyth))
#### :bug: Bug Fix
* `babel-parser`, `babel-plugin-transform-typescript`
* [#8408](https://github.com/babel/babel/pull/8408) Allow TSInterfaceDeclaration to be default export. ([@existentialism](https://github.com/existentialism))
* `babel-preset-env`
* [#8403](https://github.com/babel/babel/pull/8403) Ensure esmodule targets are parsed by browserslist. ([@existentialism](https://github.com/existentialism))
* Other
* [#8024](https://github.com/babel/babel/pull/8024) Run transform-runtime on the standalone bundle so it stays ES5-compatible.. ([@loganfsmyth](https://github.com/loganfsmyth))
#### :memo: Documentation
* [#8412](https://github.com/babel/babel/pull/8412) Update Documentation[skip ci]. ([@leongjiameng](https://github.com/leongjiameng))
## v7.0.0-beta.55 (2018-07-28)
Breaking Change in beta:
> Throws an error on using Stage presets: https://babeljs.io/blog/2018/07/27/removing-babels-stage-presets
#### :boom: Breaking Change
* `babel-core`, `babel-plugin-proposal-class-properties`, `babel-plugin-proposal-decorators`, `babel-preset-stage-0`, `babel-preset-stage-1`, `babel-preset-stage-2`, `babel-preset-stage-3`, `babel-standalone`
* [#8293](https://github.com/babel/babel/pull/8293) Remove Stage presets. ([@hzoo](https://github.com/hzoo))
#### :rocket: New Feature
* `babel-generator`, `babel-parser`, `babel-plugin-transform-typescript`, `babel-types`
* [#7754](https://github.com/babel/babel/pull/7754) TypeScript: Support type arguments on tagged templates. ([@andy-ms](https://github.com/andy-ms))
#### :bug: Bug Fix
* `babel-cli`, `babel-core`, `babel-generator`
* [#8380](https://github.com/babel/babel/pull/8380) Ensure that Identifier source mappings explicitly start and stop on the generated range. ([@loganfsmyth](https://github.com/loganfsmyth))
* `babel-preset-env`
* [#8391](https://github.com/babel/babel/pull/8391) Ensure preset-env doesn't clobber browserslist defaults. ([@existentialism](https://github.com/existentialism))
* `babel-core`
* [#8376](https://github.com/babel/babel/pull/8376) Fix order of optional argument reordering. ([@Qix-](https://github.com/Qix-))
* [#8381](https://github.com/babel/babel/pull/8381) Allow an Array for `babelrcRoots`.. ([@wtgtybhertgeghgtwtg](https://github.com/wtgtybhertgeghgtwtg))
* [#8342](https://github.com/babel/babel/pull/8342) Do not mutate ast. ([@thiagoarrais](https://github.com/thiagoarrais))
* `babel-parser`
* [#8374](https://github.com/babel/babel/pull/8374) Correctly parse interface methods named 'static'. ([@bakkot](https://github.com/bakkot))
#### :nail_care: Polish
* `babel-parser`
* [#8355](https://github.com/babel/babel/pull/8355) remove .then from `dynamic import` parser exception message. ([@dnalborczyk](https://github.com/dnalborczyk))
#### :house: Internal
* `babel-core`, `babel-preset-stage-0`, `babel-preset-stage-1`, `babel-preset-stage-2`, `babel-preset-stage-3`, `babel-standalone`
* [#8397](https://github.com/babel/babel/pull/8397) Remove our own use of stage presets. ([@hzoo](https://github.com/hzoo))
* `babel-helpers`, `babel-plugin-proposal-class-properties`
* [#8318](https://github.com/babel/babel/pull/8318) Save full descriptor instead of only value for private fields.. ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo))
* `babel-core`
* [#8381](https://github.com/babel/babel/pull/8381) Allow an Array for `babelrcRoots`.. ([@wtgtybhertgeghgtwtg](https://github.com/wtgtybhertgeghgtwtg))
* `babel-cli`, `babel-core`, `babel-generator`, `babel-helper-define-map`, `babel-helper-fixtures`, `babel-helper-module-imports`, `babel-helper-module-transforms`, `babel-helper-regex`, `babel-helper-simple-access`, `babel-helper-transform-fixture-test-runner`, `babel-node`, `babel-plugin-transform-block-scoping`, `babel-register`, `babel-template`, `babel-traverse`, `babel-types`
* [#8377](https://github.com/babel/babel/pull/8377) Bumped lodash to 4.17.10. ([@Berkmann18](https://github.com/Berkmann18))
## v7.0.0-beta.54 (2018-07-16)
> Regarding https://github.com/babel/babel/issues/8184, we aren't using `micromatch` for paths, just basic `*/**` substitution now. For anything more complicated we will recommend using a regex/`.js` config.
@@ -2261,7 +2542,7 @@ Also started Babel to compile itself with Babel 7! (We'll be working on making i
#### :nail_care: Polish
* `babel-register`
* [#5411](https://github.com/babel/babel/pull/5411) Seperate version env cache files. ([@pwmckenna](https://github.com/pwmckenna))
* [#5411](https://github.com/babel/babel/pull/5411) Separate version env cache files. ([@pwmckenna](https://github.com/pwmckenna))
#### :memo: Documentation
* `babel-plugin-transform-runtime`

View File

@@ -310,7 +310,7 @@ Note that the code shown in Chrome DevTools is compiled code and therefore diffe
- Create a new issue that describes the proposal (ex: [#538](https://github.com/babel/babylon/issues/538)). Include any relevant information like proposal repo/author, examples, parsing approaches, meeting notes, presentation slides, and more.
- The pull request should include:
- [ ] An update to the [plugins](https://github.com/babel/babel/tree/master/packages/babel-parser#plugins) part of the readme. Add a new entry to that list for the new plugin flag (and link to the proposal)
- [ ] If any new nodes or modifications need to be added to the AST, update [ast/spec.md](https://github.com/babel/babel/bloc/master/packages/babel-parser/ast/spec.md)
- [ ] If any new nodes or modifications need to be added to the AST, update [ast/spec.md](https://github.com/babel/babel/blob/master/packages/babel-parser/ast/spec.md)
- [ ] Make sure you use the `this.hasPlugin("plugin-name-here")` check in the babel parser so that your new plugin code only runs when that flag is turned on (not default behavior)
- [ ] Add failing/passing tests according to spec behavior
- Start working about the Babel transform itself!

View File

@@ -1,6 +1,6 @@
MAKEFLAGS = -j1
FLOW_COMMIT = bea8b83f50f597454941d2a7ecef6e93a881e576
TEST262_COMMIT = 06c2f019019cf7850923de4d56828e6dfd9212b8
FLOW_COMMIT = e192e1a4793dd8e43415fbfe8046d832cb513c8b
TEST262_COMMIT = 69c1efd325deedf54db92a23008399e2b00fa51e
# Fix color output until TravisCI fixes https://github.com/travis-ci/travis-ci/issues/7967
export FORCE_COLOR = true
@@ -82,7 +82,7 @@ test-ci-coverage:
bootstrap-flow:
rm -rf ./build/flow
mkdir -p ./build
git clone --branch=master --single-branch --shallow-since=2017-01-01 https://github.com/facebook/flow.git ./build/flow
git clone --branch=master --single-branch --shallow-since=2018-11-01 https://github.com/facebook/flow.git ./build/flow
cd build/flow && git checkout $(FLOW_COMMIT)
test-flow:
@@ -96,7 +96,7 @@ test-flow-update-whitelist:
bootstrap-test262:
rm -rf ./build/test262
mkdir -p ./build
git clone --branch=master --single-branch --shallow-since=2017-01-01 https://github.com/tc39/test262.git ./build/test262
git clone --branch=master --single-branch --shallow-since=2018-11-01 https://github.com/tc39/test262.git ./build/test262
cd build/test262 && git checkout $(TEST262_COMMIT)
test-test262:
@@ -125,7 +125,7 @@ prepublish:
publish: prepublish
# --only-explicit-updates
./node_modules/.bin/lerna publish
./node_modules/.bin/lerna publish --force-publish="@babel/runtime,@babel/runtime-corejs2" --dangerously-only-publish-explicit-updates-this-is-a-custom-flag-for-babel-and-you-should-not-be-using-it-just-deal-with-more-packages-being-published-it-is-not-a-big-deal
make clean
bootstrap: clean-all

View File

@@ -107,7 +107,7 @@ Mostly a handful of volunteers! Please check out our [team page](https://babeljs
### Looking for support?
For questions and support please visit join our [Slack Community](https://slack.babeljs.io/) (you can sign-up [here](https://slack.babeljs.io/) for an invite), ask a question on [Stack Overflow](https://stackoverflow.com/questions/tagged/babeljs), or ping us on [Twitter](https://twitter.com/babeljs).
For questions and support please join our [Slack Community](https://slack.babeljs.io/) (you can sign-up [here](https://slack.babeljs.io/) for an invite), ask a question on [Stack Overflow](https://stackoverflow.com/questions/tagged/babeljs), or ping us on [Twitter](https://twitter.com/babeljs).
### Is there a Babel song?

View File

@@ -1,6 +1,6 @@
{
"lerna": "2.11.0",
"version": "7.1.2",
"version": "7.1.6",
"changelog": {
"repo": "babel/babel",
"cacheDir": ".changelog",

View File

@@ -2,12 +2,6 @@
* Basic declarations for the npm modules we use.
*/
declare module "micromatch" {
declare module.exports: {
(Array<string>, Array<string>, ?{ nocase: boolean }): Array<string>,
};
}
declare module "resolve" {
declare export default {
sync: (string, {| basedir: string |}) => string;

View File

@@ -9,8 +9,8 @@
"test": "make test"
},
"devDependencies": {
"@babel/cli": "^7.1.0",
"@babel/core": "^7.1.0",
"@babel/cli": "^7.1.2",
"@babel/core": "^7.1.2",
"@babel/plugin-proposal-class-properties": "^7.1.0",
"@babel/plugin-proposal-export-namespace-from": "^7.0.0",
"@babel/plugin-proposal-numeric-separator": "^7.0.0",
@@ -19,11 +19,11 @@
"@babel/preset-env": "^7.1.0",
"@babel/preset-flow": "^7.0.0",
"@babel/register": "^7.0.0",
"@babel/runtime": "^7.0.0",
"@babel/runtime": "^7.1.2",
"babel-core": "^7.0.0-0",
"babel-eslint": "^9.0.0",
"babel-eslint": "^10.0.1",
"babel-jest": "^23.6.0",
"babel-loader": "^8.0.2",
"babel-loader": "^8.0.4",
"babel-plugin-transform-charcodes": "^0.1.0",
"browserify": "^16.2.2",
"bundle-collapser": "^1.2.1",
@@ -32,11 +32,11 @@
"derequire": "^2.0.2",
"enhanced-resolve": "^3.0.0",
"eslint": "^5.6.0",
"eslint-config-babel": "^8.0.0",
"eslint-config-babel": "^8.0.1",
"eslint-plugin-flowtype": "^2.50.1",
"eslint-plugin-local-rules": "0.1.0",
"eslint-plugin-prettier": "^2.6.2",
"flow-bin": "^0.80.0",
"flow-bin": "^0.82.0",
"graceful-fs": "^4.1.11",
"gulp": "^4.0.0",
"gulp-babel": "^8.0.0-beta.2",
@@ -55,7 +55,7 @@
"lodash": "^4.17.10",
"merge-stream": "^1.0.1",
"output-file-sync": "^2.0.0",
"prettier": "^1.14.3",
"prettier": "^1.15.1",
"pump": "^1.0.2",
"rimraf": "^2.4.3",
"rollup-plugin-babel": "^4.0.0-beta.0",

View File

@@ -1,6 +1,6 @@
{
"name": "@babel/cli",
"version": "7.1.2",
"version": "7.1.5",
"description": "Babel command line.",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",
@@ -36,7 +36,7 @@
"@babel/core": "^7.0.0-0"
},
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/core": "^7.1.5",
"@babel/helper-fixtures": "^7.0.0"
},
"bin": {

View File

@@ -81,7 +81,7 @@ commander.option(
"print a comment after any injected non-user code",
);
// General soucemap formatting.
// General source map formatting.
commander.option("-s, --source-maps [true|false|inline|both]", "", booleanify);
commander.option(
"--source-map-target [string]",

View File

@@ -1,6 +1,6 @@
{
"name": "@babel/core",
"version": "7.1.2",
"version": "7.1.6",
"description": "Babel compiler core.",
"main": "lib/index.js",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
@@ -34,15 +34,15 @@
},
"dependencies": {
"@babel/code-frame": "^7.0.0",
"@babel/generator": "^7.1.2",
"@babel/helpers": "^7.1.2",
"@babel/parser": "^7.1.2",
"@babel/generator": "^7.1.6",
"@babel/helpers": "^7.1.5",
"@babel/parser": "^7.1.6",
"@babel/template": "^7.1.2",
"@babel/traverse": "^7.1.0",
"@babel/types": "^7.1.2",
"@babel/traverse": "^7.1.6",
"@babel/types": "^7.1.6",
"convert-source-map": "^1.1.0",
"debug": "^3.1.0",
"json5": "^0.5.0",
"debug": "^4.1.0",
"json5": "^2.1.0",
"lodash": "^4.17.10",
"resolve": "^1.3.2",
"semver": "^5.4.1",

View File

@@ -155,6 +155,7 @@ export function buildRootChain(
}
let { babelrc, babelrcRoots } = opts;
let babelrcRootsDirectory = context.cwd;
const configFileChain = emptyChain();
if (configFile) {
@@ -168,6 +169,7 @@ export function buildRootChain(
babelrc = validatedFile.options.babelrc;
}
if (babelrcRoots === undefined) {
babelrcRootsDirectory = validatedFile.dirname;
babelrcRoots = validatedFile.options.babelrcRoots;
}
@@ -185,7 +187,7 @@ export function buildRootChain(
if (
(babelrc === true || babelrc === undefined) &&
pkgData &&
babelrcLoadEnabled(context, pkgData, babelrcRoots)
babelrcLoadEnabled(context, pkgData, babelrcRoots, babelrcRootsDirectory)
) {
({ ignore: ignoreFile, config: babelrcFile } = findRelativeConfig(
pkgData,
@@ -229,6 +231,7 @@ function babelrcLoadEnabled(
context: ConfigContext,
pkgData: FilePackageData,
babelrcRoots: BabelrcSearch | void,
babelrcRootsDirectory: string,
): boolean {
if (typeof babelrcRoots === "boolean") return babelrcRoots;
@@ -243,7 +246,9 @@ function babelrcLoadEnabled(
let babelrcPatterns = babelrcRoots;
if (!Array.isArray(babelrcPatterns)) babelrcPatterns = [babelrcPatterns];
babelrcPatterns = babelrcPatterns.map(pat => {
return typeof pat === "string" ? path.resolve(context.cwd, pat) : pat;
return typeof pat === "string"
? path.resolve(babelrcRootsDirectory, pat)
: pat;
});
// Fast path to avoid having to match patterns if the babelrc is just
@@ -253,10 +258,12 @@ function babelrcLoadEnabled(
}
return babelrcPatterns.some(pat => {
if (typeof pat === "string") pat = pathPatternToRegex(pat, context.cwd);
if (typeof pat === "string") {
pat = pathPatternToRegex(pat, babelrcRootsDirectory);
}
return pkgData.directories.some(directory => {
return matchPattern(pat, context.cwd, directory, context);
return matchPattern(pat, babelrcRootsDirectory, directory, context);
});
});
}

View File

@@ -132,7 +132,7 @@ function resolveStandardizedName(
} catch (e2) {}
if (resolvedOppositeType) {
e.message += `\n- Did you accidentally pass a ${type} as a ${oppositeType}?`;
e.message += `\n- Did you accidentally pass a ${oppositeType} as a ${type}?`;
}
throw e;

View File

@@ -1,14 +1,29 @@
// @flow
import type { FileResult } from "./transformation";
export default function transformFile(
filename: string,
opts?: Object = {},
callback: (?Error, FileResult | null) => void,
// duplicated from transform-file so we do not have to import anything here
type TransformFile = {
(filename: string, callback: Function): void,
(filename: string, opts: ?Object, callback: Function): void,
};
export const transformFile: TransformFile = (function transformFile(
filename,
opts,
callback,
) {
if (typeof opts === "function") {
callback = opts;
}
callback(new Error("Transforming files is not supported in browsers"), null);
}: Function);
export function transformFileSync() {
throw new Error("Transforming files is not supported in browsers");
}
export function transformFileAsync() {
return Promise.reject(
new Error("Transforming files is not supported in browsers"),
);
}

View File

@@ -1,5 +0,0 @@
// @flow
export default function transformFileSync() {
throw new Error("Transforming files is not supported in browsers");
}

View File

@@ -9,6 +9,14 @@ import {
type FileResultCallback,
} from "./transformation";
import typeof * as transformFileBrowserType from "./transform-file-browser";
import typeof * as transformFileType from "./transform-file";
// Kind of gross, but essentially asserting that the exports of this module are the same as the
// exports of transform-file-browser, since this file may be replaced at bundle time with
// transform-file-browser.
((({}: any): $Exact<transformFileBrowserType>): $Exact<transformFileType>);
type TransformFile = {
(filename: string, callback: FileResultCallback): void,
(filename: string, opts: ?InputOptions, callback: FileResultCallback): void,

View File

@@ -1,16 +1,6 @@
// @flow
const pluginNameMap = {
asyncGenerators: {
syntax: {
name: "@babel/plugin-syntax-async-generators",
url: "https://git.io/vb4SY",
},
transform: {
name: "@babel/plugin-proposal-async-generator-functions",
url: "https://git.io/vb4yp",
},
},
classProperties: {
syntax: {
name: "@babel/plugin-syntax-class-properties",
@@ -143,26 +133,6 @@ const pluginNameMap = {
url: "https://git.io/vb4yS",
},
},
objectRestSpread: {
syntax: {
name: "@babel/plugin-syntax-object-rest-spread",
url: "https://git.io/vb4y5",
},
transform: {
name: "@babel/plugin-proposal-object-rest-spread",
url: "https://git.io/vb4Ss",
},
},
optionalCatchBinding: {
syntax: {
name: "@babel/plugin-syntax-optional-catch-binding",
url: "https://git.io/vb4Sn",
},
transform: {
name: "@babel/plugin-proposal-optional-catch-binding",
url: "https://git.io/vb4SI",
},
},
optionalChaining: {
syntax: {
name: "@babel/plugin-syntax-optional-chaining",
@@ -203,6 +173,41 @@ const pluginNameMap = {
url: "https://git.io/vb4Sm",
},
},
// TODO: This plugins are now supported by default by @babel/parser: they can
// be removed from this list. Although removing them isn't a breaking change,
// it's better to keep a nice error message for users using older versions of
// the parser. They can be removed in Babel 8.
asyncGenerators: {
syntax: {
name: "@babel/plugin-syntax-async-generators",
url: "https://git.io/vb4SY",
},
transform: {
name: "@babel/plugin-proposal-async-generator-functions",
url: "https://git.io/vb4yp",
},
},
objectRestSpread: {
syntax: {
name: "@babel/plugin-syntax-object-rest-spread",
url: "https://git.io/vb4y5",
},
transform: {
name: "@babel/plugin-proposal-object-rest-spread",
url: "https://git.io/vb4Ss",
},
},
optionalCatchBinding: {
syntax: {
name: "@babel/plugin-syntax-optional-catch-binding",
url: "https://git.io/vb4Sn",
},
transform: {
name: "@babel/plugin-proposal-optional-catch-binding",
url: "https://git.io/vb4SI",
},
},
};
const getNameURLCombination = ({ name, url }) => `${name} (${url})`;

View File

@@ -769,10 +769,10 @@ describe("api", function() {
options,
function(err) {
expect(err.message).toMatch(
"Support for the experimental syntax 'asyncGenerators' isn't currently enabled (1:15):",
"Support for the experimental syntax 'logicalAssignment' isn't currently enabled (1:3):",
);
expect(err.message).toMatch(
"Add @babel/plugin-proposal-async-generator-functions (https://git.io/vb4yp) to the " +
"Add @babel/plugin-proposal-logical-assignment-operators (https://git.io/vAlRe) to the " +
"'plugins' section of your Babel config to enable transformation.",
);
done();

View File

@@ -1,4 +1 @@
async function* agf() {
await 1;
yield 2;
}
a ||= 2;

View File

@@ -1,5 +1,8 @@
{
"compact": false,
"presets": ["env"],
"plugins": ["external-helpers", "proposal-object-rest-spread"]
"plugins": [
["external-helpers", { "helperVersion": "7.1.5" }],
"proposal-object-rest-spread"
]
}

View File

@@ -400,7 +400,7 @@ describe("addon resolution", function() {
presets: ["testplugin"],
});
}).toThrow(
/Cannot find module 'babel-preset-testplugin'.*\n- Did you accidentally pass a preset as a plugin\?/,
/Cannot find module 'babel-preset-testplugin'.*\n- Did you accidentally pass a plugin as a preset\?/,
);
});
@@ -414,7 +414,7 @@ describe("addon resolution", function() {
plugins: ["testpreset"],
});
}).toThrow(
/Cannot find module 'babel-plugin-testpreset'.*\n- Did you accidentally pass a plugin as a preset\?/,
/Cannot find module 'babel-plugin-testpreset'.*\n- Did you accidentally pass a preset as a plugin\?/,
);
});

View File

@@ -1,6 +1,6 @@
{
"name": "@babel/generator",
"version": "7.1.2",
"version": "7.1.6",
"description": "Turns an AST into code.",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",
@@ -14,7 +14,7 @@
"lib"
],
"dependencies": {
"@babel/types": "^7.1.2",
"@babel/types": "^7.1.6",
"jsesc": "^2.5.1",
"lodash": "^4.17.10",
"source-map": "^0.5.0",
@@ -22,6 +22,6 @@
},
"devDependencies": {
"@babel/helper-fixtures": "^7.0.0",
"@babel/parser": "^7.0.0"
"@babel/parser": "^7.1.6"
}
}

View File

@@ -111,7 +111,25 @@ export function ArrowFunctionExpression(node: Object) {
t.isIdentifier(firstParam) &&
!hasTypes(node, firstParam)
) {
this.print(firstParam, node);
if (
this.format.retainLines &&
node.loc &&
node.body.loc &&
node.loc.start.line < node.body.loc.start.line
) {
this.token("(");
if (firstParam.loc && firstParam.loc.start.line > node.loc.start.line) {
this.indent();
this.print(firstParam, node);
this.dedent();
this._catchUp("start", node.body.loc);
} else {
this.print(firstParam, node);
}
this.token(")");
} else {
this.print(firstParam, node);
}
} else {
this._params(node);
}

View File

@@ -241,6 +241,16 @@ export function TSTupleType(node) {
this.token("]");
}
export function TSOptionalType(node) {
this.print(node.typeAnnotation, node);
this.token("?");
}
export function TSRestType(node) {
this.token("...");
this.print(node.typeAnnotation, node);
}
export function TSUnionType(node) {
this.tsPrintUnionOrIntersectionType(node, "|");
}

View File

@@ -1 +0,0 @@
{ "plugins": ["objectRestSpread"] }

View File

@@ -1 +1 @@
{ "plugins": ["asyncGenerators", "classProperties"] }
{ "plugins": ["classProperties"] }

View File

@@ -0,0 +1,11 @@
var fn = async (
arg
) => {}
async (x)
=> {}
async x => {}
async (x
) => {};

View File

@@ -0,0 +1,3 @@
{
"retainLines": true
}

View File

@@ -0,0 +1,11 @@
var fn = async (
arg
) => {};
async (x) =>
{};
async x => {};
async (x) =>
{};

View File

@@ -1 +0,0 @@
{ "plugins": ["optionalCatchBinding"] }

View File

@@ -1 +0,0 @@
{ "plugins": ["objectRestSpread"] }

View File

@@ -0,0 +1 @@
let x: [];

View File

@@ -0,0 +1 @@
let x: [];

View File

@@ -0,0 +1 @@
let x: [string, number?, (string | number)?]

View File

@@ -0,0 +1 @@
let x: [string, number?, (string | number)?];

View File

@@ -0,0 +1 @@
let x: [string, ...number[]]

View File

@@ -0,0 +1 @@
let x: [string, ...number[]];

View File

@@ -0,0 +1 @@
let x: [number, number, number];

View File

@@ -0,0 +1 @@
let x: [number, number, number];

View File

@@ -1,6 +1,6 @@
{
"name": "@babel/helpers",
"version": "7.1.2",
"version": "7.1.5",
"description": "Collection of helper functions used by Babel transforms.",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",
@@ -12,8 +12,8 @@
"main": "lib/index.js",
"dependencies": {
"@babel/template": "^7.1.2",
"@babel/traverse": "^7.1.0",
"@babel/types": "^7.1.2"
"@babel/traverse": "^7.1.5",
"@babel/types": "^7.1.5"
},
"devDependencies": {
"@babel/helper-plugin-test-runner": "^7.0.0"

View File

@@ -935,13 +935,28 @@ helpers.skipFirstGeneratorNext = helper("7.0.0-beta.0")`
}
`;
helpers.toPropertyKey = helper("7.0.0-beta.0")`
export default function _toPropertyKey(key) {
if (typeof key === "symbol") {
return key;
} else {
return String(key);
helpers.toPrimitive = helper("7.1.5")`
export default function _toPrimitive(
input,
hint /*: "default" | "string" | "number" | void */
) {
if (typeof input !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];
if (prim !== undefined) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object") return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
`;
helpers.toPropertyKey = helper("7.1.5")`
import toPrimitive from "toPrimitive";
export default function _toPropertyKey(arg) {
var key = toPrimitive(arg, "string");
return typeof key === "symbol" ? key : String(key);
}
`;
@@ -1077,10 +1092,12 @@ helpers.classStaticPrivateFieldSpecSet = helper("7.0.2")`
descriptor.value = value;
return value;
}
`;
helpers.decorate = helper("7.0.2")`
helpers.decorate = helper("7.1.5")`
import toArray from "toArray";
import toPropertyKey from "toPropertyKey";
// These comments are stripped by @babel/template
/*::
@@ -1219,6 +1236,8 @@ helpers.decorate = helper("7.0.2")`
function _createElementDescriptor(
def /*: ElementDefinition */,
) /*: ElementDescriptor */ {
var key = toPropertyKey(def.key);
var descriptor /*: PropertyDescriptor */;
if (def.kind === "method") {
descriptor = {
@@ -1227,6 +1246,10 @@ helpers.decorate = helper("7.0.2")`
configurable: true,
enumerable: false,
};
Object.defineProperty(def.value, "name", {
value: typeof key === "symbol" ? "" : key,
configurable: true,
});
} else if (def.kind === "get") {
descriptor = { get: def.value, configurable: true, enumerable: false };
} else if (def.kind === "set") {
@@ -1237,7 +1260,7 @@ helpers.decorate = helper("7.0.2")`
var element /*: ElementDescriptor */ = {
kind: def.kind === "field" ? "field" : "method",
key: def.key,
key: key,
placement: def.static
? "static"
: def.kind === "field"
@@ -1574,8 +1597,7 @@ helpers.decorate = helper("7.0.2")`
);
}
var key = elementObject.key;
if (typeof key !== "string" && typeof key !== "symbol") key = String(key);
var key = toPropertyKey(elementObject.key);
var placement = String(elementObject.placement);
if (
@@ -1716,4 +1738,4 @@ helpers.decorate = helper("7.0.2")`
}
return constructor;
}
`;
`;

View File

@@ -1,6 +1,6 @@
{
"name": "@babel/parser",
"version": "7.1.2",
"version": "7.1.6",
"description": "A JavaScript parser",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",

View File

@@ -23,6 +23,7 @@ import * as N from "../types";
import LValParser from "./lval";
import { reservedWords } from "../util/identifier";
import type { Pos, Position } from "../util/location";
import * as charCodes from "charcodes";
export default class ExpressionParser extends LValParser {
// Forward-declaration: defined in statement.js
@@ -331,8 +332,8 @@ export default class ExpressionParser extends LValParser {
this.finishNode(
node,
op === tt.logicalOR ||
op === tt.logicalAND ||
op === tt.nullishCoalescing
op === tt.logicalAND ||
op === tt.nullishCoalescing
? "LogicalExpression"
: "BinaryExpression",
);
@@ -522,10 +523,15 @@ export default class ExpressionParser extends LValParser {
}
return this.finishNode(node, "MemberExpression");
} else if (!noCalls && this.match(tt.parenL)) {
const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
const oldYOAIPAP = this.state.yieldOrAwaitInPossibleArrowParameters;
this.state.maybeInArrowParameters = true;
this.state.yieldOrAwaitInPossibleArrowParameters = null;
const possibleAsync = this.atPossibleAsync(base);
this.next();
const node = this.startNodeAt(startPos, startLoc);
let node = this.startNodeAt(startPos, startLoc);
node.callee = base;
// TODO: Clean up/merge this into `this.state` or a class like acorn's
@@ -554,13 +560,22 @@ export default class ExpressionParser extends LValParser {
);
}
return this.parseAsyncArrowFromCallExpression(
node = this.parseAsyncArrowFromCallExpression(
this.startNodeAt(startPos, startLoc),
node,
);
this.state.yieldOrAwaitInPossibleArrowParameters = oldYOAIPAP;
} else {
this.toReferencedList(node.arguments);
// We keep the old value if it isn't null, for cases like
// (x = async(yield)) => {}
this.state.yieldOrAwaitInPossibleArrowParameters =
this.state.yieldOrAwaitInPossibleArrowParameters || oldYOAIPAP;
}
this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
return node;
} else if (this.match(tt.backQuote)) {
return this.parseTaggedTemplateExpression(
@@ -685,11 +700,8 @@ export default class ExpressionParser extends LValParser {
node: N.ArrowFunctionExpression,
call: N.CallExpression,
): N.ArrowFunctionExpression {
const oldYield = this.state.yieldInPossibleArrowParameters;
this.state.yieldInPossibleArrowParameters = null;
this.expect(tt.arrow);
this.parseArrowExpression(node, call.arguments, true);
this.state.yieldInPossibleArrowParameters = oldYield;
return node;
}
@@ -707,6 +719,10 @@ export default class ExpressionParser extends LValParser {
// or `{}`.
parseExprAtom(refShorthandDefaultPos?: ?Pos): N.Expression {
// If a division operator appears in an expression position, the
// tokenizer got confused, and we force it to read a regexp instead.
if (this.state.type === tt.slash) this.readRegexp();
const canBeArrow = this.state.potentialArrowAt === this.state.start;
let node;
@@ -794,22 +810,30 @@ export default class ExpressionParser extends LValParser {
) {
this.next();
return this.parseFunction(node, false, false, true);
} else if (canBeArrow && id.name === "async" && this.match(tt.name)) {
const oldYield = this.state.yieldInPossibleArrowParameters;
this.state.yieldInPossibleArrowParameters = null;
} else if (
canBeArrow &&
!this.canInsertSemicolon() &&
id.name === "async" &&
this.match(tt.name)
) {
const oldYOAIPAP = this.state.yieldOrAwaitInPossibleArrowParameters;
const oldInAsync = this.state.inAsync;
this.state.yieldOrAwaitInPossibleArrowParameters = null;
this.state.inAsync = true;
const params = [this.parseIdentifier()];
this.expect(tt.arrow);
// let foo = bar => {};
// let foo = async bar => {};
this.parseArrowExpression(node, params, true);
this.state.yieldInPossibleArrowParameters = oldYield;
this.state.yieldOrAwaitInPossibleArrowParameters = oldYOAIPAP;
this.state.inAsync = oldInAsync;
return node;
}
if (canBeArrow && !this.canInsertSemicolon() && this.eat(tt.arrow)) {
const oldYield = this.state.yieldInPossibleArrowParameters;
this.state.yieldInPossibleArrowParameters = null;
const oldYOAIPAP = this.state.yieldOrAwaitInPossibleArrowParameters;
this.state.yieldOrAwaitInPossibleArrowParameters = null;
this.parseArrowExpression(node, [id]);
this.state.yieldInPossibleArrowParameters = oldYield;
this.state.yieldOrAwaitInPossibleArrowParameters = oldYOAIPAP;
return node;
}
@@ -923,7 +947,19 @@ export default class ExpressionParser extends LValParser {
if (isPrivate) {
this.expectOnePlugin(["classPrivateProperties", "classPrivateMethods"]);
const node = this.startNode();
const columnHashEnd = this.state.end;
this.next();
const columnIdentifierStart = this.state.start;
const spacesBetweenHashAndIdentifier =
columnIdentifierStart - columnHashEnd;
if (spacesBetweenHashAndIdentifier != 0) {
this.raise(
columnIdentifierStart,
"Unexpected space between # and identifier",
);
}
node.id = this.parseIdentifier(true);
return this.finishNode(node, "PrivateName");
} else {
@@ -933,7 +969,16 @@ export default class ExpressionParser extends LValParser {
parseFunctionExpression(): N.FunctionExpression | N.MetaProperty {
const node = this.startNode();
const meta = this.parseIdentifier(true);
// We do not do parseIdentifier here because when parseFunctionExpression
// is called we already know that the current token is a "name" with the value "function"
// This will improve perf a tiny little bit as we do not do validation but more importantly
// here is that parseIdentifier will remove an item from the expression stack
// if "function" or "class" is parsed as identifier (in objects e.g.), which should not happen here.
let meta = this.startNode();
this.next();
meta = this.createIdentifier(meta, "function");
if (this.state.inGenerator && this.eat(tt.dot)) {
return this.parseMetaProperty(node, meta, "sent");
}
@@ -1032,9 +1077,9 @@ export default class ExpressionParser extends LValParser {
this.expect(tt.parenL);
const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
const oldYield = this.state.yieldInPossibleArrowParameters;
const oldYOAIPAP = this.state.yieldOrAwaitInPossibleArrowParameters;
this.state.maybeInArrowParameters = true;
this.state.yieldInPossibleArrowParameters = null;
this.state.yieldOrAwaitInPossibleArrowParameters = null;
const innerStartPos = this.state.start;
const innerStartLoc = this.state.startLoc;
@@ -1107,11 +1152,14 @@ export default class ExpressionParser extends LValParser {
}
this.parseArrowExpression(arrowNode, exprList);
this.state.yieldInPossibleArrowParameters = oldYield;
this.state.yieldOrAwaitInPossibleArrowParameters = oldYOAIPAP;
return arrowNode;
}
this.state.yieldInPossibleArrowParameters = oldYield;
// We keep the old value if it isn't null, for cases like
// (x = (yield)) => {}
this.state.yieldOrAwaitInPossibleArrowParameters =
this.state.yieldOrAwaitInPossibleArrowParameters || oldYOAIPAP;
if (!exprList.length) {
this.unexpected(this.state.lastTokStart);
@@ -1305,7 +1353,6 @@ export default class ExpressionParser extends LValParser {
}
if (this.match(tt.ellipsis)) {
this.expectPlugin("objectRestSpread");
prop = this.parseSpread(isPattern ? { start: 0 } : undefined);
if (isPattern) {
this.toAssignable(prop, true, "object pattern");
@@ -1365,11 +1412,7 @@ export default class ExpressionParser extends LValParser {
prop.computed = false;
} else {
isAsync = true;
if (this.match(tt.star)) {
this.expectPlugin("asyncGenerators");
this.next();
isGenerator = true;
}
isGenerator = this.eat(tt.star);
this.parsePropertyName(prop);
}
} else {
@@ -1608,9 +1651,11 @@ export default class ExpressionParser extends LValParser {
): T {
const oldInFunc = this.state.inFunction;
const oldInMethod = this.state.inMethod;
const oldInAsync = this.state.inAsync;
const oldInGenerator = this.state.inGenerator;
this.state.inFunction = true;
this.state.inMethod = node.kind || true;
this.state.inAsync = isAsync;
this.state.inGenerator = isGenerator;
this.initFunction(node, isAsync);
@@ -1621,6 +1666,7 @@ export default class ExpressionParser extends LValParser {
this.state.inFunction = oldInFunc;
this.state.inMethod = oldInMethod;
this.state.inAsync = oldInAsync;
this.state.inGenerator = oldInGenerator;
return node;
@@ -1636,12 +1682,21 @@ export default class ExpressionParser extends LValParser {
): N.ArrowFunctionExpression {
// if we got there, it's no more "yield in possible arrow parameters";
// it's just "yield in arrow parameters"
if (this.state.yieldInPossibleArrowParameters) {
this.raise(
this.state.yieldInPossibleArrowParameters.start,
"yield is not allowed in the parameters of an arrow function" +
" inside a generator",
);
const yOAIPAP = this.state.yieldOrAwaitInPossibleArrowParameters;
if (yOAIPAP) {
if (yOAIPAP.type === "YieldExpression") {
this.raise(
yOAIPAP.start,
"yield is not allowed in the parameters of an arrow function" +
" inside a generator",
);
} else {
this.raise(
yOAIPAP.start,
"await is not allowed in the parameters of an arrow function" +
" inside an async function",
);
}
}
const oldInFunc = this.state.inFunction;
@@ -1649,11 +1704,14 @@ export default class ExpressionParser extends LValParser {
this.initFunction(node, isAsync);
if (params) this.setArrowFunctionParameters(node, params);
const oldInAsync = this.state.inAsync;
const oldInGenerator = this.state.inGenerator;
const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
this.state.inAsync = true;
this.state.inGenerator = false;
this.state.maybeInArrowParameters = false;
this.parseFunctionBody(node, true);
this.state.inAsync = oldInAsync;
this.state.inGenerator = oldInGenerator;
this.state.inFunction = oldInFunc;
this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
@@ -1701,9 +1759,7 @@ export default class ExpressionParser extends LValParser {
const isExpression = allowExpression && !this.match(tt.braceL);
const oldInParameters = this.state.inParameters;
const oldInAsync = this.state.inAsync;
this.state.inParameters = false;
this.state.inAsync = node.async;
if (isExpression) {
node.body = this.parseMaybeAssign();
@@ -1721,7 +1777,6 @@ export default class ExpressionParser extends LValParser {
this.state.inGenerator = oldInGen;
this.state.labels = oldLabels;
}
this.state.inAsync = oldInAsync;
this.checkFunctionNameAndParams(node, allowExpression);
this.state.inParameters = oldInParameters;
@@ -1822,8 +1877,14 @@ export default class ExpressionParser extends LValParser {
parseIdentifier(liberal?: boolean): N.Identifier {
const node = this.startNode();
const name = this.parseIdentifierName(node.start, liberal);
return this.createIdentifier(node, name);
}
createIdentifier(node: N.Identifier, name: string): N.Identifier {
node.name = name;
node.loc.identifierName = name;
return this.finishNode(node, "Identifier");
}
@@ -1843,6 +1904,19 @@ export default class ExpressionParser extends LValParser {
name = this.state.value;
} else if (this.state.type.keyword) {
name = this.state.type.keyword;
// `class` and `function` keywords push new context into this.context.
// But there is no chance to pop the context if the keyword is consumed
// as an identifier such as a property name.
// If the previous token is a dot, this does not apply because the
// context-managing code already ignored the keyword
if (
(name === "class" || name === "function") &&
(this.state.lastTokEnd !== this.state.lastTokStart + 1 ||
this.input.charCodeAt(this.state.lastTokStart) !== charCodes.dot)
) {
this.state.context.pop();
}
} else {
throw this.unexpected();
}
@@ -1898,12 +1972,27 @@ export default class ExpressionParser extends LValParser {
) {
this.unexpected();
}
if (this.state.inParameters) {
this.raise(
node.start,
"await is not allowed in async function parameters",
);
}
if (this.match(tt.star)) {
this.raise(
node.start,
"await* has been removed from the async functions proposal. Use Promise.all() instead.",
);
}
if (
this.state.maybeInArrowParameters &&
// We only set yieldOrAwaitInPossibleArrowParameters if we haven't already
// found a possible invalid AwaitExpression.
!this.state.yieldOrAwaitInPossibleArrowParameters
) {
this.state.yieldOrAwaitInPossibleArrowParameters = node;
}
node.argument = this.parseMaybeUnary();
return this.finishNode(node, "AwaitExpression");
}
@@ -1918,11 +2007,11 @@ export default class ExpressionParser extends LValParser {
}
if (
this.state.maybeInArrowParameters &&
// We only set yieldInPossibleArrowParameters if we haven't already
// We only set yieldOrAwaitInPossibleArrowParameters if we haven't already
// found a possible invalid YieldExpression.
!this.state.yieldInPossibleArrowParameters
!this.state.yieldOrAwaitInPossibleArrowParameters
) {
this.state.yieldInPossibleArrowParameters = node;
this.state.yieldOrAwaitInPossibleArrowParameters = node;
}
this.next();

View File

@@ -177,6 +177,7 @@ export default class LValParser extends NodeUtils {
toReferencedList(
exprList: $ReadOnlyArray<?Expression>,
isInParens?: boolean, // eslint-disable-line no-unused-vars
): $ReadOnlyArray<?Expression> {
return exprList;
}

View File

@@ -305,15 +305,7 @@ export default class StatementParser extends ExpressionParser {
}
}
if (this.eat(tt.parenL)) {
const node = this.startNodeAt(startPos, startLoc);
node.callee = expr;
node.arguments = this.parseCallExpressionArguments(tt.parenR, false);
this.toReferencedList(node.arguments);
expr = this.finishNode(node, "CallExpression");
}
node.expression = expr;
node.expression = this.parseMaybeDecoratorArguments(expr);
this.state.decoratorStack.pop();
} else {
node.expression = this.parseMaybeAssign();
@@ -321,6 +313,18 @@ export default class StatementParser extends ExpressionParser {
return this.finishNode(node, "Decorator");
}
parseMaybeDecoratorArguments(expr: N.Expression): N.Expression {
if (this.eat(tt.parenL)) {
const node = this.startNodeAtNode(expr);
node.callee = expr;
node.arguments = this.parseCallExpressionArguments(tt.parenR, false);
this.toReferencedList(node.arguments);
return this.finishNode(node, "CallExpression");
}
return expr;
}
parseBreakContinueStatement(
node: N.BreakStatement | N.ContinueStatement,
keyword: string,
@@ -387,7 +391,6 @@ export default class StatementParser extends ExpressionParser {
let forAwait = false;
if (this.state.inAsync && this.isContextual("await")) {
this.expectPlugin("asyncGenerators");
forAwait = true;
this.next();
}
@@ -552,7 +555,6 @@ export default class StatementParser extends ExpressionParser {
this.checkLVal(clause.param, true, clashes, "catch clause");
this.expect(tt.parenR);
} else {
this.expectPlugin("optionalCatchBinding");
clause.param = null;
}
clause.body = this.parseBlock();
@@ -617,8 +619,8 @@ export default class StatementParser extends ExpressionParser {
const kind = this.state.type.isLoop
? "loop"
: this.match(tt._switch)
? "switch"
: null;
? "switch"
: null;
for (let i = this.state.labels.length - 1; i >= 0; i--) {
const label = this.state.labels[i];
if (label.statementStart === node.start) {
@@ -840,6 +842,7 @@ export default class StatementParser extends ExpressionParser {
): T {
const oldInFunc = this.state.inFunction;
const oldInMethod = this.state.inMethod;
const oldInAsync = this.state.inAsync;
const oldInGenerator = this.state.inGenerator;
const oldInClassProperty = this.state.inClassProperty;
this.state.inFunction = true;
@@ -849,9 +852,6 @@ export default class StatementParser extends ExpressionParser {
this.initFunction(node, isAsync);
if (this.match(tt.star)) {
if (node.async) {
this.expectPlugin("asyncGenerators");
}
node.generator = true;
this.next();
}
@@ -873,11 +873,18 @@ export default class StatementParser extends ExpressionParser {
// valid because yield is parsed as if it was outside the generator.
// Therefore, this.state.inGenerator is set before or after parsing the
// function id according to the "isStatement" parameter.
if (!isStatement) this.state.inGenerator = node.generator;
// The same applies to await & async functions.
if (!isStatement) {
this.state.inAsync = isAsync;
this.state.inGenerator = node.generator;
}
if (this.match(tt.name) || this.match(tt._yield)) {
node.id = this.parseBindingIdentifier();
}
if (isStatement) this.state.inGenerator = node.generator;
if (isStatement) {
this.state.inAsync = isAsync;
this.state.inGenerator = node.generator;
}
this.parseFunctionParams(node);
this.parseFunctionBodyAndFinish(
@@ -888,6 +895,7 @@ export default class StatementParser extends ExpressionParser {
this.state.inFunction = oldInFunc;
this.state.inMethod = oldInMethod;
this.state.inAsync = oldInAsync;
this.state.inGenerator = oldInGenerator;
this.state.inClassProperty = oldInClassProperty;
@@ -1149,11 +1157,7 @@ export default class StatementParser extends ExpressionParser {
}
} else if (isSimple && key.name === "async" && !this.isLineTerminator()) {
// an async method
const isGenerator = this.match(tt.star);
if (isGenerator) {
this.expectPlugin("asyncGenerators");
this.next();
}
const isGenerator = this.eat(tt.star);
method.kind = "method";
// The so-called parsed name would have been "async": get the real name.

View File

@@ -6,10 +6,11 @@ import * as N from "../types";
import type { Options } from "../options";
import type { Pos, Position } from "../util/location";
import type State from "../tokenizer/state";
import { types as tc } from "../tokenizer/context";
import * as charCodes from "charcodes";
import { isIteratorStart } from "../util/identifier";
const primitiveTypes = [
const reservedTypes = [
"any",
"bool",
"boolean",
@@ -23,6 +24,9 @@ const primitiveTypes = [
"true",
"typeof",
"void",
"interface",
"extends",
"_",
];
function isEsModuleType(bodyElement: N.Node): boolean {
@@ -463,7 +467,13 @@ export default (superClass: Class<Parser>): Class<Parser> =>
} while (this.eat(tt.comma));
}
node.body = this.flowParseObjectType(isClass, false, false, isClass);
node.body = this.flowParseObjectType({
allowStatic: isClass,
allowExact: false,
allowSpread: false,
allowProto: isClass,
allowInexact: false,
});
}
flowParseInterfaceExtends(): N.FlowInterfaceExtends {
@@ -484,9 +494,18 @@ export default (superClass: Class<Parser>): Class<Parser> =>
return this.finishNode(node, "InterfaceDeclaration");
}
checkNotUnderscore(word: string) {
if (word === "_") {
throw this.unexpected(
null,
"`_` is only allowed as a type argument to call or new",
);
}
}
checkReservedType(word: string, startLoc: number) {
if (primitiveTypes.indexOf(word) > -1) {
this.raise(startLoc, `Cannot overwrite primitive type ${word}`);
if (reservedTypes.indexOf(word) > -1) {
this.raise(startLoc, `Cannot overwrite reserved type ${word}`);
}
}
@@ -632,12 +651,36 @@ export default (superClass: Class<Parser>): Class<Parser> =>
this.state.inType = true;
this.expectRelational("<");
const oldNoAnonFunctionType = this.state.noAnonFunctionType;
this.state.noAnonFunctionType = false;
while (!this.isRelational(">")) {
node.params.push(this.flowParseType());
if (!this.isRelational(">")) {
this.expect(tt.comma);
}
}
this.state.noAnonFunctionType = oldNoAnonFunctionType;
this.expectRelational(">");
this.state.inType = oldInType;
return this.finishNode(node, "TypeParameterInstantiation");
}
flowParseTypeParameterInstantiationCallOrNew(): N.TypeParameterInstantiation {
const node = this.startNode();
const oldInType = this.state.inType;
node.params = [];
this.state.inType = true;
this.expectRelational("<");
while (!this.isRelational(">")) {
node.params.push(this.flowParseTypeOrImplicitInstantiation());
if (!this.isRelational(">")) {
this.expect(tt.comma);
}
}
this.expectRelational(">");
this.state.inType = oldInType;
@@ -656,7 +699,13 @@ export default (superClass: Class<Parser>): Class<Parser> =>
} while (this.eat(tt.comma));
}
node.body = this.flowParseObjectType(false, false, false, false);
node.body = this.flowParseObjectType({
allowStatic: false,
allowExact: false,
allowSpread: false,
allowProto: false,
allowInexact: false,
});
return this.finishNode(node, "InterfaceTypeAnnotation");
}
@@ -754,12 +803,19 @@ export default (superClass: Class<Parser>): Class<Parser> =>
return this.finishNode(node, "ObjectTypeCallProperty");
}
flowParseObjectType(
flowParseObjectType({
allowStatic,
allowExact,
allowSpread,
allowProto,
allowInexact,
}: {
allowStatic: boolean,
allowExact: boolean,
allowSpread: boolean,
allowProto: boolean,
): N.FlowObjectTypeAnnotation {
allowInexact: boolean,
}): N.FlowObjectTypeAnnotation {
const oldInType = this.state.inType;
this.state.inType = true;
@@ -772,6 +828,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
let endDelim;
let exact;
let inexact = false;
if (allowExact && this.match(tt.braceBarL)) {
this.expect(tt.braceBarL);
endDelim = tt.braceBarR;
@@ -852,16 +909,21 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}
}
nodeStart.properties.push(
this.flowParseObjectTypeProperty(
node,
isStatic,
protoStart,
variance,
kind,
allowSpread,
),
const propOrInexact = this.flowParseObjectTypeProperty(
node,
isStatic,
protoStart,
variance,
kind,
allowSpread,
allowInexact,
);
if (propOrInexact === null) {
inexact = true;
} else {
nodeStart.properties.push(propOrInexact);
}
}
this.flowObjectTypeSemicolon();
@@ -869,6 +931,15 @@ export default (superClass: Class<Parser>): Class<Parser> =>
this.expect(endDelim);
/* The inexact flag should only be added on ObjectTypeAnnotations that
* are not the body of an interface, declare interface, or declare class.
* Since spreads are only allowed in objec types, checking that is
* sufficient here.
*/
if (allowSpread) {
nodeStart.inexact = inexact;
}
const out = this.finishNode(nodeStart, "ObjectTypeAnnotation");
this.state.inType = oldInType;
@@ -883,7 +954,8 @@ export default (superClass: Class<Parser>): Class<Parser> =>
variance: ?N.FlowVariance,
kind: string,
allowSpread: boolean,
): N.FlowObjectTypeProperty | N.FlowObjectTypeSpreadProperty {
allowInexact: boolean,
): (N.FlowObjectTypeProperty | N.FlowObjectTypeSpreadProperty) | null {
if (this.match(tt.ellipsis)) {
if (!allowSpread) {
this.unexpected(
@@ -901,8 +973,30 @@ export default (superClass: Class<Parser>): Class<Parser> =>
);
}
this.expect(tt.ellipsis);
node.argument = this.flowParseType();
const isInexactToken = this.eat(tt.comma) || this.eat(tt.semi);
if (this.match(tt.braceR)) {
if (allowInexact) return null;
this.unexpected(
null,
"Explicit inexact syntax is only allowed inside inexact objects",
);
}
if (this.match(tt.braceBarR)) {
this.unexpected(
null,
"Explicit inexact syntax cannot appear inside an explicit exact object type",
);
}
if (isInexactToken) {
this.unexpected(
null,
"Explicit inexact syntax must appear at the end of an inexact object",
);
}
node.argument = this.flowParseType();
return this.finishNode(node, "ObjectTypeSpreadProperty");
} else {
node.key = this.flowParseObjectPropertyKey();
@@ -1116,6 +1210,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
return this.finishNode(node, "StringTypeAnnotation");
default:
this.checkNotUnderscore(id.name);
return this.flowParseGenericType(startPos, startLoc, id);
}
}
@@ -1146,10 +1241,22 @@ export default (superClass: Class<Parser>): Class<Parser> =>
);
case tt.braceL:
return this.flowParseObjectType(false, false, true, false);
return this.flowParseObjectType({
allowStatic: false,
allowExact: false,
allowSpread: true,
allowProto: false,
allowInexact: true,
});
case tt.braceBarL:
return this.flowParseObjectType(false, true, true, false);
return this.flowParseObjectType({
allowStatic: false,
allowExact: true,
allowSpread: true,
allowProto: false,
allowInexact: false,
});
case tt.bracketL:
return this.flowParseTupleType();
@@ -1359,6 +1466,17 @@ export default (superClass: Class<Parser>): Class<Parser> =>
return type;
}
flowParseTypeOrImplicitInstantiation(): N.FlowTypeAnnotation {
if (this.state.type === tt.name && this.state.value === "_") {
const startPos = this.state.start;
const startLoc = this.state.startLoc;
const node = this.parseIdentifier();
return this.flowParseGenericType(startPos, startLoc, node);
} else {
return this.flowParseType();
}
}
flowParseTypeAnnotation(): N.FlowTypeAnnotation {
const node = this.startNode();
node.typeAnnotation = this.flowParseTypeInitialiser();
@@ -1859,40 +1977,26 @@ export default (superClass: Class<Parser>): Class<Parser> =>
// type casts that we've found that are illegal in this context
toReferencedList(
exprList: $ReadOnlyArray<?N.Expression>,
isInParens?: boolean,
): $ReadOnlyArray<?N.Expression> {
for (let i = 0; i < exprList.length; i++) {
const expr = exprList[i];
if (expr && expr._exprListItem && expr.type === "TypeCastExpression") {
this.raise(expr.start, "Unexpected type cast");
if (
expr &&
expr.type === "TypeCastExpression" &&
(!expr.extra || !expr.extra.parenthesized) &&
(exprList.length > 1 || !isInParens)
) {
this.raise(
expr.typeAnnotation.start,
"The type cast expression is expected to be wrapped with parenthesis",
);
}
}
return exprList;
}
// parse an item inside a expression list eg. `(NODE, NODE)` where NODE represents
// the position where this function is called
parseExprListItem(
allowEmpty: ?boolean,
refShorthandDefaultPos: ?Pos,
refNeedsArrowPos: ?Pos,
): ?N.Expression {
const container = this.startNode();
const node = super.parseExprListItem(
allowEmpty,
refShorthandDefaultPos,
refNeedsArrowPos,
);
if (this.match(tt.colon)) {
container._exprListItem = true;
container.expression = node;
container.typeAnnotation = this.flowParseTypeAnnotation();
return this.finishNode(container, "TypeCastExpression");
} else {
return node;
}
}
checkLVal(
expr: N.Expression,
isBinding: ?boolean,
@@ -2289,7 +2393,10 @@ export default (superClass: Class<Parser>): Class<Parser> =>
refNeedsArrowPos?: ?Pos,
): N.Expression {
let jsxError = null;
if (tt.jsxTagStart && this.match(tt.jsxTagStart)) {
if (
this.hasPlugin("jsx") &&
(this.match(tt.jsxTagStart) || this.isRelational("<"))
) {
const state = this.state.clone();
try {
return super.parseMaybeAssign(
@@ -2305,7 +2412,10 @@ export default (superClass: Class<Parser>): Class<Parser> =>
// Remove `tc.j_expr` and `tc.j_oTag` from context added
// by parsing `jsxTagStart` to stop the JSX plugin from
// messing with the tokens
this.state.context.length -= 2;
const cLength = this.state.context.length;
if (this.state.context[cLength - 1] === tc.j_oTag) {
this.state.context.length -= 2;
}
jsxError = err;
} else {
@@ -2510,7 +2620,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
node.callee = base;
const state = this.state.clone();
try {
node.typeArguments = this.flowParseTypeParameterInstantiation();
node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
this.expect(tt.parenL);
node.arguments = this.parseCallExpressionArguments(tt.parenR, false);
if (subscriptState.optionalChainMember) {
@@ -2541,7 +2651,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
if (this.shouldParseTypes() && this.isRelational("<")) {
const state = this.state.clone();
try {
targs = this.flowParseTypeParameterInstantiation();
targs = this.flowParseTypeParameterInstantiationCallOrNew();
} catch (e) {
if (e instanceof SyntaxError) {
this.state = state;

View File

@@ -506,6 +506,15 @@ export default (superClass: Class<Parser>): Class<Parser> =>
return this.parseLiteral(this.state.value, "JSXText");
} else if (this.match(tt.jsxTagStart)) {
return this.jsxParseElement();
} else if (
this.isRelational("<") &&
this.state.input.charCodeAt(this.state.pos) !==
charCodes.exclamationMark
) {
// In case we encounter an lt token here it will always be the start of
// jsx as the lt sign is not allowed in places that expect an expression
this.finishToken(tt.jsxTagStart);
return this.jsxParseElement();
} else {
return super.parseExprAtom(refShortHandDefaultPos);
}
@@ -538,7 +547,12 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}
}
if (code === charCodes.lessThan && this.state.exprAllowed) {
if (
code === charCodes.lessThan &&
this.state.exprAllowed &&
this.state.input.charCodeAt(this.state.pos + 1) !==
charCodes.exclamationMark
) {
++this.state.pos;
return this.finishToken(tt.jsxTagStart);
}

View File

@@ -503,13 +503,55 @@ export default (superClass: Class<Parser>): Class<Parser> =>
const node: N.TsTupleType = this.startNode();
node.elementTypes = this.tsParseBracketedList(
"TupleElementTypes",
this.tsParseType.bind(this),
this.tsParseTupleElementType.bind(this),
/* bracket */ true,
/* skipFirstToken */ false,
);
// Validate the elementTypes to ensure:
// No mandatory elements may follow optional elements
// If there's a rest element, it must be at the end of the tuple
let seenOptionalElement = false;
node.elementTypes.forEach((elementNode, i) => {
if (elementNode.type === "TSRestType") {
if (i !== node.elementTypes.length - 1) {
this.raise(
elementNode.start,
"A rest element must be last in a tuple type.",
);
}
} else if (elementNode.type === "TSOptionalType") {
seenOptionalElement = true;
} else if (seenOptionalElement) {
this.raise(
elementNode.start,
"A required element cannot follow an optional element.",
);
}
});
return this.finishNode(node, "TSTupleType");
}
tsParseTupleElementType(): N.TsType {
// parses `...TsType[]`
if (this.match(tt.ellipsis)) {
const restNode: N.TsRestType = this.startNode();
this.next(); // skips ellipsis
restNode.typeAnnotation = this.tsParseType();
return this.finishNode(restNode, "TSRestType");
}
const type = this.tsParseType();
// parses `TsType?`
if (this.eat(tt.question)) {
const optionalTypeNode: N.TsOptionalType = this.startNodeAtNode(type);
optionalTypeNode.typeAnnotation = type;
return this.finishNode(optionalTypeNode, "TSOptionalType");
}
return type;
}
tsParseParenthesizedType(): N.TsParenthesizedType {
const node = this.startNode();
this.expect(tt.parenL);
@@ -555,8 +597,8 @@ export default (superClass: Class<Parser>): Class<Parser> =>
const type = this.match(tt._void)
? "TSVoidKeyword"
: this.match(tt._null)
? "TSNullKeyword"
: keywordTypeFromName(this.state.value);
? "TSNullKeyword"
: keywordTypeFromName(this.state.value);
if (type !== undefined && this.lookahead().type !== tt.dot) {
const node: N.TsKeywordType = this.startNode();
this.next();
@@ -649,8 +691,8 @@ export default (superClass: Class<Parser>): Class<Parser> =>
return operator
? this.tsParseTypeOperator(operator)
: this.isContextual("infer")
? this.tsParseInferType()
: this.tsParseArrayTypeOrHigher();
? this.tsParseInferType()
: this.tsParseArrayTypeOrHigher();
}
tsParseUnionOrIntersectionType(
@@ -1339,8 +1381,8 @@ export default (superClass: Class<Parser>): Class<Parser> =>
type === "FunctionDeclaration"
? "TSDeclareFunction"
: type === "ClassMethod"
? "TSDeclareMethod"
: undefined;
? "TSDeclareMethod"
: undefined;
if (bodilessType && !this.match(tt.braceL) && this.isLineTerminator()) {
this.finishNode(node, bodilessType);
return;
@@ -1368,10 +1410,11 @@ export default (superClass: Class<Parser>): Class<Parser> =>
return this.finishNode(nonNullExpression, "TSNonNullExpression");
}
// There are number of things we are going to "maybe" parse, like type arguments on
// tagged template expressions. If any of them fail, walk it back and continue.
const result = this.tsTryParseAndCatch(() => {
if (this.isRelational("<")) {
if (this.isRelational("<")) {
// tsTryParseAndCatch is expensive, so avoid if not necessary.
// There are number of things we are going to "maybe" parse, like type arguments on
// tagged template expressions. If any of them fail, walk it back and continue.
const result = this.tsTryParseAndCatch(() => {
if (!noCalls && this.atPossibleAsync(base)) {
// Almost certainly this is a generic async function `async <T>() => ...
// But it might be a call with a type argument `async<T>();`
@@ -1409,12 +1452,12 @@ export default (superClass: Class<Parser>): Class<Parser> =>
);
}
}
}
this.unexpected();
});
this.unexpected();
});
if (result) return result;
if (result) return result;
}
return super.parseSubscript(base, startPos, startLoc, noCalls, state);
}
@@ -2046,6 +2089,22 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}
}
parseMaybeDecoratorArguments(expr: N.Expression): N.Expression {
if (this.isRelational("<")) {
const typeArguments = this.tsParseTypeArguments();
if (this.match(tt.parenL)) {
const call = super.parseMaybeDecoratorArguments(expr);
call.typeParameters = typeArguments;
return call;
}
this.unexpected(this.state.start, tt.parenL);
}
return super.parseMaybeDecoratorArguments(expr);
}
// === === === === === === === === === === === === === === === ===
// Note: All below methods are duplicates of something in flow.js.
// Not sure what the best way to combine these is.
@@ -2115,6 +2174,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
toReferencedList(
exprList: $ReadOnlyArray<?N.Expression>,
isInParens?: boolean, // eslint-disable-line no-unused-vars
): $ReadOnlyArray<?N.Expression> {
for (let i = 0; i < exprList.length; i++) {
const expr = exprList[i];

View File

@@ -12,7 +12,7 @@ export class TokContext {
token: string,
isExpr?: boolean,
preserveSpace?: boolean,
override?: Function, // Takes a Tokenizer as a this-parameter, and returns void.
override?: ?Function, // Takes a Tokenizer as a this-parameter, and returns void.
) {
this.token = token;
this.isExpr = !!isExpr;
@@ -31,11 +31,12 @@ export const types: {
} = {
braceStatement: new TokContext("{", false),
braceExpression: new TokContext("{", true),
templateQuasi: new TokContext("${", true),
templateQuasi: new TokContext("${", false),
parenStatement: new TokContext("(", false),
parenExpression: new TokContext("(", true),
template: new TokContext("`", true, true, p => p.readTmplToken()),
functionExpression: new TokContext("function", true),
functionStatement: new TokContext("function", false),
};
// Token-specific context update code
@@ -46,33 +47,26 @@ tt.parenR.updateContext = tt.braceR.updateContext = function() {
return;
}
const out = this.state.context.pop();
if (
out === types.braceStatement &&
this.curContext() === types.functionExpression
) {
this.state.context.pop();
this.state.exprAllowed = false;
} else if (out === types.templateQuasi) {
this.state.exprAllowed = true;
} else {
this.state.exprAllowed = !out.isExpr;
let out = this.state.context.pop();
if (out === types.braceStatement && this.curContext().token === "function") {
out = this.state.context.pop();
}
this.state.exprAllowed = !out.isExpr;
};
tt.name.updateContext = function(prevType) {
if (this.state.value === "of" && this.curContext() === types.parenStatement) {
this.state.exprAllowed = !prevType.beforeExpr;
return;
}
this.state.exprAllowed = false;
if (prevType === tt._let || prevType === tt._const || prevType === tt._var) {
if (lineBreak.test(this.input.slice(this.state.end))) {
this.state.exprAllowed = true;
let allowed = false;
if (prevType !== tt.dot) {
if (
(this.state.value === "of" && !this.state.exprAllowed) ||
(this.state.value === "yield" && this.state.inGenerator)
) {
allowed = true;
}
}
this.state.exprAllowed = allowed;
if (this.state.isIterator) {
this.state.isIterator = false;
}
@@ -106,9 +100,23 @@ tt.incDec.updateContext = function() {
// tokExprAllowed stays unchanged
};
tt._function.updateContext = function(prevType) {
if (this.state.exprAllowed && !this.braceIsBlock(prevType)) {
tt._function.updateContext = tt._class.updateContext = function(prevType) {
if (
prevType.beforeExpr &&
prevType !== tt.semi &&
prevType !== tt._else &&
!(
prevType === tt._return &&
lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.start))
) &&
!(
(prevType === tt.colon || prevType === tt.braceL) &&
this.curContext() === types.b_stat
)
) {
this.state.context.push(types.functionExpression);
} else {
this.state.context.push(types.functionStatement);
}
this.state.exprAllowed = false;

View File

@@ -881,10 +881,10 @@ export default class Tokenizer extends LocationParser {
radix === 16
? allowedNumericSeparatorSiblings.hex
: radix === 10
? allowedNumericSeparatorSiblings.dec
: radix === 8
? allowedNumericSeparatorSiblings.oct
: allowedNumericSeparatorSiblings.bin;
? allowedNumericSeparatorSiblings.dec
: radix === 8
? allowedNumericSeparatorSiblings.oct
: allowedNumericSeparatorSiblings.bin;
let total = 0;
@@ -1070,7 +1070,6 @@ export default class Tokenizer extends LocationParser {
readString(quote: number): void {
let out = "",
chunkStart = ++this.state.pos;
const hasJsonStrings = this.hasPlugin("jsonStrings");
for (;;) {
if (this.state.pos >= this.input.length) {
this.raise(this.state.start, "Unterminated string constant");
@@ -1083,10 +1082,11 @@ export default class Tokenizer extends LocationParser {
out += this.readEscapedChar(false);
chunkStart = this.state.pos;
} else if (
hasJsonStrings &&
(ch === charCodes.lineSeparator || ch === charCodes.paragraphSeparator)
ch === charCodes.lineSeparator ||
ch === charCodes.paragraphSeparator
) {
++this.state.pos;
++this.state.curLine;
} else if (isNewLine(ch)) {
this.raise(this.state.start, "Unterminated string constant");
} else {
@@ -1324,14 +1324,25 @@ export default class Tokenizer extends LocationParser {
}
braceIsBlock(prevType: TokenType): boolean {
if (prevType === tt.colon) {
const parent = this.curContext();
if (parent === ct.braceStatement || parent === ct.braceExpression) {
return !parent.isExpr;
}
const parent = this.curContext();
if (parent === ct.functionExpression || parent === ct.functionStatement) {
return true;
}
if (
prevType === tt.colon &&
(parent === ct.braceStatement || parent === ct.braceExpression)
) {
return !parent.isExpr;
}
if (prevType === tt._return) {
// The check for `tt.name && exprAllowed` detects whether we are
// after a `yield` or `of` construct. See the `updateContext` for
// `tt.name`.
if (
prevType === tt._return ||
prevType === tt._yield ||
(prevType === tt.name && this.state.exprAllowed)
) {
return lineBreak.test(
this.input.slice(this.state.lastTokEnd, this.state.start),
);
@@ -1341,13 +1352,22 @@ export default class Tokenizer extends LocationParser {
prevType === tt._else ||
prevType === tt.semi ||
prevType === tt.eof ||
prevType === tt.parenR
prevType === tt.parenR ||
prevType === tt.arrow
) {
return true;
}
if (prevType === tt.braceL) {
return this.curContext() === ct.braceStatement;
return parent === ct.braceStatement;
}
if (
prevType === tt._var ||
prevType === tt._let ||
prevType === tt._const
) {
return false;
}
if (prevType === tt.relational) {

View File

@@ -39,7 +39,7 @@ export default class State {
this.decoratorStack = [[]];
this.yieldInPossibleArrowParameters = null;
this.yieldOrAwaitInPossibleArrowParameters = null;
this.tokens = [];
@@ -126,10 +126,10 @@ export default class State {
// where @foo belongs to the outer class and @bar to the inner
decoratorStack: Array<Array<N.Decorator>>;
// The first yield expression inside parenthesized expressions and arrow
// function parameters. It is used to disallow yield in arrow function
// parameters.
yieldInPossibleArrowParameters: ?N.YieldExpression;
// The first yield or await expression inside parenthesized expressions
// and arrow function parameters. It is used to disallow yield and await in
// arrow function parameters.
yieldOrAwaitInPossibleArrowParameters: ?N.YieldExpression;
// Token store.
tokens: Array<Token | N.Comment>;

View File

@@ -174,7 +174,7 @@ export const keywords = {
new: new KeywordTokenType("new", { beforeExpr, startsExpr }),
this: new KeywordTokenType("this", { startsExpr }),
super: new KeywordTokenType("super", { startsExpr }),
class: new KeywordTokenType("class"),
class: new KeywordTokenType("class", { startsExpr }),
extends: new KeywordTokenType("extends", { beforeExpr }),
export: new KeywordTokenType("export"),
import: new KeywordTokenType("import", { startsExpr }),

View File

@@ -398,7 +398,7 @@ export type ObjectMemberBase = NodeBase & {
decorators: $ReadOnlyArray<Decorator>,
kind?: "get" | "set" | "method",
method: boolean, // TODO: Not in spec
typeParameters?: ?TypeParameterInstantiationBase, // TODO: Not in spec
variance?: ?FlowVariance, // TODO: Not in spec
};
@@ -1104,6 +1104,8 @@ export type TsType =
| TsTypeLiteral
| TsArrayType
| TsTupleType
| TsOptionalType
| TsRestType
| TsUnionOrIntersectionType
| TsConditionalType
| TsInferType
@@ -1184,6 +1186,16 @@ export type TsTupleType = TsTypeBase & {
elementTypes: $ReadOnlyArray<TsType>,
};
export type TsOptionalType = TsTypeBase & {
type: "TSOptionalType",
typeAnnotation: TsType,
};
export type TsRestType = TsTypeBase & {
type: "TSRestType",
typeAnnotation: TsType,
};
export type TsUnionOrIntersectionType = TsUnionType | TsIntersectionType;
export type TsUnionOrIntersectionTypeBase = TsTypeBase & {

View File

@@ -1,3 +0,0 @@
{
"plugins": ["objectRestSpread"]
}

View File

@@ -0,0 +1,9 @@
x = class{} / foo
x = class{}
/ foo / g
(x = class{} / foo)
(x = class{}
/ foo / g)

View File

@@ -0,0 +1,561 @@
{
"type": "File",
"start": 0,
"end": 86,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 9,
"column": 10
}
},
"program": {
"type": "Program",
"start": 0,
"end": 86,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 9,
"column": 10
}
},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 17
}
},
"expression": {
"type": "AssignmentExpression",
"start": 0,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 17
}
},
"operator": "=",
"left": {
"type": "Identifier",
"start": 0,
"end": 1,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 1
},
"identifierName": "x"
},
"name": "x"
},
"right": {
"type": "BinaryExpression",
"start": 4,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 17
}
},
"left": {
"type": "ClassExpression",
"start": 4,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 11
}
},
"id": null,
"superClass": null,
"body": {
"type": "ClassBody",
"start": 9,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 11
}
},
"body": []
}
},
"operator": "/",
"right": {
"type": "Identifier",
"start": 14,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 17
},
"identifierName": "foo"
},
"name": "foo"
}
}
}
},
{
"type": "ExpressionStatement",
"start": 19,
"end": 86,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 9,
"column": 10
}
},
"expression": {
"type": "AssignmentExpression",
"start": 19,
"end": 86,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 9,
"column": 10
}
},
"operator": "=",
"left": {
"type": "Identifier",
"start": 19,
"end": 20,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 1
},
"identifierName": "x"
},
"name": "x"
},
"right": {
"type": "BinaryExpression",
"start": 23,
"end": 86,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 9,
"column": 10
}
},
"left": {
"type": "BinaryExpression",
"start": 23,
"end": 36,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 4,
"column": 5
}
},
"left": {
"type": "ClassExpression",
"start": 23,
"end": 30,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 11
}
},
"id": null,
"superClass": null,
"body": {
"type": "ClassBody",
"start": 28,
"end": 30,
"loc": {
"start": {
"line": 3,
"column": 9
},
"end": {
"line": 3,
"column": 11
}
},
"body": []
}
},
"operator": "/",
"right": {
"type": "Identifier",
"start": 33,
"end": 36,
"loc": {
"start": {
"line": 4,
"column": 2
},
"end": {
"line": 4,
"column": 5
},
"identifierName": "foo"
},
"name": "foo"
}
},
"operator": "/",
"right": {
"type": "CallExpression",
"start": 39,
"end": 86,
"loc": {
"start": {
"line": 4,
"column": 8
},
"end": {
"line": 9,
"column": 10
}
},
"callee": {
"type": "CallExpression",
"start": 39,
"end": 61,
"loc": {
"start": {
"line": 4,
"column": 8
},
"end": {
"line": 6,
"column": 19
}
},
"callee": {
"type": "Identifier",
"start": 39,
"end": 40,
"loc": {
"start": {
"line": 4,
"column": 8
},
"end": {
"line": 4,
"column": 9
},
"identifierName": "g"
},
"name": "g"
},
"arguments": [
{
"type": "AssignmentExpression",
"start": 43,
"end": 60,
"loc": {
"start": {
"line": 6,
"column": 1
},
"end": {
"line": 6,
"column": 18
}
},
"operator": "=",
"left": {
"type": "Identifier",
"start": 43,
"end": 44,
"loc": {
"start": {
"line": 6,
"column": 1
},
"end": {
"line": 6,
"column": 2
},
"identifierName": "x"
},
"name": "x"
},
"right": {
"type": "BinaryExpression",
"start": 47,
"end": 60,
"loc": {
"start": {
"line": 6,
"column": 5
},
"end": {
"line": 6,
"column": 18
}
},
"left": {
"type": "ClassExpression",
"start": 47,
"end": 54,
"loc": {
"start": {
"line": 6,
"column": 5
},
"end": {
"line": 6,
"column": 12
}
},
"id": null,
"superClass": null,
"body": {
"type": "ClassBody",
"start": 52,
"end": 54,
"loc": {
"start": {
"line": 6,
"column": 10
},
"end": {
"line": 6,
"column": 12
}
},
"body": []
}
},
"operator": "/",
"right": {
"type": "Identifier",
"start": 57,
"end": 60,
"loc": {
"start": {
"line": 6,
"column": 15
},
"end": {
"line": 6,
"column": 18
},
"identifierName": "foo"
},
"name": "foo"
}
}
}
]
},
"arguments": [
{
"type": "AssignmentExpression",
"start": 64,
"end": 85,
"loc": {
"start": {
"line": 8,
"column": 1
},
"end": {
"line": 9,
"column": 9
}
},
"operator": "=",
"left": {
"type": "Identifier",
"start": 64,
"end": 65,
"loc": {
"start": {
"line": 8,
"column": 1
},
"end": {
"line": 8,
"column": 2
},
"identifierName": "x"
},
"name": "x"
},
"right": {
"type": "BinaryExpression",
"start": 68,
"end": 85,
"loc": {
"start": {
"line": 8,
"column": 5
},
"end": {
"line": 9,
"column": 9
}
},
"left": {
"type": "BinaryExpression",
"start": 68,
"end": 81,
"loc": {
"start": {
"line": 8,
"column": 5
},
"end": {
"line": 9,
"column": 5
}
},
"left": {
"type": "ClassExpression",
"start": 68,
"end": 75,
"loc": {
"start": {
"line": 8,
"column": 5
},
"end": {
"line": 8,
"column": 12
}
},
"id": null,
"superClass": null,
"body": {
"type": "ClassBody",
"start": 73,
"end": 75,
"loc": {
"start": {
"line": 8,
"column": 10
},
"end": {
"line": 8,
"column": 12
}
},
"body": []
}
},
"operator": "/",
"right": {
"type": "Identifier",
"start": 78,
"end": 81,
"loc": {
"start": {
"line": 9,
"column": 2
},
"end": {
"line": 9,
"column": 5
},
"identifierName": "foo"
},
"name": "foo"
}
},
"operator": "/",
"right": {
"type": "Identifier",
"start": 84,
"end": 85,
"loc": {
"start": {
"line": 9,
"column": 8
},
"end": {
"line": 9,
"column": 9
},
"identifierName": "g"
},
"name": "g"
}
}
}
]
}
}
}
}
],
"directives": []
}
}

View File

@@ -0,0 +1 @@
for (const {a} of /b/) {}

View File

@@ -0,0 +1,194 @@
{
"type": "File",
"start": 0,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 25
}
},
"program": {
"type": "Program",
"start": 0,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 25
}
},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ForOfStatement",
"start": 0,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 25
}
},
"await": false,
"left": {
"type": "VariableDeclaration",
"start": 5,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 14
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 11,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 14
}
},
"id": {
"type": "ObjectPattern",
"start": 11,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 14
}
},
"properties": [
{
"type": "ObjectProperty",
"start": 12,
"end": 13,
"loc": {
"start": {
"line": 1,
"column": 12
},
"end": {
"line": 1,
"column": 13
}
},
"method": false,
"key": {
"type": "Identifier",
"start": 12,
"end": 13,
"loc": {
"start": {
"line": 1,
"column": 12
},
"end": {
"line": 1,
"column": 13
},
"identifierName": "a"
},
"name": "a"
},
"computed": false,
"shorthand": true,
"value": {
"type": "Identifier",
"start": 12,
"end": 13,
"loc": {
"start": {
"line": 1,
"column": 12
},
"end": {
"line": 1,
"column": 13
},
"identifierName": "a"
},
"name": "a"
},
"extra": {
"shorthand": true
}
}
]
},
"init": null
}
],
"kind": "const"
},
"right": {
"type": "RegExpLiteral",
"start": 18,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 18
},
"end": {
"line": 1,
"column": 21
}
},
"extra": {
"raw": "/b/"
},
"pattern": "b",
"flags": ""
},
"body": {
"type": "BlockStatement",
"start": 23,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 23
},
"end": {
"line": 1,
"column": 25
}
},
"body": [],
"directives": []
}
}
],
"directives": []
}
}

View File

@@ -0,0 +1 @@
for (let {a} of /b/) {}

View File

@@ -0,0 +1,194 @@
{
"type": "File",
"start": 0,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 23
}
},
"program": {
"type": "Program",
"start": 0,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 23
}
},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ForOfStatement",
"start": 0,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 23
}
},
"await": false,
"left": {
"type": "VariableDeclaration",
"start": 5,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 12
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 9,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 12
}
},
"id": {
"type": "ObjectPattern",
"start": 9,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 12
}
},
"properties": [
{
"type": "ObjectProperty",
"start": 10,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 11
}
},
"method": false,
"key": {
"type": "Identifier",
"start": 10,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 11
},
"identifierName": "a"
},
"name": "a"
},
"computed": false,
"shorthand": true,
"value": {
"type": "Identifier",
"start": 10,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 11
},
"identifierName": "a"
},
"name": "a"
},
"extra": {
"shorthand": true
}
}
]
},
"init": null
}
],
"kind": "let"
},
"right": {
"type": "RegExpLiteral",
"start": 16,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 19
}
},
"extra": {
"raw": "/b/"
},
"pattern": "b",
"flags": ""
},
"body": {
"type": "BlockStatement",
"start": 21,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 21
},
"end": {
"line": 1,
"column": 23
}
},
"body": [],
"directives": []
}
}
],
"directives": []
}
}

View File

@@ -0,0 +1 @@
for (var {a} of /b/) {}

View File

@@ -0,0 +1,194 @@
{
"type": "File",
"start": 0,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 23
}
},
"program": {
"type": "Program",
"start": 0,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 23
}
},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ForOfStatement",
"start": 0,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 23
}
},
"await": false,
"left": {
"type": "VariableDeclaration",
"start": 5,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 12
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 9,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 12
}
},
"id": {
"type": "ObjectPattern",
"start": 9,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 12
}
},
"properties": [
{
"type": "ObjectProperty",
"start": 10,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 11
}
},
"method": false,
"key": {
"type": "Identifier",
"start": 10,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 11
},
"identifierName": "a"
},
"name": "a"
},
"computed": false,
"shorthand": true,
"value": {
"type": "Identifier",
"start": 10,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 11
},
"identifierName": "a"
},
"name": "a"
},
"extra": {
"shorthand": true
}
}
]
},
"init": null
}
],
"kind": "var"
},
"right": {
"type": "RegExpLiteral",
"start": 16,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 19
}
},
"extra": {
"raw": "/b/"
},
"pattern": "b",
"flags": ""
},
"body": {
"type": "BlockStatement",
"start": 21,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 21
},
"end": {
"line": 1,
"column": 23
}
},
"body": [],
"directives": []
}
}
],
"directives": []
}
}

View File

@@ -0,0 +1,3 @@
function *f() { yield
{}/1/g
}

View File

@@ -0,0 +1,172 @@
{
"type": "File",
"start": 0,
"end": 30,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 30,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "FunctionDeclaration",
"start": 0,
"end": 30,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 10,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 11
},
"identifierName": "f"
},
"name": "f"
},
"generator": true,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 14,
"end": 30,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 3,
"column": 1
}
},
"body": [
{
"type": "ExpressionStatement",
"start": 16,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 21
}
},
"expression": {
"type": "YieldExpression",
"start": 16,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 21
}
},
"delegate": false,
"argument": null
}
},
{
"type": "BlockStatement",
"start": 22,
"end": 24,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 2
}
},
"body": [],
"directives": []
},
{
"type": "ExpressionStatement",
"start": 24,
"end": 28,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 6
}
},
"expression": {
"type": "RegExpLiteral",
"start": 24,
"end": 28,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 6
}
},
"extra": {
"raw": "/1/g"
},
"pattern": "1",
"flags": "g"
}
}
],
"directives": []
}
}
],
"directives": []
}
}

View File

@@ -0,0 +1 @@
function* bar() { yield class {} }

View File

@@ -0,0 +1,152 @@
{
"type": "File",
"start": 0,
"end": 34,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 34
}
},
"program": {
"type": "Program",
"start": 0,
"end": 34,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 34
}
},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "FunctionDeclaration",
"start": 0,
"end": 34,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 34
}
},
"id": {
"type": "Identifier",
"start": 10,
"end": 13,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 13
},
"identifierName": "bar"
},
"name": "bar"
},
"generator": true,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 16,
"end": 34,
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 34
}
},
"body": [
{
"type": "ExpressionStatement",
"start": 18,
"end": 32,
"loc": {
"start": {
"line": 1,
"column": 18
},
"end": {
"line": 1,
"column": 32
}
},
"expression": {
"type": "YieldExpression",
"start": 18,
"end": 32,
"loc": {
"start": {
"line": 1,
"column": 18
},
"end": {
"line": 1,
"column": 32
}
},
"delegate": false,
"argument": {
"type": "ClassExpression",
"start": 24,
"end": 32,
"loc": {
"start": {
"line": 1,
"column": 24
},
"end": {
"line": 1,
"column": 32
}
},
"id": null,
"superClass": null,
"body": {
"type": "ClassBody",
"start": 30,
"end": 32,
"loc": {
"start": {
"line": 1,
"column": 30
},
"end": {
"line": 1,
"column": 32
}
},
"body": []
}
}
}
}
],
"directives": []
}
}
],
"directives": []
}
}

View File

@@ -0,0 +1,2 @@
async
x => x

View File

@@ -0,0 +1,136 @@
{
"type": "File",
"start": 0,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 6
}
},
"program": {
"type": "Program",
"start": 0,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 6
}
},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 5,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 5
}
},
"expression": {
"type": "Identifier",
"start": 0,
"end": 5,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 5
},
"identifierName": "async"
},
"name": "async"
}
},
{
"type": "ExpressionStatement",
"start": 6,
"end": 12,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 6
}
},
"expression": {
"type": "ArrowFunctionExpression",
"start": 6,
"end": 12,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 6
}
},
"id": null,
"generator": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 6,
"end": 7,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 1
},
"identifierName": "x"
},
"name": "x"
}
],
"body": {
"type": "Identifier",
"start": 11,
"end": 12,
"loc": {
"start": {
"line": 2,
"column": 5
},
"end": {
"line": 2,
"column": 6
},
"identifierName": "x"
},
"name": "x"
}
}
}
],
"directives": []
}
}

Some files were not shown because too many files have changed in this diff Show More