Compare commits
380 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
531d4f1937 | ||
|
|
f155bc249c | ||
|
|
452d0ef30e | ||
|
|
005754ba98 | ||
|
|
c3c4cf17e3 | ||
|
|
0866e5a403 | ||
|
|
15f5e658fc | ||
|
|
574e6da132 | ||
|
|
da6d27ed16 | ||
|
|
4e87809ff9 | ||
|
|
f4267aaab0 | ||
|
|
4f255d103a | ||
|
|
502cc13aed | ||
|
|
0a1154e6fd | ||
|
|
f5b3d72730 | ||
|
|
e9bcccffbd | ||
|
|
aaf4cbf06f | ||
|
|
5080534974 | ||
|
|
02cb397873 | ||
|
|
d9169a87ad | ||
|
|
f3b6f2fc61 | ||
|
|
04cc24ee82 | ||
|
|
f32079ef42 | ||
|
|
d1b69656ae | ||
|
|
09453a490b | ||
|
|
e2e7627f0f | ||
|
|
4fe24a9a3b | ||
|
|
d26e7ad577 | ||
|
|
571cb4928f | ||
|
|
c12e8122f8 | ||
|
|
92e7a01d14 | ||
|
|
b9ca9d42dc | ||
|
|
479c3e477a | ||
|
|
2c3d3d8105 | ||
|
|
ea03f67505 | ||
|
|
ee0c88a070 | ||
|
|
98206df864 | ||
|
|
1066a42fb2 | ||
|
|
062175586c | ||
|
|
0dc6b582a6 | ||
|
|
d8d70ba137 | ||
|
|
f23c916520 | ||
|
|
8ae4601177 | ||
|
|
9a466d3ef9 | ||
|
|
713845d14c | ||
|
|
471d60e5cd | ||
|
|
43864e0686 | ||
|
|
4c2ae5dd19 | ||
|
|
a540cbe801 | ||
|
|
34cc577fa2 | ||
|
|
c855b55133 | ||
|
|
16c86c25b7 | ||
|
|
4345f7945b | ||
|
|
f44c93add2 | ||
|
|
09e45c51a4 | ||
|
|
1a42b72b15 | ||
|
|
d30415d74a | ||
|
|
616ef8d840 | ||
|
|
56437f94bc | ||
|
|
881fa6430b | ||
|
|
b7971690f3 | ||
|
|
c01d0abbd3 | ||
|
|
7043119346 | ||
|
|
b5325df57f | ||
|
|
0fc958e0fc | ||
|
|
9cb16711dd | ||
|
|
04766b13f5 | ||
|
|
433d704739 | ||
|
|
30204d2ee6 | ||
|
|
374b7cca2c | ||
|
|
152ae388f0 | ||
|
|
04344026bb | ||
|
|
cfffaf6cdb | ||
|
|
2952d94e60 | ||
|
|
0276c3ae81 | ||
|
|
c00f8dce3f | ||
|
|
4e24ae39cf | ||
|
|
12bd6494b7 | ||
|
|
e35c7550fe | ||
|
|
e7046abe72 | ||
|
|
affa7f0c6f | ||
|
|
be650ffc61 | ||
|
|
3078d48178 | ||
|
|
0be93563dd | ||
|
|
3e55980145 | ||
|
|
470ebf3a46 | ||
|
|
b695369126 | ||
|
|
f4611469b4 | ||
|
|
68bfafe745 | ||
|
|
f72782b71c | ||
|
|
0f1f5e3565 | ||
|
|
dfe126f3d4 | ||
|
|
4c9cb957a9 | ||
|
|
8f997f8825 | ||
|
|
d789a6e7aa | ||
|
|
4007148d9f | ||
|
|
998f1d544e | ||
|
|
deed48a3db | ||
|
|
00c0a958db | ||
|
|
1511dcbd73 | ||
|
|
12fef25803 | ||
|
|
fd30eb1839 | ||
|
|
63344eb0a4 | ||
|
|
6e4e11a365 | ||
|
|
e330efe058 | ||
|
|
ce86eca8b0 | ||
|
|
03dbaa3e0e | ||
|
|
2bd35fac6e | ||
|
|
cdca4e50d9 | ||
|
|
bb041c1bd6 | ||
|
|
a36c1b4a92 | ||
|
|
b760daca21 | ||
|
|
ff63d8f60c | ||
|
|
74f04ed6a1 | ||
|
|
74d880bf18 | ||
|
|
5ce38cacaa | ||
|
|
829f642ad8 | ||
|
|
80a4b95da4 | ||
|
|
dc2a20dbcd | ||
|
|
f6278e43ce | ||
|
|
30bc80000b | ||
|
|
ef56042c93 | ||
|
|
b6498103db | ||
|
|
7af4302d07 | ||
|
|
543770960c | ||
|
|
a2975a72cc | ||
|
|
beb3fd51d8 | ||
|
|
9360860601 | ||
|
|
7d4ecea8fb | ||
|
|
a44831b3fa | ||
|
|
8357f3900f | ||
|
|
6b1c5bc358 | ||
|
|
3564309a77 | ||
|
|
c9518bb60d | ||
|
|
0f1215e33e | ||
|
|
d7b0b5bec0 | ||
|
|
3e5af404ab | ||
|
|
1818094577 | ||
|
|
6d712b3d14 | ||
|
|
11389fe165 | ||
|
|
0ee9531db3 | ||
|
|
1622d2498d | ||
|
|
b76e6f8e5b | ||
|
|
beac006832 | ||
|
|
20d7603c0b | ||
|
|
24b13c5e49 | ||
|
|
9e21074e88 | ||
|
|
9a825bced7 | ||
|
|
fcb78436c6 | ||
|
|
bb30a64f8d | ||
|
|
b483c16fe2 | ||
|
|
569f046045 | ||
|
|
4e969d3d92 | ||
|
|
0bca1de285 | ||
|
|
3a5bd06a7e | ||
|
|
66a908aaa7 | ||
|
|
cd0ed08237 | ||
|
|
dd84b554e6 | ||
|
|
b51411f090 | ||
|
|
4cc843ded3 | ||
|
|
47d253c732 | ||
|
|
09901274ab | ||
|
|
35196e20c7 | ||
|
|
35af771a29 | ||
|
|
dee80caa09 | ||
|
|
46b7cc0a72 | ||
|
|
3b189e22b7 | ||
|
|
6ca565d7fb | ||
|
|
64f5480f96 | ||
|
|
828fdc8769 | ||
|
|
6763c4415e | ||
|
|
fb30e79e03 | ||
|
|
85fb4304b0 | ||
|
|
c2da77d7ec | ||
|
|
c54c3d3c15 | ||
|
|
2a7c954155 | ||
|
|
3fb7f7c7cc | ||
|
|
c4b2818336 | ||
|
|
061561bfd8 | ||
|
|
d4944d606b | ||
|
|
736b689c3b | ||
|
|
e12b377014 | ||
|
|
5fd5b815ab | ||
|
|
92db8312f6 | ||
|
|
e080fe547d | ||
|
|
b967ecf063 | ||
|
|
365b7285d2 | ||
|
|
a40d532b0e | ||
|
|
0487bf911d | ||
|
|
57c72d1cd0 | ||
|
|
335bdffec2 | ||
|
|
e1d76a1dfe | ||
|
|
a4845323a2 | ||
|
|
792951b489 | ||
|
|
5adda836af | ||
|
|
4c2c3098c3 | ||
|
|
087c714098 | ||
|
|
5a33e4fe05 | ||
|
|
5f8667eaa7 | ||
|
|
31b4468514 | ||
|
|
2be9678bbe | ||
|
|
b5210877cf | ||
|
|
658dde768e | ||
|
|
8df1d81ca4 | ||
|
|
a505e4a121 | ||
|
|
71eafdcac7 | ||
|
|
65060b0c97 | ||
|
|
09883962f1 | ||
|
|
1583262807 | ||
|
|
04c7cd5c0c | ||
|
|
3f6969f4f8 | ||
|
|
23db842cb8 | ||
|
|
41c82e00f9 | ||
|
|
766099e783 | ||
|
|
53bc54b3b2 | ||
|
|
bb70f37123 | ||
|
|
8a0317132e | ||
|
|
f598c70841 | ||
|
|
61b57ea055 | ||
|
|
a971ad7fd2 | ||
|
|
27b6f804ce | ||
|
|
8ab79f3a72 | ||
|
|
0c2bf2f5a2 | ||
|
|
7e1a4be085 | ||
|
|
bbc951dfe1 | ||
|
|
b3e4aefe12 | ||
|
|
26b5174dfa | ||
|
|
652d3c7320 | ||
|
|
edc2cd320c | ||
|
|
274a6e01dc | ||
|
|
3561efdb86 | ||
|
|
1a30f1aafc | ||
|
|
e362512af3 | ||
|
|
cf5d2429b4 | ||
|
|
72098036b2 | ||
|
|
7905f48280 | ||
|
|
aba2d1c23c | ||
|
|
5326e0543d | ||
|
|
1360c93e4b | ||
|
|
235cbc18cf | ||
|
|
98c5255b91 | ||
|
|
2a9777cc20 | ||
|
|
a8702be756 | ||
|
|
0995cc3f4e | ||
|
|
1cfca745a4 | ||
|
|
a3459deecf | ||
|
|
070152f6c1 | ||
|
|
719fdf5ca1 | ||
|
|
f2460c6173 | ||
|
|
155c640409 | ||
|
|
7de4718b27 | ||
|
|
4e6aed0408 | ||
|
|
3be8ccf68d | ||
|
|
704b31f44f | ||
|
|
1a9f193841 | ||
|
|
7ff67589a7 | ||
|
|
80f109efeb | ||
|
|
77c72bb5a6 | ||
|
|
6c5e0e6590 | ||
|
|
83324b977d | ||
|
|
5feab11d3f | ||
|
|
7b4172ce7b | ||
|
|
84439384c0 | ||
|
|
c9e7c306cc | ||
|
|
1e398e45ff | ||
|
|
475324c4b5 | ||
|
|
407daf4bac | ||
|
|
4155590cd8 | ||
|
|
0be6fd7abe | ||
|
|
cf51bf1395 | ||
|
|
06a31c419a | ||
|
|
da566110c0 | ||
|
|
c12c4a5c39 | ||
|
|
d114349890 | ||
|
|
8d6ae0e1eb | ||
|
|
cb8b47ee2f | ||
|
|
daf24c5c59 | ||
|
|
cdb2784e75 | ||
|
|
93feabb82e | ||
|
|
982c142bf6 | ||
|
|
de5520a94f | ||
|
|
c239d06f10 | ||
|
|
a5fed376d8 | ||
|
|
e99fd77d89 | ||
|
|
1374863b9c | ||
|
|
e88c28f88b | ||
|
|
7a0fd26f56 | ||
|
|
17583e4807 | ||
|
|
37dd5137ff | ||
|
|
24fced406e | ||
|
|
0ab1362893 | ||
|
|
96506f4249 | ||
|
|
ed747f88bd | ||
|
|
3987545b4f | ||
|
|
148aa3f96d | ||
|
|
0cb5a7c91e | ||
|
|
fc34d5a9b0 | ||
|
|
f8d56d9612 | ||
|
|
737be0e95e | ||
|
|
26e2b392e8 | ||
|
|
708cdfb993 | ||
|
|
8cb3aabefa | ||
|
|
4a87b35d20 | ||
|
|
543554b258 | ||
|
|
afd95cf663 | ||
|
|
87ce4b9cd8 | ||
|
|
6b76f26ed8 | ||
|
|
c2776e63ae | ||
|
|
3f2fe363d1 | ||
|
|
8de28098f4 | ||
|
|
584532cc2c | ||
|
|
9a28f3fdb1 | ||
|
|
88941b3270 | ||
|
|
3a768db2bf | ||
|
|
320a39f4c4 | ||
|
|
dc98ac7c93 | ||
|
|
6e456f0ec1 | ||
|
|
793090628d | ||
|
|
9ed251cb08 | ||
|
|
480fa7f4e0 | ||
|
|
3e642dfa1b | ||
|
|
d9cbce1862 | ||
|
|
4bd19da3c2 | ||
|
|
7c710a0378 | ||
|
|
56335409d3 | ||
|
|
91d78afc67 | ||
|
|
54c6339f20 | ||
|
|
fdcf64265e | ||
|
|
ffdfb491eb | ||
|
|
eedd431f2b | ||
|
|
db9ed0235f | ||
|
|
6c98d39937 | ||
|
|
20651df3ce | ||
|
|
f3155919fe | ||
|
|
0ac8330899 | ||
|
|
67201e9698 | ||
|
|
c715d96e46 | ||
|
|
b7a08100a6 | ||
|
|
5f91ee8a1a | ||
|
|
bc1abb5103 | ||
|
|
4b9207e5df | ||
|
|
e847f3685f | ||
|
|
d64c2c0c45 | ||
|
|
76d0fb4ba6 | ||
|
|
0f33b7bfbc | ||
|
|
630224e504 | ||
|
|
62980ab6b4 | ||
|
|
d34480b42b | ||
|
|
306de2edbf | ||
|
|
c33e84730d | ||
|
|
20f28aba64 | ||
|
|
9c312607d1 | ||
|
|
33659711c3 | ||
|
|
b154af48a7 | ||
|
|
bad877946f | ||
|
|
dff3751e7f | ||
|
|
23038dcfff | ||
|
|
7c7a7ee17f | ||
|
|
9f467ef7c0 | ||
|
|
a52f9ab346 | ||
|
|
5ccbed585b | ||
|
|
f7c7da7526 | ||
|
|
ed58c80c64 | ||
|
|
d7fb9f67df | ||
|
|
eef6002324 | ||
|
|
32bcf4c3a5 | ||
|
|
86060cb0ce | ||
|
|
66a836d435 | ||
|
|
ecc14c2a31 | ||
|
|
7e9b60fba5 | ||
|
|
313f1e755a | ||
|
|
8c7ef0a2c9 | ||
|
|
8f79010b16 | ||
|
|
022e6f26aa | ||
|
|
138fa6c9f8 | ||
|
|
c07704cc80 | ||
|
|
bf811ea34a | ||
|
|
8af3ea1c43 | ||
|
|
5fbe147a5e | ||
|
|
a9e214b1db |
8
.babelrc
8
.babelrc
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"experimental": true,
|
"stage": 0,
|
||||||
"playground": true,
|
"loose": ["all"],
|
||||||
"loose": true,
|
"blacklist": ["es6.tailCall"],
|
||||||
"blacklist": ["es6.tailCall"]
|
"optional": ["optimisation.flow.forOf"]
|
||||||
}
|
}
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -11,6 +11,7 @@ test/core/tmp
|
|||||||
coverage
|
coverage
|
||||||
dist
|
dist
|
||||||
.package.json
|
.package.json
|
||||||
|
packages/babel-runtime/core-js
|
||||||
packages/babel-runtime/helpers/*.js
|
packages/babel-runtime/helpers/*.js
|
||||||
packages/babel-runtime/regenerator/*.js
|
packages/babel-runtime/regenerator/*.js
|
||||||
lib
|
lib
|
||||||
|
|||||||
6
.gitmodules
vendored
6
.gitmodules
vendored
@@ -1,12 +1,6 @@
|
|||||||
[submodule "vendor/traceur"]
|
[submodule "vendor/traceur"]
|
||||||
path = vendor/traceur
|
path = vendor/traceur
|
||||||
url = https://github.com/google/traceur-compiler
|
url = https://github.com/google/traceur-compiler
|
||||||
[submodule "vendor/regenerator"]
|
|
||||||
path = vendor/regenerator
|
|
||||||
url = https://github.com/babel/regenerator-babel
|
|
||||||
[submodule "vendor/test262"]
|
|
||||||
path = vendor/test262
|
|
||||||
url = https://github.com/tc39/test262
|
|
||||||
[submodule "vendor/compat-table"]
|
[submodule "vendor/compat-table"]
|
||||||
path = vendor/compat-table
|
path = vendor/compat-table
|
||||||
url = https://github.com/kangax/compat-table
|
url = https://github.com/kangax/compat-table
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
sudo: false
|
#sudo: false
|
||||||
language: node_js
|
language: node_js
|
||||||
|
cache:
|
||||||
|
directories:
|
||||||
|
- node_modules
|
||||||
node_js:
|
node_js:
|
||||||
- "0.12"
|
- "0.12"
|
||||||
- "iojs"
|
- "iojs"
|
||||||
|
|||||||
230
CHANGELOG.md
230
CHANGELOG.md
@@ -13,6 +13,236 @@ _Note: Gaps between patch versions are faulty/broken releases._
|
|||||||
|
|
||||||
See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
|
See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
|
||||||
|
|
||||||
|
## 5.2.3
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Fix plugin containers being called with an undefined import. Thanks [@timbur](https://github.com/timbur)!
|
||||||
|
* Allow Flow object separators to be commas. Thanks [@monsanto](https://github.com/monsanto)!
|
||||||
|
* Add missing `Statement` and `Declaration` node aliases to flow types.
|
||||||
|
|
||||||
|
## 5.2.2
|
||||||
|
|
||||||
|
* **Internal**
|
||||||
|
* Allow `util.arrayify` to take arbitrary types and coerce it into an array.
|
||||||
|
|
||||||
|
## 5.2.1
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Fix regression in `node/register` that caused `node_modules` to not be ignored.
|
||||||
|
|
||||||
|
## 5.2.0
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Fix plugin strings splitting arbitrarily on `:` which caused full paths on Windows to fail as they include `:` after the drive letter.
|
||||||
|
* Call class property `initializer`s with their target instead of their descriptor.
|
||||||
|
* Fix `ignore` and `only` not properly working on Windows path separators. Thanks [@stagas](https://github.com/stagas)!
|
||||||
|
* Fix `resolveRc` running on files twice causing issues. Thanks [@lukescott](https://github.com/lukescott)!
|
||||||
|
* Fix shorthand properties not correctly being target for `isReferenced` checks. Thanks [@monsanto](https://github.com/monsanto)!
|
||||||
|
* **Polish**
|
||||||
|
* Allow passing an array of globs to `babel/register` `only` and `ignore` options. Thanks [@Mark-Simulacrum](https://github.com/Mark-Simulacrum)!
|
||||||
|
* When inferring function names that collide with upper bindings, instead of doing the wrapper, instead rename them.
|
||||||
|
* Consider constant-like variable declaration functions to always refer to themselves so TOC can be performed.
|
||||||
|
* Process globs manually when using `$ babel` as some shells such as Windows don't explode them. Thanks [@jden](https://github.com/jden)!
|
||||||
|
* Add alternative way to execute plugins via a closure that's called with the current Babel instance.
|
||||||
|
* **Internal**
|
||||||
|
* Remove multiple internal transformers in favor of directly doing things when we need to. Previously, declarations such as `_ref` that we needed to create in specific scopes were done at the very end via the `_declarations` transformer. Now, they're done and added to the scope **right** when they're needed. This gets rid of the crappy `_declarations` property on scope nodes and fixes the crappy regenerator bug where it was creating a new `BlockStatement` so the declarations were being lost.
|
||||||
|
* Rework transformer traversal optimisation. Turns out that calling a `check` function for **every single node** in the AST is ridiculously expensive. 300,000 nodes timesed by ~30 transformers meant that it took tens of seconds to perform while it's quicker to just do the unnecessary traversal. Seems obvious in hindsight.
|
||||||
|
* **New Feature**
|
||||||
|
* Add `jscript` transformer that turns named function expressions into function declarations to get around [JScript's horribly broken function expression semantics](https://kangax.github.io/nfe/#jscript-bugs). Thanks [@kondi](https://github.com/kondi)!
|
||||||
|
* Add `@@hasInstance` support to objects when using the `es6.spec.symbols` transformer.
|
||||||
|
* Add `retainLines` option that retains the line (but not the columns!) of the input code.
|
||||||
|
|
||||||
|
## 5.1.13
|
||||||
|
|
||||||
|
* **Polish**
|
||||||
|
* Remove symbol check from `defineProperty` helper.
|
||||||
|
|
||||||
|
## 5.1.12
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Fix `resolveModuleSource` not being ran on `ExportAllDeclaration`s.
|
||||||
|
* Fix `.babelrc` being resolved multiple times when using the require hook.
|
||||||
|
* Fix parse error on spread properties in assignment position.
|
||||||
|
* Fix `externalHelpers` option being incorrectly listed as type `string`.
|
||||||
|
* **Internal**
|
||||||
|
* Upgrade `core-js` to `0.9.0`.
|
||||||
|
* **Spec Compliancy**
|
||||||
|
* Fix object decorators not using the `initializer` pattern.
|
||||||
|
* Remove property initializer descriptor reflection.
|
||||||
|
|
||||||
|
## 5.1.11
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Memoise and bind member expression decorators.
|
||||||
|
* Move JSX children cleaning to opening element visitor. Fixes elements not being cleaned in certain scenarios.
|
||||||
|
* Consider `SwitchStatement`s to be `Scopable`.
|
||||||
|
* Fix `bluebirdCoroutines` calling `interopRequireWildcard` before it's defined.
|
||||||
|
* Add space to `do...while` code generation.
|
||||||
|
* Validate `super` use before `this` on `super` exit rather than entrance.
|
||||||
|
* **Polish**
|
||||||
|
* Add Babel name to logger.
|
||||||
|
|
||||||
|
## 5.1.10
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Remove `makePredicate` from acorn in favor of an `indexOf`.
|
||||||
|
* Remove statements to expression explosion when inserting a block statement.
|
||||||
|
* **Internal**
|
||||||
|
* Remove runtime compatibility check.
|
||||||
|
|
||||||
|
## 5.1.9
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Fix class property initializers with `undefined` values not being correctly writable.
|
||||||
|
* Fix self inferring generators incorrectly causing a stack error.
|
||||||
|
* Fix default export specifiers not triggering AMD `module` argument inclusion.
|
||||||
|
* Fix assignments not having their module references properly remapped.
|
||||||
|
* **Internal**
|
||||||
|
* Upgrade to latest `acorn`.
|
||||||
|
* **Polish**
|
||||||
|
* Make invalid LHS pattern error messages nicer.
|
||||||
|
|
||||||
|
## 5.1.8
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Only make parenthesized object pattern LHS illegal.
|
||||||
|
|
||||||
|
## 5.1.7
|
||||||
|
|
||||||
|
* **Internal**
|
||||||
|
* Add `parse` node API.
|
||||||
|
|
||||||
|
## 5.1.6
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Fix `runtime` built-in catchall not properly checking for local variables.
|
||||||
|
|
||||||
|
## 5.1.5
|
||||||
|
|
||||||
|
* **Internal**
|
||||||
|
* Bump `core-js` version.
|
||||||
|
|
||||||
|
## 5.1.4
|
||||||
|
|
||||||
|
* **Polish**
|
||||||
|
* Add missing `Reflect` methods to runtime transformer.
|
||||||
|
|
||||||
|
## 5.1.3
|
||||||
|
|
||||||
|
* **Internal**
|
||||||
|
* Switch entirely to vanilla regenerator.
|
||||||
|
* Clean up and make the parsing of decorators stateless.
|
||||||
|
* **Bug Fix**
|
||||||
|
* Don't do TCO on generators and async functions.
|
||||||
|
* Add missing `core-js` runtime definitions.
|
||||||
|
|
||||||
|
## 5.1.2
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Add `getIterator` and `isIterable` to `babel-runtime` build script.
|
||||||
|
|
||||||
|
## 5.1.1
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Add missing runtime symbol definitions.
|
||||||
|
|
||||||
|
## 5.1.0
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Fix super reference when using decorators.
|
||||||
|
* Don't do array unpack optimisation when member expressions are present.
|
||||||
|
* Add missing descriptors for undecorated class properties.
|
||||||
|
* Don't consider `arguments` and `eval` valid function names when doing function name inferrence.
|
||||||
|
* Fix scope tracking of constants in loop heads.
|
||||||
|
* Parse `AwaitExpression` as a unary instead of an assignment.
|
||||||
|
* Fix regex evaluation when attempting static evaluation.
|
||||||
|
* Don't emit tokens when doing a lookahead.
|
||||||
|
* Add missing `test` declaration to `utility.deadCodeElimination` transformer.
|
||||||
|
* **Internal**
|
||||||
|
* Upgrade `regenerator` to the latest and use my branch with the hope of eventually switching to vanilla regenerator.
|
||||||
|
* Add support for the replacement of for loop `init`s with statements.
|
||||||
|
* Upgrade dependencies.
|
||||||
|
* **Polish**
|
||||||
|
* When adding the scope IIFE when using default parameters, don't shadow the function expression, just `apply` `this` and `arguments` if necessary.
|
||||||
|
* Use path basename as non-default import fallback.
|
||||||
|
* **New Feature**
|
||||||
|
* Add [trailing function comma proposal](https://github.com/jeffmo/es-trailing-function-commas). Thanks [@AluisioASG](https://github.com/AluisioASG)!
|
||||||
|
* Add support for object literal decorators.
|
||||||
|
* Make core-js modular when using the `runtime` transformer.
|
||||||
|
|
||||||
|
## 5.0.12
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Fix incorrect remapping of module references inside of a function id redirection container.
|
||||||
|
|
||||||
|
## 5.0.11
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Fix new `for...of` loops not properly inheriting their original loop.
|
||||||
|
* **Internal**
|
||||||
|
* Disable scope instance cache.
|
||||||
|
* **Polish**
|
||||||
|
* Allow comments in `.babelrc` JSON.
|
||||||
|
|
||||||
|
## 5.0.9
|
||||||
|
|
||||||
|
* **Polish**
|
||||||
|
* Use `moduleId` for UMD global name if available.
|
||||||
|
* **Bug Fix**
|
||||||
|
* Fix UMD global `module` variable shadowing the `amd`/`common` `module` variable.
|
||||||
|
* Fix Flow param type annotation regression.
|
||||||
|
* Fix function name collision `toString` wrapper. Thanks [@alawatthe](https://github.com/alawatthe)!
|
||||||
|
|
||||||
|
## 5.0.8
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Fix falsy static class properties not being writable.
|
||||||
|
* Fix block scoping collisions not properly detecting modules and function clashes.
|
||||||
|
* Skip `this` before `super` for derived constructors on functions.
|
||||||
|
|
||||||
|
## 5.0.7
|
||||||
|
|
||||||
|
* **New Feature**
|
||||||
|
* Add `--ignore` and `--only` support to the CLI.
|
||||||
|
* **Bug Fix**
|
||||||
|
* Remove `HOMEPATH` environment variable from home resolution in `babel/register` cache.
|
||||||
|
* **Internal**
|
||||||
|
* Disable WIP path resolution introducing infinite recursion in some code examples.
|
||||||
|
* **Polish**
|
||||||
|
* Add live binding to CommonJS default imports.
|
||||||
|
|
||||||
|
## 5.0.6
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Fix mangling of import references that collide with properties on `Object.prototype`.
|
||||||
|
* Fix duplicate declarations incorrectly being reported for `var`.
|
||||||
|
|
||||||
|
## 5.0.5
|
||||||
|
|
||||||
|
* **Internal**
|
||||||
|
* Upgrade `core-js`.
|
||||||
|
* **Bug Fix**
|
||||||
|
* Fix arrays not being supported in `util.list`.
|
||||||
|
|
||||||
|
## 5.0.4
|
||||||
|
|
||||||
|
* **Polish**
|
||||||
|
* Check for top level `breakConfig` in `resolveRc`.
|
||||||
|
|
||||||
|
## 5.0.3
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Make relative location absolute before calling `resolveRc`.
|
||||||
|
* **Internal**
|
||||||
|
* Switch to global UID registry.
|
||||||
|
* Add `breakConfig` option to prevent Babel from erroring when hitting that option.
|
||||||
|
|
||||||
|
## 5.0.1
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Fix duplicate declaration regression.
|
||||||
|
* Fix not being able to call non-writable methods.
|
||||||
|
|
||||||
## 5.0.0
|
## 5.0.0
|
||||||
|
|
||||||
* **New Feature**
|
* **New Feature**
|
||||||
|
|||||||
102
CONTRIBUTING.md
102
CONTRIBUTING.md
@@ -1,9 +1,24 @@
|
|||||||
|
<p align="center">
|
||||||
|
<strong><a href="#setup">Setup</a></strong>
|
||||||
|
|
|
||||||
|
<strong><a href="#running-tests">Running tests</a></strong>
|
||||||
|
|
|
||||||
|
<strong><a href="#workflow">Workflow</a></strong>
|
||||||
|
|
|
||||||
|
<strong><a href="#dependencies">Dependencies</a></strong>
|
||||||
|
|
|
||||||
|
<strong><a href="#code-standards">Code Standards</a></strong>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
# Contributing
|
# Contributing
|
||||||
|
|
||||||
Contributions are always welcome, no matter how large or small. Before
|
Contributions are always welcome, no matter how large or small. Before
|
||||||
contributing, please read the
|
contributing, please read the
|
||||||
[code of conduct](https://github.com/babel/babel/blob/master/CODE_OF_CONDUCT.md).
|
[code of conduct](https://github.com/babel/babel/blob/master/CODE_OF_CONDUCT.md).
|
||||||
|
|
||||||
|
|
||||||
## Developing
|
## Developing
|
||||||
|
|
||||||
#### Setup
|
#### Setup
|
||||||
@@ -14,14 +29,19 @@ $ cd babel
|
|||||||
$ make bootstrap
|
$ make bootstrap
|
||||||
```
|
```
|
||||||
|
|
||||||
Then you need to run:
|
Then you can either run:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ make build-core
|
||||||
|
```
|
||||||
|
|
||||||
|
to build Babel **once** or:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ make watch-core
|
$ make watch-core
|
||||||
```
|
```
|
||||||
|
|
||||||
This will compile Babel and then sit in the background and on file modification
|
to have Babel build itself then incrementally build files on change.
|
||||||
recompile the necessary files.
|
|
||||||
|
|
||||||
#### Running tests
|
#### Running tests
|
||||||
|
|
||||||
@@ -35,15 +55,20 @@ This is mostly overkill and you can limit the tests to a select few by directly
|
|||||||
running them with `mocha`:
|
running them with `mocha`:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ mocha test/transformation.js
|
$ mocha test/core/transformation.js
|
||||||
```
|
```
|
||||||
|
|
||||||
Use mocha's `--grep` option to run a subset of tests by name:
|
Use mocha's `--grep` option to run a subset of tests by name:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ mocha test/transformation.js --grep es7
|
$ mocha test/core/transformation.js --grep es7
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If you don't have `mocha` installed globally, you can still use it from Babel's
|
||||||
|
dependencies in `node_modules`, but make sure `node_modules/.bin` is added to
|
||||||
|
your [`$PATH`](http://unix.stackexchange.com/questions/26047/how-to-correctly-add-a-path-to-path) environment variable.
|
||||||
|
|
||||||
|
|
||||||
#### Workflow
|
#### Workflow
|
||||||
|
|
||||||
* Fork the repository
|
* Fork the repository
|
||||||
@@ -54,24 +79,91 @@ $ mocha test/transformation.js --grep es7
|
|||||||
* Ensure the test are passing (`make test`)
|
* Ensure the test are passing (`make test`)
|
||||||
* Create new pull request explaining your proposed change or reference an issue in your commit message
|
* Create new pull request explaining your proposed change or reference an issue in your commit message
|
||||||
|
|
||||||
|
|
||||||
|
#### Dependencies
|
||||||
|
|
||||||
|
+ [ast-types](http://ghub.io/ast-types) This is required to monkeypatch regenerators AST definitions. Could be improved in the future.
|
||||||
|
|
||||||
|
+ [chalk](http://ghub.io/chalk) This is used for terminal color highlighting for syntax errors.
|
||||||
|
|
||||||
|
+ [convert-source-map](http://ghub.io/convert-source-map) Turns a source map object into a comment etc.
|
||||||
|
|
||||||
|
+ [core-js](http://ghub.io/core-js) Used for the polyfill.
|
||||||
|
|
||||||
|
+ [debug](http://ghub.io/debug) Used to output debugging information when NODE_DEBUG is set to babel.
|
||||||
|
|
||||||
|
+ [detect-indent](http://ghub.io/detect-indent) This is used in the code generator so it can infer indentation.
|
||||||
|
|
||||||
|
+ [estraverse](http://ghub.io/estraverse) The only method on this is attachComments. I'd like to implement our own comment attachment algorithm eventually though.
|
||||||
|
|
||||||
|
+ [esutils](http://ghub.io/esutils) Various ES related utilities. Check whether something is a keyword etc.
|
||||||
|
|
||||||
|
+ [fs-readdir-recursive](http://ghub.io/fs-readdir-recursive) Recursively search a directory for.
|
||||||
|
|
||||||
|
+ [globals](http://ghub.io/globals) A list of JavaScript global variables. This is used by the scope tracking to check for colliding variables.
|
||||||
|
|
||||||
|
+ [is-integer](http://ghub.io/is-integer) Checks if something is an integer.
|
||||||
|
|
||||||
|
+ [js-tokens](http://ghub.io/js-tokens) This is used to get tokens for syntax error highlighting.
|
||||||
|
|
||||||
|
+ [leven](http://ghub.io/leven) A levenstein algorithm to determine how close a word is to another. This is used to offer suggestions when using the utility.undeclaredVariableCheck transformer.
|
||||||
|
|
||||||
|
+ [line-numbers](http://ghub.io/line-numbers) Used to produce the code frames in syntax errors.
|
||||||
|
|
||||||
|
+ [lodash](http://ghub.io/lodash) Used for various utilities.
|
||||||
|
|
||||||
|
+ [minimatch](http://ghub.io/minimatch) This is used to match glob-style ignore/only filters.
|
||||||
|
|
||||||
|
+ [output-file-sync](http://ghub.io/output-file-sync) Synchronously writes a file and create its ancestor directories if needed.
|
||||||
|
|
||||||
|
+ [path-is-absolute](http://ghub.io/path-is-absolute) Checks if a path is absolute. C:\foo and \foo are considered absolute.
|
||||||
|
|
||||||
|
+ [regenerator](http://ghub.io/regenerator) This is used to transform generators/async functions.
|
||||||
|
|
||||||
|
+ [regexpu](http://ghub.io/regexpu) Used to transform unicode regex patterns.
|
||||||
|
|
||||||
|
+ [repeating](http://ghub.io/repeating) Repeats a string.
|
||||||
|
|
||||||
|
+ [shebang-regex](http://ghub.io/shebang-regex) Literally just a regex that matches shebangs.
|
||||||
|
|
||||||
|
+ [slash](http://ghub.io/slash) Normalises path separators.
|
||||||
|
|
||||||
|
+ [source-map](http://ghub.io/source-map) Generates sourcemaps.
|
||||||
|
|
||||||
|
+ [source-map-support](http://ghub.io/source-map-support) Adds source map support to babel-node/babel/register.
|
||||||
|
|
||||||
|
+ [strip-json-comments](http://ghub.io/strip-json-comments) Remove comments from a JSON string. This is used for .babelrc files.
|
||||||
|
|
||||||
|
+ [to-fast-properties](http://ghub.io/to-fast-properties) A V8 trick to put an object into fast properties mode.
|
||||||
|
|
||||||
|
+ [trim-right](http://ghub.io/trim-right) Trims the rightside whitespace.
|
||||||
|
|
||||||
|
+ [user-home](http://ghub.io/user-home) Gets the users home directory. This is used to resolve the babel-node/babel/register cache.
|
||||||
|
|
||||||
|
|
||||||
#### Code Standards
|
#### Code Standards
|
||||||
|
|
||||||
* **General**
|
* **General**
|
||||||
* Max of five arguments for functions
|
* Max of five arguments for functions
|
||||||
* Max depth of four nested blocks
|
* Max depth of four nested blocks
|
||||||
* 2-spaced soft tabs
|
* 2-spaced soft tabs
|
||||||
|
|
||||||
* **Naming**
|
* **Naming**
|
||||||
* CamelCase all class names
|
* CamelCase all class names
|
||||||
* camelBack all variable names
|
* camelBack all variable names
|
||||||
|
|
||||||
* **Spacing**
|
* **Spacing**
|
||||||
* Spaces after all keywords
|
* Spaces after all keywords
|
||||||
* Spaces before all left curly braces
|
* Spaces before all left curly braces
|
||||||
|
|
||||||
* **Comments**
|
* **Comments**
|
||||||
* Use JSDoc-style comments for methods
|
* Use JSDoc-style comments for methods
|
||||||
* Single-line comments for ambiguous code
|
* Single-line comments for ambiguous code
|
||||||
|
|
||||||
* **Quotes**
|
* **Quotes**
|
||||||
* Always use double quotes
|
* Always use double quotes
|
||||||
* Only use single quotes when the string contains a double quote
|
* Only use single quotes when the string contains a double quote
|
||||||
|
|
||||||
* **Declaration**
|
* **Declaration**
|
||||||
* No unused variables
|
* No unused variables
|
||||||
* No pollution of global variables and prototypes
|
* No pollution of global variables and prototypes
|
||||||
|
|||||||
16
Makefile
16
Makefile
@@ -9,17 +9,20 @@ BABEL_CMD = node_modules/babel/bin/babel
|
|||||||
|
|
||||||
export NODE_ENV = test
|
export NODE_ENV = test
|
||||||
|
|
||||||
.PHONY: clean test test-cov test-clean test-travis test-simple test-all test-browser test-parser publish build bootstrap publish-core publish-runtime build-core watch-core build-core-test
|
.PHONY: clean test test-cov test-clean test-travis test-simple test-all test-browser test-parser publish build bootstrap publish-core publish-runtime build-core watch-core build-core-test clean-core
|
||||||
|
|
||||||
build-core:
|
build-core: clean-core
|
||||||
node $(BABEL_CMD) src --out-dir lib --copy-files
|
node $(BABEL_CMD) src --out-dir lib --copy-files
|
||||||
|
|
||||||
build-core-test:
|
build-core-test: clean-core
|
||||||
node $(BABEL_CMD) src --out-dir lib --copy-files --auxiliary-comment "istanbul ignore next"
|
node $(BABEL_CMD) src --out-dir lib --copy-files --auxiliary-comment "istanbul ignore next"
|
||||||
|
|
||||||
watch-core:
|
watch-core: clean-core
|
||||||
node $(BABEL_CMD) src --out-dir lib --watch --copy-files
|
node $(BABEL_CMD) src --out-dir lib --watch --copy-files
|
||||||
|
|
||||||
|
clean-core:
|
||||||
|
rm -rf lib
|
||||||
|
|
||||||
build:
|
build:
|
||||||
mkdir -p dist
|
mkdir -p dist
|
||||||
make build-core
|
make build-core
|
||||||
@@ -109,9 +112,10 @@ publish-cli:
|
|||||||
npm publish
|
npm publish
|
||||||
|
|
||||||
bootstrap:
|
bootstrap:
|
||||||
|
npm list --global --depth 1 babel >/dev/null 2>&1 && npm uninstall -g babel || true
|
||||||
npm install
|
npm install
|
||||||
npm link
|
npm link
|
||||||
cd packages/babel-cli && npm install && npm link
|
cd packages/babel-cli && npm install && npm link && npm link babel-core
|
||||||
git submodule update --init
|
git submodule update --init
|
||||||
cd vendor/regenerator && npm install
|
|
||||||
cd vendor/compat-table && npm install object-assign
|
cd vendor/compat-table && npm install object-assign
|
||||||
|
make build
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
For questions and support please visit the <a href="https://gitter.im/babel/babel">gitter room</a> or <a href="stackoverflow.com">StackOverflow</a>. The Babel issue tracker is <strong>exclusively</strong> for bug reports and future requests.
|
For questions and support please visit the <a href="https://gitter.im/babel/babel">gitter room</a> or <a href="http://stackoverflow.com/questions/tagged/babeljs">StackOverflow</a>. The Babel issue tracker is <strong>exclusively</strong> for bug reports and feature requests.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
|
|||||||
38
package.json
38
package.json
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "babel-core",
|
"name": "babel-core",
|
||||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||||
"version": "5.0.0",
|
"version": "5.2.3",
|
||||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||||
"homepage": "https://babeljs.io/",
|
"homepage": "https://babeljs.io/",
|
||||||
"repository": "babel/babel",
|
"repository": "babel/babel",
|
||||||
@@ -28,45 +28,49 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ast-types": "~0.7.0",
|
"ast-types": "~0.7.0",
|
||||||
|
"bluebird": "^2.9.25",
|
||||||
"chalk": "^1.0.0",
|
"chalk": "^1.0.0",
|
||||||
"convert-source-map": "^0.5.0",
|
"convert-source-map": "^1.1.0",
|
||||||
"core-js": "^0.8.0",
|
"core-js": "^0.9.0",
|
||||||
"debug": "^2.1.1",
|
"debug": "^2.1.1",
|
||||||
"detect-indent": "^3.0.0",
|
"detect-indent": "^3.0.0",
|
||||||
"estraverse": "^1.9.1",
|
"estraverse": "^3.0.0",
|
||||||
"esutils": "^1.1.6",
|
"esutils": "^2.0.0",
|
||||||
"fs-readdir-recursive": "^0.1.0",
|
"fs-readdir-recursive": "^0.1.0",
|
||||||
"globals": "^6.2.0",
|
"globals": "^6.4.0",
|
||||||
"is-integer": "^1.0.4",
|
"is-integer": "^1.0.4",
|
||||||
"js-tokens": "1.0.0",
|
"js-tokens": "1.0.0",
|
||||||
"leven": "^1.0.1",
|
"leven": "^1.0.1",
|
||||||
"line-numbers": "0.2.0",
|
"line-numbers": "0.2.0",
|
||||||
"lodash": "^3.2.0",
|
"lodash": "^3.6.0",
|
||||||
"minimatch": "^2.0.3",
|
"minimatch": "^2.0.3",
|
||||||
"output-file-sync": "^1.1.0",
|
"output-file-sync": "^1.1.0",
|
||||||
"path-is-absolute": "^1.0.0",
|
"path-is-absolute": "^1.0.0",
|
||||||
"private": "^0.1.6",
|
"private": "^0.1.6",
|
||||||
"regenerator-babel": "0.8.13-2",
|
"regenerator": "^0.8.20",
|
||||||
"regexpu": "^1.1.2",
|
"regexpu": "^1.1.2",
|
||||||
"repeating": "^1.1.2",
|
"repeating": "^1.1.2",
|
||||||
|
"resolve": "^1.1.6",
|
||||||
"shebang-regex": "^1.0.0",
|
"shebang-regex": "^1.0.0",
|
||||||
"slash": "^1.0.0",
|
"slash": "^1.0.0",
|
||||||
"source-map": "^0.4.0",
|
"source-map": "^0.4.0",
|
||||||
"source-map-support": "^0.2.9",
|
"source-map-support": "^0.2.10",
|
||||||
|
"strip-json-comments": "^1.0.2",
|
||||||
"to-fast-properties": "^1.0.0",
|
"to-fast-properties": "^1.0.0",
|
||||||
"trim-right": "^1.0.0"
|
"trim-right": "^1.0.0",
|
||||||
|
"user-home": "^1.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel": "4.7.13",
|
"babel": "5.1.13",
|
||||||
"browserify": "^9.0.3",
|
"browserify": "^9.0.8",
|
||||||
"chai": "^2.0.0",
|
"chai": "^2.2.0",
|
||||||
"eslint": "^0.15.1",
|
"eslint": "^0.18.0",
|
||||||
"babel-eslint": "^1.0.1",
|
"babel-eslint": "^2.0.0",
|
||||||
"esvalid": "^1.1.0",
|
"esvalid": "^1.1.0",
|
||||||
"istanbul": "^0.3.5",
|
"istanbul": "^0.3.5",
|
||||||
"matcha": "^0.6.0",
|
"matcha": "^0.6.0",
|
||||||
"mocha": "^2.1.0",
|
"mocha": "2.2.0",
|
||||||
"rimraf": "^2.2.8",
|
"rimraf": "^2.3.2",
|
||||||
"uglify-js": "^2.4.16"
|
"uglify-js": "^2.4.16"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
5
packages/babel-cli/README.md
Normal file
5
packages/babel-cli/README.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# babel-cli
|
||||||
|
|
||||||
|
Babel CLI
|
||||||
|
|
||||||
|
For more information please look at [babel](https://github.com/babel/babel).
|
||||||
@@ -4,6 +4,7 @@ var pathIsAbsolute = require("path-is-absolute");
|
|||||||
var commander = require("commander");
|
var commander = require("commander");
|
||||||
var Module = require("module");
|
var Module = require("module");
|
||||||
var babel = require("babel-core");
|
var babel = require("babel-core");
|
||||||
|
var inspect = require("util").inspect;
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
var repl = require("repl");
|
var repl = require("repl");
|
||||||
var util = require("babel-core").util;
|
var util = require("babel-core").util;
|
||||||
@@ -71,7 +72,10 @@ if (program.eval || program.print) {
|
|||||||
global.require = module.require.bind(module);
|
global.require = module.require.bind(module);
|
||||||
|
|
||||||
var result = _eval(code, global.__filename);
|
var result = _eval(code, global.__filename);
|
||||||
if (program.print) console.log(result);
|
if (program.print) {
|
||||||
|
var output = _.isString(result) ? result : inspect(result);
|
||||||
|
process.stdout.write(output + "\n");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (program.args.length) {
|
if (program.args.length) {
|
||||||
// slice all arguments up to the first filename since they're babel args that we handle
|
// slice all arguments up to the first filename since they're babel args that we handle
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ module.exports = function (commander, filenames, opts) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var handleFile = function (src, filename) {
|
var handleFile = function (src, filename) {
|
||||||
|
if (util.shouldIgnore(src)) return;
|
||||||
|
|
||||||
if (util.canCompile(filename)) {
|
if (util.canCompile(filename)) {
|
||||||
write(src, filename);
|
write(src, filename);
|
||||||
} else if (commander.copyFiles) {
|
} else if (commander.copyFiles) {
|
||||||
|
|||||||
@@ -107,6 +107,8 @@ module.exports = function (commander, filenames, opts) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
_.each(_filenames, function (filename) {
|
_.each(_filenames, function (filename) {
|
||||||
|
if (util.shouldIgnore(filename)) return;
|
||||||
|
|
||||||
results.push(util.compile(filename));
|
results.push(util.compile(filename));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ var util = require("babel-core").util;
|
|||||||
var each = require("lodash/collection/each");
|
var each = require("lodash/collection/each");
|
||||||
var keys = require("lodash/object/keys");
|
var keys = require("lodash/object/keys");
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
|
var glob = require("glob");
|
||||||
|
|
||||||
each(options, function (option, key) {
|
each(options, function (option, key) {
|
||||||
if (option.hidden) return;
|
if (option.hidden) return;
|
||||||
@@ -69,7 +70,9 @@ commander.parse(process.argv);
|
|||||||
|
|
||||||
var errors = [];
|
var errors = [];
|
||||||
|
|
||||||
var filenames = commander.args;
|
var filenames = commander.args.reduce(function (globbed, input) {
|
||||||
|
return globbed.concat(glob.sync(input));
|
||||||
|
}, []);
|
||||||
|
|
||||||
each(filenames, function (filename) {
|
each(filenames, function (filename) {
|
||||||
if (!fs.existsSync(filename)) {
|
if (!fs.existsSync(filename)) {
|
||||||
@@ -102,12 +105,15 @@ if (errors.length) {
|
|||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
exports.opts = {};
|
var opts = exports.opts = {};
|
||||||
|
|
||||||
each(options, function (opt, key) {
|
each(options, function (opt, key) {
|
||||||
exports.opts[key] = commander[key];
|
opts[key] = commander[key];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
opts.ignore = util.arrayify(opts.ignore, util.regexify);
|
||||||
|
opts.only = util.arrayify(opts.only, util.regexify);
|
||||||
|
|
||||||
var fn;
|
var fn;
|
||||||
|
|
||||||
if (commander.outDir) {
|
if (commander.outDir) {
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ exports.readdir = readdir;
|
|||||||
|
|
||||||
exports.canCompile = util.canCompile;
|
exports.canCompile = util.canCompile;
|
||||||
|
|
||||||
|
exports.shouldIgnore = function (loc) {
|
||||||
|
return util.shouldIgnore(loc, index.opts.ignore, index.opts.only);
|
||||||
|
};
|
||||||
|
|
||||||
exports.addSourceMappingUrl = function (code, loc) {
|
exports.addSourceMappingUrl = function (code, loc) {
|
||||||
return code + "\n//# sourceMappingURL=" + path.basename(loc);
|
return code + "\n//# sourceMappingURL=" + path.basename(loc);
|
||||||
};
|
};
|
||||||
@@ -23,6 +27,8 @@ exports.addSourceMappingUrl = function (code, loc) {
|
|||||||
exports.transform = function (filename, code, opts) {
|
exports.transform = function (filename, code, opts) {
|
||||||
opts = _.defaults(opts || {}, index.opts);
|
opts = _.defaults(opts || {}, index.opts);
|
||||||
opts.filename = filename;
|
opts.filename = filename;
|
||||||
|
opts.ignore = null;
|
||||||
|
opts.only = null;
|
||||||
|
|
||||||
var result = babel.transform(code, opts);
|
var result = babel.transform(code, opts);
|
||||||
result.filename = filename;
|
result.filename = filename;
|
||||||
|
|||||||
@@ -1,19 +1,21 @@
|
|||||||
{
|
{
|
||||||
"name": "babel",
|
"name": "babel",
|
||||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||||
"version": "5.0.0-beta4",
|
"version": "5.2.2",
|
||||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||||
"homepage": "https://babeljs.io/",
|
"homepage": "https://babeljs.io/",
|
||||||
"repository": "babel/babel",
|
"repository": "babel/babel",
|
||||||
"preferGlobal": true,
|
"preferGlobal": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chokidar": "^0.12.6",
|
"babel-core": "^5.2.2",
|
||||||
"babel-core": "5.0.0-beta4",
|
"chokidar": "^1.0.0",
|
||||||
"commander": "^2.6.0",
|
"commander": "^2.6.0",
|
||||||
|
"convert-source-map": "^1.1.0",
|
||||||
"fs-readdir-recursive": "^0.1.0",
|
"fs-readdir-recursive": "^0.1.0",
|
||||||
"output-file-sync": "^1.1.0",
|
"glob": "^5.0.5",
|
||||||
"lodash": "^3.2.0",
|
"lodash": "^3.2.0",
|
||||||
"convert-source-map": "^0.5.0",
|
"output-file-sync": "^1.1.0",
|
||||||
|
"path-is-absolute": "^1.0.0",
|
||||||
"source-map": "^0.4.0"
|
"source-map": "^0.4.0"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
@@ -21,4 +23,4 @@
|
|||||||
"babel-node": "./bin/babel-node",
|
"babel-node": "./bin/babel-node",
|
||||||
"babel-external-helpers": "./bin/babel-external-helpers"
|
"babel-external-helpers": "./bin/babel-external-helpers"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
1
packages/babel-cli/register-without-polyfill.js
Normal file
1
packages/babel-cli/register-without-polyfill.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
module.exports = require("babel-core/register-without-polyfill");
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"name": "babel-runtime",
|
"name": "babel-runtime",
|
||||||
"description": "babel selfContained runtime",
|
"description": "babel selfContained runtime",
|
||||||
"version": "5.0.0-beta4",
|
"version": "5.2.2",
|
||||||
"repository": "babel/babel",
|
"repository": "babel/babel",
|
||||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"core-js": "^0.8.0"
|
"core-js": "^0.9.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,6 @@ var pkg = require(pkgLoc);
|
|||||||
var mainPkg = require("../package.json");
|
var mainPkg = require("../package.json");
|
||||||
|
|
||||||
pkg.version = mainPkg.version;
|
pkg.version = mainPkg.version;
|
||||||
pkg.dependencies["babel-core"] = mainPkg.version;
|
pkg.dependencies["babel-core"] = "^" + mainPkg.version;
|
||||||
|
|
||||||
outputFile(pkgLoc, JSON.stringify(pkg, null, 2));
|
outputFile(pkgLoc, JSON.stringify(pkg, null, 2));
|
||||||
|
|||||||
@@ -13,16 +13,20 @@ function relative(filename) {
|
|||||||
return __dirname + "/babel-runtime/" + filename;
|
return __dirname + "/babel-runtime/" + filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
function readFile(filename, defaultify) {
|
function readFile(filename, shouldDefaultify) {
|
||||||
var file = fs.readFileSync(require.resolve(filename), "utf8");
|
var file = fs.readFileSync(require.resolve(filename), "utf8");
|
||||||
|
|
||||||
if (defaultify) {
|
if (shouldDefaultify) {
|
||||||
file += '\nmodule.exports = { "default": module.exports, __esModule: true };\n';
|
file += "\n" + defaultify("module.exports") + "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function defaultify(name) {
|
||||||
|
return 'module.exports = { "default": ' + name + ', __esModule: true };';
|
||||||
|
}
|
||||||
|
|
||||||
function updatePackage() {
|
function updatePackage() {
|
||||||
var pkgLoc = relative("package.json");
|
var pkgLoc = relative("package.json");
|
||||||
var pkg = require(pkgLoc);
|
var pkg = require(pkgLoc);
|
||||||
@@ -66,7 +70,29 @@ each(File.helpers, function (helperName) {
|
|||||||
writeFile("helpers/" + helperName + ".js", buildHelper(helperName));
|
writeFile("helpers/" + helperName + ".js", buildHelper(helperName));
|
||||||
});
|
});
|
||||||
|
|
||||||
writeFile("regenerator/index.js", readFile("regenerator-babel/runtime-module", true));
|
writeFile("regenerator/index.js", readFile("regenerator/runtime-module", true));
|
||||||
writeFile("regenerator/runtime.js", selfContainify(readFile("regenerator-babel/runtime")));
|
writeFile("regenerator/runtime.js", selfContainify(readFile("regenerator/runtime")));
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
var coreDefinitions = require("../lib/babel/transformation/transformers/other/runtime/definitions");
|
||||||
|
|
||||||
|
var paths = ["is-iterable", "get-iterator"];
|
||||||
|
|
||||||
|
each(coreDefinitions.builtins, function (path) {
|
||||||
|
paths.push(path);
|
||||||
|
});
|
||||||
|
|
||||||
|
each(coreDefinitions.methods, function (props) {
|
||||||
|
each(props, function (path) {
|
||||||
|
paths.push(path);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
each(paths, function (path) {
|
||||||
|
writeFile("core-js/" + path + ".js", defaultify('require("core-js/library/fn/' + path + '")'));
|
||||||
|
});
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
updatePackage();
|
updatePackage();
|
||||||
|
|||||||
1
register-without-polyfill.js
Normal file
1
register-without-polyfill.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
module.exports = require("./lib/babel/api/register/node");
|
||||||
@@ -1 +1 @@
|
|||||||
module.exports = require("./lib/babel/api/register/node");
|
module.exports = require("./lib/babel/api/register/node-polyfill");
|
||||||
|
|||||||
3
src/acorn/index.js
Normal file
3
src/acorn/index.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export * from "./src/index";
|
||||||
|
import "./plugins/flow";
|
||||||
|
import "./plugins/jsx";
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "acorn",
|
"name": "acorn",
|
||||||
"description": "ECMAScript parser",
|
"description": "ECMAScript parser",
|
||||||
"homepage": "https://github.com/marijnh/acorn",
|
"homepage": "https://github.com/marijnh/acorn",
|
||||||
"main": "src/index.js",
|
"main": "index.js",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.4.0"
|
"node": ">=0.4.0"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
var acorn = require("..")
|
var acorn = require("../src/index")
|
||||||
|
|
||||||
var pp = acorn.Parser.prototype
|
var pp = acorn.Parser.prototype
|
||||||
var tt = acorn.tokTypes
|
var tt = acorn.tokTypes
|
||||||
@@ -322,7 +322,7 @@ pp.flow_parseObjectType = function (allowStatic) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pp.flow_objectTypeSemicolon = function () {
|
pp.flow_objectTypeSemicolon = function () {
|
||||||
if (!this.eat(tt.semi) && this.type !== tt.braceR) {
|
if (!this.eat(tt.semi) && !this.eat(tt.comma) && this.type !== tt.braceR) {
|
||||||
this.unexpected()
|
this.unexpected()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
var acorn = require("..")
|
var acorn = require("../src/index")
|
||||||
|
|
||||||
var tt = acorn.tokTypes;
|
var tt = acorn.tokTypes;
|
||||||
var tc = acorn.tokContexts;
|
var tc = acorn.tokContexts;
|
||||||
|
|||||||
@@ -93,19 +93,25 @@ pp.parseMaybeAssign = function(noIn, refShorthandDefaultPos, afterLeftParse) {
|
|||||||
failOnShorthandAssign = false
|
failOnShorthandAssign = false
|
||||||
}
|
}
|
||||||
let start = this.markPosition()
|
let start = this.markPosition()
|
||||||
|
if (this.type == tt.parenL || this.type == tt.name)
|
||||||
|
this.potentialArrowAt = this.start
|
||||||
let left = this.parseMaybeConditional(noIn, refShorthandDefaultPos)
|
let left = this.parseMaybeConditional(noIn, refShorthandDefaultPos)
|
||||||
if (afterLeftParse) left = afterLeftParse.call(this, left, start)
|
if (afterLeftParse) left = afterLeftParse.call(this, left, start)
|
||||||
if (this.type.isAssign) {
|
if (this.type.isAssign) {
|
||||||
let node = this.startNodeAt(start)
|
let node = this.startNodeAt(start)
|
||||||
node.operator = this.value
|
node.operator = this.value
|
||||||
node.left = this.type === tt.eq ? this.toAssignable(left) : left
|
node.left = this.type === tt.eq ? this.toAssignable(left) : left
|
||||||
refShorthandDefaultPos.start = 0; // reset because shorthand default was used correctly
|
refShorthandDefaultPos.start = 0 // reset because shorthand default was used correctly
|
||||||
this.checkLVal(left)
|
this.checkLVal(left)
|
||||||
if (left.parenthesizedExpression) {
|
if (left.parenthesizedExpression) {
|
||||||
|
let errorMsg
|
||||||
if (left.type === "ObjectPattern") {
|
if (left.type === "ObjectPattern") {
|
||||||
this.raise(left.start, "You're trying to assign to a parenthesized expression, instead of `({ foo }) = {}` use `({ foo } = {})`");
|
errorMsg = "`({a}) = 0` use `({a} = 0)`"
|
||||||
} else {
|
} else if (left.type === "ArrayPattern") {
|
||||||
this.raise(left.start, "Parenthesized left hand expressions are illegal");
|
errorMsg = "`([a]) = 0` use `([a] = 0)`"
|
||||||
|
}
|
||||||
|
if (errorMsg) {
|
||||||
|
this.raise(left.start, `You're trying to assign to a parenthesized expression, eg. instead of ${errorMsg}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.next()
|
this.next()
|
||||||
@@ -224,7 +230,7 @@ pp.parseSubscripts = function(base, start, noCalls) {
|
|||||||
} else if (!noCalls && this.eat(tt.parenL)) {
|
} else if (!noCalls && this.eat(tt.parenL)) {
|
||||||
let node = this.startNodeAt(start)
|
let node = this.startNodeAt(start)
|
||||||
node.callee = base
|
node.callee = base
|
||||||
node.arguments = this.parseExprList(tt.parenR, false)
|
node.arguments = this.parseExprList(tt.parenR, this.options.features["es7.trailingFunctionCommas"])
|
||||||
return this.parseSubscripts(this.finishNode(node, "CallExpression"), start, noCalls)
|
return this.parseSubscripts(this.finishNode(node, "CallExpression"), start, noCalls)
|
||||||
} else if (this.type === tt.backQuote) {
|
} else if (this.type === tt.backQuote) {
|
||||||
let node = this.startNodeAt(start)
|
let node = this.startNodeAt(start)
|
||||||
@@ -240,7 +246,7 @@ pp.parseSubscripts = function(base, start, noCalls) {
|
|||||||
// or `{}`.
|
// or `{}`.
|
||||||
|
|
||||||
pp.parseExprAtom = function(refShorthandDefaultPos) {
|
pp.parseExprAtom = function(refShorthandDefaultPos) {
|
||||||
let node
|
let node, canBeArrow = this.potentialArrowAt == this.start
|
||||||
switch (this.type) {
|
switch (this.type) {
|
||||||
case tt._this:
|
case tt._this:
|
||||||
case tt._super:
|
case tt._super:
|
||||||
@@ -250,7 +256,7 @@ pp.parseExprAtom = function(refShorthandDefaultPos) {
|
|||||||
return this.finishNode(node, type)
|
return this.finishNode(node, type)
|
||||||
|
|
||||||
case tt._yield:
|
case tt._yield:
|
||||||
if (this.inGenerator) unexpected()
|
if (this.inGenerator) this.unexpected()
|
||||||
|
|
||||||
case tt._do:
|
case tt._do:
|
||||||
if (this.options.features["es7.doExpressions"]) {
|
if (this.options.features["es7.doExpressions"]) {
|
||||||
@@ -271,7 +277,7 @@ pp.parseExprAtom = function(refShorthandDefaultPos) {
|
|||||||
if (id.name === "async") {
|
if (id.name === "async") {
|
||||||
// arrow functions
|
// arrow functions
|
||||||
if (this.type === tt.parenL) {
|
if (this.type === tt.parenL) {
|
||||||
let expr = this.parseParenAndDistinguishExpression(start, true)
|
let expr = this.parseParenAndDistinguishExpression(start, true, true)
|
||||||
if (expr && expr.type === "ArrowFunctionExpression") {
|
if (expr && expr.type === "ArrowFunctionExpression") {
|
||||||
return expr
|
return expr
|
||||||
} else {
|
} else {
|
||||||
@@ -302,9 +308,8 @@ pp.parseExprAtom = function(refShorthandDefaultPos) {
|
|||||||
}
|
}
|
||||||
//
|
//
|
||||||
|
|
||||||
if (!this.canInsertSemicolon() && this.eat(tt.arrow)) {
|
if (canBeArrow && !this.canInsertSemicolon() && this.eat(tt.arrow))
|
||||||
return this.parseArrowExpression(this.startNodeAt(start), [id])
|
return this.parseArrowExpression(this.startNodeAt(start), [id])
|
||||||
}
|
|
||||||
return id
|
return id
|
||||||
|
|
||||||
case tt.regexp:
|
case tt.regexp:
|
||||||
@@ -324,7 +329,7 @@ pp.parseExprAtom = function(refShorthandDefaultPos) {
|
|||||||
return this.finishNode(node, "Literal")
|
return this.finishNode(node, "Literal")
|
||||||
|
|
||||||
case tt.parenL:
|
case tt.parenL:
|
||||||
return this.parseParenAndDistinguishExpression()
|
return this.parseParenAndDistinguishExpression(null, null, canBeArrow)
|
||||||
|
|
||||||
case tt.bracketL:
|
case tt.bracketL:
|
||||||
node = this.startNode()
|
node = this.startNode()
|
||||||
@@ -378,7 +383,7 @@ pp.parseParenExpression = function() {
|
|||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
pp.parseParenAndDistinguishExpression = function(start, isAsync) {
|
pp.parseParenAndDistinguishExpression = function(start, isAsync, canBeArrow) {
|
||||||
start = start || this.markPosition()
|
start = start || this.markPosition()
|
||||||
let val
|
let val
|
||||||
if (this.options.ecmaVersion >= 6) {
|
if (this.options.ecmaVersion >= 6) {
|
||||||
@@ -407,7 +412,7 @@ pp.parseParenAndDistinguishExpression = function(start, isAsync) {
|
|||||||
let innerEnd = this.markPosition()
|
let innerEnd = this.markPosition()
|
||||||
this.expect(tt.parenR)
|
this.expect(tt.parenR)
|
||||||
|
|
||||||
if (!this.canInsertSemicolon() && this.eat(tt.arrow)) {
|
if (canBeArrow && !this.canInsertSemicolon() && this.eat(tt.arrow)) {
|
||||||
if (innerParenStart) this.unexpected(innerParenStart)
|
if (innerParenStart) this.unexpected(innerParenStart)
|
||||||
return this.parseParenArrowList(start, exprList, isAsync)
|
return this.parseParenArrowList(start, exprList, isAsync)
|
||||||
}
|
}
|
||||||
@@ -508,14 +513,21 @@ pp.parseTemplate = function() {
|
|||||||
pp.parseObj = function(isPattern, refShorthandDefaultPos) {
|
pp.parseObj = function(isPattern, refShorthandDefaultPos) {
|
||||||
let node = this.startNode(), first = true, propHash = {}
|
let node = this.startNode(), first = true, propHash = {}
|
||||||
node.properties = []
|
node.properties = []
|
||||||
|
let decorators = []
|
||||||
this.next()
|
this.next()
|
||||||
while (!this.eat(tt.braceR)) {
|
while (!this.eat(tt.braceR)) {
|
||||||
if (!first) {
|
if (!first) {
|
||||||
this.expect(tt.comma)
|
this.expect(tt.comma)
|
||||||
if (this.afterTrailingComma(tt.braceR)) break
|
if (this.afterTrailingComma(tt.braceR)) break
|
||||||
} else first = false
|
} else first = false
|
||||||
|
while (this.type === tt.at) {
|
||||||
|
decorators.push(this.parseDecorator())
|
||||||
|
}
|
||||||
let prop = this.startNode(), isGenerator = false, isAsync = false, start
|
let prop = this.startNode(), isGenerator = false, isAsync = false, start
|
||||||
|
if (decorators.length) {
|
||||||
|
prop.decorators = decorators
|
||||||
|
decorators = []
|
||||||
|
}
|
||||||
if (this.options.features["es7.objectRestSpread"] && this.type === tt.ellipsis) {
|
if (this.options.features["es7.objectRestSpread"] && this.type === tt.ellipsis) {
|
||||||
prop = this.parseSpread()
|
prop = this.parseSpread()
|
||||||
prop.type = "SpreadProperty"
|
prop.type = "SpreadProperty"
|
||||||
@@ -546,6 +558,9 @@ pp.parseObj = function(isPattern, refShorthandDefaultPos) {
|
|||||||
this.checkPropClash(prop, propHash)
|
this.checkPropClash(prop, propHash)
|
||||||
node.properties.push(this.finishNode(prop, "Property"))
|
node.properties.push(this.finishNode(prop, "Property"))
|
||||||
}
|
}
|
||||||
|
if (decorators.length) {
|
||||||
|
this.raise(this.start, "You have trailing decorators with no property");
|
||||||
|
}
|
||||||
return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
|
return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -726,7 +741,7 @@ pp.parseAwait = function (node) {
|
|||||||
this.unexpected()
|
this.unexpected()
|
||||||
}
|
}
|
||||||
node.all = this.eat(tt.star)
|
node.all = this.eat(tt.star)
|
||||||
node.argument = this.parseMaybeAssign(true)
|
node.argument = this.parseMaybeUnary()
|
||||||
return this.finishNode(node, "AwaitExpression")
|
return this.finishNode(node, "AwaitExpression")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -9,41 +9,9 @@
|
|||||||
|
|
||||||
function makePredicate(words) {
|
function makePredicate(words) {
|
||||||
words = words.split(" ")
|
words = words.split(" ")
|
||||||
let f = "", cats = []
|
return function(str) {
|
||||||
out: for (let i = 0; i < words.length; ++i) {
|
return words.indexOf(str) >= 0
|
||||||
for (let j = 0; j < cats.length; ++j)
|
|
||||||
if (cats[j][0].length == words[i].length) {
|
|
||||||
cats[j].push(words[i])
|
|
||||||
continue out
|
|
||||||
}
|
|
||||||
cats.push([words[i]])
|
|
||||||
}
|
}
|
||||||
function compareTo(arr) {
|
|
||||||
if (arr.length == 1) return f += "return str === " + JSON.stringify(arr[0]) + ";"
|
|
||||||
f += "switch(str){"
|
|
||||||
for (let i = 0; i < arr.length; ++i) f += "case " + JSON.stringify(arr[i]) + ":"
|
|
||||||
f += "return true}return false;"
|
|
||||||
}
|
|
||||||
|
|
||||||
// When there are more than three length categories, an outer
|
|
||||||
// switch first dispatches on the lengths, to save on comparisons.
|
|
||||||
|
|
||||||
if (cats.length > 3) {
|
|
||||||
cats.sort((a, b) => b.length - a.length)
|
|
||||||
f += "switch(str.length){"
|
|
||||||
for (let i = 0; i < cats.length; ++i) {
|
|
||||||
let cat = cats[i]
|
|
||||||
f += "case " + cat[0].length + ":"
|
|
||||||
compareTo(cat)
|
|
||||||
}
|
|
||||||
f += "}"
|
|
||||||
|
|
||||||
// Otherwise, simply generate a flat `switch` statement.
|
|
||||||
|
|
||||||
} else {
|
|
||||||
compareTo(words)
|
|
||||||
}
|
|
||||||
return new Function("str", f)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reserved word lists for various dialects of the language
|
// Reserved word lists for various dialects of the language
|
||||||
|
|||||||
@@ -38,9 +38,6 @@ export {isIdentifierChar, isIdentifierStart} from "./identifier"
|
|||||||
export {Token} from "./tokenize"
|
export {Token} from "./tokenize"
|
||||||
export {isNewLine, lineBreak, lineBreakG} from "./whitespace"
|
export {isNewLine, lineBreak, lineBreakG} from "./whitespace"
|
||||||
|
|
||||||
import "../plugins/flow";
|
|
||||||
import "../plugins/jsx";
|
|
||||||
|
|
||||||
export const version = "1.0.0"
|
export const version = "1.0.0"
|
||||||
|
|
||||||
// The main exported interface (under `self.acorn` when in the
|
// The main exported interface (under `self.acorn` when in the
|
||||||
|
|||||||
@@ -18,17 +18,19 @@ var STATE_KEYS = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
pp.getState = function () {
|
pp.getState = function () {
|
||||||
var state = {};
|
var state = {}
|
||||||
for (var i = 0; i < STATE_KEYS.length; i++) {
|
for (var i = 0; i < STATE_KEYS.length; i++) {
|
||||||
var key = STATE_KEYS[i];
|
var key = STATE_KEYS[i]
|
||||||
state[key] = this[key];
|
state[key] = this[key]
|
||||||
}
|
}
|
||||||
return state;
|
return state
|
||||||
};
|
};
|
||||||
|
|
||||||
pp.lookahead = function() {
|
pp.lookahead = function() {
|
||||||
var old = this.getState();
|
var old = this.getState();
|
||||||
this.next();
|
this.isLookahead = true
|
||||||
|
this.next()
|
||||||
|
this.isLookahead = false
|
||||||
var curr = this.getState();
|
var curr = this.getState();
|
||||||
for (var key in old) this[key] = old[key];
|
for (var key in old) this[key] = old[key];
|
||||||
return curr;
|
return curr;
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ pp.toAssignable = function(node, isBinding) {
|
|||||||
node.type = "ObjectPattern"
|
node.type = "ObjectPattern"
|
||||||
for (let i = 0; i < node.properties.length; i++) {
|
for (let i = 0; i < node.properties.length; i++) {
|
||||||
let prop = node.properties[i]
|
let prop = node.properties[i]
|
||||||
|
if (prop.type === "SpreadProperty") continue;
|
||||||
if (prop.kind !== "init") this.raise(prop.key.start, "Object pattern can't contain getter or setter")
|
if (prop.kind !== "init") this.raise(prop.key.start, "Object pattern can't contain getter or setter")
|
||||||
this.toAssignable(prop.value, isBinding)
|
this.toAssignable(prop.value, isBinding)
|
||||||
}
|
}
|
||||||
@@ -125,7 +126,9 @@ pp.parseBindingList = function(close, allowEmpty, allowTrailingComma) {
|
|||||||
this.expect(close)
|
this.expect(close)
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
elts.push(this.parseAssignableListItemTypes(this.parseMaybeDefault()))
|
var left = this.parseMaybeDefault()
|
||||||
|
this.parseAssignableListItemTypes(left)
|
||||||
|
elts.push(this.parseMaybeDefault(null, left))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return elts
|
return elts
|
||||||
|
|||||||
@@ -46,6 +46,9 @@ export function Parser(options, input, startPos) {
|
|||||||
this.inModule = this.options.sourceType === "module"
|
this.inModule = this.options.sourceType === "module"
|
||||||
this.strict = this.options.strictMode === false ? false : this.inModule
|
this.strict = this.options.strictMode === false ? false : this.inModule
|
||||||
|
|
||||||
|
// Used to signify the start of a potential arrow function
|
||||||
|
this.potentialArrowAt = -1
|
||||||
|
|
||||||
// Flags to track whether we are in a function, a generator.
|
// Flags to track whether we are in a function, a generator.
|
||||||
this.inFunction = this.inGenerator = false
|
this.inFunction = this.inGenerator = false
|
||||||
// Labels in scope.
|
// Labels in scope.
|
||||||
|
|||||||
@@ -458,7 +458,7 @@ pp.parseFunction = function(node, isStatement, allowExpressionBody, isAsync) {
|
|||||||
|
|
||||||
pp.parseFunctionParams = function(node) {
|
pp.parseFunctionParams = function(node) {
|
||||||
this.expect(tt.parenL)
|
this.expect(tt.parenL)
|
||||||
node.params = this.parseBindingList(tt.parenR, false, false)
|
node.params = this.parseBindingList(tt.parenR, false, this.options.features["es7.trailingFunctionCommas"])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse a class declaration or literal (depending on the
|
// Parse a class declaration or literal (depending on the
|
||||||
@@ -471,14 +471,18 @@ pp.parseClass = function(node, isStatement) {
|
|||||||
var classBody = this.startNode()
|
var classBody = this.startNode()
|
||||||
classBody.body = []
|
classBody.body = []
|
||||||
this.expect(tt.braceL)
|
this.expect(tt.braceL)
|
||||||
|
let decorators = []
|
||||||
while (!this.eat(tt.braceR)) {
|
while (!this.eat(tt.braceR)) {
|
||||||
if (this.eat(tt.semi)) continue
|
if (this.eat(tt.semi)) continue
|
||||||
if (this.type === tt.at) {
|
if (this.type === tt.at) {
|
||||||
this.decorators.push(this.parseDecorator())
|
decorators.push(this.parseDecorator())
|
||||||
continue;
|
continue
|
||||||
}
|
}
|
||||||
var method = this.startNode()
|
var method = this.startNode()
|
||||||
this.takeDecorators(method)
|
if (decorators.length) {
|
||||||
|
method.decorators = decorators
|
||||||
|
decorators = []
|
||||||
|
}
|
||||||
var isGenerator = this.eat(tt.star), isAsync = false
|
var isGenerator = this.eat(tt.star), isAsync = false
|
||||||
this.parsePropertyName(method)
|
this.parsePropertyName(method)
|
||||||
if (this.type !== tt.parenL && !method.computed && method.key.type === "Identifier" &&
|
if (this.type !== tt.parenL && !method.computed && method.key.type === "Identifier" &&
|
||||||
@@ -517,7 +521,7 @@ pp.parseClass = function(node, isStatement) {
|
|||||||
}
|
}
|
||||||
this.parseClassMethod(classBody, method, isGenerator, isAsync)
|
this.parseClassMethod(classBody, method, isGenerator, isAsync)
|
||||||
}
|
}
|
||||||
if (this.decorators.length) {
|
if (decorators.length) {
|
||||||
this.raise(this.start, "You have trailing decorators with no method");
|
this.raise(this.start, "You have trailing decorators with no method");
|
||||||
}
|
}
|
||||||
node.body = this.finishNode(classBody, "ClassBody")
|
node.body = this.finishNode(classBody, "ClassBody")
|
||||||
@@ -687,7 +691,6 @@ pp.parseImport = function(node) {
|
|||||||
if (this.type === tt.string) {
|
if (this.type === tt.string) {
|
||||||
node.specifiers = empty
|
node.specifiers = empty
|
||||||
node.source = this.parseExprAtom()
|
node.source = this.parseExprAtom()
|
||||||
node.kind = ""
|
|
||||||
} else {
|
} else {
|
||||||
node.specifiers = []
|
node.specifiers = []
|
||||||
this.parseImportSpecifiers(node)
|
this.parseImportSpecifiers(node)
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ const pp = Parser.prototype
|
|||||||
// Move to the next token
|
// Move to the next token
|
||||||
|
|
||||||
pp.next = function() {
|
pp.next = function() {
|
||||||
if (this.options.onToken)
|
if (this.options.onToken && !this.isLookahead)
|
||||||
this.options.onToken(new Token(this))
|
this.options.onToken(new Token(this))
|
||||||
|
|
||||||
this.lastTokEnd = this.end
|
this.lastTokEnd = this.end
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ kw("do", {isLoop: true})
|
|||||||
kw("else", beforeExpr)
|
kw("else", beforeExpr)
|
||||||
kw("finally")
|
kw("finally")
|
||||||
kw("for", {isLoop: true})
|
kw("for", {isLoop: true})
|
||||||
kw("function")
|
kw("function", startsExpr)
|
||||||
kw("if")
|
kw("if")
|
||||||
kw("return", beforeExpr)
|
kw("return", beforeExpr)
|
||||||
kw("switch")
|
kw("switch")
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ transform.run = function (code, opts = {}) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
transform.load = function (url, callback, opts = {}, hold) {
|
transform.load = function (url, callback, opts = {}, hold) {
|
||||||
opts.filename ||= url;
|
opts.filename = opts.filename || url;
|
||||||
|
|
||||||
var xhr = global.ActiveXObject ? new global.ActiveXObject("Microsoft.XMLHTTP") : new global.XMLHttpRequest();
|
var xhr = global.ActiveXObject ? new global.ActiveXObject("Microsoft.XMLHTTP") : new global.XMLHttpRequest();
|
||||||
xhr.open("GET", url, true);
|
xhr.open("GET", url, true);
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ import * as acorn from "../../acorn";
|
|||||||
import * as util from "../util";
|
import * as util from "../util";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
|
||||||
export { util, acorn };
|
export { util, acorn, transform };
|
||||||
export { canCompile } from "../util";
|
export { canCompile } from "../util";
|
||||||
|
|
||||||
export { default as options } from "../transformation/file/options";
|
export { default as options } from "../transformation/file/options";
|
||||||
export { default as Transformer } from "../transformation/transformer";
|
export { default as Transformer } from "../transformation/transformer";
|
||||||
export { default as transform } from "../transformation";
|
export { default as Pipeline } from "../transformation/transformer-pipeline";
|
||||||
export { default as traverse } from "../traversal";
|
export { default as traverse } from "../traversal";
|
||||||
export { default as buildExternalHelpers } from "../tools/build-external-helpers";
|
export { default as buildExternalHelpers } from "../tools/build-external-helpers";
|
||||||
export { version } from "../../../package";
|
export { version } from "../../../package";
|
||||||
@@ -18,7 +18,7 @@ import * as t from "../types";
|
|||||||
export { t as types };
|
export { t as types };
|
||||||
|
|
||||||
export function register(opts?: Object) {
|
export function register(opts?: Object) {
|
||||||
var callback = require("./register/node");
|
var callback = require("./register/node-polyfill");
|
||||||
if (opts != null) callback(opts);
|
if (opts != null) callback(opts);
|
||||||
return callback;
|
return callback;
|
||||||
}
|
}
|
||||||
@@ -54,3 +54,19 @@ export function transformFileSync(filename: string, opts?: Object = {}) {
|
|||||||
opts.filename = filename;
|
opts.filename = filename;
|
||||||
return transform(fs.readFileSync(filename), opts);
|
return transform(fs.readFileSync(filename), opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function parse(code, opts = {}) {
|
||||||
|
opts.sourceType = "module";
|
||||||
|
opts.ecmaVersion = Infinity;
|
||||||
|
opts.plugins = {
|
||||||
|
flow: true,
|
||||||
|
jsx: true
|
||||||
|
};
|
||||||
|
opts.features = {};
|
||||||
|
|
||||||
|
for (var key in transform.transformers) {
|
||||||
|
opts.features[key] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return acorn.parse(code, opts);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import os from "os";
|
import os from "os";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
import userHome from "user-home";
|
||||||
|
|
||||||
function getUserHome() {
|
const FILENAME = process.env.BABEL_CACHE_PATH || path.join(userHome || os.tmpdir(), ".babel.json");
|
||||||
return process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE;
|
|
||||||
}
|
|
||||||
|
|
||||||
const FILENAME = process.env.BABEL_CACHE_PATH || path.join(getUserHome() || os.tmpdir(), ".babel.json");
|
|
||||||
var data = {};
|
var data = {};
|
||||||
|
|
||||||
export function save() {
|
export function save() {
|
||||||
|
|||||||
2
src/babel/api/register/node-polyfill.js
Normal file
2
src/babel/api/register/node-polyfill.js
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
import "../../polyfill";
|
||||||
|
export { default } from "./node";
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import "../../polyfill";
|
|
||||||
import sourceMapSupport from "source-map-support";
|
import sourceMapSupport from "source-map-support";
|
||||||
import * as registerCache from "./cache";
|
import * as registerCache from "./cache";
|
||||||
import resolveRc from "../../tools/resolve-rc";
|
import resolveRc from "../../tools/resolve-rc";
|
||||||
@@ -7,6 +6,7 @@ import * as babel from "../node";
|
|||||||
import each from "lodash/collection/each";
|
import each from "lodash/collection/each";
|
||||||
import * as util from "../../util";
|
import * as util from "../../util";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
import slash from "slash";
|
||||||
|
|
||||||
sourceMapSupport.install({
|
sourceMapSupport.install({
|
||||||
handleUncaughtExceptions: false,
|
handleUncaughtExceptions: false,
|
||||||
@@ -31,8 +31,10 @@ var cache = registerCache.get();
|
|||||||
//
|
//
|
||||||
|
|
||||||
var transformOpts = {};
|
var transformOpts = {};
|
||||||
var ignoreRegex = /node_modules/;
|
|
||||||
var onlyRegex;
|
var ignore;
|
||||||
|
var only;
|
||||||
|
|
||||||
var oldHandlers = {};
|
var oldHandlers = {};
|
||||||
var maps = {};
|
var maps = {};
|
||||||
|
|
||||||
@@ -76,7 +78,11 @@ var compile = function (filename) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var shouldIgnore = function (filename) {
|
var shouldIgnore = function (filename) {
|
||||||
return (ignoreRegex && ignoreRegex.test(filename)) || (onlyRegex && !onlyRegex.test(filename));
|
if (!ignore && !only) {
|
||||||
|
return /node_modules/.test(filename);
|
||||||
|
} else {
|
||||||
|
return util.shouldIgnore(filename, ignore || [], only || []);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var istanbulMonkey = {};
|
var istanbulMonkey = {};
|
||||||
@@ -142,8 +148,8 @@ var hookExtensions = function (_exts) {
|
|||||||
hookExtensions(util.canCompile.EXTENSIONS);
|
hookExtensions(util.canCompile.EXTENSIONS);
|
||||||
|
|
||||||
export default function (opts = {}) {
|
export default function (opts = {}) {
|
||||||
if (opts.only != null) onlyRegex = util.regexify(opts.only);
|
if (opts.only != null) only = util.arrayify(opts.only, util.regexify);
|
||||||
if (opts.ignore != null) ignoreRegex = util.regexify(opts.ignore);
|
if (opts.ignore != null) ignore = util.arrayify(opts.ignore, util.regexify);
|
||||||
|
|
||||||
if (opts.extensions) hookExtensions(util.arrayify(opts.extensions));
|
if (opts.extensions) hookExtensions(util.arrayify(opts.extensions));
|
||||||
|
|
||||||
@@ -156,16 +162,3 @@ export default function (opts = {}) {
|
|||||||
|
|
||||||
extend(transformOpts, opts);
|
extend(transformOpts, opts);
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
try {
|
|
||||||
var runtimePackage = require("babel-runtime/package");
|
|
||||||
var version = require("../../../../package").version;
|
|
||||||
if (runtimePackage.version !== version) {
|
|
||||||
throw new ReferenceError(`The verison of babel-runtime of ${runtimePackage.runtime} that you have installed does not match the babel verison of ${version}`);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
if (err.code !== "MODULE_NOT_FOUND") throw err;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -70,14 +70,14 @@ export default class Buffer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
newline(i, removeLast) {
|
newline(i, removeLast) {
|
||||||
if (this.format.compact) return;
|
if (this.format.compact || this.format.retainLines) return;
|
||||||
|
|
||||||
if (this.format.concise) {
|
if (this.format.concise) {
|
||||||
this.space();
|
this.space();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
removeLast ||= false;
|
removeLast = removeLast || false;
|
||||||
|
|
||||||
if (isNumber(i)) {
|
if (isNumber(i)) {
|
||||||
i = Math.min(2, i);
|
i = Math.min(2, i);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export function BlockStatement(node, print) {
|
|||||||
this.push("{");
|
this.push("{");
|
||||||
this.newline();
|
this.newline();
|
||||||
print.sequence(node.body, { indent: true });
|
print.sequence(node.body, { indent: true });
|
||||||
this.removeLast("\n");
|
if (!this.format.retainLines) this.removeLast("\n");
|
||||||
this.rightBrace();
|
this.rightBrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -169,4 +169,8 @@ export function MemberExpression(node, print) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { MemberExpression as MetaProperty };
|
export function MetaProperty(node, print) {
|
||||||
|
print(node.meta);
|
||||||
|
this.push(".");
|
||||||
|
print(node.property);
|
||||||
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export function JSXElement(node, print) {
|
|||||||
this.indent();
|
this.indent();
|
||||||
each(node.children, (child) => {
|
each(node.children, (child) => {
|
||||||
if (t.isLiteral(child)) {
|
if (t.isLiteral(child)) {
|
||||||
this.push(child.value);
|
this.push(child.value, true);
|
||||||
} else {
|
} else {
|
||||||
print(child);
|
print(child);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,5 +75,16 @@ export function ArrowFunctionExpression(node, print) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.push(" => ");
|
this.push(" => ");
|
||||||
|
|
||||||
|
const bodyNeedsParens = t.isObjectExpression(node.body);
|
||||||
|
|
||||||
|
if (bodyNeedsParens) {
|
||||||
|
this.push("(");
|
||||||
|
}
|
||||||
|
|
||||||
print(node.body);
|
print(node.body);
|
||||||
|
|
||||||
|
if (bodyNeedsParens) {
|
||||||
|
this.push(")");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ export var ForInStatement = buildForXStatement("in");
|
|||||||
export var ForOfStatement = buildForXStatement("of");
|
export var ForOfStatement = buildForXStatement("of");
|
||||||
|
|
||||||
export function DoWhileStatement(node, print) {
|
export function DoWhileStatement(node, print) {
|
||||||
this.keyword("do");
|
this.push("do ");
|
||||||
print(node.body);
|
print(node.body);
|
||||||
this.space();
|
this.space();
|
||||||
this.keyword("while");
|
this.keyword("while");
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import * as t from "../types";
|
|||||||
|
|
||||||
class CodeGenerator {
|
class CodeGenerator {
|
||||||
constructor(ast, opts, code) {
|
constructor(ast, opts, code) {
|
||||||
opts ||= {};
|
opts = opts || {};
|
||||||
|
|
||||||
this.comments = ast.comments || [];
|
this.comments = ast.comments || [];
|
||||||
this.tokens = ast.tokens || [];
|
this.tokens = ast.tokens || [];
|
||||||
@@ -34,9 +34,10 @@ class CodeGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var format = {
|
var format = {
|
||||||
|
retainLines: opts.retainLines,
|
||||||
comments: opts.comments == null || opts.comments,
|
comments: opts.comments == null || opts.comments,
|
||||||
compact: opts.compact,
|
compact: opts.compact,
|
||||||
quotes: CodeGenerator.findCommonStringDelimeter(code, tokens),
|
quotes: CodeGenerator.findCommonStringDelimiter(code, tokens),
|
||||||
indent: {
|
indent: {
|
||||||
adjustMultilineComment: true,
|
adjustMultilineComment: true,
|
||||||
style: style,
|
style: style,
|
||||||
@@ -48,14 +49,14 @@ class CodeGenerator {
|
|||||||
format.compact = code.length > 100000; // 100KB
|
format.compact = code.length > 100000; // 100KB
|
||||||
|
|
||||||
if (format.compact) {
|
if (format.compact) {
|
||||||
console.error(messages.get("codeGeneratorDeopt", opts.filename, "100KB"));
|
console.error("[BABEL] " + messages.get("codeGeneratorDeopt", opts.filename, "100KB"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
static findCommonStringDelimeter(code, tokens) {
|
static findCommonStringDelimiter(code, tokens) {
|
||||||
var occurences = {
|
var occurences = {
|
||||||
single: 0,
|
single: 0,
|
||||||
double: 0
|
double: 0
|
||||||
@@ -146,6 +147,22 @@ class CodeGenerator {
|
|||||||
return print;
|
return print;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
catchUp(node, parent) {
|
||||||
|
// catch up to this nodes newline if we're behind
|
||||||
|
if (node.loc && this.format.retainLines && this.buffer.buf) {
|
||||||
|
var needsParens = false;
|
||||||
|
if (parent && this.position.line < node.loc.start.line && t.isTerminatorless(parent)) {
|
||||||
|
needsParens = true;
|
||||||
|
this._push("(");
|
||||||
|
}
|
||||||
|
while (this.position.line < node.loc.start.line) {
|
||||||
|
this._push("\n");
|
||||||
|
}
|
||||||
|
return needsParens;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
print(node, parent, opts = {}) {
|
print(node, parent, opts = {}) {
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
|
|
||||||
@@ -197,6 +214,8 @@ class CodeGenerator {
|
|||||||
|
|
||||||
this.printLeadingComments(node, parent);
|
this.printLeadingComments(node, parent);
|
||||||
|
|
||||||
|
var needsParensFromCatchup = this.catchUp(node, parent);
|
||||||
|
|
||||||
newline(true);
|
newline(true);
|
||||||
|
|
||||||
if (opts.before) opts.before();
|
if (opts.before) opts.before();
|
||||||
@@ -208,7 +227,7 @@ class CodeGenerator {
|
|||||||
this.newline();
|
this.newline();
|
||||||
this.dedent();
|
this.dedent();
|
||||||
}
|
}
|
||||||
if (needsParens) this.push(")");
|
if (needsParens || needsParensFromCatchup) this.push(")");
|
||||||
|
|
||||||
this.map.mark(node, "end");
|
this.map.mark(node, "end");
|
||||||
if (opts.after) opts.after();
|
if (opts.after) opts.after();
|
||||||
@@ -328,6 +347,8 @@ class CodeGenerator {
|
|||||||
|
|
||||||
if (skip) return;
|
if (skip) return;
|
||||||
|
|
||||||
|
this.catchUp(comment);
|
||||||
|
|
||||||
// whitespace before
|
// whitespace before
|
||||||
this.newline(this.whitespace.getNewlinesBefore(comment));
|
this.newline(this.whitespace.getNewlinesBefore(comment));
|
||||||
|
|
||||||
@@ -340,7 +361,6 @@ class CodeGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
if (comment.type === "Block" && this.format.indent.adjustMultilineComment) {
|
if (comment.type === "Block" && this.format.indent.adjustMultilineComment) {
|
||||||
var offset = comment.loc.start.column;
|
var offset = comment.loc.start.column;
|
||||||
if (offset) {
|
if (offset) {
|
||||||
@@ -356,8 +376,13 @@ class CodeGenerator {
|
|||||||
val = this.getIndent() + val;
|
val = this.getIndent() + val;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
// force a newline for line comments when retainLines is set in case the next printed node
|
||||||
|
// doesn't catch up
|
||||||
|
if (this.format.retainLines && comment.type === "Line") {
|
||||||
|
val += "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
this._push(val);
|
this._push(val);
|
||||||
|
|
||||||
// whitespace after
|
// whitespace after
|
||||||
|
|||||||
@@ -85,16 +85,7 @@ export default class Node {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t.isYieldExpression(parent) || t.isAwaitExpression(parent)) {
|
return t.isTerminatorless(parent);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (t.isContinueStatement(parent) || t.isBreakStatement(parent) ||
|
|
||||||
t.isReturnStatement(parent) || t.isThrowStatement(parent)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -171,4 +171,10 @@ export function ConditionalExpression(node, parent) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export { ConditionalExpression as AssignmentExpression };
|
export function AssignmentExpression(node) {
|
||||||
|
if (t.isObjectPattern(node.left)) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return ConditionalExpression(...arguments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ function crawl(node, state = {}) {
|
|||||||
} else if (t.isFunction(node)) {
|
} else if (t.isFunction(node)) {
|
||||||
state.hasFunction = true;
|
state.hasFunction = true;
|
||||||
} else if (t.isIdentifier(node)) {
|
} else if (t.isIdentifier(node)) {
|
||||||
state.hasHelper ||= isHelper(node.callee);
|
state.hasHelper = state.hasHelper || isHelper(node.callee);
|
||||||
}
|
}
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
|
|||||||
@@ -22,7 +22,19 @@ export const MESSAGES = {
|
|||||||
codeGeneratorDeopt: "Note: The code generator has deoptimised the styling of $1 as it exceeds the max of $2.",
|
codeGeneratorDeopt: "Note: The code generator has deoptimised the styling of $1 as it exceeds the max of $2.",
|
||||||
missingTemplatesDirectory: "no templates directory - this is most likely the result of a broken `npm publish`. Please report to https://github.com/babel/babel/issues",
|
missingTemplatesDirectory: "no templates directory - this is most likely the result of a broken `npm publish`. Please report to https://github.com/babel/babel/issues",
|
||||||
unsupportedOutputType: "Unsupported output type $1",
|
unsupportedOutputType: "Unsupported output type $1",
|
||||||
illegalMethodName: "Illegal method name $1"
|
illegalMethodName: "Illegal method name $1",
|
||||||
|
traverseNeedsParent: "Must pass a scope and parentPath unless traversing a Program/File got a $1 node",
|
||||||
|
traverseVerifyRootFunction: "You passed `traverse()` a function when it expected a visitor object, are you sure you didn't mean `{ enter: Function }`?",
|
||||||
|
traverseVerifyVisitorFunction: "Hey! You passed \`traverse()\` a visitor object with the key $1 that's a straight up `Function` instead of `{ enter: Function }`. You need to normalise it with `traverse.explode(visitor)`.",
|
||||||
|
traverseVerifyVisitorProperty: "You passed `traverse()` a visitor object with the property $1 that has the invalid property $2",
|
||||||
|
|
||||||
|
pluginIllegalKind: "Illegal kind $1 for plugin $2",
|
||||||
|
pluginIllegalPosition: "Illegal position $1 for plugin $2",
|
||||||
|
pluginKeyCollision: "The plugin $1 collides with another of the same name",
|
||||||
|
pluginNotTransformer: "The plugin $1 didn't export a Transformer instance",
|
||||||
|
pluginUnknown: "Unknown plugin $1",
|
||||||
|
|
||||||
|
transformerNotFile: "Transformer $1 is resolving to a different Babel version to what is doing the actual transformation..."
|
||||||
};
|
};
|
||||||
|
|
||||||
export function get(key: String, ...args) {
|
export function get(key: String, ...args) {
|
||||||
|
|||||||
@@ -7,15 +7,15 @@ import * as t from "./types";
|
|||||||
|
|
||||||
extend(estraverse.VisitorKeys, t.VISITOR_KEYS);
|
extend(estraverse.VisitorKeys, t.VISITOR_KEYS);
|
||||||
|
|
||||||
// regenerator-babel/ast-types
|
// regenerator/ast-types
|
||||||
|
|
||||||
var def = types.Type.def;
|
var def = types.Type.def;
|
||||||
var or = types.Type.or;
|
var or = types.Type.or;
|
||||||
|
|
||||||
def("File")
|
//def("File")
|
||||||
.bases("Node")
|
// .bases("Node")
|
||||||
.build("program")
|
// .build("program")
|
||||||
.field("program", def("Program"));
|
// .field("program", def("Program"));
|
||||||
|
|
||||||
def("AssignmentPattern")
|
def("AssignmentPattern")
|
||||||
.bases("Pattern")
|
.bases("Pattern")
|
||||||
@@ -55,4 +55,18 @@ def("ExportNamedDeclaration")
|
|||||||
)])
|
)])
|
||||||
.field("source", or(def("ModuleSpecifier"), null));
|
.field("source", or(def("ModuleSpecifier"), null));
|
||||||
|
|
||||||
|
def("ExportNamespaceSpecifier")
|
||||||
|
.bases("Specifier")
|
||||||
|
.field("exported", def("Identifier"));
|
||||||
|
|
||||||
|
def("ExportDefaultSpecifier")
|
||||||
|
.bases("Specifier")
|
||||||
|
.field("exported", def("Identifier"));
|
||||||
|
|
||||||
|
def("ExportAllDeclaration")
|
||||||
|
.bases("Declaration")
|
||||||
|
.build("exported", "source")
|
||||||
|
.field("exported", def("Identifier"))
|
||||||
|
.field("source", def("Literal"));
|
||||||
|
|
||||||
types.finalize();
|
types.finalize();
|
||||||
|
|||||||
@@ -4,4 +4,4 @@ if (global._babelPolyfill) {
|
|||||||
global._babelPolyfill = true;
|
global._babelPolyfill = true;
|
||||||
|
|
||||||
import "core-js/shim";
|
import "core-js/shim";
|
||||||
import "regenerator-babel/runtime";
|
import "regenerator/runtime";
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import stripJsonComments from "strip-json-comments";
|
||||||
import merge from "lodash/object/merge";
|
import merge from "lodash/object/merge";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
@@ -16,24 +17,40 @@ function exists(filename) {
|
|||||||
export default function (loc, opts = {}) {
|
export default function (loc, opts = {}) {
|
||||||
var rel = ".babelrc";
|
var rel = ".babelrc";
|
||||||
|
|
||||||
|
if (!opts.babelrc) {
|
||||||
|
opts.babelrc = [];
|
||||||
|
}
|
||||||
|
|
||||||
function find(start, rel) {
|
function find(start, rel) {
|
||||||
var file = path.join(start, rel);
|
var file = path.join(start, rel);
|
||||||
|
|
||||||
|
if (opts.babelrc.indexOf(file) >= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (exists(file)) {
|
if (exists(file)) {
|
||||||
var content = fs.readFileSync(file, "utf8");
|
var content = fs.readFileSync(file, "utf8");
|
||||||
var json;
|
var json;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
json = jsons[content] ||= JSON.parse(content);
|
json = jsons[content] = jsons[content] || JSON.parse(stripJsonComments(content));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
err.message = `${file}: ${err.message}`;
|
err.message = `${file}: ${err.message}`;
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
opts.babelrc.push(file);
|
||||||
|
|
||||||
if (json.breakConfig) return;
|
if (json.breakConfig) return;
|
||||||
merge(opts, json, function(a, b) {
|
merge(opts, json, function(a, b) {
|
||||||
if (Array.isArray(a)) {
|
if (Array.isArray(a)) {
|
||||||
return a.concat(b);
|
var c = a.slice(0);
|
||||||
|
for (var v of b) {
|
||||||
|
if (a.indexOf(v) < 0) {
|
||||||
|
c.push(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -44,7 +61,9 @@ export default function (loc, opts = {}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
find(loc, rel);
|
if (opts.babelrc.indexOf(loc) < 0 && opts.breakConfig !== true) {
|
||||||
|
find(loc, rel);
|
||||||
|
}
|
||||||
|
|
||||||
return opts;
|
return opts;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import convertSourceMap from "convert-source-map";
|
import convertSourceMap from "convert-source-map";
|
||||||
import * as optionParsers from "./option-parsers";
|
import * as optionParsers from "./option-parsers";
|
||||||
|
import moduleFormatters from "../modules";
|
||||||
|
import PluginManager from "./plugin-manager";
|
||||||
import shebangRegex from "shebang-regex";
|
import shebangRegex from "shebang-regex";
|
||||||
import TraversalPath from "../../traversal/path";
|
import TraversalPath from "../../traversal/path";
|
||||||
import isFunction from "lodash/lang/isFunction";
|
import isFunction from "lodash/lang/isFunction";
|
||||||
@@ -16,39 +18,42 @@ import Logger from "./logger";
|
|||||||
import parse from "../../helpers/parse";
|
import parse from "../../helpers/parse";
|
||||||
import Scope from "../../traversal/scope";
|
import Scope from "../../traversal/scope";
|
||||||
import slash from "slash";
|
import slash from "slash";
|
||||||
|
import clone from "lodash/lang/clone";
|
||||||
import * as util from "../../util";
|
import * as util from "../../util";
|
||||||
|
import * as api from "../../api/node";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import each from "lodash/collection/each";
|
import each from "lodash/collection/each";
|
||||||
import * as t from "../../types";
|
import * as t from "../../types";
|
||||||
|
|
||||||
var checkTransformerVisitor = {
|
var checkTransformerVisitor = {
|
||||||
enter(node, parent, scope, state) {
|
exit(node, parent, scope, state) {
|
||||||
checkNode(state.stack, node, scope);
|
checkPath(state.stack, this);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function checkNode(stack, node, scope) {
|
function checkPath(stack, path) {
|
||||||
each(stack, function (pass) {
|
each(stack, function (pass) {
|
||||||
if (pass.shouldRun || pass.ran) return;
|
if (pass.shouldRun || pass.ran) return;
|
||||||
pass.checkNode(node, scope);
|
pass.checkPath(path);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class File {
|
export default class File {
|
||||||
constructor(opts = {}) {
|
constructor(opts = {}, pipeline) {
|
||||||
this.dynamicImportedNoDefault = [];
|
this.dynamicImportTypes = {};
|
||||||
this.dynamicImportIds = {};
|
this.dynamicImportIds = {};
|
||||||
this.dynamicImported = [];
|
this.dynamicImports = [];
|
||||||
this.dynamicImports = [];
|
|
||||||
|
|
||||||
this.usedHelpers = {};
|
this.declarations = {};
|
||||||
this.dynamicData = {};
|
this.usedHelpers = {};
|
||||||
this.data = {};
|
this.dynamicData = {};
|
||||||
|
this.data = {};
|
||||||
|
this.uids = {};
|
||||||
|
|
||||||
this.lastStatements = [];
|
this.pipeline = pipeline;
|
||||||
this.log = new Logger(this, opts.filename || "unknown");
|
this.log = new Logger(this, opts.filename || "unknown");
|
||||||
this.opts = this.normalizeOptions(opts);
|
this.opts = this.normalizeOptions(opts);
|
||||||
this.ast = {};
|
this.ast = {};
|
||||||
|
|
||||||
this.buildTransformers();
|
this.buildTransformers();
|
||||||
}
|
}
|
||||||
@@ -58,9 +63,10 @@ export default class File {
|
|||||||
"defaults",
|
"defaults",
|
||||||
"create-class",
|
"create-class",
|
||||||
"create-decorated-class",
|
"create-decorated-class",
|
||||||
|
"create-decorated-object",
|
||||||
|
"define-decorated-property-descriptor",
|
||||||
"tagged-template-literal",
|
"tagged-template-literal",
|
||||||
"tagged-template-literal-loose",
|
"tagged-template-literal-loose",
|
||||||
"interop-require",
|
|
||||||
"to-array",
|
"to-array",
|
||||||
"to-consumable-array",
|
"to-consumable-array",
|
||||||
"sliced-to-array",
|
"sliced-to-array",
|
||||||
@@ -72,6 +78,7 @@ export default class File {
|
|||||||
"define-property",
|
"define-property",
|
||||||
"async-to-generator",
|
"async-to-generator",
|
||||||
"interop-require-wildcard",
|
"interop-require-wildcard",
|
||||||
|
"interop-require-default",
|
||||||
"typeof",
|
"typeof",
|
||||||
"extends",
|
"extends",
|
||||||
"get",
|
"get",
|
||||||
@@ -81,7 +88,16 @@ export default class File {
|
|||||||
"temporal-undefined",
|
"temporal-undefined",
|
||||||
"temporal-assert-defined",
|
"temporal-assert-defined",
|
||||||
"self-global",
|
"self-global",
|
||||||
"default-props"
|
"default-props",
|
||||||
|
"instanceof",
|
||||||
|
|
||||||
|
// legacy
|
||||||
|
"interop-require",
|
||||||
|
];
|
||||||
|
|
||||||
|
static soloHelpers = [
|
||||||
|
"ludicrous-proxy-create",
|
||||||
|
"ludicrous-proxy-directory"
|
||||||
];
|
];
|
||||||
|
|
||||||
static options = require("./options");
|
static options = require("./options");
|
||||||
@@ -89,8 +105,10 @@ export default class File {
|
|||||||
normalizeOptions(opts: Object) {
|
normalizeOptions(opts: Object) {
|
||||||
opts = assign({}, opts);
|
opts = assign({}, opts);
|
||||||
|
|
||||||
if (opts.filename && isAbsolute(opts.filename)) {
|
if (opts.filename) {
|
||||||
opts = resolveRc(opts.filename, opts);
|
var rcFilename = opts.filename;
|
||||||
|
if (!isAbsolute(rcFilename)) rcFilename = path.join(process.cwd(), rcFilename);
|
||||||
|
opts = resolveRc(rcFilename, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -112,13 +130,15 @@ export default class File {
|
|||||||
throw new Error("Deprecated option " + key + ": " + option.deprecated);
|
throw new Error("Deprecated option " + key + ": " + option.deprecated);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (val == null) val = option.default || val;
|
if (val == null) {
|
||||||
|
val = clone(option.default);
|
||||||
|
}
|
||||||
|
|
||||||
var optionParser = optionParsers[option.type];
|
var optionParser = optionParsers[option.type];
|
||||||
if (optionParser) val = optionParser(key, val);
|
if (optionParser) val = optionParser(key, val, this.pipeline);
|
||||||
|
|
||||||
if (option.alias) {
|
if (option.alias) {
|
||||||
opts[option.alias] ||= val;
|
opts[option.alias] = opts[option.alias] || val;
|
||||||
} else {
|
} else {
|
||||||
opts[key] = val;
|
opts[key] = val;
|
||||||
}
|
}
|
||||||
@@ -182,7 +202,7 @@ export default class File {
|
|||||||
var stack = [];
|
var stack = [];
|
||||||
|
|
||||||
// build internal transformers
|
// build internal transformers
|
||||||
each(transform.transformers, function (transformer, key) {
|
each(this.pipeline.transformers, function (transformer, key) {
|
||||||
var pass = transformers[key] = transformer.buildPass(file);
|
var pass = transformers[key] = transformer.buildPass(file);
|
||||||
|
|
||||||
if (pass.canTransform()) {
|
if (pass.canTransform()) {
|
||||||
@@ -201,8 +221,14 @@ export default class File {
|
|||||||
// init plugins!
|
// init plugins!
|
||||||
var beforePlugins = [];
|
var beforePlugins = [];
|
||||||
var afterPlugins = [];
|
var afterPlugins = [];
|
||||||
|
var pluginManager = new PluginManager({
|
||||||
|
file: this,
|
||||||
|
transformers: this.transformers,
|
||||||
|
before: beforePlugins,
|
||||||
|
after: afterPlugins
|
||||||
|
});
|
||||||
for (var i = 0; i < file.opts.plugins.length; i++) {
|
for (var i = 0; i < file.opts.plugins.length; i++) {
|
||||||
this.addPlugin(file.opts.plugins[i], beforePlugins, afterPlugins);
|
pluginManager.add(file.opts.plugins[i]);
|
||||||
}
|
}
|
||||||
stack = beforePlugins.concat(stack, afterPlugins);
|
stack = beforePlugins.concat(stack, afterPlugins);
|
||||||
|
|
||||||
@@ -211,7 +237,7 @@ export default class File {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getModuleFormatter(type: string) {
|
getModuleFormatter(type: string) {
|
||||||
var ModuleFormatter = isFunction(type) ? type : transform.moduleFormatters[type];
|
var ModuleFormatter = isFunction(type) ? type : moduleFormatters[type];
|
||||||
|
|
||||||
if (!ModuleFormatter) {
|
if (!ModuleFormatter) {
|
||||||
var loc = util.resolveRelative(type);
|
var loc = util.resolveRelative(type);
|
||||||
@@ -225,57 +251,6 @@ export default class File {
|
|||||||
return new ModuleFormatter(this);
|
return new ModuleFormatter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
addPlugin(name, before, after) {
|
|
||||||
var position = "before";
|
|
||||||
var plugin;
|
|
||||||
|
|
||||||
if (name) {
|
|
||||||
if (typeof name === "string") {
|
|
||||||
// this is a plugin in the form of "foobar" or "foobar:after"
|
|
||||||
// where the optional colon is the delimiter for plugin position in the transformer stack
|
|
||||||
|
|
||||||
[name, position = "before"] = name.split(":");
|
|
||||||
|
|
||||||
var loc = util.resolveRelative(name) || util.resolveRelative(`babel-plugin-${name}`);
|
|
||||||
if (loc) {
|
|
||||||
plugin = require(loc)
|
|
||||||
} else {
|
|
||||||
throw new ReferenceError(`Unknown plugin ${JSON.stringify(name)}`);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// not a string so we'll just assume that it's a direct Transformer instance, if not then
|
|
||||||
// the checks later on will complain
|
|
||||||
plugin = name;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new TypeError(`Ilegal kind ${typeof name} for plugin name ${JSON.stringify(name)}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// validate position
|
|
||||||
if (position !== "before" && position !== "after") {
|
|
||||||
throw new TypeError(`Plugin ${JSON.stringify(name)} has an illegal position of ${JSON.stringify(position)}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// validate transformer key
|
|
||||||
var key = plugin.key;
|
|
||||||
if (this.transformers[key]) {
|
|
||||||
throw new ReferenceError(`The key for plugin ${JSON.stringify(name)} of ${key} collides with an existing plugin`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// validate Transformer instance
|
|
||||||
if (!plugin.buildPass || plugin.constructor.name !== "Transformer") {
|
|
||||||
throw new TypeError(`Plugin ${JSON.stringify(name)} didn't export default a Transformer instance`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// build!
|
|
||||||
var pass = this.transformers[key] = plugin.buildPass(this);
|
|
||||||
if (pass.canTransform()) {
|
|
||||||
var stack = before;
|
|
||||||
if (position === "after") stack = after;
|
|
||||||
stack.push(pass);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
parseInputSourceMap(code: string) {
|
parseInputSourceMap(code: string) {
|
||||||
var opts = this.opts;
|
var opts = this.opts;
|
||||||
|
|
||||||
@@ -329,8 +304,8 @@ export default class File {
|
|||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
addImport(source: string, name?: string, noDefault?: boolean): Object {
|
addImport(source: string, name?: string, type?: string): Object {
|
||||||
name ||= source;
|
name = name || source;
|
||||||
var id = this.dynamicImportIds[name];
|
var id = this.dynamicImportIds[name];
|
||||||
|
|
||||||
if (!id) {
|
if (!id) {
|
||||||
@@ -341,8 +316,10 @@ export default class File {
|
|||||||
var declar = t.importDeclaration(specifiers, t.literal(source));
|
var declar = t.importDeclaration(specifiers, t.literal(source));
|
||||||
declar._blockHoist = 3;
|
declar._blockHoist = 3;
|
||||||
|
|
||||||
this.dynamicImported.push(declar);
|
if (type) {
|
||||||
if (noDefault) this.dynamicImportedNoDefault.push(declar);
|
var modules = this.dynamicImportTypes[type] = this.dynamicImportTypes[type] || [];
|
||||||
|
modules.push(declar);
|
||||||
|
}
|
||||||
|
|
||||||
if (this.transformers["es6.modules"].canTransform()) {
|
if (this.transformers["es6.modules"].canTransform()) {
|
||||||
this.moduleFormatter.importSpecifier(specifiers[0], declar, this.dynamicImports);
|
this.moduleFormatter.importSpecifier(specifiers[0], declar, this.dynamicImports);
|
||||||
@@ -355,14 +332,10 @@ export default class File {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
isConsequenceExpressionStatement(node: Object): boolean {
|
|
||||||
return t.isExpressionStatement(node) && this.lastStatements.indexOf(node) >= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
attachAuxiliaryComment(node: Object): Object {
|
attachAuxiliaryComment(node: Object): Object {
|
||||||
var comment = this.opts.auxiliaryComment;
|
var comment = this.opts.auxiliaryComment;
|
||||||
if (comment) {
|
if (comment) {
|
||||||
node.leadingComments ||= [];
|
node.leadingComments = node.leadingComments || [];
|
||||||
node.leadingComments.push({
|
node.leadingComments.push({
|
||||||
type: "Line",
|
type: "Line",
|
||||||
value: " " + comment
|
value: " " + comment
|
||||||
@@ -372,35 +345,39 @@ export default class File {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addHelper(name: string): Object {
|
addHelper(name: string): Object {
|
||||||
if (!includes(File.helpers, name)) {
|
var isSolo = includes(File.soloHelpers, name);
|
||||||
|
|
||||||
|
if (!isSolo && !includes(File.helpers, name)) {
|
||||||
throw new ReferenceError(`Unknown helper ${name}`);
|
throw new ReferenceError(`Unknown helper ${name}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
var program = this.ast.program;
|
var program = this.ast.program;
|
||||||
|
|
||||||
var declar = program._declarations && program._declarations[name];
|
var declar = this.declarations[name];
|
||||||
if (declar) return declar.id;
|
if (declar) return declar;
|
||||||
|
|
||||||
this.usedHelpers[name] = true;
|
this.usedHelpers[name] = true;
|
||||||
|
|
||||||
var generator = this.get("helperGenerator");
|
if (!isSolo) {
|
||||||
var runtime = this.get("helpersNamespace");
|
var generator = this.get("helperGenerator");
|
||||||
if (generator) {
|
var runtime = this.get("helpersNamespace");
|
||||||
return generator(name);
|
if (generator) {
|
||||||
} else if (runtime) {
|
return generator(name);
|
||||||
var id = t.identifier(t.toIdentifier(name));
|
} else if (runtime) {
|
||||||
return t.memberExpression(runtime, id);
|
var id = t.identifier(t.toIdentifier(name));
|
||||||
} else {
|
return t.memberExpression(runtime, id);
|
||||||
var ref = util.template("helper-" + name);
|
}
|
||||||
ref._compact = true;
|
|
||||||
var uid = this.scope.generateUidIdentifier(name);
|
|
||||||
this.scope.push({
|
|
||||||
key: name,
|
|
||||||
id: uid,
|
|
||||||
init: ref
|
|
||||||
});
|
|
||||||
return uid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ref = util.template("helper-" + name);
|
||||||
|
ref._compact = true;
|
||||||
|
var uid = this.declarations[name] = this.scope.generateUidIdentifier(name);
|
||||||
|
this.scope.push({
|
||||||
|
id: uid,
|
||||||
|
init: ref,
|
||||||
|
unique: true
|
||||||
|
});
|
||||||
|
return uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
errorWithNode(node, msg, Error = SyntaxError) {
|
errorWithNode(node, msg, Error = SyntaxError) {
|
||||||
@@ -419,23 +396,7 @@ export default class File {
|
|||||||
|
|
||||||
shouldIgnore() {
|
shouldIgnore() {
|
||||||
var opts = this.opts;
|
var opts = this.opts;
|
||||||
|
return util.shouldIgnore(opts.filename, opts.ignore, opts.only);
|
||||||
var filename = opts.filename;
|
|
||||||
var ignore = opts.ignore;
|
|
||||||
var only = opts.only;
|
|
||||||
|
|
||||||
if (only.length) {
|
|
||||||
for (var i = 0; i < only.length; i++) {
|
|
||||||
if (only[i].test(filename)) return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else if (ignore.length) {
|
|
||||||
for (var i = 0; i < ignore.length; i++) {
|
|
||||||
if (ignore[i].test(filename)) return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parse(code: string) {
|
parse(code: string) {
|
||||||
@@ -471,9 +432,12 @@ export default class File {
|
|||||||
parseOpts.strictMode = features.strict;
|
parseOpts.strictMode = features.strict;
|
||||||
parseOpts.sourceType = "module";
|
parseOpts.sourceType = "module";
|
||||||
|
|
||||||
|
this.log.debug("Parse start");
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
return parse(parseOpts, code, (tree) => {
|
return parse(parseOpts, code, (tree) => {
|
||||||
|
this.log.debug("Parse stop");
|
||||||
this.transform(tree);
|
this.transform(tree);
|
||||||
return this.generate();
|
return this.generate();
|
||||||
});
|
});
|
||||||
@@ -496,25 +460,25 @@ export default class File {
|
|||||||
}
|
}
|
||||||
|
|
||||||
transform(ast) {
|
transform(ast) {
|
||||||
this.log.debug();
|
this.log.debug("Start set AST");
|
||||||
|
|
||||||
this.setAst(ast);
|
this.setAst(ast);
|
||||||
|
this.log.debug("End set AST");
|
||||||
|
|
||||||
this.lastStatements = t.getLastStatements(ast.program);
|
this.log.debug("Start prepass");
|
||||||
|
this.checkPath(this.path);
|
||||||
|
this.log.debug("End prepass");
|
||||||
|
|
||||||
|
this.log.debug("Start module formatter init");
|
||||||
var modFormatter = this.moduleFormatter = this.getModuleFormatter(this.opts.modules);
|
var modFormatter = this.moduleFormatter = this.getModuleFormatter(this.opts.modules);
|
||||||
if (modFormatter.init && this.transformers["es6.modules"].canTransform()) {
|
if (modFormatter.init && this.transformers["es6.modules"].canTransform()) {
|
||||||
modFormatter.init();
|
modFormatter.init();
|
||||||
}
|
}
|
||||||
|
this.log.debug("End module formatter init");
|
||||||
this.checkNode(ast);
|
|
||||||
|
|
||||||
this.call("pre");
|
this.call("pre");
|
||||||
|
|
||||||
each(this.transformerStack, function (pass) {
|
each(this.transformerStack, function (pass) {
|
||||||
pass.transform();
|
pass.transform();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.call("post");
|
this.call("post");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -527,20 +491,19 @@ export default class File {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
checkNode(node, scope) {
|
checkPath(path) {
|
||||||
if (Array.isArray(node)) {
|
if (Array.isArray(path)) {
|
||||||
for (var i = 0; i < node.length; i++) {
|
for (var i = 0; i < path.length; i++) {
|
||||||
this.checkNode(node[i], scope);
|
this.checkPath(path[i]);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var stack = this.transformerStack;
|
var stack = this.transformerStack;
|
||||||
scope ||= this.scope;
|
|
||||||
|
|
||||||
checkNode(stack, node, scope);
|
checkPath(stack, path);
|
||||||
|
|
||||||
scope.traverse(node, checkTransformerVisitor, {
|
path.traverse(checkTransformerVisitor, {
|
||||||
stack: stack
|
stack: stack
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -590,10 +553,14 @@ export default class File {
|
|||||||
if (opts.ast) result.ast = ast;
|
if (opts.ast) result.ast = ast;
|
||||||
if (!opts.code) return result;
|
if (!opts.code) return result;
|
||||||
|
|
||||||
|
this.log.debug("Generation start");
|
||||||
|
|
||||||
var _result = generate(ast, opts, this.code);
|
var _result = generate(ast, opts, this.code);
|
||||||
result.code = _result.code;
|
result.code = _result.code;
|
||||||
result.map = _result.map;
|
result.map = _result.map;
|
||||||
|
|
||||||
|
this.log.debug("Generation end");
|
||||||
|
|
||||||
if (this.shebang) {
|
if (this.shebang) {
|
||||||
// add back shebang
|
// add back shebang
|
||||||
result.code = `${this.shebang}\n${result.code}`;
|
result.code = `${this.shebang}\n${result.code}`;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ export default class Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_buildMessage(msg: string): string {
|
_buildMessage(msg: string): string {
|
||||||
var parts = this.filename;
|
var parts = `[BABEL] ${this.filename}`;
|
||||||
if (msg) parts += `: ${msg}`;
|
if (msg) parts += `: ${msg}`;
|
||||||
return parts;
|
return parts;
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,7 @@ export default class Logger {
|
|||||||
|
|
||||||
deprecate(msg) {
|
deprecate(msg) {
|
||||||
if (!this.file.opts.suppressDeprecationMessages) {
|
if (!this.file.opts.suppressDeprecationMessages) {
|
||||||
console.error(msg);
|
console.error(this._buildMessage(msg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
import transform from "./../index";
|
|
||||||
import * as util from "../../util";
|
import * as util from "../../util";
|
||||||
|
|
||||||
export function transformerList(key, val) {
|
export function transformerList(key, val, pipeline) {
|
||||||
val = util.arrayify(val);
|
val = util.arrayify(val);
|
||||||
|
|
||||||
if (val.indexOf("all") >= 0 || val.indexOf(true) >= 0) {
|
if (val.indexOf("all") >= 0 || val.indexOf(true) >= 0) {
|
||||||
val = Object.keys(transform.transformers);
|
val = Object.keys(pipeline.transformers);
|
||||||
}
|
}
|
||||||
|
|
||||||
return transform._ensureTransformerNames(key, val);
|
return pipeline._ensureTransformerNames(key, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function number(key, val) {
|
export function number(key, val) {
|
||||||
|
|||||||
@@ -15,11 +15,23 @@
|
|||||||
"hidden": true
|
"hidden": true
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"extra": {
|
||||||
|
"hidden": true,
|
||||||
|
"default": {}
|
||||||
|
},
|
||||||
|
|
||||||
"moduleId": {
|
"moduleId": {
|
||||||
"description": "specify a custom name for module ids",
|
"description": "specify a custom name for module ids",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"retainLines": {
|
||||||
|
"hidden": true,
|
||||||
|
"type": "boolean",
|
||||||
|
"default": false,
|
||||||
|
"description": "retain line numbers - will result in really ugly code"
|
||||||
|
},
|
||||||
|
|
||||||
"nonStandard": {
|
"nonStandard": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": true,
|
"default": true,
|
||||||
@@ -152,7 +164,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
"externalHelpers": {
|
"externalHelpers": {
|
||||||
"type": "string",
|
"type": "boolean",
|
||||||
"default": false,
|
"default": false,
|
||||||
"shorthand": "r",
|
"shorthand": "r",
|
||||||
"description": "uses a reference to `babelHelpers` instead of placing helpers at the top of your code."
|
"description": "uses a reference to `babelHelpers` instead of placing helpers at the top of your code."
|
||||||
@@ -194,5 +206,17 @@
|
|||||||
"moduleRoot": {
|
"moduleRoot": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "optional prefix for the AMD module formatter that will be prepend to the filename on module definitions"
|
"description": "optional prefix for the AMD module formatter that will be prepend to the filename on module definitions"
|
||||||
|
},
|
||||||
|
|
||||||
|
"breakConfig": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": false,
|
||||||
|
"hidden": true,
|
||||||
|
"description": "stop trying to load .babelrc files"
|
||||||
|
},
|
||||||
|
|
||||||
|
"babelrc": {
|
||||||
|
"hidden": true,
|
||||||
|
"description": "do not load the same .babelrc file twice"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
105
src/babel/transformation/file/plugin-manager.js
Normal file
105
src/babel/transformation/file/plugin-manager.js
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
import * as node from "../../api/node";
|
||||||
|
import * as messages from "../../messages";
|
||||||
|
import * as util from "../../util";
|
||||||
|
|
||||||
|
export default class PluginManager {
|
||||||
|
static memoisedPlugins = [];
|
||||||
|
|
||||||
|
static memoisePluginContainer(fn) {
|
||||||
|
for (var i = 0; i < PluginManager.memoisedPlugins.length; i++) {
|
||||||
|
var plugin = PluginManager.memoisedPlugins[i];
|
||||||
|
if (plugin.container === fn) return plugin.transformer;
|
||||||
|
}
|
||||||
|
|
||||||
|
var transformer = fn(node);
|
||||||
|
PluginManager.memoisedPlugins.push({
|
||||||
|
container: fn,
|
||||||
|
transformer: transformer
|
||||||
|
});
|
||||||
|
return transformer;
|
||||||
|
}
|
||||||
|
|
||||||
|
static positions = ["before", "after"];
|
||||||
|
|
||||||
|
constructor({ file, transformers, before, after } = { transformers: {}, before: [], after: [] }) {
|
||||||
|
this.transformers = transformers;
|
||||||
|
this.file = file;
|
||||||
|
this.before = before;
|
||||||
|
this.after = after;
|
||||||
|
}
|
||||||
|
|
||||||
|
subnormaliseString(name, position) {
|
||||||
|
// this is a plugin in the form of "foobar" or "foobar:after"
|
||||||
|
// where the optional colon is the delimiter for plugin position in the transformer stack
|
||||||
|
|
||||||
|
var match = name.match(/^(.*?):(after|before)$/);
|
||||||
|
if (match) [, name, position] = match;
|
||||||
|
|
||||||
|
var loc = util.resolveRelative(name) || util.resolveRelative(`babel-plugin-${name}`);
|
||||||
|
if (loc) {
|
||||||
|
return {
|
||||||
|
position: position,
|
||||||
|
plugin: require(loc)
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
throw new ReferenceError(messages.get("pluginUnknown", name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
validate(name, plugin) {
|
||||||
|
// validate transformer key
|
||||||
|
var key = plugin.key;
|
||||||
|
if (this.transformers[key]) {
|
||||||
|
throw new ReferenceError(messages.get("pluginKeyCollision", key));
|
||||||
|
}
|
||||||
|
|
||||||
|
// validate Transformer instance
|
||||||
|
if (!plugin.buildPass || plugin.constructor.name !== "Transformer") {
|
||||||
|
throw new TypeError(messages.get("pluginNotTransformer", name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
add(name) {
|
||||||
|
var position;
|
||||||
|
var plugin;
|
||||||
|
|
||||||
|
if (name) {
|
||||||
|
if (typeof name === "object" && name.transformer) {
|
||||||
|
({ plugin: name, position } = name);
|
||||||
|
} else if (typeof name !== "string") {
|
||||||
|
// not a string so we'll just assume that it's a direct Transformer instance, if not then
|
||||||
|
// the checks later on will complain
|
||||||
|
plugin = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof name === "string") {
|
||||||
|
({ plugin, position } = this.subnormaliseString(name, position));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new TypeError(messages.get("pluginIllegalKind", typeof name, name));
|
||||||
|
}
|
||||||
|
|
||||||
|
// default position
|
||||||
|
position = position || "before";
|
||||||
|
|
||||||
|
// validate position
|
||||||
|
if (PluginManager.positions.indexOf(position) < 0) {
|
||||||
|
throw new TypeError(messages.get("pluginIllegalPosition", position, name));
|
||||||
|
}
|
||||||
|
|
||||||
|
// allow plugin containers to be specified so they don't have to manually require
|
||||||
|
if (typeof plugin === "function") {
|
||||||
|
plugin = PluginManager.memoisePluginContainer(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
this.validate(name, plugin);
|
||||||
|
|
||||||
|
// build!
|
||||||
|
var pass = this.transformers[plugin.key] = plugin.buildPass(this.file);
|
||||||
|
if (pass.canTransform()) {
|
||||||
|
var stack = position === "before" ? this.before : this.after;
|
||||||
|
stack.push(pass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,9 +10,13 @@ export default function (exports, opts) {
|
|||||||
return t.assignmentExpression("=", left, right);
|
return t.assignmentExpression("=", left, right);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.shouldVisit = function (node) {
|
||||||
|
return node.operator && (node.operator === opts.operator || node.operator === opts.operator + "=");
|
||||||
|
};
|
||||||
|
|
||||||
exports.ExpressionStatement = function (node, parent, scope, file) {
|
exports.ExpressionStatement = function (node, parent, scope, file) {
|
||||||
// hit the `AssignmentExpression` one below
|
// hit the `AssignmentExpression` one below
|
||||||
if (file.isConsequenceExpressionStatement(node)) return;
|
if (this.isCompletionRecord()) return;
|
||||||
|
|
||||||
var expr = node.expression;
|
var expr = node.expression;
|
||||||
if (!isAssignment(expr)) return;
|
if (!isAssignment(expr)) return;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export default function (exports, opts) {
|
|||||||
|
|
||||||
exports.ExpressionStatement = function (node, parent, scope, file) {
|
exports.ExpressionStatement = function (node, parent, scope, file) {
|
||||||
// hit the `AssignmentExpression` one below
|
// hit the `AssignmentExpression` one below
|
||||||
if (file.isConsequenceExpressionStatement(node)) return;
|
if (this.isCompletionRecord()) return;
|
||||||
|
|
||||||
var expr = node.expression;
|
var expr = node.expression;
|
||||||
if (!opts.is(expr, file)) return;
|
if (!opts.is(expr, file)) return;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export default function (exports, opts) {
|
|||||||
exports.JSXIdentifier = function (node, parent) {
|
exports.JSXIdentifier = function (node, parent) {
|
||||||
if (node.name === "this" && t.isReferenced(node, parent)) {
|
if (node.name === "this" && t.isReferenced(node, parent)) {
|
||||||
return t.thisExpression();
|
return t.thisExpression();
|
||||||
} else if (esutils.keyword.isIdentifierName(node.name)) {
|
} else if (esutils.keyword.isIdentifierNameES6(node.name)) {
|
||||||
node.type = "Identifier";
|
node.type = "Identifier";
|
||||||
} else {
|
} else {
|
||||||
return t.literal(node.name);
|
return t.literal(node.name);
|
||||||
@@ -57,6 +57,8 @@ export default function (exports, opts) {
|
|||||||
|
|
||||||
exports.JSXOpeningElement = {
|
exports.JSXOpeningElement = {
|
||||||
exit(node, parent, scope, file) {
|
exit(node, parent, scope, file) {
|
||||||
|
parent.children = react.buildChildren(parent);
|
||||||
|
|
||||||
var tagExpr = node.name;
|
var tagExpr = node.name;
|
||||||
var args = [];
|
var args = [];
|
||||||
|
|
||||||
@@ -144,10 +146,6 @@ export default function (exports, opts) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.JSXElement = {
|
exports.JSXElement = {
|
||||||
enter(node) {
|
|
||||||
node.children = react.buildChildren(node);
|
|
||||||
},
|
|
||||||
|
|
||||||
exit(node) {
|
exit(node) {
|
||||||
var callExpr = node.openingElement;
|
var callExpr = node.openingElement;
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,33 @@
|
|||||||
|
import traverse from "../../traversal";
|
||||||
import * as t from "../../types";
|
import * as t from "../../types";
|
||||||
|
|
||||||
export default function (node) {
|
var visitor = {
|
||||||
var container = t.functionExpression(null, [], node.body, node.generator, node.async);
|
enter(node, parent, scope, state) {
|
||||||
container.shadow = true;
|
if (this.isThisExpression() || this.isReferencedIdentifier({ name: "arguments" })) {
|
||||||
|
state.found = true;
|
||||||
|
this.stop();
|
||||||
|
}
|
||||||
|
|
||||||
var call = t.callExpression(container, []);
|
if (this.isFunction()) {
|
||||||
|
this.skip();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function (node, scope) {
|
||||||
|
var container = t.functionExpression(null, [], node.body, node.generator, node.async);
|
||||||
|
|
||||||
|
var callee = container;
|
||||||
|
var args = [];
|
||||||
|
|
||||||
|
var state = { found: false };
|
||||||
|
scope.traverse(node, visitor, state);
|
||||||
|
if (state.found) {
|
||||||
|
callee = t.memberExpression(container, t.identifier("apply"));
|
||||||
|
args = [t.thisExpression(), t.identifier("arguments")];
|
||||||
|
}
|
||||||
|
|
||||||
|
var call = t.callExpression(callee, args);
|
||||||
if (node.generator) call = t.yieldExpression(call, true);
|
if (node.generator) call = t.yieldExpression(call, true);
|
||||||
|
|
||||||
return t.returnStatement(call);
|
return t.returnStatement(call);
|
||||||
|
|||||||
@@ -4,17 +4,45 @@ import each from "lodash/collection/each";
|
|||||||
import has from "lodash/object/has";
|
import has from "lodash/object/has";
|
||||||
import * as t from "../../types";
|
import * as t from "../../types";
|
||||||
|
|
||||||
export function push(mutatorMap, key, kind, computed, value) {
|
export function push(mutatorMap, node, kind, file) {
|
||||||
var alias = t.toKeyAlias({ computed }, key);
|
var alias = t.toKeyAlias(node);
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
var map = {};
|
var map = {};
|
||||||
if (has(mutatorMap, alias)) map = mutatorMap[alias];
|
if (has(mutatorMap, alias)) map = mutatorMap[alias];
|
||||||
mutatorMap[alias] = map;
|
mutatorMap[alias] = map;
|
||||||
|
|
||||||
map._key = key;
|
//
|
||||||
if (computed) map._computed = true;
|
|
||||||
|
|
||||||
map[kind] = value;
|
map._inherits = map._inherits || [];
|
||||||
|
map._inherits.push(node);
|
||||||
|
|
||||||
|
map._key = node.key;
|
||||||
|
|
||||||
|
if (node.computed) {
|
||||||
|
map._computed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.decorators) {
|
||||||
|
var decorators = map.decorators = map.decorators || t.arrayExpression([]);
|
||||||
|
decorators.elements = decorators.elements.concat(node.decorators.map(dec => dec.expression));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (map.value || map.initializer) {
|
||||||
|
throw file.errorWithNode(node, "Key conflict with sibling node");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.value) {
|
||||||
|
if (node.kind === "init") kind = "value";
|
||||||
|
if (node.kind === "get") kind = "get";
|
||||||
|
if (node.kind === "set") kind = "set";
|
||||||
|
|
||||||
|
t.inheritsComments(node.value, node);
|
||||||
|
map[kind] = node.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function hasComputed(mutatorMap) {
|
export function hasComputed(mutatorMap) {
|
||||||
|
|||||||
37
src/babel/transformation/helpers/memoise-decorators.js
Normal file
37
src/babel/transformation/helpers/memoise-decorators.js
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import * as t from "../../types";
|
||||||
|
|
||||||
|
export default function (decorators, scope) {
|
||||||
|
for (var i = 0; i < decorators.length; i++) {
|
||||||
|
var decorator = decorators[i];
|
||||||
|
var expression = decorator.expression;
|
||||||
|
if (!t.isMemberExpression(expression)) continue;
|
||||||
|
|
||||||
|
var temp = scope.generateMemoisedReference(expression.object);
|
||||||
|
var ref;
|
||||||
|
|
||||||
|
var nodes = [];
|
||||||
|
|
||||||
|
if (temp) {
|
||||||
|
ref = temp;
|
||||||
|
nodes.push(t.assignmentExpression("=", temp, expression.object));
|
||||||
|
} else {
|
||||||
|
ref = expression.object;
|
||||||
|
}
|
||||||
|
|
||||||
|
nodes.push(t.callExpression(
|
||||||
|
t.memberExpression(
|
||||||
|
t.memberExpression(ref, expression.property, expression.computed),
|
||||||
|
t.identifier("bind")
|
||||||
|
),
|
||||||
|
[ref]
|
||||||
|
));
|
||||||
|
|
||||||
|
if (nodes.length === 1) {
|
||||||
|
decorator.expression = nodes[0];
|
||||||
|
} else {
|
||||||
|
decorator.expression = t.sequenceExpression(nodes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return decorators;
|
||||||
|
}
|
||||||
@@ -20,26 +20,32 @@ var visitor = {
|
|||||||
|
|
||||||
var wrap = function (state, method, id, scope) {
|
var wrap = function (state, method, id, scope) {
|
||||||
if (state.selfReference) {
|
if (state.selfReference) {
|
||||||
var templateName = "property-method-assignment-wrapper";
|
if (scope.hasBinding(id.name)) {
|
||||||
if (method.generator) templateName += "-generator";
|
// we can just munge the local binding
|
||||||
var template = util.template(templateName, {
|
scope.rename(id.name);
|
||||||
FUNCTION: method,
|
} else {
|
||||||
FUNCTION_ID: id,
|
// need to add a wrapper since we can't change the references
|
||||||
FUNCTION_KEY: scope.generateUidIdentifier(id.name)
|
var templateName = "property-method-assignment-wrapper";
|
||||||
});
|
if (method.generator) templateName += "-generator";
|
||||||
|
var template = util.template(templateName, {
|
||||||
|
FUNCTION: method,
|
||||||
|
FUNCTION_ID: id,
|
||||||
|
FUNCTION_KEY: scope.generateUidIdentifier(id.name)
|
||||||
|
});
|
||||||
|
template.callee._skipModulesRemap = true;
|
||||||
|
|
||||||
// shim in dummy params to retain function arity, if you try to read the
|
// shim in dummy params to retain function arity, if you try to read the
|
||||||
// source then you'll get the original since it's proxied so it's all good
|
// source then you'll get the original since it's proxied so it's all good
|
||||||
var params = template.callee.body.body[0].params;
|
var params = template.callee.body.body[0].params;
|
||||||
for (var i = 0, len = getFunctionArity(method); i < len; i++) {
|
for (var i = 0, len = getFunctionArity(method); i < len; i++) {
|
||||||
params.push(scope.generateUidIdentifier("x"));
|
params.push(scope.generateUidIdentifier("x"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return template;
|
||||||
}
|
}
|
||||||
|
|
||||||
return template;
|
|
||||||
} else {
|
|
||||||
method.id = id;
|
|
||||||
return method;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
method.id = id;
|
||||||
};
|
};
|
||||||
|
|
||||||
var visit = function (node, name, scope) {
|
var visit = function (node, name, scope) {
|
||||||
@@ -81,7 +87,7 @@ var visit = function (node, name, scope) {
|
|||||||
// so we can safely just set the id and move along as it shadows the
|
// so we can safely just set the id and move along as it shadows the
|
||||||
// bound function id
|
// bound function id
|
||||||
}
|
}
|
||||||
} else {
|
} else if (state.outerDeclar || scope.hasGlobal(name)) {
|
||||||
scope.traverse(node, visitor, state);
|
scope.traverse(node, visitor, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,19 +101,20 @@ export function custom(node, id, scope) {
|
|||||||
|
|
||||||
export function property(node, file, scope) {
|
export function property(node, file, scope) {
|
||||||
var key = t.toComputedKey(node, node.key);
|
var key = t.toComputedKey(node, node.key);
|
||||||
if (!t.isLiteral(key)) return node; // we can't set a function id with this
|
if (!t.isLiteral(key)) return; // we can't set a function id with this
|
||||||
|
|
||||||
var name = t.toIdentifier(key.value);
|
var name = t.toIdentifier(key.value);
|
||||||
|
if (name === "eval" || name === "arguments") name = "_" + name;
|
||||||
var id = t.identifier(name);
|
var id = t.identifier(name);
|
||||||
|
|
||||||
var method = node.value;
|
var method = node.value;
|
||||||
var state = visit(method, name, scope);
|
var state = visit(method, name, scope);
|
||||||
node.value = wrap(state, method, id, scope);
|
node.value = wrap(state, method, id, scope) || method;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function bare(node, parent, scope) {
|
export function bare(node, parent, scope) {
|
||||||
// has an `id` so we don't need to infer one
|
// has an `id` so we don't need to infer one
|
||||||
if (node.id) return node;
|
if (node.id) return;
|
||||||
|
|
||||||
var id;
|
var id;
|
||||||
if (t.isProperty(parent) && parent.kind === "init" && (!parent.computed || t.isLiteral(parent.key))) {
|
if (t.isProperty(parent) && parent.kind === "init" && (!parent.computed || t.isLiteral(parent.key))) {
|
||||||
@@ -116,8 +123,17 @@ export function bare(node, parent, scope) {
|
|||||||
} else if (t.isVariableDeclarator(parent)) {
|
} else if (t.isVariableDeclarator(parent)) {
|
||||||
// var foo = function () {};
|
// var foo = function () {};
|
||||||
id = parent.id;
|
id = parent.id;
|
||||||
|
|
||||||
|
if (t.isIdentifier(id)) {
|
||||||
|
var bindingInfo = scope.parent.getBinding(id.name);
|
||||||
|
if (bindingInfo && bindingInfo.constant && scope.getBinding(id.name) === bindingInfo) {
|
||||||
|
// always going to reference this method
|
||||||
|
node.id = id;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return node;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var name;
|
var name;
|
||||||
|
|||||||
5
src/babel/transformation/helpers/react.js
vendored
5
src/babel/transformation/helpers/react.js
vendored
@@ -34,9 +34,8 @@ function cleanJSXElementLiteralChild(child, args) {
|
|||||||
var lines = child.value.split(/\r\n|\n|\r/);
|
var lines = child.value.split(/\r\n|\n|\r/);
|
||||||
|
|
||||||
var lastNonEmptyLine = 0;
|
var lastNonEmptyLine = 0;
|
||||||
var i;
|
|
||||||
|
|
||||||
for (i = 0; i < lines.length; i++) {
|
for (let i = 0; i < lines.length; i++) {
|
||||||
if (lines[i].match(/[^ \t]/)) {
|
if (lines[i].match(/[^ \t]/)) {
|
||||||
lastNonEmptyLine = i;
|
lastNonEmptyLine = i;
|
||||||
}
|
}
|
||||||
@@ -44,7 +43,7 @@ function cleanJSXElementLiteralChild(child, args) {
|
|||||||
|
|
||||||
var str = "";
|
var str = "";
|
||||||
|
|
||||||
for (i = 0; i < lines.length; i++) {
|
for (let i = 0; i < lines.length; i++) {
|
||||||
var line = lines[i];
|
var line = lines[i];
|
||||||
|
|
||||||
var isFirstLine = i === 0;
|
var isFirstLine = i === 0;
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ var referenceVisitor = {
|
|||||||
enter(node, parent, scope, state) {
|
enter(node, parent, scope, state) {
|
||||||
var name = state.id.name;
|
var name = state.id.name;
|
||||||
if (t.isReferencedIdentifier(node, parent, { name: name }) && scope.bindingIdentifierEquals(name, state.id)) {
|
if (t.isReferencedIdentifier(node, parent, { name: name }) && scope.bindingIdentifierEquals(name, state.id)) {
|
||||||
return state.ref ||= scope.generateUidIdentifier(name);
|
return state.ref = state.ref || scope.generateUidIdentifier(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ export default class ReplaceSupers {
|
|||||||
return this.setSuperProperty(node.left.property, node.right, node.left.computed, getThisReference());
|
return this.setSuperProperty(node.left.property, node.right, node.left.computed, getThisReference());
|
||||||
} else {
|
} else {
|
||||||
// super.age += 2; -> var _ref = super.age; super.age = _ref + 2;
|
// super.age += 2; -> var _ref = super.age; super.age = _ref + 2;
|
||||||
ref ||= path.scope.generateUidIdentifier("ref");
|
ref = ref || path.scope.generateUidIdentifier("ref");
|
||||||
return [
|
return [
|
||||||
t.variableDeclaration("var", [
|
t.variableDeclaration("var", [
|
||||||
t.variableDeclarator(ref, node.left)
|
t.variableDeclarator(ref, node.left)
|
||||||
|
|||||||
@@ -1,68 +1,34 @@
|
|||||||
import normalizeAst from "../helpers/normalize-ast";
|
import Pipeline from "./transformer-pipeline";
|
||||||
import Transformer from "./transformer";
|
|
||||||
import object from "../helpers/object";
|
|
||||||
import File from "./file";
|
|
||||||
import each from "lodash/collection/each";
|
|
||||||
|
|
||||||
export default function transform(code: string, opts?: Object) {
|
var pipeline = new Pipeline;
|
||||||
var file = new File(opts);
|
|
||||||
return file.parse(code);
|
|
||||||
}
|
|
||||||
|
|
||||||
transform.fromAst = function (ast, code, opts) {
|
//
|
||||||
ast = normalizeAst(ast);
|
|
||||||
|
|
||||||
var file = new File(opts);
|
import transformers from "./transformers";
|
||||||
file.addCode(code);
|
pipeline.addTransformers(transformers);
|
||||||
file.transform(ast);
|
|
||||||
return file.generate();
|
|
||||||
};
|
|
||||||
|
|
||||||
transform._ensureTransformerNames = function (type: string, rawKeys: Array<string>) {
|
//
|
||||||
var keys = [];
|
|
||||||
|
|
||||||
for (var i = 0; i < rawKeys.length; i++) {
|
import deprecated from "./transformers/deprecated";
|
||||||
var key = rawKeys[i];
|
pipeline.addDeprecated(deprecated);
|
||||||
|
|
||||||
var deprecatedKey = transform.deprecatedTransformerMap[key];
|
//
|
||||||
var aliasKey = transform.aliasTransformerMap[key];
|
|
||||||
if (aliasKey) {
|
|
||||||
keys.push(aliasKey);
|
|
||||||
} else if (deprecatedKey) {
|
|
||||||
// deprecated key, remap it to the new one
|
|
||||||
console.error(`The transformer ${key} has been renamed to ${deprecatedKey}`);
|
|
||||||
rawKeys.push(deprecatedKey);
|
|
||||||
} else if (transform.transformers[key]) {
|
|
||||||
// valid key
|
|
||||||
keys.push(key);
|
|
||||||
} else if (transform.namespaces[key]) {
|
|
||||||
// namespace, append all transformers within this namespace
|
|
||||||
keys = keys.concat(transform.namespaces[key]);
|
|
||||||
} else {
|
|
||||||
// invalid key
|
|
||||||
throw new ReferenceError(`Unknown transformer ${key} specified in ${type}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return keys;
|
import aliases from "./transformers/aliases";
|
||||||
};
|
pipeline.addDeprecated(aliases);
|
||||||
|
|
||||||
transform.transformerNamespaces = object();
|
//
|
||||||
transform.transformers = object();
|
|
||||||
transform.namespaces = object();
|
|
||||||
|
|
||||||
transform.deprecatedTransformerMap = require("./transformers/deprecated");
|
import * as filters from "./transformers/filters";
|
||||||
transform.aliasTransformerMap = require("./transformers/aliases");
|
pipeline.addFilter(filters.internal);
|
||||||
transform.moduleFormatters = require("./modules");
|
pipeline.addFilter(filters.blacklist);
|
||||||
|
pipeline.addFilter(filters.whitelist);
|
||||||
|
pipeline.addFilter(filters.stage);
|
||||||
|
pipeline.addFilter(filters.optional);
|
||||||
|
|
||||||
import rawTransformers from "./transformers";
|
//
|
||||||
|
|
||||||
each(rawTransformers, function (transformer, key) {
|
var transform = pipeline.transform.bind(pipeline);
|
||||||
var namespace = key.split(".")[0];
|
transform.fromAst = pipeline.transformFromAst.bind(pipeline);
|
||||||
|
transform.pipeline = pipeline;
|
||||||
transform.namespaces[namespace] ||= [];
|
export default transform;
|
||||||
transform.namespaces[namespace].push(key);
|
|
||||||
transform.transformerNamespaces[key] = namespace;
|
|
||||||
|
|
||||||
transform.transformers[key] = new Transformer(key, transformer);
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -46,10 +46,15 @@ var remapVisitor = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t.isAssignmentExpression(node)) {
|
if (node._skipModulesRemap) {
|
||||||
|
return this.skip();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
exit(node, parent, scope, formatter) {
|
||||||
|
if (t.isAssignmentExpression(node) && !node._ignoreModulesRemap) {
|
||||||
var exported = formatter.getExport(node.left, scope);
|
var exported = formatter.getExport(node.left, scope);
|
||||||
if (exported) {
|
if (exported) {
|
||||||
this.skip();
|
|
||||||
return formatter.remapExportAssignment(node, exported);
|
return formatter.remapExportAssignment(node, exported);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -61,7 +66,6 @@ var importsVisitor = {
|
|||||||
enter(node, parent, scope, formatter) {
|
enter(node, parent, scope, formatter) {
|
||||||
formatter.hasLocalImports = true;
|
formatter.hasLocalImports = true;
|
||||||
extend(formatter.localImports, this.getBindingIdentifiers());
|
extend(formatter.localImports, this.getBindingIdentifiers());
|
||||||
formatter.bumpImportOccurences(node);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -69,7 +73,7 @@ var importsVisitor = {
|
|||||||
var exportsVisitor = traverse.explode({
|
var exportsVisitor = traverse.explode({
|
||||||
ExportDeclaration: {
|
ExportDeclaration: {
|
||||||
enter(node, parent, scope, formatter) {
|
enter(node, parent, scope, formatter) {
|
||||||
formatter.hasLocalImports = true;
|
formatter.hasLocalExports = true;
|
||||||
|
|
||||||
var declar = this.get("declaration");
|
var declar = this.get("declaration");
|
||||||
if (declar.isStatement()) {
|
if (declar.isStatement()) {
|
||||||
@@ -96,29 +100,23 @@ var exportsVisitor = traverse.explode({
|
|||||||
formatter.hasNonDefaultExports = true;
|
formatter.hasNonDefaultExports = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.source) {
|
|
||||||
formatter.bumpImportOccurences(node);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export default class DefaultFormatter {
|
export default class DefaultFormatter {
|
||||||
constructor(file) {
|
constructor(file) {
|
||||||
this.internalRemap = {};
|
this.internalRemap = object();
|
||||||
|
this.defaultIds = object();
|
||||||
this.defaultIds = object();
|
this.scope = file.scope;
|
||||||
this.scope = file.scope;
|
this.file = file;
|
||||||
this.file = file;
|
this.ids = object();
|
||||||
this.ids = object();
|
|
||||||
|
|
||||||
this.hasNonDefaultExports = false;
|
this.hasNonDefaultExports = false;
|
||||||
|
|
||||||
this.hasLocalExports = false;
|
this.hasLocalExports = false;
|
||||||
this.hasLocalImports = false;
|
this.hasLocalImports = false;
|
||||||
|
|
||||||
this.localImportOccurences = object();
|
|
||||||
this.localExports = object();
|
this.localExports = object();
|
||||||
this.localImports = object();
|
this.localImports = object();
|
||||||
|
|
||||||
@@ -126,6 +124,11 @@ export default class DefaultFormatter {
|
|||||||
this.getLocalImports();
|
this.getLocalImports();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isModuleType(node, type) {
|
||||||
|
var modules = this.file.dynamicImportTypes[type];
|
||||||
|
return modules && modules.indexOf(node) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
transform() {
|
transform() {
|
||||||
this.remapAssignments();
|
this.remapAssignments();
|
||||||
}
|
}
|
||||||
@@ -134,15 +137,6 @@ export default class DefaultFormatter {
|
|||||||
return (t.isExportDefaultDeclaration(node) || t.isSpecifierDefault(node)) && !this.noInteropRequireExport && !this.hasNonDefaultExports;
|
return (t.isExportDefaultDeclaration(node) || t.isSpecifierDefault(node)) && !this.noInteropRequireExport && !this.hasNonDefaultExports;
|
||||||
}
|
}
|
||||||
|
|
||||||
bumpImportOccurences(node) {
|
|
||||||
var source = node.source.value;
|
|
||||||
var occurs = this.localImportOccurences;
|
|
||||||
occurs[source] ||= 0;
|
|
||||||
if (node.specifiers) {
|
|
||||||
occurs[source] += node.specifiers.length;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getLocalExports() {
|
getLocalExports() {
|
||||||
this.file.path.traverse(exportsVisitor, this);
|
this.file.path.traverse(exportsVisitor, this);
|
||||||
}
|
}
|
||||||
@@ -152,7 +146,7 @@ export default class DefaultFormatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
remapAssignments() {
|
remapAssignments() {
|
||||||
if (this.hasLocalImports) {
|
if (this.hasLocalExports || this.hasLocalImports) {
|
||||||
this.file.path.traverse(remapVisitor, this);
|
this.file.path.traverse(remapVisitor, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -172,7 +166,7 @@ export default class DefaultFormatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_addExport(name, exported) {
|
_addExport(name, exported) {
|
||||||
var info = this.localExports[name] ||= {
|
var info = this.localExports[name] = this.localExports[name] || {
|
||||||
binding: this.scope.getBindingIdentifier(name),
|
binding: this.scope.getBindingIdentifier(name),
|
||||||
exported: []
|
exported: []
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ import * as util from "../../util";
|
|||||||
import * as t from "../../types";
|
import * as t from "../../types";
|
||||||
|
|
||||||
export default class AMDFormatter extends DefaultFormatter {
|
export default class AMDFormatter extends DefaultFormatter {
|
||||||
init = CommonFormatter.prototype.init;
|
init() {
|
||||||
|
CommonFormatter.prototype._init.call(this, this.hasNonDefaultExports);
|
||||||
|
}
|
||||||
|
|
||||||
buildDependencyLiterals() {
|
buildDependencyLiterals() {
|
||||||
var names = [];
|
var names = [];
|
||||||
@@ -78,9 +80,12 @@ export default class AMDFormatter extends DefaultFormatter {
|
|||||||
this.defaultIds[key] = specifier.local;
|
this.defaultIds[key] = specifier.local;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (includes(this.file.dynamicImportedNoDefault, node)) {
|
if (this.isModuleType(node, "absolute")) {
|
||||||
// Prevent unnecessary renaming of dynamic imports.
|
// absolute module reference
|
||||||
|
} else if (this.isModuleType(node, "absoluteDefault")) {
|
||||||
|
// prevent unnecessary renaming of dynamic imports
|
||||||
this.ids[node.source.value] = ref;
|
this.ids[node.source.value] = ref;
|
||||||
|
ref = t.memberExpression(ref, t.identifier("default"));
|
||||||
} else if (t.isImportNamespaceSpecifier(specifier)) {
|
} else if (t.isImportNamespaceSpecifier(specifier)) {
|
||||||
// import * as bar from "foo";
|
// import * as bar from "foo";
|
||||||
} else if (!includes(this.file.dynamicImported, node) && t.isSpecifierDefault(specifier) && !this.noInteropRequireImport) {
|
} else if (!includes(this.file.dynamicImported, node) && t.isSpecifierDefault(specifier) && !this.noInteropRequireImport) {
|
||||||
@@ -100,15 +105,35 @@ export default class AMDFormatter extends DefaultFormatter {
|
|||||||
this.internalRemap[specifier.local.name] = ref;
|
this.internalRemap[specifier.local.name] = ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
exportSpecifier() {
|
exportSpecifier(specifier, node, nodes) {
|
||||||
CommonFormatter.prototype.exportSpecifier.apply(this, arguments);
|
if (this.doDefaultExportInterop(specifier)) {
|
||||||
|
this.passModuleArg = true;
|
||||||
|
nodes.push(util.template("exports-default-assign", {
|
||||||
|
VALUE: specifier.local
|
||||||
|
}, true));
|
||||||
|
} else {
|
||||||
|
CommonFormatter.prototype.exportSpecifier.apply(this, arguments);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exportDeclaration(node) {
|
exportDeclaration(node, nodes) {
|
||||||
if (this.doDefaultExportInterop(node)) {
|
if (this.doDefaultExportInterop(node)) {
|
||||||
this.passModuleArg = true;
|
this.passModuleArg = true;
|
||||||
|
|
||||||
|
var declar = node.declaration;
|
||||||
|
var assign = util.template("exports-default-assign", {
|
||||||
|
VALUE: this._pushStatement(declar, nodes)
|
||||||
|
}, true);
|
||||||
|
|
||||||
|
if (t.isFunctionDeclaration(declar)) {
|
||||||
|
// we can hoist this assignment to the top of the file
|
||||||
|
assign._blockHoist = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
nodes.push(assign);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CommonFormatter.prototype.exportDeclaration.apply(this, arguments);
|
DefaultFormatter.prototype.exportDeclaration.apply(this, arguments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,18 +5,36 @@ import * as t from "../../types";
|
|||||||
|
|
||||||
export default class CommonJSFormatter extends DefaultFormatter {
|
export default class CommonJSFormatter extends DefaultFormatter {
|
||||||
init() {
|
init() {
|
||||||
|
this._init(this.hasLocalExports);
|
||||||
|
}
|
||||||
|
|
||||||
|
_init(conditional) {
|
||||||
var file = this.file;
|
var file = this.file;
|
||||||
var scope = file.scope;
|
var scope = file.scope;
|
||||||
|
|
||||||
scope.rename("module");
|
scope.rename("module");
|
||||||
scope.rename("exports");
|
scope.rename("exports");
|
||||||
|
|
||||||
if (!this.noInteropRequireImport && this.hasNonDefaultExports) {
|
if (!this.noInteropRequireImport && conditional) {
|
||||||
var templateName = "exports-module-declaration";
|
var templateName = "exports-module-declaration";
|
||||||
if (this.file.isLoose("es6.modules")) templateName += "-loose";
|
if (this.file.isLoose("es6.modules")) templateName += "-loose";
|
||||||
var declar = util.template(templateName, true);
|
var declar = util.template(templateName, true);
|
||||||
declar._blockHoist = 3;
|
declar._blockHoist = 3;
|
||||||
file.ast.program.body.unshift(declar);
|
file.path.unshiftContainer("body", [declar]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
transform(program) {
|
||||||
|
DefaultFormatter.prototype.transform.apply(this, arguments);
|
||||||
|
|
||||||
|
if (this.hasDefaultOnlyExport) {
|
||||||
|
program.body.push(
|
||||||
|
t.expressionStatement(t.assignmentExpression(
|
||||||
|
"=",
|
||||||
|
t.memberExpression(t.identifier("module"), t.identifier("exports")),
|
||||||
|
t.memberExpression(t.identifier("exports"), t.identifier("default"))
|
||||||
|
))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,16 +45,20 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
|||||||
|
|
||||||
// import foo from "foo";
|
// import foo from "foo";
|
||||||
if (t.isSpecifierDefault(specifier)) {
|
if (t.isSpecifierDefault(specifier)) {
|
||||||
if (includes(this.file.dynamicImportedNoDefault, node)) {
|
if (this.isModuleType(node, "absolute")) {
|
||||||
|
// absolute module reference
|
||||||
|
} else if (this.isModuleType(node, "absoluteDefault")) {
|
||||||
this.internalRemap[variableName.name] = ref;
|
this.internalRemap[variableName.name] = ref;
|
||||||
|
} else if (this.noInteropRequireImport) {
|
||||||
|
this.internalRemap[variableName.name] = t.memberExpression(ref, t.identifier("default"));
|
||||||
} else {
|
} else {
|
||||||
if (this.noInteropRequireImport) {
|
var uid = this.scope.generateUidBasedOnNode(node, "import");
|
||||||
this.internalRemap[variableName.name] = t.memberExpression(ref, t.identifier("default"))
|
|
||||||
} else if (!includes(this.file.dynamicImported, node)) {
|
nodes.push(t.variableDeclaration("var", [
|
||||||
nodes.push(t.variableDeclaration("var", [
|
t.variableDeclarator(uid, t.callExpression(this.file.addHelper("interop-require-default"), [ref]))
|
||||||
t.variableDeclarator(variableName, t.callExpression(this.file.addHelper("interop-require"), [ref]))
|
]));
|
||||||
]));
|
|
||||||
}
|
this.internalRemap[variableName.name] = t.memberExpression(uid, t.identifier("default"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (t.isImportNamespaceSpecifier(specifier)) {
|
if (t.isImportNamespaceSpecifier(specifier)) {
|
||||||
@@ -64,29 +86,15 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
|||||||
|
|
||||||
exportSpecifier(specifier, node, nodes) {
|
exportSpecifier(specifier, node, nodes) {
|
||||||
if (this.doDefaultExportInterop(specifier)) {
|
if (this.doDefaultExportInterop(specifier)) {
|
||||||
nodes.push(util.template("exports-default-assign", {
|
this.hasDefaultOnlyExport = true;
|
||||||
VALUE: specifier.local
|
|
||||||
}, true));
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
DefaultFormatter.prototype.exportSpecifier.apply(this, arguments);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DefaultFormatter.prototype.exportSpecifier.apply(this, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
exportDeclaration(node, nodes) {
|
exportDeclaration(node, nodes) {
|
||||||
if (this.doDefaultExportInterop(node)) {
|
if (this.doDefaultExportInterop(node)) {
|
||||||
var declar = node.declaration;
|
this.hasDefaultOnlyExport = true;
|
||||||
var assign = util.template("exports-default-assign", {
|
|
||||||
VALUE: this._pushStatement(declar, nodes)
|
|
||||||
}, true);
|
|
||||||
|
|
||||||
if (t.isFunctionDeclaration(declar)) {
|
|
||||||
// we can hoist this assignment to the top of the file
|
|
||||||
assign._blockHoist = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
nodes.push(assign);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DefaultFormatter.prototype.exportDeclaration.apply(this, arguments);
|
DefaultFormatter.prototype.exportDeclaration.apply(this, arguments);
|
||||||
@@ -98,13 +106,16 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
|||||||
var call = t.callExpression(t.identifier("require"), [node.source]);
|
var call = t.callExpression(t.identifier("require"), [node.source]);
|
||||||
var uid;
|
var uid;
|
||||||
|
|
||||||
if (includes(this.file.dynamicImported, node) && !includes(this.file.dynamicImportedNoDefault, node)) {
|
if (this.isModuleType(node, "absolute")) {
|
||||||
|
// absolute module reference
|
||||||
|
} else if (this.isModuleType(node, "absoluteDefault")) {
|
||||||
call = t.memberExpression(call, t.identifier("default"));
|
call = t.memberExpression(call, t.identifier("default"));
|
||||||
uid = node.specifiers[0].local;
|
|
||||||
} else {
|
} else {
|
||||||
uid = this.scope.generateUidBasedOnNode(node, "import");
|
uid = this.scope.generateUidBasedOnNode(node, "import");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uid = uid || node.specifiers[0].local;
|
||||||
|
|
||||||
var declar = t.variableDeclaration("var", [
|
var declar = t.variableDeclaration("var", [
|
||||||
t.variableDeclarator(uid, call)
|
t.variableDeclarator(uid, call)
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -6,12 +6,8 @@ import each from "lodash/collection/each";
|
|||||||
import map from "lodash/collection/map";
|
import map from "lodash/collection/map";
|
||||||
import * as t from "../../types";
|
import * as t from "../../types";
|
||||||
|
|
||||||
var canHoist = function (node, file) {
|
|
||||||
return node._blockHoist && !file.transformers.runtime.canTransform();
|
|
||||||
}
|
|
||||||
|
|
||||||
var hoistVariablesVisitor = {
|
var hoistVariablesVisitor = {
|
||||||
enter(node, parent, scope, hoistDeclarators) {
|
enter(node, parent, scope, state) {
|
||||||
if (t.isFunction(node)) {
|
if (t.isFunction(node)) {
|
||||||
// nothing inside is accessible
|
// nothing inside is accessible
|
||||||
return this.skip();
|
return this.skip();
|
||||||
@@ -24,13 +20,13 @@ var hoistVariablesVisitor = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ignore block hoisted nodes as these can be left in
|
// ignore block hoisted nodes as these can be left in
|
||||||
if (canHoist(node, scope.file)) return;
|
if (state.formatter.canHoist(node)) return;
|
||||||
|
|
||||||
var nodes = [];
|
var nodes = [];
|
||||||
|
|
||||||
for (var i = 0; i < node.declarations.length; i++) {
|
for (var i = 0; i < node.declarations.length; i++) {
|
||||||
var declar = node.declarations[i];
|
var declar = node.declarations[i];
|
||||||
hoistDeclarators.push(t.variableDeclarator(declar.id));
|
state.hoistDeclarators.push(t.variableDeclarator(declar.id));
|
||||||
if (declar.init) {
|
if (declar.init) {
|
||||||
// no initializer so we can just hoist it as-is
|
// no initializer so we can just hoist it as-is
|
||||||
var assign = t.expressionStatement(t.assignmentExpression("=", declar.id, declar.init));
|
var assign = t.expressionStatement(t.assignmentExpression("=", declar.id, declar.init));
|
||||||
@@ -40,14 +36,8 @@ var hoistVariablesVisitor = {
|
|||||||
|
|
||||||
// for (var i in test)
|
// for (var i in test)
|
||||||
// for (var i = 0;;)
|
// for (var i = 0;;)
|
||||||
if (t.isFor(parent)) {
|
if (t.isFor(parent) && parent.left === node) {
|
||||||
if (parent.left === node) {
|
return node.declarations[0].id;
|
||||||
return node.declarations[0].id;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parent.init === node) {
|
|
||||||
return nodes;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nodes;
|
return nodes;
|
||||||
@@ -56,11 +46,11 @@ var hoistVariablesVisitor = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var hoistFunctionsVisitor = {
|
var hoistFunctionsVisitor = {
|
||||||
enter(node, parent, scope, handlerBody) {
|
enter(node, parent, scope, state) {
|
||||||
if (t.isFunction(node)) this.skip();
|
if (t.isFunction(node)) this.skip();
|
||||||
|
|
||||||
if (t.isFunctionDeclaration(node) || canHoist(node, scope.file)) {
|
if (t.isFunctionDeclaration(node) || state.formatter.canHoist(node)) {
|
||||||
handlerBody.push(node);
|
state.handlerBody.push(node);
|
||||||
this.remove();
|
this.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -87,11 +77,11 @@ var runnerSettersVisitor = {
|
|||||||
|
|
||||||
export default class SystemFormatter extends AMDFormatter {
|
export default class SystemFormatter extends AMDFormatter {
|
||||||
constructor(file) {
|
constructor(file) {
|
||||||
|
super(file);
|
||||||
|
|
||||||
this.exportIdentifier = file.scope.generateUidIdentifier("export");
|
this.exportIdentifier = file.scope.generateUidIdentifier("export");
|
||||||
this.noInteropRequireExport = true;
|
this.noInteropRequireExport = true;
|
||||||
this.noInteropRequireImport = true;
|
this.noInteropRequireImport = true;
|
||||||
|
|
||||||
DefaultFormatter.apply(this, arguments);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_addImportSource(node, exportNode) {
|
_addImportSource(node, exportNode) {
|
||||||
@@ -174,6 +164,10 @@ export default class SystemFormatter extends AMDFormatter {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
canHoist(node) {
|
||||||
|
return node._blockHoist && !this.file.dynamicImports.length;
|
||||||
|
}
|
||||||
|
|
||||||
transform(program) {
|
transform(program) {
|
||||||
DefaultFormatter.prototype.transform.apply(this, arguments);
|
DefaultFormatter.prototype.transform.apply(this, arguments);
|
||||||
|
|
||||||
@@ -197,7 +191,10 @@ export default class SystemFormatter extends AMDFormatter {
|
|||||||
var returnStatement = handlerBody.pop();
|
var returnStatement = handlerBody.pop();
|
||||||
|
|
||||||
// hoist up all variable declarations
|
// hoist up all variable declarations
|
||||||
this.file.scope.traverse(block, hoistVariablesVisitor, hoistDeclarators);
|
this.file.scope.traverse(block, hoistVariablesVisitor, {
|
||||||
|
formatter: this,
|
||||||
|
hoistDeclarators: hoistDeclarators
|
||||||
|
});
|
||||||
|
|
||||||
if (hoistDeclarators.length) {
|
if (hoistDeclarators.length) {
|
||||||
var hoistDeclar = t.variableDeclaration("var", hoistDeclarators);
|
var hoistDeclar = t.variableDeclaration("var", hoistDeclarators);
|
||||||
@@ -206,7 +203,10 @@ export default class SystemFormatter extends AMDFormatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// hoist up function declarations for circular references
|
// hoist up function declarations for circular references
|
||||||
this.file.scope.traverse(block, hoistFunctionsVisitor, handlerBody);
|
this.file.scope.traverse(block, hoistFunctionsVisitor, {
|
||||||
|
formatter: this,
|
||||||
|
handlerBody: handlerBody
|
||||||
|
});
|
||||||
|
|
||||||
handlerBody.push(returnStatement);
|
handlerBody.push(returnStatement);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import DefaultFormatter from "./_default";
|
import DefaultFormatter from "./_default";
|
||||||
import AMDFormatter from "./amd";
|
import AMDFormatter from "./amd";
|
||||||
import values from "lodash/object/values";
|
import values from "lodash/object/values";
|
||||||
|
import path from "path";
|
||||||
import * as util from "../../util";
|
import * as util from "../../util";
|
||||||
import * as t from "../../types";
|
import * as t from "../../types";
|
||||||
|
|
||||||
@@ -47,11 +48,11 @@ export default class UMDFormatter extends AMDFormatter {
|
|||||||
|
|
||||||
// globals
|
// globals
|
||||||
|
|
||||||
var browserArgs = [t.memberExpression(t.identifier("module"), t.identifier("exports"))];
|
var browserArgs = [];
|
||||||
if (this.passModuleArg) browserArgs.push(t.identifier("module"));
|
if (this.passModuleArg) browserArgs.push(t.identifier("mod"));
|
||||||
|
|
||||||
for (let name in this.ids) {
|
for (let name in this.ids) {
|
||||||
var id = this.defaultIds[name] || t.identifier(t.toIdentifier(name));
|
var id = this.defaultIds[name] || t.identifier(t.toIdentifier(path.basename(name, path.extname(name))));
|
||||||
browserArgs.push(t.memberExpression(t.identifier("global"), id));
|
browserArgs.push(t.memberExpression(t.identifier("global"), id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,12 +61,17 @@ export default class UMDFormatter extends AMDFormatter {
|
|||||||
var moduleName = this.getModuleName();
|
var moduleName = this.getModuleName();
|
||||||
if (moduleName) defineArgs.unshift(t.literal(moduleName));
|
if (moduleName) defineArgs.unshift(t.literal(moduleName));
|
||||||
|
|
||||||
|
//
|
||||||
|
var globalArg = this.file.opts.basename;
|
||||||
|
if (moduleName) globalArg = moduleName;
|
||||||
|
globalArg = t.identifier(t.toIdentifier(globalArg));
|
||||||
|
|
||||||
var runner = util.template("umd-runner-body", {
|
var runner = util.template("umd-runner-body", {
|
||||||
AMD_ARGUMENTS: defineArgs,
|
AMD_ARGUMENTS: defineArgs,
|
||||||
COMMON_TEST: commonTests,
|
COMMON_TEST: commonTests,
|
||||||
COMMON_ARGUMENTS: commonArgs,
|
COMMON_ARGUMENTS: commonArgs,
|
||||||
BROWSER_ARGUMENTS: browserArgs,
|
BROWSER_ARGUMENTS: browserArgs,
|
||||||
GLOBAL_ARG: t.identifier(t.toIdentifier(this.file.opts.basename))
|
GLOBAL_ARG: globalArg
|
||||||
});
|
});
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"blacklist": ["useStrict", "es6.blockScoping", "regenerator"],
|
"blacklist": ["useStrict", "es6.blockScoping", "regenerator", "es6.spread"],
|
||||||
"loose": ["es6.modules"]
|
"loose": ["es6.modules"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
this.KEY = INITIALIZERS.KEY.call(this);
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
CONSTRUCTOR.KEY = INITIALIZERS.KEY.call(CONSTRUCTOR);
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
if (SUPER_NAME != null) {
|
||||||
|
var NATIVE_REF = new SUPER_NAME(...arguments);
|
||||||
|
NATIVE_REF.__proto__ = CLASS_NAME.prototype;
|
||||||
|
return NATIVE_REF;
|
||||||
|
}
|
||||||
@@ -1 +0,0 @@
|
|||||||
CORE_ID.isIterable(VALUE);
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
CORE_ID.getIterator(VALUE);
|
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
var descriptor = props[i];
|
var descriptor = props[i];
|
||||||
descriptor.enumerable = descriptor.enumerable || false;
|
descriptor.enumerable = descriptor.enumerable || false;
|
||||||
descriptor.configurable = true;
|
descriptor.configurable = true;
|
||||||
if (descriptor.value) descriptor.writable = true;
|
if ("value" in descriptor) descriptor.writable = true;
|
||||||
Object.defineProperty(target, descriptor.key, descriptor);
|
Object.defineProperty(target, descriptor.key, descriptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,11 @@
|
|||||||
throw new TypeError("The decorator for method " + descriptor.key + " is of the invalid type " + typeof decorator);
|
throw new TypeError("The decorator for method " + descriptor.key + " is of the invalid type " + typeof decorator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (initializers) initializers[key] = descriptor.initializer;
|
|
||||||
|
if (descriptor.initializer !== undefined) {
|
||||||
|
initializers[key] = descriptor;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.defineProperty(target, key, descriptor);
|
Object.defineProperty(target, key, descriptor);
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
(function (descriptors) {
|
||||||
|
var target = {};
|
||||||
|
|
||||||
|
for (var i = 0; i < descriptors.length; i ++) {
|
||||||
|
var descriptor = descriptors[i];
|
||||||
|
var decorators = descriptor.decorators;
|
||||||
|
var key = descriptor.key;
|
||||||
|
|
||||||
|
// don't want to expose these to userland since i know people will rely on them
|
||||||
|
// and think it's spec behaviour
|
||||||
|
delete descriptor.key;
|
||||||
|
delete descriptor.decorators;
|
||||||
|
|
||||||
|
descriptor.enumerable = true;
|
||||||
|
descriptor.configurable = true;
|
||||||
|
descriptor.writable = true;
|
||||||
|
|
||||||
|
if (decorators) {
|
||||||
|
for (var f = 0; f < decorators.length; f++) {
|
||||||
|
var decorator = decorators[f];
|
||||||
|
if (typeof decorator === "function") {
|
||||||
|
descriptor = decorator(target, key, descriptor) || descriptor;
|
||||||
|
} else {
|
||||||
|
throw new TypeError("The decorator for method " + descriptor.key + " is of the invalid type " + typeof decorator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (descriptor.initializer) {
|
||||||
|
descriptor.value = descriptor.initializer.call(target);
|
||||||
|
Object.defineProperty(target, key, descriptor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return target;
|
||||||
|
})
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
(function (target, key, descriptors) {
|
||||||
|
var _descriptor = descriptors[key];
|
||||||
|
|
||||||
|
// clone it
|
||||||
|
var descriptor = {};
|
||||||
|
for (var _key in _descriptor) descriptor[_key] = _descriptor[_key];
|
||||||
|
|
||||||
|
// initialize it
|
||||||
|
if (!descriptor.initializer) return;
|
||||||
|
descriptor.value = descriptor.initializer.call(target);
|
||||||
|
|
||||||
|
Object.defineProperty(target, key, descriptor);
|
||||||
|
})
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
(function (obj, key, value) {
|
(function (obj, key, value) {
|
||||||
return Object.defineProperty(obj, key, {
|
return Object.defineProperty(obj, key, {
|
||||||
value: value,
|
value: value,
|
||||||
enumerable: key == null || typeof Symbol == "undefined" || key.constructor !== Symbol,
|
enumerable: true,
|
||||||
configurable: true,
|
configurable: true,
|
||||||
writable: true
|
writable: true
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
} else {
|
} else {
|
||||||
return get(parent, property, receiver);
|
return get(parent, property, receiver);
|
||||||
}
|
}
|
||||||
} else if ("value" in desc && desc.writable) {
|
} else if ("value" in desc) {
|
||||||
return desc.value;
|
return desc.value;
|
||||||
} else {
|
} else {
|
||||||
var getter = desc.get;
|
var getter = desc.get;
|
||||||
|
|||||||
7
src/babel/transformation/templates/helper-instanceof.js
Normal file
7
src/babel/transformation/templates/helper-instanceof.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
(function (left, right) {
|
||||||
|
if (right != null && right[Symbol.hasInstance]) {
|
||||||
|
return right[Symbol.hasInstance](left);
|
||||||
|
} else {
|
||||||
|
return left instanceof right;
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
(function (obj) {
|
||||||
|
return obj && obj.__esModule ? obj : { default: obj };
|
||||||
|
})
|
||||||
@@ -1,3 +1,14 @@
|
|||||||
(function (obj) {
|
(function (obj) {
|
||||||
return obj && obj.__esModule ? obj : { default: obj };
|
if (obj && obj.__esModule) {
|
||||||
|
return obj;
|
||||||
|
} else {
|
||||||
|
var newObj = {};
|
||||||
|
if (obj != null) {
|
||||||
|
for (var key in obj) {
|
||||||
|
if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newObj.default = obj;
|
||||||
|
return newObj;
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
(function (proxy, directory) {
|
||||||
|
directory.push(proxy);
|
||||||
|
return proxy;
|
||||||
|
})
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
[];
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
(function (FUNCTION_KEY) {
|
(function (FUNCTION_KEY) {
|
||||||
function* FUNCTION_ID() {
|
function* FUNCTION_ID() {
|
||||||
return yield* FUNCTION_ID.apply(this, arguments);
|
return yield* FUNCTION_KEY.apply(this, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
FUNCTION_ID.toString = function () {
|
FUNCTION_ID.toString = function () {
|
||||||
return FUNCTION_ID.toString();
|
return FUNCTION_KEY.toString();
|
||||||
};
|
};
|
||||||
|
|
||||||
return FUNCTION_ID;
|
return FUNCTION_ID;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
FUNCTION_ID.toString = function () {
|
FUNCTION_ID.toString = function () {
|
||||||
return FUNCTION_ID.toString();
|
return FUNCTION_KEY.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
return FUNCTION_ID;
|
return FUNCTION_ID;
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
} else if (COMMON_TEST) {
|
} else if (COMMON_TEST) {
|
||||||
factory(COMMON_ARGUMENTS);
|
factory(COMMON_ARGUMENTS);
|
||||||
} else {
|
} else {
|
||||||
var module = { exports: {} };
|
var mod = { exports: {} };
|
||||||
factory(BROWSER_ARGUMENTS);
|
factory(mod.exports, BROWSER_ARGUMENTS);
|
||||||
global.GLOBAL_ARG = module.exports;
|
global.GLOBAL_ARG = mod.exports;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -8,58 +8,35 @@ import traverse from "../traversal";
|
|||||||
|
|
||||||
export default class TransformerPass {
|
export default class TransformerPass {
|
||||||
constructor(file: File, transformer: Transformer) {
|
constructor(file: File, transformer: Transformer) {
|
||||||
this.transformer = transformer;
|
this.shouldTransform = !transformer.shouldVisit;
|
||||||
this.shouldRun = !transformer.check;
|
this.transformer = transformer;
|
||||||
this.handlers = transformer.handlers;
|
this.handlers = transformer.handlers;
|
||||||
this.file = file;
|
this.skipKey = transformer.skipKey;
|
||||||
this.ran = false;
|
this.file = file;
|
||||||
|
this.ran = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
canTransform(): boolean {
|
canTransform(): boolean {
|
||||||
var transformer = this.transformer;
|
return this.file.pipeline.canTransform(this.transformer, this.file.opts);
|
||||||
|
|
||||||
var opts = this.file.opts;
|
|
||||||
var key = transformer.key;
|
|
||||||
|
|
||||||
// internal
|
|
||||||
if (key[0] === "_") return true;
|
|
||||||
|
|
||||||
// blacklist
|
|
||||||
var blacklist = opts.blacklist;
|
|
||||||
if (blacklist.length && includes(blacklist, key)) return false;
|
|
||||||
|
|
||||||
// whitelist
|
|
||||||
var whitelist = opts.whitelist;
|
|
||||||
if (whitelist) return includes(whitelist, key);
|
|
||||||
|
|
||||||
// stage
|
|
||||||
var stage = transformer.metadata.stage;
|
|
||||||
if (stage != null && stage >= opts.stage) return true;
|
|
||||||
|
|
||||||
// optional
|
|
||||||
if (transformer.metadata.optional && !includes(opts.optional, key)) return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
checkNode(node: Object): boolean {
|
checkPath(path: TraversalPath): boolean {
|
||||||
var check = this.transformer.check;
|
if (this.shouldTransform || this.ran) return;
|
||||||
if (check) {
|
|
||||||
return this.shouldRun = check(node);
|
this.shouldTransform = this.transformer.shouldVisit(path.node);
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
transform() {
|
transform() {
|
||||||
if (!this.shouldRun) return;
|
if (!this.shouldTransform) return;
|
||||||
|
|
||||||
var file = this.file;
|
var file = this.file;
|
||||||
|
|
||||||
file.log.debug(`Running transformer ${this.transformer.key}`);
|
file.log.debug(`Start transformer ${this.transformer.key}`);
|
||||||
|
|
||||||
traverse(file.ast, this.handlers, file.scope, file);
|
traverse(file.ast, this.handlers, file.scope, file);
|
||||||
|
|
||||||
|
file.log.debug(`Finish transformer ${this.transformer.key}`);
|
||||||
|
|
||||||
this.ran = true;
|
this.ran = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
100
src/babel/transformation/transformer-pipeline.js
Normal file
100
src/babel/transformation/transformer-pipeline.js
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
import Transformer from "./transformer";
|
||||||
|
import normalizeAst from "../helpers/normalize-ast";
|
||||||
|
import assign from "lodash/object/assign";
|
||||||
|
import object from "../helpers/object";
|
||||||
|
import File from "./file";
|
||||||
|
|
||||||
|
export default class TransformerPipeline {
|
||||||
|
constructor() {
|
||||||
|
this.transformers = object();
|
||||||
|
this.namespaces = object();
|
||||||
|
this.deprecated = object();
|
||||||
|
this.aliases = object();
|
||||||
|
this.filters = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
addTransformers(transformers) {
|
||||||
|
for (var key in transformers) {
|
||||||
|
this.addTransformer(key, transformers[key]);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
addTransformer(key, transformer) {
|
||||||
|
if (this.transformers[key]) throw new Error(); // todo: error
|
||||||
|
|
||||||
|
var namespace = key.split(".")[0];
|
||||||
|
this.namespaces[namespace] = this.namespaces[namespace] || [];
|
||||||
|
this.namespaces[namespace].push(key);
|
||||||
|
this.namespaces[key] = namespace;
|
||||||
|
|
||||||
|
this.transformers[key] = new Transformer(key, transformer);
|
||||||
|
}
|
||||||
|
|
||||||
|
addAliases(names) {
|
||||||
|
assign(this.aliases, names);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
addDeprecated(names) {
|
||||||
|
assign(this.deprecated, names);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
addFilter(filter: Function) {
|
||||||
|
this.filters.push(filter);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
canTransform(transformer, fileOpts) {
|
||||||
|
for (var filter of (this.filters: Array)) {
|
||||||
|
var result = filter(transformer, fileOpts);
|
||||||
|
if (result != null) return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
transform(code: string, opts?: Object) {
|
||||||
|
var file = new File(opts, this);
|
||||||
|
return file.parse(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
transformFromAst(ast, code, opts) {
|
||||||
|
ast = normalizeAst(ast);
|
||||||
|
|
||||||
|
var file = new File(opts, this);
|
||||||
|
file.addCode(code);
|
||||||
|
file.transform(ast);
|
||||||
|
return file.generate();
|
||||||
|
}
|
||||||
|
|
||||||
|
_ensureTransformerNames(type: string, rawKeys: Array<string>) {
|
||||||
|
var keys = [];
|
||||||
|
|
||||||
|
for (var i = 0; i < rawKeys.length; i++) {
|
||||||
|
var key = rawKeys[i];
|
||||||
|
|
||||||
|
var deprecatedKey = this.deprecated[key];
|
||||||
|
var aliasKey = this.aliases[key];
|
||||||
|
if (aliasKey) {
|
||||||
|
keys.push(aliasKey);
|
||||||
|
} else if (deprecatedKey) {
|
||||||
|
// deprecated key, remap it to the new one
|
||||||
|
console.error(`The transformer ${key} has been renamed to ${deprecatedKey}`);
|
||||||
|
rawKeys.push(deprecatedKey);
|
||||||
|
} else if (this.transformers[key]) {
|
||||||
|
// valid key
|
||||||
|
keys.push(key);
|
||||||
|
} else if (this.namespaces[key]) {
|
||||||
|
// namespace, append all transformers within this namespace
|
||||||
|
keys = keys.concat(this.namespaces[key]);
|
||||||
|
} else {
|
||||||
|
// invalid key
|
||||||
|
throw new ReferenceError(`Unknown transformer ${key} specified in ${type}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import TransformerPass from "./transformer-pass";
|
import TransformerPass from "./transformer-pass";
|
||||||
|
import * as messages from "../messages";
|
||||||
import isFunction from "lodash/lang/isFunction";
|
import isFunction from "lodash/lang/isFunction";
|
||||||
import traverse from "../traversal";
|
import traverse from "../traversal";
|
||||||
import isObject from "lodash/lang/isObject";
|
import isObject from "lodash/lang/isObject";
|
||||||
@@ -14,7 +15,7 @@ import each from "lodash/collection/each";
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export default class Transformer {
|
export default class Transformer {
|
||||||
constructor(transformerKey: key, transformer: Object, opts: Object) {
|
constructor(transformerKey: string, transformer: Object) {
|
||||||
transformer = assign({}, transformer);
|
transformer = assign({}, transformer);
|
||||||
|
|
||||||
var take = function (key) {
|
var take = function (key) {
|
||||||
@@ -24,19 +25,34 @@ export default class Transformer {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.manipulateOptions = take("manipulateOptions");
|
this.manipulateOptions = take("manipulateOptions");
|
||||||
|
this.shouldVisit = take("shouldVisit");
|
||||||
this.metadata = take("metadata") || {};
|
this.metadata = take("metadata") || {};
|
||||||
this.parser = take("parser");
|
this.parser = take("parser");
|
||||||
this.check = take("check");
|
|
||||||
this.post = take("post");
|
this.post = take("post");
|
||||||
this.pre = take("pre");
|
this.pre = take("pre");
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
if (this.metadata.stage != null) {
|
if (this.metadata.stage != null) {
|
||||||
this.metadata.optional = true;
|
this.metadata.optional = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
this.handlers = this.normalize(transformer);
|
this.handlers = this.normalize(transformer);
|
||||||
this.opts ||= {};
|
|
||||||
this.key = transformerKey;
|
this.key = transformerKey;
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
if (!this.shouldVisit) {
|
||||||
|
var types = Object.keys(this.handlers);
|
||||||
|
this.shouldVisit = function (node) {
|
||||||
|
for (var i = 0; i < types.length; i++) {
|
||||||
|
if (node.type === types[i]) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
normalize(transformer: Object): Object {
|
normalize(transformer: Object): Object {
|
||||||
@@ -71,7 +87,7 @@ export default class Transformer {
|
|||||||
buildPass(file: File): TransformerPass {
|
buildPass(file: File): TransformerPass {
|
||||||
// validate Transformer instance
|
// validate Transformer instance
|
||||||
if (!(file instanceof File)) {
|
if (!(file instanceof File)) {
|
||||||
throw new TypeError(`Transformer ${this.key} is resolving to a different Babel version to what is doing the actual transformation...`);
|
throw new TypeError(messages.get("transformerNotFile", this.key));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new TransformerPass(file, this);
|
return new TransformerPass(file, this);
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
import * as defineMap from "../../helpers/define-map";
|
import * as defineMap from "../../helpers/define-map";
|
||||||
import * as t from "../../../types";
|
import * as t from "../../../types";
|
||||||
|
|
||||||
export function check(node) {
|
export function shouldVisit(node) {
|
||||||
return t.isProperty(node) && (node.kind === "get" || node.kind === "set");
|
return t.isProperty(node) && (node.kind === "get" || node.kind === "set");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ObjectExpression(node) {
|
export function ObjectExpression(node, parent, scope, file) {
|
||||||
var mutatorMap = {};
|
var mutatorMap = {};
|
||||||
var hasAny = false;
|
var hasAny = false;
|
||||||
|
|
||||||
node.properties = node.properties.filter(function (prop) {
|
node.properties = node.properties.filter(function (prop) {
|
||||||
if (prop.kind === "get" || prop.kind === "set") {
|
if (prop.kind === "get" || prop.kind === "set") {
|
||||||
hasAny = true;
|
hasAny = true;
|
||||||
defineMap.push(mutatorMap, prop.key, prop.kind, prop.computed, prop.value);
|
defineMap.push(mutatorMap, prop, prop.kind, file);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user