Compare commits
400 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9385c7e4ad | ||
|
|
3c06e68cae | ||
|
|
e8810f5124 | ||
|
|
3c258c4716 | ||
|
|
193a3c167e | ||
|
|
4b525daf72 | ||
|
|
e46f42872a | ||
|
|
4790e4068a | ||
|
|
26cb5d5a65 | ||
|
|
031bda61cc | ||
|
|
61f1fae83b | ||
|
|
d911bdaf63 | ||
|
|
f322252c36 | ||
|
|
da16bf1e42 | ||
|
|
4a1addc558 | ||
|
|
857abf5024 | ||
|
|
6d67105bab | ||
|
|
078b09676f | ||
|
|
b719eaf6ab | ||
|
|
b63accca25 | ||
|
|
2d41b09c3b | ||
|
|
0b44137d1f | ||
|
|
8d8dd5fa37 | ||
|
|
16b7ff972c | ||
|
|
ca41612109 | ||
|
|
8fc7af5480 | ||
|
|
1c6cb7ce40 | ||
|
|
24d6c3f488 | ||
|
|
d877a04397 | ||
|
|
4844882f5e | ||
|
|
a80945cfb4 | ||
|
|
6a884c58a7 | ||
|
|
7c4701716c | ||
|
|
ecfd5fadc6 | ||
|
|
c6be5cccd7 | ||
|
|
dd256dc3f8 | ||
|
|
622da331a6 | ||
|
|
5a44793dcb | ||
|
|
9c9a9b0325 | ||
|
|
2534f7f2a0 | ||
|
|
36a933a004 | ||
|
|
62c168b13c | ||
|
|
810c97d7ab | ||
|
|
c2b20b18b3 | ||
|
|
309d19960f | ||
|
|
774cb66d9b | ||
|
|
d360bd5bb7 | ||
|
|
74f5a73d31 | ||
|
|
26395a86fa | ||
|
|
436c488ee3 | ||
|
|
93d99077e5 | ||
|
|
0bb52d6e3d | ||
|
|
320c78b815 | ||
|
|
ddd59b94b0 | ||
|
|
c210d64557 | ||
|
|
a0f605bbab | ||
|
|
f4b2768194 | ||
|
|
95d9f59668 | ||
|
|
c41d799b9b | ||
|
|
e7d4642d48 | ||
|
|
41949fd58b | ||
|
|
d0dc972840 | ||
|
|
621e66e9ac | ||
|
|
529544ce0e | ||
|
|
f298cd3f0f | ||
|
|
67029ac8e8 | ||
|
|
b54800234f | ||
|
|
ecd85f53b4 | ||
|
|
9098852897 | ||
|
|
3eb4d5b466 | ||
|
|
ddb1c718f1 | ||
|
|
8919873ea1 | ||
|
|
eb9cd95d5a | ||
|
|
4ec701fc44 | ||
|
|
ff9511d435 | ||
|
|
ac5a6da1fa | ||
|
|
616640a128 | ||
|
|
1f9ce96e43 | ||
|
|
dc6a862bec | ||
|
|
f9480b5280 | ||
|
|
8dc4996547 | ||
|
|
4f01f67dd6 | ||
|
|
938026abeb | ||
|
|
76b8945207 | ||
|
|
e78859fae0 | ||
|
|
d68f1e9910 | ||
|
|
20e97f2d9b | ||
|
|
750ec7783f | ||
|
|
14ae438735 | ||
|
|
2f8bdd7e27 | ||
|
|
87da9fcfc5 | ||
|
|
51f6cfddca | ||
|
|
b9ad4c2773 | ||
|
|
228b3dbc34 | ||
|
|
a01802300f | ||
|
|
51c6a3fffc | ||
|
|
4668e1d67b | ||
|
|
75e9097e19 | ||
|
|
0627cd94d4 | ||
|
|
71879d6e8f | ||
|
|
d7810cac08 | ||
|
|
dc9efd21d3 | ||
|
|
347e490614 | ||
|
|
e512264be7 | ||
|
|
9624663e60 | ||
|
|
3cf8a6df01 | ||
|
|
88eacecd72 | ||
|
|
fcd3c9ce65 | ||
|
|
1733bac3bb | ||
|
|
21cd063274 | ||
|
|
db5750643a | ||
|
|
60dae7a88d | ||
|
|
790c924b54 | ||
|
|
50d7a46c7f | ||
|
|
6f7da38957 | ||
|
|
80764c214a | ||
|
|
55054e45da | ||
|
|
060aa5ba0b | ||
|
|
688d619bfe | ||
|
|
6db7fce543 | ||
|
|
41ff1d4ace | ||
|
|
1c6eeba2e9 | ||
|
|
488b719fde | ||
|
|
af32080287 | ||
|
|
4c1cd13536 | ||
|
|
1002cf7796 | ||
|
|
081dd33e73 | ||
|
|
bd9dc4f15d | ||
|
|
c7ba566ad6 | ||
|
|
a1b326a0ab | ||
|
|
a452f781b8 | ||
|
|
e5463cc2a9 | ||
|
|
7d732ef503 | ||
|
|
25cb0c6344 | ||
|
|
45a52bf478 | ||
|
|
a14f971b8a | ||
|
|
da65500545 | ||
|
|
58a91ee9e9 | ||
|
|
19eaa181a5 | ||
|
|
c7c90acf3f | ||
|
|
c6f3a55c03 | ||
|
|
e01b7d288f | ||
|
|
98c0e185b8 | ||
|
|
bf66d78210 | ||
|
|
b60eca0a76 | ||
|
|
44f06c0b4c | ||
|
|
6c5606b7e8 | ||
|
|
07ddfbeb5d | ||
|
|
87b890c172 | ||
|
|
245fcfe110 | ||
|
|
4744719040 | ||
|
|
a3b814a897 | ||
|
|
f5f17f0ccb | ||
|
|
f6a2acdfb1 | ||
|
|
e8dba2ad1e | ||
|
|
8ce5c5b608 | ||
|
|
0dfea1a51b | ||
|
|
a4e528e2b3 | ||
|
|
99ca9b7e9a | ||
|
|
313e932e7c | ||
|
|
6a57a4e565 | ||
|
|
fc3a5f25fb | ||
|
|
e258b85420 | ||
|
|
6b836de306 | ||
|
|
fe6f53d471 | ||
|
|
3b259c6b1e | ||
|
|
2005df3fa2 | ||
|
|
4fdcf685d3 | ||
|
|
afd3af834d | ||
|
|
8afec8b12a | ||
|
|
f25ed0b5de | ||
|
|
4898770d60 | ||
|
|
bd2fa77446 | ||
|
|
1c2bafe0e1 | ||
|
|
f8915333b0 | ||
|
|
f8275adc6f | ||
|
|
2a97a4233d | ||
|
|
70eae9f6ce | ||
|
|
f560062d82 | ||
|
|
0f55a66f5b | ||
|
|
f14f72b635 | ||
|
|
9aa010d987 | ||
|
|
bd179ace86 | ||
|
|
4df6d6043e | ||
|
|
7ed7475c46 | ||
|
|
b2dc560a2d | ||
|
|
010dbe1cce | ||
|
|
75cd0bab02 | ||
|
|
3283991ed0 | ||
|
|
a66ce5b6ce | ||
|
|
9620f50f22 | ||
|
|
cc049ea851 | ||
|
|
e5a04ae117 | ||
|
|
e07e74f010 | ||
|
|
7b04c501eb | ||
|
|
70349dd4b3 | ||
|
|
2cedc843a8 | ||
|
|
cf40fe3430 | ||
|
|
09ffeed139 | ||
|
|
18f79d6253 | ||
|
|
6f5270f38f | ||
|
|
aac7aac373 | ||
|
|
9361470dc7 | ||
|
|
cf579f4b6e | ||
|
|
2e497eef98 | ||
|
|
7867daaa04 | ||
|
|
eabbcd31ad | ||
|
|
17d198f3d6 | ||
|
|
afd5376c8d | ||
|
|
02a50c9f7e | ||
|
|
df9fa32b82 | ||
|
|
831b420df3 | ||
|
|
123186003c | ||
|
|
ea627ed57c | ||
|
|
157bb48776 | ||
|
|
76a3771943 | ||
|
|
54f8889a30 | ||
|
|
bab159bc08 | ||
|
|
23950963e5 | ||
|
|
d1daac5550 | ||
|
|
d93ece5ccf | ||
|
|
c8c667bf16 | ||
|
|
49cdacbcb4 | ||
|
|
f97bd584f7 | ||
|
|
f1328aa82f | ||
|
|
e298a5d350 | ||
|
|
89a6ef0b26 | ||
|
|
c7ac9b7815 | ||
|
|
55c99b9122 | ||
|
|
545c8c3adb | ||
|
|
d093dc8231 | ||
|
|
eaf9d58b8d | ||
|
|
6131cea5b2 | ||
|
|
ca4831febe | ||
|
|
9cf8d05a19 | ||
|
|
2a4f03330b | ||
|
|
83bc614bad | ||
|
|
99ccb4111a | ||
|
|
f6c72e9ae9 | ||
|
|
a90730d4bf | ||
|
|
29503d2d37 | ||
|
|
35451ed408 | ||
|
|
7167aeb65a | ||
|
|
29d0489443 | ||
|
|
82aa2686f9 | ||
|
|
24616fa08a | ||
|
|
9f3e1eabfd | ||
|
|
286d2f84bd | ||
|
|
7fc484d82e | ||
|
|
ad6ab57fe3 | ||
|
|
348fe045d3 | ||
|
|
980b20316b | ||
|
|
5b52e507ca | ||
|
|
9853c9d78d | ||
|
|
72ec771725 | ||
|
|
75e97d9f7e | ||
|
|
295faf185c | ||
|
|
54b05f33f2 | ||
|
|
1985146760 | ||
|
|
13a52dd300 | ||
|
|
9d4bea70e6 | ||
|
|
421906bcc1 | ||
|
|
508b3531e5 | ||
|
|
c67c407cd0 | ||
|
|
aa552fea0d | ||
|
|
9bbf109dc8 | ||
|
|
393d52088a | ||
|
|
5783973734 | ||
|
|
55e01afd0d | ||
|
|
1231dc6cef | ||
|
|
b08f2061b5 | ||
|
|
1536d3de91 | ||
|
|
fddacb1612 | ||
|
|
9d1ff2b71b | ||
|
|
1c8d24f78c | ||
|
|
b619e843a9 | ||
|
|
e6a71c5849 | ||
|
|
682668c219 | ||
|
|
dd64297838 | ||
|
|
944a9d3908 | ||
|
|
d6922c9b75 | ||
|
|
fb0fcc7138 | ||
|
|
89148e6029 | ||
|
|
28d10b8eb4 | ||
|
|
3509990563 | ||
|
|
c5960fb9f7 | ||
|
|
07131576cf | ||
|
|
e75e778300 | ||
|
|
f6cb14c975 | ||
|
|
af1912ab7a | ||
|
|
8c478f29bc | ||
|
|
5b4d6d7ba9 | ||
|
|
1776b072b0 | ||
|
|
726fad1b6c | ||
|
|
23c16b0094 | ||
|
|
24f70ee4d0 | ||
|
|
fe9b0afd95 | ||
|
|
47695a8710 | ||
|
|
e1c7584280 | ||
|
|
3e63e6cd4b | ||
|
|
ba643680e5 | ||
|
|
611137c7d7 | ||
|
|
6240e5111f | ||
|
|
324a4a1b22 | ||
|
|
035f667a8f | ||
|
|
98985dd253 | ||
|
|
0a207903ce | ||
|
|
90437d262b | ||
|
|
4aba7ec192 | ||
|
|
a924c9c218 | ||
|
|
a2ed0ea9c5 | ||
|
|
c5cd729c3d | ||
|
|
b065d43a6d | ||
|
|
281003c7bd | ||
|
|
6650336c64 | ||
|
|
f904734695 | ||
|
|
0528560d81 | ||
|
|
4362ba93de | ||
|
|
ca12e87370 | ||
|
|
ebaa735adc | ||
|
|
62e406a6fe | ||
|
|
0d45a8975c | ||
|
|
8f64fe2332 | ||
|
|
a8a7587c1f | ||
|
|
7736fa11f2 | ||
|
|
d203924541 | ||
|
|
cd23e500a1 | ||
|
|
bf24a0d6b5 | ||
|
|
279d1affea | ||
|
|
2a1e012240 | ||
|
|
a307a961a6 | ||
|
|
fe5b1dc542 | ||
|
|
f057347ae9 | ||
|
|
98f2287267 | ||
|
|
e60e0e0b0e | ||
|
|
81fb8647b6 | ||
|
|
e8387c7de5 | ||
|
|
655196f3ce | ||
|
|
eef371c3df | ||
|
|
a3d21f02c6 | ||
|
|
ad4386c0ed | ||
|
|
3c82a61af1 | ||
|
|
3c154f9f6d | ||
|
|
22c972e85b | ||
|
|
6d7e14fb2b | ||
|
|
9287449372 | ||
|
|
44a35400f5 | ||
|
|
2305e2447f | ||
|
|
c420d1ffc3 | ||
|
|
fa42b076a7 | ||
|
|
0d23c1cfdb | ||
|
|
0dafdd6969 | ||
|
|
a9af8d39a2 | ||
|
|
1cc606d4d0 | ||
|
|
2a09c0a5a5 | ||
|
|
92359520cd | ||
|
|
50e5bd4680 | ||
|
|
64ef26a937 | ||
|
|
bfd6ffe471 | ||
|
|
8c1760bea2 | ||
|
|
bdb8f87480 | ||
|
|
7f6bc54920 | ||
|
|
b6af2f826d | ||
|
|
7455b6d9b9 | ||
|
|
0d2e876178 | ||
|
|
57ce1b201d | ||
|
|
5f56da457c | ||
|
|
ed988dc2bb | ||
|
|
2c471968ea | ||
|
|
fd1a91bf9c | ||
|
|
9e7de5ad2e | ||
|
|
06927288ba | ||
|
|
9342aee6bd | ||
|
|
4f5669f53c | ||
|
|
262fd995da | ||
|
|
1696f77980 | ||
|
|
dfa51954b8 | ||
|
|
216b8c2fd1 | ||
|
|
ca2cbb02f1 | ||
|
|
b72427cdd0 | ||
|
|
44e9812ad4 | ||
|
|
b7814e5e24 | ||
|
|
ec67a83326 | ||
|
|
6a560cea25 | ||
|
|
46f9ed7d74 | ||
|
|
92366dfc7b | ||
|
|
f520a46175 | ||
|
|
88bec1196b | ||
|
|
ff0098f3f3 | ||
|
|
d01d7722f4 | ||
|
|
abc90778e8 | ||
|
|
56f1683f06 | ||
|
|
520dd7e947 | ||
|
|
17ce21509d | ||
|
|
a4c8895dc3 | ||
|
|
af4009694a | ||
|
|
941a8cc5ea | ||
|
|
359c4e8786 | ||
|
|
7ac98c1532 | ||
|
|
61c3e0a3de |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -10,3 +10,4 @@ test/tmp
|
|||||||
/runtime.js
|
/runtime.js
|
||||||
coverage
|
coverage
|
||||||
dist
|
dist
|
||||||
|
.package.json
|
||||||
|
|||||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -4,3 +4,6 @@
|
|||||||
[submodule "vendor/regenerator"]
|
[submodule "vendor/regenerator"]
|
||||||
path = vendor/regenerator
|
path = vendor/regenerator
|
||||||
url = https://github.com/facebook/regenerator
|
url = https://github.com/facebook/regenerator
|
||||||
|
[submodule "vendor/test262"]
|
||||||
|
path = vendor/test262
|
||||||
|
url = https://github.com/tc39/test262
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
"camelcase": true,
|
"camelcase": true,
|
||||||
"unused": true,
|
"unused": true,
|
||||||
"eqnull": true,
|
"eqnull": true,
|
||||||
"proto": true,
|
|
||||||
"newcap": true,
|
"newcap": true,
|
||||||
"supernew": true,
|
"supernew": true,
|
||||||
"noyield": true,
|
"noyield": true,
|
||||||
@@ -14,8 +13,6 @@
|
|||||||
"boss": true,
|
"boss": true,
|
||||||
"expr": true,
|
"expr": true,
|
||||||
"undef": true,
|
"undef": true,
|
||||||
"loopfunc": true,
|
|
||||||
"white": true,
|
|
||||||
"maxparams": 5,
|
"maxparams": 5,
|
||||||
"maxdepth": 4,
|
"maxdepth": 4,
|
||||||
|
|
||||||
|
|||||||
@@ -9,3 +9,6 @@ Makefile
|
|||||||
dist
|
dist
|
||||||
tests.json
|
tests.json
|
||||||
CHANGELOG.md
|
CHANGELOG.md
|
||||||
|
.package.json
|
||||||
|
coverage
|
||||||
|
vendor
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
sudo: false
|
||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
- "0.10"
|
- "0.10"
|
||||||
|
|||||||
275
CHANGELOG.md
275
CHANGELOG.md
@@ -7,25 +7,272 @@
|
|||||||
> - [Breaking Change]
|
> - [Breaking Change]
|
||||||
> - [Documentation]
|
> - [Documentation]
|
||||||
> - [Internal]
|
> - [Internal]
|
||||||
> - [Misc]
|
> - [Polish]
|
||||||
|
|
||||||
_Note: Gaps between patch versions are faulty/broken releases._
|
_Note: Gaps between patch versions are faulty/broken releases._
|
||||||
|
|
||||||
|
## 2.13.4
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Fix ordering of destructuring and default params.
|
||||||
|
* Fix loop body scope.
|
||||||
|
* Fix `for...of` transformation not retaining it's scope.
|
||||||
|
* Add destructuring assignment support to scope tracking.
|
||||||
|
* **Polish**
|
||||||
|
* More reliable newlines for pretty printing variable declarations.
|
||||||
|
|
||||||
|
## 2.13.3
|
||||||
|
|
||||||
|
* **Internal**
|
||||||
|
* Add `coverage` and `vendor` to npmignore.
|
||||||
|
|
||||||
|
## 2.13.2
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Fix `super` inside of nested functions.
|
||||||
|
* **Internal**
|
||||||
|
* Move let scoping TDZ into a separate transformer until it's more solid.
|
||||||
|
* Use `process.stdin.write` instead of `console.log` in `bin` to avoid sprintfification.
|
||||||
|
|
||||||
|
## 2.13.1
|
||||||
|
|
||||||
|
* **New Feature**
|
||||||
|
* Temporal dead zone for block binding.
|
||||||
|
|
||||||
|
## 2.13.0
|
||||||
|
|
||||||
|
* **New Feature**
|
||||||
|
* Block scoped functions.
|
||||||
|
* Add `--loose all` option.
|
||||||
|
* Add playground mallet operator thanks to [@jridgewell](https://github.com/jridgewell).
|
||||||
|
* **Bug Fix**
|
||||||
|
* Rewrote large parts of the let scoping transformer. Now passes all known tests.
|
||||||
|
* **Internal**
|
||||||
|
* Even more optimisations thanks to the awesome [@gaearon](https://github.com/gaearon).
|
||||||
|
* Upgrade `acorn-6to5`.
|
||||||
|
* Fixes exponentation operator thanks to [@charliesome](https://github.com/charliesome).
|
||||||
|
* Fix flow optional parameters with types.
|
||||||
|
* Upgrade `chokidar` to `0.12.6`.
|
||||||
|
* Upgrade `commander` to `2.6.0`.
|
||||||
|
* Upgrade `core-js` to `0.4.5`.
|
||||||
|
* Upgrade `estraverse` to `1.9.1`.
|
||||||
|
* Upgrade `jshint` to `2.5.11`.
|
||||||
|
* Upgrade `regenerator` to `0.8.9`.
|
||||||
|
* Upgrade `regexpu` to `1.0.0`.
|
||||||
|
* Upgrade `source-map` to `0.1.43`.
|
||||||
|
* Upgrade `source-map-support` to `0.2.9`.
|
||||||
|
* Upgrade `browserify` to `8.1.1`.
|
||||||
|
* Upgrade `chai` to `1.10.0`.
|
||||||
|
* Upgrade `istanbul` to `0.3.5`.
|
||||||
|
* Upgrade `mocha` to `2.1.0`.
|
||||||
|
* Upgrade `uglify-js` to `2.4.16`.
|
||||||
|
|
||||||
|
## 2.12.6
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Add missing flow type traversal keys.
|
||||||
|
|
||||||
|
## 2.12.5
|
||||||
|
|
||||||
|
* **Internal**
|
||||||
|
* Fix incorrect `for...in` loop still causing `ember-script` issues.
|
||||||
|
|
||||||
|
## 2.12.4
|
||||||
|
|
||||||
|
* **Polish**
|
||||||
|
* Rest parameters now allocate the array before populating.
|
||||||
|
* **Internal**
|
||||||
|
* `for...in` loops have been changed to optimised `for` loops - better performance and no enumeration of protoype keys.
|
||||||
|
* Parts of the code generator have now been optimised thanks to [gaearon](https://github.com/gaearon).
|
||||||
|
|
||||||
|
## 2.12.3
|
||||||
|
|
||||||
|
* **Spec Compliancy**
|
||||||
|
* Optional `typeof` transformer checks for `undefined` before passing it to the helper.
|
||||||
|
* Class methods are now named.
|
||||||
|
|
||||||
|
## 2.12.2
|
||||||
|
|
||||||
|
* **Internal**
|
||||||
|
* Exclude nodes in function parameters and catch clauses from `isReferenced` check.
|
||||||
|
|
||||||
|
## 2.12.1
|
||||||
|
|
||||||
|
* **Internal**
|
||||||
|
* Add `.jsx` to list of allowed extensions.
|
||||||
|
|
||||||
|
## 2.12.0
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Support non-string JSX literals.
|
||||||
|
* **New Feature**
|
||||||
|
* Loose mode for some transformers that enables non-spec behaviour.
|
||||||
|
* **Internal**
|
||||||
|
* Uglify `--mangle sort` has been added to the build script, cutting minified scripts in half.
|
||||||
|
|
||||||
|
## 2.11.4
|
||||||
|
|
||||||
|
* **Internal**
|
||||||
|
* Make all dependency versions fixed.
|
||||||
|
|
||||||
|
## 2.11.3
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Allow a string to be passed as the `optional` option.
|
||||||
|
|
||||||
|
## 2.11.2
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Support esprima-style catch clause handlers.
|
||||||
|
* **Polish**
|
||||||
|
* Don't print a stacktrace for syntax errors in the CLI.
|
||||||
|
|
||||||
|
## 2.11.1
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Remove stray `console.log` outputting debug code.
|
||||||
|
* Remove `Dict` from `coreAliasing`.
|
||||||
|
|
||||||
|
## 2.11.0
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Fix unnecessary IIFE in default parameters on method calls.
|
||||||
|
* Add support for supers inside of closures.
|
||||||
|
* **New Feature**
|
||||||
|
* Add `--keep-module-id-extensions`/`keepModuleIdExtensions` option to keep extensions in module ids.
|
||||||
|
* **Polish**
|
||||||
|
* Special case single argument spread properties in `super` inside classes.
|
||||||
|
* Don't use a variable declaration for class declaration IFFE.
|
||||||
|
* Rename `inherits` helper parameters.
|
||||||
|
* `coreAliasing` transformer now aliases `Promise`, `Set`, `Map` and more. Thanks [@AluisioASG](https://github.com/AluisioASG).
|
||||||
|
|
||||||
|
## 2.10.1
|
||||||
|
|
||||||
|
* **Internal**
|
||||||
|
* Upgrade `core-js` to `0.4.4`.
|
||||||
|
* **New Feature**
|
||||||
|
* Added `--include-regenerator` option to CLI and `includeRegenerator` option to API that includes the regenerator runtime if necessary.
|
||||||
|
|
||||||
|
## 2.10.0
|
||||||
|
|
||||||
|
* **New Feature**
|
||||||
|
* Add `classesFastSuper` optional transformer that doesn't support parent getters and prototype changing.
|
||||||
|
* Add `forOfFast` transformer that speeds up `for...of` on arrays but produces more code.
|
||||||
|
* Add `--react-compat` to `bin/6to5`.
|
||||||
|
* **Spec Compliancy**
|
||||||
|
* Disallow setters without a single parameter.
|
||||||
|
* Add `configurable` and `writable` to defined properties.
|
||||||
|
* Use define instead of assignment for class methods.
|
||||||
|
* **Polish**
|
||||||
|
* Fix bin name in `6to5-node --help`.
|
||||||
|
* Fix shorthand `--whitelist` name in `bin/6to5`.
|
||||||
|
* **Internal**
|
||||||
|
* Hot code optimisation of traversal etc thanks to [gaearon](https://github.com/gaearon).
|
||||||
|
|
||||||
|
## 2.9.4
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Support `UpdateExpression`s as `MemberExpression` objects.
|
||||||
|
|
||||||
|
## 2.9.3
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Remove `exportsWildcard` helper in favor of `defaults`.
|
||||||
|
|
||||||
|
## 2.9.2
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Pass `exports` to `exportWildcard` helper to allow for use inside the optional runtime.
|
||||||
|
|
||||||
|
## 2.9.1
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Fix runtime generator breaking the helper inclusion loop.
|
||||||
|
|
||||||
|
## 2.9.0
|
||||||
|
|
||||||
|
* **Internal**
|
||||||
|
* Upgrade `acorn-6to5`.
|
||||||
|
* Now supports destructuring shorthand properties.
|
||||||
|
|
||||||
|
## 2.8.1
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Fix computed accessors on object literals.
|
||||||
|
|
||||||
|
## 2.8.0
|
||||||
|
|
||||||
|
* **New Feature**
|
||||||
|
* Add `commonStrict`, `amdStrict` and `umdStrict` module formatters that remove `module.exports` interop assignment.
|
||||||
|
* Add `--indent` option to the 6to5 CLI.
|
||||||
|
|
||||||
|
## 2.7.4
|
||||||
|
|
||||||
|
* **Polish**
|
||||||
|
* Inherit assignments from their declaration in destructuring.
|
||||||
|
* Properly align multi-declarator variable declarations.
|
||||||
|
|
||||||
|
## 2.7.3
|
||||||
|
|
||||||
|
* **Polish**
|
||||||
|
* Indent and add newlines to `React.createElement` calls in `react` transformer.
|
||||||
|
* Remove `Object.assign` calls and replace it with an `extends` helper.
|
||||||
|
|
||||||
|
## 2.7.1
|
||||||
|
|
||||||
|
* **New Feature**
|
||||||
|
* Expose `version` on browser and node API.
|
||||||
|
* **Internal**
|
||||||
|
* Upgrade `core-js` to 0.4.1
|
||||||
|
|
||||||
|
## 2.7.0
|
||||||
|
|
||||||
|
* **Spec Compliancy**
|
||||||
|
* Disallow reassignments of imports.
|
||||||
|
* **New Feature**
|
||||||
|
* `reactCompat` option to enable pre-v0.12 react components.
|
||||||
|
|
||||||
|
## 2.6.3
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Fix 2.6.0 regression caused by faulty export default from a source handling.
|
||||||
|
|
||||||
|
## 2.6.2
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Fix rest parameter keys when on functions with params.
|
||||||
|
|
||||||
|
## 2.6.1
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Fix rest parameter arguments key.
|
||||||
|
|
||||||
## 2.6.0
|
## 2.6.0
|
||||||
|
|
||||||
* [Internal] Fix incorrect AST node `identifier("this")`.
|
* **Bug Fix**
|
||||||
* [Spec Compliancy] Add `interopRequireWildcard` around wildcard imports and exports to handle non-object exports.
|
* Better handling of number literal property keys.
|
||||||
* [Internal] Upgrade `acorn-6to5`.
|
* Handle `NewExpression` paren insertion edegcases better.
|
||||||
* [New Feature] Basic destructuring defaults
|
* **Internal**
|
||||||
* [New Feature] Add `.es` to list of supported extensions.
|
* Fix incorrect AST node `identifier("this")`.
|
||||||
* [New Feature] Add optional `typeofSymbol` transformer.
|
* Better `toIdentifier` method that handles reserved words.
|
||||||
* [Bug Fix] Better handling of number literal property keys.
|
* Upgrade `acorn-6to5`.
|
||||||
* [Bug Fix] [Internal] Better `toIdentifier` method that handles reserved words.
|
* Fix exponentiation operator precedence.
|
||||||
* [Internal] Upgrade to `core-js` 4.0.0.
|
* Fix line terminators after async contextual keywords.
|
||||||
* [Internal] Upgrade to `regenerator` 0.8.3.
|
* Add semicolons as class elements inside of a class body.
|
||||||
* [Bug Fix] Handle `NewExpression` paren insertion edegcases better.
|
* Upgrade to `core-js` 4.0.0.
|
||||||
* [Spec Compliancy] Class inheritance now has a `function` or `null` type check.
|
* Upgrade to `regenerator` 0.8.3.
|
||||||
* [Misc] Move `"use strict";` to inside module bodies instead of at the top of the file.
|
* Fix non-loop labeled statements.
|
||||||
|
* **New Feature**
|
||||||
|
* Basic destructuring defaults
|
||||||
|
* Add `.es` to list of supported extensions.
|
||||||
|
* Add optional `typeofSymbol` transformer.
|
||||||
|
* Use a `for` loop for rest parameters instead of `Array.prototype.slice`.
|
||||||
|
* **Polish**
|
||||||
|
* Move `"use strict";` to inside module bodies instead of at the top of the file.
|
||||||
|
* Better handling of dynamic imports.
|
||||||
|
* **Spec Compliancy**
|
||||||
|
* Class inheritance now has a `function` or `null` type check.
|
||||||
|
* Add `interopRequireWildcard` around wildcard imports and exports to handle non-object exports.
|
||||||
|
|
||||||
## 2.5.0
|
## 2.5.0
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,20 @@
|
|||||||
# Contributing
|
# Contributing
|
||||||
|
|
||||||
Before contributing, please read the [code of conduct](https://github.com/6to5/6to5/blob/master/CODE_OF_CONDUCT.md).
|
Contributions are always welcome, no matter how large or small. Before contributing, please read the [code of conduct](https://github.com/6to5/6to5/blob/master/CODE_OF_CONDUCT.md).
|
||||||
|
|
||||||
|
## Developing
|
||||||
|
|
||||||
|
#### Workflow
|
||||||
|
|
||||||
|
* Fork the repository
|
||||||
|
* Clone your fork and change directory to it (`git clone git@github.com:yourUserName/6to5.git && cd 6to5`)
|
||||||
|
* Install the project dependencies (`make bootstrap`)
|
||||||
|
* Link your forked clone (`npm link`)
|
||||||
|
* Develop your changes ensuring you're fetching updates from upstream often
|
||||||
|
* Ensure the test are passing (`make test`)
|
||||||
|
* Create new pull request explaining your proposed change or reference an issue in your commit message
|
||||||
|
|
||||||
|
#### Code Standards
|
||||||
|
|
||||||
* **General**
|
* **General**
|
||||||
* No ES6 syntax features or methods, exclusively ES5.
|
* No ES6 syntax features or methods, exclusively ES5.
|
||||||
|
|||||||
42
Makefile
42
Makefile
@@ -1,12 +1,13 @@
|
|||||||
BROWSERIFY_CMD = node_modules/browserify/bin/cmd.js
|
BROWSERIFY_CMD = node_modules/browserify/bin/cmd.js
|
||||||
ISTANBUL_CMD = node_modules/istanbul/lib/cli.js cover
|
ISTANBUL_CMD = node_modules/istanbul/lib/cli.js cover
|
||||||
UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs
|
UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs
|
||||||
|
#UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs --mangle sort
|
||||||
JSHINT_CMD = node_modules/jshint/bin/jshint
|
JSHINT_CMD = node_modules/jshint/bin/jshint
|
||||||
MOCHA_CMD = node_modules/mocha/bin/_mocha
|
MOCHA_CMD = node_modules/mocha/bin/_mocha
|
||||||
|
|
||||||
export NODE_ENV = test
|
export NODE_ENV = test
|
||||||
|
|
||||||
.PHONY: clean test test-cov test-clean lint test-travis test-spec test-browser publish bench build bootstrap
|
.PHONY: clean test test-cov test-clean lint test-travis test-simple test-all test-browser publish build bootstrap publish-core
|
||||||
|
|
||||||
build:
|
build:
|
||||||
mkdir -p dist
|
mkdir -p dist
|
||||||
@@ -27,12 +28,8 @@ build:
|
|||||||
clean:
|
clean:
|
||||||
rm -rf coverage templates.json test/tmp dist
|
rm -rf coverage templates.json test/tmp dist
|
||||||
|
|
||||||
bench:
|
|
||||||
npm install es6-transpiler traceur esnext es6now jstransform
|
|
||||||
node node_modules/matcha/bin/_matcha
|
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
$(JSHINT_CMD) --reporter node_modules/jshint-stylish/stylish.js lib bin benchmark/index.js
|
$(JSHINT_CMD) --reporter node_modules/jshint-stylish/stylish.js lib bin
|
||||||
|
|
||||||
test-clean:
|
test-clean:
|
||||||
rm -rf test/tmp
|
rm -rf test/tmp
|
||||||
@@ -41,14 +38,23 @@ test: lint
|
|||||||
$(MOCHA_CMD)
|
$(MOCHA_CMD)
|
||||||
make test-clean
|
make test-clean
|
||||||
|
|
||||||
|
test-simple:
|
||||||
|
# excludes test262
|
||||||
|
export SIMPLE_6TO5_TESTS=1
|
||||||
|
make test
|
||||||
|
|
||||||
|
test-all:
|
||||||
|
# includes traceur, esnext, regenerator
|
||||||
|
export ALL_6TO5_TESTS=1
|
||||||
|
make test
|
||||||
|
|
||||||
test-cov:
|
test-cov:
|
||||||
|
export SIMPLE_6TO5_TESTS=1
|
||||||
rm -rf coverage
|
rm -rf coverage
|
||||||
node $(ISTANBUL_CMD) $(MOCHA_CMD) --
|
node $(ISTANBUL_CMD) $(MOCHA_CMD) --
|
||||||
|
|
||||||
test-spec:
|
test-travis: bootstrap
|
||||||
node $(ISTANBUL_CMD) $(MOCHA_CMD) -- --reporter spec
|
node $(ISTANBUL_CMD) $(MOCHA_CMD) --
|
||||||
|
|
||||||
test-travis: test-spec
|
|
||||||
if test -n "$$CODECLIMATE_REPO_TOKEN"; then codeclimate < coverage/lcov.info; fi
|
if test -n "$$CODECLIMATE_REPO_TOKEN"; then codeclimate < coverage/lcov.info; fi
|
||||||
|
|
||||||
test-browser:
|
test-browser:
|
||||||
@@ -66,6 +72,9 @@ publish:
|
|||||||
|
|
||||||
make test
|
make test
|
||||||
|
|
||||||
|
read -p "Version: " version; \
|
||||||
|
npm version $$version --message "v%s"
|
||||||
|
|
||||||
make build
|
make build
|
||||||
cp dist/6to5.min.js browser.js
|
cp dist/6to5.min.js browser.js
|
||||||
cp dist/polyfill.min.js browser-polyfill.js
|
cp dist/polyfill.min.js browser-polyfill.js
|
||||||
@@ -74,12 +83,21 @@ publish:
|
|||||||
node bin/cache-templates
|
node bin/cache-templates
|
||||||
test -f templates.json
|
test -f templates.json
|
||||||
|
|
||||||
read -p "Version: " version; \
|
|
||||||
npm version $$version --message "v%s"
|
|
||||||
npm publish
|
npm publish
|
||||||
|
|
||||||
git push --follow-tags
|
git push --follow-tags
|
||||||
|
|
||||||
|
# generate
|
||||||
|
bin/generate-core-package-json >package2.json
|
||||||
|
mv package.json .package.json
|
||||||
|
mv package2.json package.json
|
||||||
|
|
||||||
|
npm publish
|
||||||
|
|
||||||
|
# restore
|
||||||
|
rm -rf package.json
|
||||||
|
mv .package.json package.json
|
||||||
|
|
||||||
rm -rf templates.json browser.js runtime.js browser-polyfill.js
|
rm -rf templates.json browser.js runtime.js browser-polyfill.js
|
||||||
|
|
||||||
bootstrap:
|
bootstrap:
|
||||||
|
|||||||
13
NOTES.md
13
NOTES.md
@@ -1,3 +1,14 @@
|
|||||||
# Notes
|
# Notes
|
||||||
|
|
||||||
* Wildcard exports/imports wont normalise if `export default` is a non-object.
|
* Wildcard exports/imports wont normalise if `export default` is a non-object. See [#224](https://github.com/6to5/6to5/issues/224).
|
||||||
|
|
||||||
|
## 3.0.0 breaking changes
|
||||||
|
|
||||||
|
* Remove `allowImportExportEverywhere` option from acorn.
|
||||||
|
* Remove this shorthand from playground.
|
||||||
|
* Remove `super()` inside non-constructors - add descriptive error message.
|
||||||
|
* Split up ES5 getter/setter transforming and ES6 property methods into separate transformers.
|
||||||
|
* Add autoindentation.
|
||||||
|
* Move `super` transformation from classes into a separate transformer that also supports object expressions.
|
||||||
|
* Remove fast transformer backwards compatibility.
|
||||||
|
* Rename let scoping transformer to block scoping.
|
||||||
|
|||||||
@@ -1,99 +0,0 @@
|
|||||||
var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
||||||
var obj = {};
|
|
||||||
var foo = "foo";
|
|
||||||
var bar = "bar";
|
|
||||||
|
|
||||||
// constants
|
|
||||||
const MULTIPLIER = 5;
|
|
||||||
|
|
||||||
// classes
|
|
||||||
class Foo {
|
|
||||||
constructor() {
|
|
||||||
this.foo = "bar";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Bar extends Foo {
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
// default parameters
|
|
||||||
go(foo = "bar", bar = "foo") {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// not supported by jstransform
|
|
||||||
//get foo() {
|
|
||||||
// return this._foo;
|
|
||||||
//}
|
|
||||||
//set foo(val) {
|
|
||||||
// this._foo = val + " foo!";
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
// arrow functions
|
|
||||||
arr.map(x => x * x);
|
|
||||||
|
|
||||||
// block binding
|
|
||||||
for (let key in arr) {
|
|
||||||
let val = arr[key];
|
|
||||||
console.log(key, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
// computed property names
|
|
||||||
obj = {
|
|
||||||
["foo" + bar]: "foobar"
|
|
||||||
};
|
|
||||||
|
|
||||||
// destructuring
|
|
||||||
var [a, [b], c, d] = ["hello", [", ", "junk"], ["world"]];
|
|
||||||
console.log(a + b + c);
|
|
||||||
|
|
||||||
// array comprehension
|
|
||||||
// [for (i of [1, 2, 3]) i * i]; // not supported by es6now
|
|
||||||
|
|
||||||
// for-of
|
|
||||||
for (var i of [1, 2, 3]) {
|
|
||||||
console.log(i * i);
|
|
||||||
}
|
|
||||||
|
|
||||||
// property method assignment
|
|
||||||
obj = {
|
|
||||||
foo() {
|
|
||||||
return "foobar";
|
|
||||||
},
|
|
||||||
|
|
||||||
get bar() {
|
|
||||||
return this._bar;
|
|
||||||
},
|
|
||||||
|
|
||||||
set bar(val) {
|
|
||||||
this._bar = val;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// property name shorthand
|
|
||||||
function f(x, y) {
|
|
||||||
return { x, y };
|
|
||||||
}
|
|
||||||
|
|
||||||
// rest parameters
|
|
||||||
function printList(name, ...items) {
|
|
||||||
console.log("list %s has the following items", name);
|
|
||||||
items.forEach(function (item) {
|
|
||||||
console.log(item);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// spread
|
|
||||||
function add(x, y) {
|
|
||||||
return x + y;
|
|
||||||
}
|
|
||||||
var numbers = [5, 10];
|
|
||||||
add(...numbers);
|
|
||||||
|
|
||||||
// template literals
|
|
||||||
var x = 5;
|
|
||||||
var y = 10;
|
|
||||||
console.log(`${x} + ${y} = ${x + y}`);
|
|
||||||
@@ -1,168 +0,0 @@
|
|||||||
Error.stackTraceLimit = Infinity;
|
|
||||||
|
|
||||||
var jsTrans = require("jstransform");
|
|
||||||
var traceur = require("traceur");
|
|
||||||
//var es6tr = require("es6-transpiler");
|
|
||||||
var es6now = require("es6now");
|
|
||||||
//var esnext = require("esnext");
|
|
||||||
var to5 = require("../lib/6to5");
|
|
||||||
|
|
||||||
//var uglify = require("uglify-js");
|
|
||||||
var matcha = require("matcha");
|
|
||||||
var path = require("path");
|
|
||||||
var fs = require("fs");
|
|
||||||
var _ = require("lodash");
|
|
||||||
|
|
||||||
var readResolve = function (filename) {
|
|
||||||
try {
|
|
||||||
filename = require.resolve(filename);
|
|
||||||
} catch (err) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return fs.readFileSync(filename, "utf8");
|
|
||||||
};
|
|
||||||
|
|
||||||
var getVersion = function (name) {
|
|
||||||
return require(name + "/package.json").version;
|
|
||||||
};
|
|
||||||
|
|
||||||
var jsTransVisitors = [];
|
|
||||||
|
|
||||||
_.each([
|
|
||||||
"arrow-function-visitors", "class-visitors", "destructuring-visitors",
|
|
||||||
"object-concise-method-visitors", "object-short-notation-visitors",
|
|
||||||
"rest-param-visitors", "template-visitors"
|
|
||||||
], function (name) {
|
|
||||||
var mod = require("jstransform/visitors/es6-" + name);
|
|
||||||
jsTransVisitors = jsTransVisitors.concat(mod.visitorList);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
var compilers = {
|
|
||||||
"6to5": {
|
|
||||||
version: getVersion(".."),
|
|
||||||
compile: function (code, filename) {
|
|
||||||
return to5.transform(code, { filename: filename }).code;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
traceur: {
|
|
||||||
runtime: readResolve("traceur/bin/traceur-runtime.js"),
|
|
||||||
compile: function (code) {
|
|
||||||
return traceur.compile(code, {
|
|
||||||
modules: "commonjs",
|
|
||||||
experimental: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
/*esnext: {
|
|
||||||
runtime: readResolve("esnext/node_modules/regenerator/runtime.js") || readResolve("regenerator/runtime.js"),
|
|
||||||
compile: function (code) {
|
|
||||||
return esnext.compile(code).code;
|
|
||||||
}
|
|
||||||
},*/
|
|
||||||
|
|
||||||
es6now: {
|
|
||||||
runtime: readResolve("es6now/runtime/ES6.js"),
|
|
||||||
compile: function (code) {
|
|
||||||
return es6now.translate(code);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
/*"es6-transpiler": {
|
|
||||||
compile: function (code) {
|
|
||||||
var result = es6tr.run({ src: code });
|
|
||||||
if (result.errors.length) throw new Error(result.join("; "));
|
|
||||||
return result.src;
|
|
||||||
}
|
|
||||||
},*/
|
|
||||||
|
|
||||||
jstransform: {
|
|
||||||
compile: function (code) {
|
|
||||||
return jsTrans.transform(jsTransVisitors, code).code;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// versions
|
|
||||||
|
|
||||||
//var uglifyTitle = "uglify v" + getVersion("uglify-js");
|
|
||||||
|
|
||||||
_.each(compilers, function (compiler, name) {
|
|
||||||
compiler.title = name + " v" + (compiler.version || getVersion(name));
|
|
||||||
});
|
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
var sizeBenchmark = function (code, loc, name, compiler) {
|
|
||||||
var log = function (output, title) {
|
|
||||||
title = [compiler.title].concat(title || []).join(" + ");
|
|
||||||
|
|
||||||
var text;
|
|
||||||
var color;
|
|
||||||
if (output.stack) {
|
|
||||||
text = "error";
|
|
||||||
color = "red";
|
|
||||||
} else {
|
|
||||||
var kilo = (output.length / 1024).toFixed(2);
|
|
||||||
text = kilo + "KB";
|
|
||||||
color = "cyan";
|
|
||||||
}
|
|
||||||
|
|
||||||
text = matcha.utils.color(matcha.utils.padBefore(text, 22), color);
|
|
||||||
|
|
||||||
console.log(text, matcha.utils.color("» " + title, "gray"));
|
|
||||||
|
|
||||||
if (output.stack) {
|
|
||||||
console.error(output.stack);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var go = function (getOutput, title) {
|
|
||||||
var code;
|
|
||||||
try {
|
|
||||||
code = getOutput();
|
|
||||||
} catch (err) {
|
|
||||||
log(err, title);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
log(code, title);
|
|
||||||
};
|
|
||||||
|
|
||||||
var output;
|
|
||||||
go(function () {
|
|
||||||
return output = compiler.compile(code, loc);
|
|
||||||
});
|
|
||||||
if (!output) return;
|
|
||||||
|
|
||||||
//go(function () {
|
|
||||||
// return uglify.minify(output, { fromString: true }).code;
|
|
||||||
//}, uglifyTitle);
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
_.each(fs.readdirSync(__dirname + "/fixtures"), function (name) {
|
|
||||||
var alias = path.basename(name, path.extname(name));
|
|
||||||
|
|
||||||
suite(alias, function () {
|
|
||||||
set("delay", 0);
|
|
||||||
|
|
||||||
var loc = __dirname + "/fixtures/" + name;
|
|
||||||
var code = fs.readFileSync(loc, "utf8");
|
|
||||||
|
|
||||||
before(function () {
|
|
||||||
_.each(compilers, function (compiler, name) {
|
|
||||||
sizeBenchmark(code, loc, name, compiler);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
_.each(compilers, function (compiler) {
|
|
||||||
bench(compiler.title, function () {
|
|
||||||
compiler.compile(code, loc);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
var chokidar = require("chokidar");
|
var outputFileSync = require("output-file-sync");
|
||||||
var mkdirp = require("mkdirp");
|
var chokidar = require("chokidar");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
var util = require("./util");
|
var util = require("./util");
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var _ = require("lodash");
|
var _ = require("lodash");
|
||||||
|
|
||||||
module.exports = function (commander, filenames, opts) {
|
module.exports = function (commander, filenames, opts) {
|
||||||
if (commander.sourceMapsInline) {
|
if (commander.sourceMapsInline) {
|
||||||
@@ -15,16 +15,13 @@ module.exports = function (commander, filenames, opts) {
|
|||||||
|
|
||||||
var data = util.compile(src, { sourceMapName: dest });
|
var data = util.compile(src, { sourceMapName: dest });
|
||||||
|
|
||||||
var up = path.normalize(dest + "/..");
|
|
||||||
mkdirp.sync(up);
|
|
||||||
|
|
||||||
if (commander.sourceMaps) {
|
if (commander.sourceMaps) {
|
||||||
var mapLoc = dest + ".map";
|
var mapLoc = dest + ".map";
|
||||||
data.code = util.addSourceMappingUrl(data.code, mapLoc);
|
data.code = util.addSourceMappingUrl(data.code, mapLoc);
|
||||||
fs.writeFileSync(mapLoc, JSON.stringify(data.map));
|
outputFileSync(mapLoc, JSON.stringify(data.map));
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.writeFileSync(dest, data.code);
|
outputFileSync(dest, data.code);
|
||||||
|
|
||||||
console.log(src + " -> " + dest);
|
console.log(src + " -> " + dest);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ module.exports = function (commander, filenames) {
|
|||||||
map.setSourceContent(filename, result.actual);
|
map.setSourceContent(filename, result.actual);
|
||||||
|
|
||||||
consumer.eachMapping(function (mapping) {
|
consumer.eachMapping(function (mapping) {
|
||||||
map._mappings.push({
|
map._mappings.add({
|
||||||
generatedLine: mapping.generatedLine + offset,
|
generatedLine: mapping.generatedLine + offset,
|
||||||
generatedColumn: mapping.generatedColumn,
|
generatedColumn: mapping.generatedColumn,
|
||||||
originalLine: mapping.originalLine,
|
originalLine: mapping.originalLine,
|
||||||
@@ -63,7 +63,7 @@ module.exports = function (commander, filenames) {
|
|||||||
|
|
||||||
fs.writeFileSync(commander.outFile, result.code);
|
fs.writeFileSync(commander.outFile, result.code);
|
||||||
} else {
|
} else {
|
||||||
console.log(result.code);
|
process.stdout.write(result.code + "\n");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -15,27 +15,29 @@ commander.option("-e, --experimental", "Enable experimental support for proposed
|
|||||||
commander.option("-p, --playground", "Enable playground support");
|
commander.option("-p, --playground", "Enable playground support");
|
||||||
|
|
||||||
commander.option("-m, --modules [modules]", "Module formatter type to use [common]", "common");
|
commander.option("-m, --modules [modules]", "Module formatter type to use [common]", "common");
|
||||||
commander.option("-w, --whitelist [whitelist]", "Whitelist of transformers to ONLY use", util.list);
|
commander.option("-l, --whitelist [whitelist]", "Whitelist of transformers to ONLY use", util.list);
|
||||||
commander.option("-b, --blacklist [blacklist]", "Blacklist of transformers to NOT use", util.list);
|
commander.option("-b, --blacklist [blacklist]", "Blacklist of transformers to NOT use", util.list);
|
||||||
commander.option("-i, --optional [list]", "List of optional transformers to enable", util.list);
|
commander.option("-i, --optional [list]", "List of optional transformers to enable", util.list);
|
||||||
|
commander.option("--loose [list]", "List of transformers to enable their loose mode", util.list);
|
||||||
commander.option("-o, --out-file [out]", "Compile all input files into a single file");
|
commander.option("-o, --out-file [out]", "Compile all input files into a single file");
|
||||||
commander.option("-d, --out-dir [out]", "Compile an input directory of modules into an output directory");
|
commander.option("-d, --out-dir [out]", "Compile an input directory of modules into an output directory");
|
||||||
commander.option("-c, --remove-comments", "Remove comments from the compiled code", false);
|
commander.option("-c, --remove-comments", "Remove comments from the compiled code", false);
|
||||||
|
commander.option("-I, --indent [width]", "Indent width [2]", 2);
|
||||||
commander.option("-a, --amd-module-ids", "Insert module id in AMD modules", false); // todo: remove in 3.0.0
|
commander.option("-a, --amd-module-ids", "Insert module id in AMD modules", false); // todo: remove in 3.0.0
|
||||||
commander.option("-m, --module-ids", "Insert module id in modules", false);
|
commander.option("-m, --module-ids", "Insert module id in modules", false);
|
||||||
|
commander.option("-R, --react-compat", "Makes the react transformer produce pre-v0.12 code");
|
||||||
|
commander.option("-E, --include-regenerator", "Include the regenerator runtime if necessary", false);
|
||||||
|
commander.option("--keep-module-id-extensions", "Keep extensions when generating module ids", false);
|
||||||
|
|
||||||
commander.on("--help", function(){
|
commander.on("--help", function(){
|
||||||
var outKeys = function (title, obj) {
|
var outKeys = function (title, obj) {
|
||||||
console.log(" " + title + ":");
|
console.log(" " + title + ":");
|
||||||
console.log();
|
console.log();
|
||||||
|
|
||||||
var hasOptional = true;
|
|
||||||
|
|
||||||
_.each(_.keys(obj).sort(), function (key) {
|
_.each(_.keys(obj).sort(), function (key) {
|
||||||
if (key[0] === "_") return;
|
if (key[0] === "_") return;
|
||||||
|
|
||||||
if (obj[key].optional) {
|
if (obj[key].optional) {
|
||||||
hasOptional = true;
|
|
||||||
key = "[" + key + "]";
|
key = "[" + key + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,17 +100,26 @@ if (errors.length) {
|
|||||||
//
|
//
|
||||||
|
|
||||||
exports.opts = {
|
exports.opts = {
|
||||||
sourceMapName: commander.outFile,
|
keepModuleIdExtensions: commander.keepModuleIdExtensions,
|
||||||
experimental: commander.experimental,
|
includeRegenerator: commander.includeRegenerator,
|
||||||
playground: commander.playground,
|
sourceMapName: commander.outFile,
|
||||||
moduleIds: commander.amdModuleIds || commander.moduleIds,
|
experimental: commander.experimental,
|
||||||
blacklist: commander.blacklist,
|
reactCompat: commander.reactCompat,
|
||||||
whitelist: commander.whitelist,
|
playground: commander.playground,
|
||||||
sourceMap: commander.sourceMaps || commander.sourceMapsInline,
|
moduleIds: commander.amdModuleIds || commander.moduleIds,
|
||||||
optional: commander.optional,
|
blacklist: commander.blacklist,
|
||||||
comments: !commander.removeComments,
|
whitelist: commander.whitelist,
|
||||||
runtime: commander.runtime,
|
sourceMap: commander.sourceMaps || commander.sourceMapsInline,
|
||||||
modules: commander.modules
|
optional: commander.optional,
|
||||||
|
comments: !commander.removeComments,
|
||||||
|
runtime: commander.runtime,
|
||||||
|
modules: commander.modules,
|
||||||
|
loose: commander.loose,
|
||||||
|
format: {
|
||||||
|
indent: {
|
||||||
|
style: util.repeat(parseInt(commander.indent))
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var fn;
|
var fn;
|
||||||
|
|||||||
@@ -20,7 +20,17 @@ exports.transform = function (filename, code, opts) {
|
|||||||
opts = _.extend(opts || {}, index.opts);
|
opts = _.extend(opts || {}, index.opts);
|
||||||
opts.filename = filename;
|
opts.filename = filename;
|
||||||
|
|
||||||
var result = to5.transform(code, opts);
|
var result;
|
||||||
|
try {
|
||||||
|
result = to5.transform(code, opts);
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof SyntaxError) {
|
||||||
|
console.error("SyntaxError:", e.message);
|
||||||
|
process.exit(1);
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
result.filename = filename;
|
result.filename = filename;
|
||||||
result.actual = code;
|
result.actual = code;
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -10,29 +10,31 @@ var util = require("../lib/6to5/util");
|
|||||||
var vm = require("vm");
|
var vm = require("vm");
|
||||||
var _ = require("lodash");
|
var _ = require("lodash");
|
||||||
|
|
||||||
commander.option("-e, --eval [script]", "Evaluate script");
|
var program = new commander.Command("6to5-node");
|
||||||
commander.option("-p, --print", "Evaluate script and print result");
|
|
||||||
commander.option("-i, --ignore [regex]", "Ignore all files that match this regex when using the require hook");
|
program.option("-e, --eval [script]", "Evaluate script");
|
||||||
commander.option("-x, --extensions [extensions]", "List of extensions to hook into [.es6,.js]");
|
program.option("-p, --print", "Evaluate script and print result");
|
||||||
commander.option("-r, --experimental", "Enable experimental support for proposed ES7 features");
|
program.option("-i, --ignore [regex]", "Ignore all files that match this regex when using the require hook");
|
||||||
commander.option("-g, --playground", "Enable playground support");
|
program.option("-x, --extensions [extensions]", "List of extensions to hook into [.es6,.js]");
|
||||||
commander.option("-c, --cache", "Cache compiled files and require paths");
|
program.option("-r, --experimental", "Enable experimental support for proposed ES7 features");
|
||||||
|
program.option("-g, --playground", "Enable playground support");
|
||||||
|
program.option("-c, --cache", "Cache compiled files and require paths");
|
||||||
|
|
||||||
var pkg = require("../package.json");
|
var pkg = require("../package.json");
|
||||||
commander.version(pkg.version);
|
program.version(pkg.version);
|
||||||
commander.usage("[options] [ -e script | script.js ] [arguments]");
|
program.usage("[options] [ -e script | script.js ] [arguments]");
|
||||||
commander.parse(process.argv);
|
program.parse(process.argv);
|
||||||
|
|
||||||
if (commander.cache) roadrunner.load();
|
if (program.cache) roadrunner.load();
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
to5.register({
|
to5.register({
|
||||||
experimental: commander.experimental,
|
experimental: program.experimental,
|
||||||
extensions: commander.extensions,
|
extensions: program.extensions,
|
||||||
playground: commander.playground,
|
playground: program.playground,
|
||||||
ignore: commander.ignore,
|
ignore: program.ignore,
|
||||||
cache: commander.cache && roadrunner.get("6to5")
|
cache: program.cache && roadrunner.get("6to5")
|
||||||
});
|
});
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -41,17 +43,17 @@ var _eval = function (code, filename) {
|
|||||||
code = to5.transform(code, {
|
code = to5.transform(code, {
|
||||||
filename: filename,
|
filename: filename,
|
||||||
blacklist: ["useStrict"],
|
blacklist: ["useStrict"],
|
||||||
experimental: commander.experimental,
|
experimental: program.experimental,
|
||||||
playground: commander.playground
|
playground: program.playground
|
||||||
}).code;
|
}).code;
|
||||||
return vm.runInThisContext(code, filename);
|
return vm.runInThisContext(code, filename);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (commander.eval) {
|
if (program.eval) {
|
||||||
var result = _eval(commander.eval, "eval");
|
var result = _eval(program.eval, "eval");
|
||||||
if (commander.print) console.log(result);
|
if (program.print) console.log(result);
|
||||||
} else {
|
} else {
|
||||||
if (commander.args.length) {
|
if (program.args.length) {
|
||||||
// slice all arguments up to the first filename since they're 6to5 args that we handle
|
// slice all arguments up to the first filename since they're 6to5 args that we handle
|
||||||
var args = process.argv.slice(2);
|
var args = process.argv.slice(2);
|
||||||
|
|
||||||
@@ -77,7 +79,7 @@ if (commander.eval) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (commander.cache) roadrunner.save();
|
if (program.cache) roadrunner.save();
|
||||||
|
|
||||||
function replStart() {
|
function replStart() {
|
||||||
repl.start({
|
repl.start({
|
||||||
@@ -94,8 +96,8 @@ function replEval(code, context, filename, callback) {
|
|||||||
var result;
|
var result;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (/^\((.*?)\n\)$/.test(code)) {
|
if (code[0] === "(" && code[code.length - 1] === ")") {
|
||||||
code = code.slice(1, -2); // remove "(" and "\n)"
|
code = code.slice(1, -1); // remove "(" and ")"
|
||||||
}
|
}
|
||||||
|
|
||||||
result = _eval(code, filename);
|
result = _eval(code, filename);
|
||||||
|
|||||||
11
bin/generate-core-package-json
Executable file
11
bin/generate-core-package-json
Executable file
@@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
var pkg = require("../package.json");
|
||||||
|
pkg.name += "-core";
|
||||||
|
delete pkg.dependencies.chokidar;
|
||||||
|
delete pkg.optionalDependencies;
|
||||||
|
delete pkg.devDependencies;
|
||||||
|
delete pkg.preferGlobal;
|
||||||
|
delete pkg.scripts;
|
||||||
|
delete pkg.bin;
|
||||||
|
console.log(JSON.stringify(pkg, null, " "));
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
# Browser
|
|
||||||
|
|
||||||
A browser version of 6to5 is available from `browser.js` inside the 6to5
|
|
||||||
directory in an npm release.
|
|
||||||
|
|
||||||
## Scripts
|
|
||||||
|
|
||||||
While it's not recommended for serious use, when the browser version is included
|
|
||||||
all scripts with the type `text/ecmascript-6` and `text/6to5` are automatically
|
|
||||||
compiled and ran.
|
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script src="node_modules/6to5/browser.js"></script>
|
|
||||||
<script type="text/6to5">
|
|
||||||
class Test {
|
|
||||||
test() {
|
|
||||||
return "test";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var test = new Test;
|
|
||||||
test.test();
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
## Build
|
|
||||||
|
|
||||||
You can build a browser version of the compiler by running the following in the
|
|
||||||
6to5 directory:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ make build
|
|
||||||
```
|
|
||||||
|
|
||||||
This will output the files `dist/6to5.js` and `dist/6to5.min.js`.
|
|
||||||
|
|
||||||
## Test
|
|
||||||
|
|
||||||
To test 6to5 in your browser run:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ make test-browser
|
|
||||||
```
|
|
||||||
|
|
||||||
And open `test/browser.html` in your browser if it doesn't open automatically.
|
|
||||||
|
|
||||||
## API
|
|
||||||
|
|
||||||
### to5.transform(code, [opts])
|
|
||||||
|
|
||||||
See [options](usage.md#options) for additional documentation.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
to5.transform("class Test {}").code;
|
|
||||||
```
|
|
||||||
|
|
||||||
### to5.run(code, [opts])
|
|
||||||
|
|
||||||
See [options](usage.md#options) for additional documentation.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
to5.run("class Test {}");
|
|
||||||
```
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
# Caveats
|
|
||||||
|
|
||||||
In order for certain features to work they require certain polyfills. You can
|
|
||||||
satisfy **all** 6to5 feature requirements by using the included
|
|
||||||
[polyfill](polyfill.md).
|
|
||||||
|
|
||||||
You may alternatively selectively include what you need:
|
|
||||||
|
|
||||||
| Feature | Requirements |
|
|
||||||
| --------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
|
|
||||||
| Abstract References | [experimental](experimental.md), `Symbol` |
|
|
||||||
| Array destructuring | `Array.from` |
|
|
||||||
| Async functions, Generators | [experimental](experimental.md), [regenerator runtime](https://github.com/facebook/regenerator/blob/master/runtime.js) |
|
|
||||||
| Comprehensions | [experimental](experimental.md), `Array.from` |
|
|
||||||
| For Of | `Symbol`, `prototype[Symbol.iterator]` |
|
|
||||||
| Modules | `Object.assign`* |
|
|
||||||
| Object spread/rest | [experimental](experimental.md), `Object.assign` |
|
|
||||||
| Spread | `Array.from` |
|
|
||||||
|
|
||||||
*Only required for exporting a non-function `default` with additional `export`s.
|
|
||||||
|
|
||||||
## ES5
|
|
||||||
|
|
||||||
Since 6to5 assumes that your code will be ran in an ES5 environment it uses ES5
|
|
||||||
functions. So if you're using an environment that has limited or no support for
|
|
||||||
ES5 such as lower versions of IE then using the
|
|
||||||
[es5-shim](https://github.com/es-shims/es5-shim) along with the
|
|
||||||
[6to5 polyfill](polyfill.md) will add support for these methods.
|
|
||||||
|
|
||||||
## Internet Explorer
|
|
||||||
|
|
||||||
### Classes (10 and below)
|
|
||||||
|
|
||||||
If you're inheriting from a class then static properties are inherited from it
|
|
||||||
via [\_\_proto\_\_](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto),
|
|
||||||
this is widely supported but you may run into problems with much older browsers.
|
|
||||||
|
|
||||||
**NOTE:** `__proto__` is not supported in IE <= 10 so static properties
|
|
||||||
**will not** be inherited. A possible workaround is to use `super();`:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
class Foo {
|
|
||||||
static foo() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Bar extends Foo {
|
|
||||||
static foo() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Getters/setters (8 and below)
|
|
||||||
|
|
||||||
In IE8 `Object.defineProperty` can only be used on DOM objects. This is
|
|
||||||
unfortunate as it's required to set getters and setters. Due to this if
|
|
||||||
you plan on supporting IE8 or below then the user of getters and setters
|
|
||||||
isn't recommended.
|
|
||||||
|
|
||||||
**Reference**: [MDN](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty#Internet_Explorer_8_specific_notes).
|
|
||||||
@@ -1,137 +0,0 @@
|
|||||||
# Differences
|
|
||||||
|
|
||||||
There are three main points that separate 6to5 from all other transpilers.
|
|
||||||
|
|
||||||
### Readable code
|
|
||||||
|
|
||||||
The fundamental concept behind 6to5 is that the generated code must be close as
|
|
||||||
possible to the original, retaining all the same formatting and readability.
|
|
||||||
|
|
||||||
Many other transpilers are just concerned with making the code work while 6to5
|
|
||||||
is concerned with making sure it works **and** is readable at the same time.
|
|
||||||
|
|
||||||
For example, given the following array comprehension:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var seattlers = [for (c of customers) if (c.city == "Seattle") { name: c.name, age: c.age }];
|
|
||||||
```
|
|
||||||
|
|
||||||
is generated to the following with 6to5:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var seattlers = Array.from(customers).filter(function (c) {
|
|
||||||
return c.city == "Seattle";
|
|
||||||
}).map(function (c) {
|
|
||||||
return {
|
|
||||||
name: c.name,
|
|
||||||
age: c.age
|
|
||||||
};
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
The following is what Traceur generates:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var seattlers = (function() {
|
|
||||||
var c;
|
|
||||||
var $__20 = 0,
|
|
||||||
$__21 = [];
|
|
||||||
for (var $__22 = customers[$traceurRuntime.toProperty(Symbol.iterator)](),
|
|
||||||
$__23; !($__23 = $__22.next()).done; ) {
|
|
||||||
c = $__23.value;
|
|
||||||
if (c.city == "Seattle")
|
|
||||||
$traceurRuntime.setProperty($__21, $__20++, {
|
|
||||||
name: c.name,
|
|
||||||
age: c.age
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return $__21;
|
|
||||||
}());
|
|
||||||
```
|
|
||||||
|
|
||||||
As you can tell, it's not very pretty. Instead of mapping directly to a
|
|
||||||
runtime, like other transpilers, 6to5 maps directly to the equivalent ES5.
|
|
||||||
|
|
||||||
Sometimes there are little inline functions that 6to5 needs. These are
|
|
||||||
placed at the top of your file much like coffee-script does. If these
|
|
||||||
bother you then you can use the [optional runtime](optional-runtime.md).
|
|
||||||
We promise that these inline functions will never be significant and will
|
|
||||||
always be used as little as possible.
|
|
||||||
|
|
||||||
### Static analysis
|
|
||||||
|
|
||||||
6to5 uses a lot of static analysis to simplify code as much as possible.
|
|
||||||
Not many other transpilers do this, and those that do don't do it nearly
|
|
||||||
as much as 6to5. This process is pretty intensive but it leads to higher
|
|
||||||
quality code.
|
|
||||||
|
|
||||||
### Spec compliancy
|
|
||||||
|
|
||||||
6to5 prides itself on
|
|
||||||
[spec compliancy](https://kangax.github.io/compat-table/es6/). We have
|
|
||||||
excellent support for edgecases, something that many other transpilers
|
|
||||||
suffer from, including Traceur. When you use 6to5 you can be confident
|
|
||||||
that when you turn it off and use your code in a full ES6 environment
|
|
||||||
**it'll just work**.
|
|
||||||
|
|
||||||
## Comparison to other transpilers
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
| | 6to5 | Traceur | es6-transpiler | es6now | jstransform |
|
|
||||||
| ---------------------------- | ---- | ------- | -------------- | ------ | ----------- |
|
|
||||||
| Source maps | ✓ | ✓ | ✓ | | ✓ |
|
|
||||||
| No compiler global pollution | ✓ | | ✓ | | ✓ |
|
|
||||||
| Optional runtime | ✓ | | ✓ | | ✓ |
|
|
||||||
| Browser compiler | ✓ | ✓ | | | |
|
|
||||||
|
|
||||||
### Language Support
|
|
||||||
|
|
||||||
| | 6to5 | Traceur | es6-transpiler | es6now | jstransform |
|
|
||||||
| ---------------------------- | ---- | ------- | -------------- | ------ | ----------- |
|
|
||||||
| Abstract references | ✓ | | | | |
|
|
||||||
| Array comprehension | ✓ | ✓ | ✓ | | |
|
|
||||||
| Arrow functions | ✓ | ✓ | ✓ | ✓ | ✓ |
|
|
||||||
| Async functions | ✓ | ✓ | | | |
|
|
||||||
| Async generator functions | ✓ | ✓ | | | |
|
|
||||||
| Classes | ✓ | ✓ | ✓ | ✓ | ✓ |
|
|
||||||
| Computed property names | ✓ | ✓ | ✓ | ✓ | |
|
|
||||||
| Constants | ✓ | ✓ | ✓ | | |
|
|
||||||
| Default parameters | ✓ | ✓ | ✓ | ✓ | |
|
|
||||||
| Destructuring | ✓ | ✓ | ✓ | ✓ | ✓ |
|
|
||||||
| Exponentiation operator | ✓ | ✓ | | | |
|
|
||||||
| Flow types | ✓ | | | | ✓ |
|
|
||||||
| For-of | ✓ | ✓ | ✓ | ✓ | |
|
|
||||||
| Generators | ✓ | ✓ | | | |
|
|
||||||
| Generator comprehension | ✓ | ✓ | | | |
|
|
||||||
| JSX | ✓ | | | | |
|
|
||||||
| Let scoping | ✓ | ✓ | ✓ | | |
|
|
||||||
| Modules | ✓ | ✓ | | ✓ | |
|
|
||||||
| Object rest/spread | ✓ | | | | ✓ |
|
|
||||||
| Property method assignment | ✓ | ✓ | ✓ | ✓ | ✓ |
|
|
||||||
| Property name shorthand | ✓ | ✓ | ✓ | ✓ | ✓ |
|
|
||||||
| Rest parameters | ✓ | ✓ | ✓ | ✓ | ✓ |
|
|
||||||
| React | ✓ | | | | |
|
|
||||||
| Spread | ✓ | ✓ | ✓ | ✓ | |
|
|
||||||
| Template literals | ✓ | ✓ | ✓ | ✓ | ✓ |
|
|
||||||
| Unicode regex | ✓ | ✓ | ✓ | | |
|
|
||||||
|
|
||||||
### [Traceur](https://github.com/google/traceur-compiler)
|
|
||||||
|
|
||||||
Traceur requires quite a bulky runtime (~75KB) and produces quite verbose code.
|
|
||||||
While this can be trimmed down by selectively building the runtime, it's an
|
|
||||||
unnecessary step when a large runtime can be eliminated entirely.
|
|
||||||
|
|
||||||
### [es6now](https://github.com/zenparsing/es6now)
|
|
||||||
|
|
||||||
es6now doesn't output sourcemaps. This is cited as a positive as line-to-line
|
|
||||||
mapping is the goal. This however obviously doesn't retain column mapping
|
|
||||||
resulting in the output code not being very pleasant.
|
|
||||||
|
|
||||||
### [es6-transpiler](https://github.com/termi/es6-transpiler)
|
|
||||||
|
|
||||||
The es6-transpiler compiler requires shims to operate which pollutes the global
|
|
||||||
scope resulting in possible collisions.
|
|
||||||
|
|
||||||
es6-transpiler maps line-by-line, just like es6now, this results in the same
|
|
||||||
issues such as lack of column information and unpleasant code output.
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
## Experimental
|
|
||||||
|
|
||||||
6to5 also has experimental support for ES7 proposals. You can enable this with
|
|
||||||
the `experimental: true` option when using the [Node API](#node) or
|
|
||||||
`--experimental` when using the [CLI](#cli).
|
|
||||||
|
|
||||||
**WARNING:** These proposals are subject to change so use with
|
|
||||||
**extreme caution**.
|
|
||||||
283
doc/features.md
283
doc/features.md
@@ -1,283 +0,0 @@
|
|||||||
# Features
|
|
||||||
|
|
||||||
## Abstract references ([experimental](experimental.md)) ([spec](https://github.com/zenparsing/es-abstract-refs))
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
foo::bar;
|
|
||||||
foo::bar = baz;
|
|
||||||
delete foo::bar;
|
|
||||||
```
|
|
||||||
|
|
||||||
## Array comprehensions ([experimental](experimental.md))
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var results = [for (c of customers) if (c.city == "Seattle") { name: c.name, age: c.age }]
|
|
||||||
```
|
|
||||||
|
|
||||||
## Arrow functions
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
// Expression bodies
|
|
||||||
var odds = evens.map(v => v + 1);
|
|
||||||
var nums = evens.map((v, i) => v + i);
|
|
||||||
|
|
||||||
// Statement bodies
|
|
||||||
nums.forEach(v => {
|
|
||||||
if (v % 5 === 0)
|
|
||||||
fives.push(v);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Lexical this
|
|
||||||
var bob = {
|
|
||||||
_name: "Bob",
|
|
||||||
_friends: [],
|
|
||||||
printFriends() {
|
|
||||||
this._friends.forEach(f => {
|
|
||||||
console.log(this._name + " knows " + f);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
## Async functions ([experimental](experimental.md)) ([spec](https://github.com/lukehoban/ecmascript-asyncawait))
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
async function chainAnimationsAsync(elem, animations) {
|
|
||||||
for (var anim of animations) {
|
|
||||||
await anim(elem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Async generator functions ([experimental](experimental.md)) ([spec](https://github.com/jhusain/asyncgenerator))
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
## Classes
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
class SkinnedMesh extends THREE.Mesh {
|
|
||||||
constructor(geometry, materials) {
|
|
||||||
super(geometry, materials);
|
|
||||||
|
|
||||||
this.idMatrix = SkinnedMesh.defaultMatrix();
|
|
||||||
this.bones = [];
|
|
||||||
this.boneMatrices = [];
|
|
||||||
//...
|
|
||||||
}
|
|
||||||
|
|
||||||
update(camera) {
|
|
||||||
//...
|
|
||||||
super.update();
|
|
||||||
}
|
|
||||||
|
|
||||||
static defaultMatrix() {
|
|
||||||
return new THREE.Matrix4();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Computed property names
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var foo = "foo";
|
|
||||||
var bar = "bar";
|
|
||||||
var obj = {
|
|
||||||
["foo" + bar]: "heh",
|
|
||||||
["bar" + foo]: "noo",
|
|
||||||
foo: "foo",
|
|
||||||
bar: "bar"
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
## Constants
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
const MULTIPLIER = 5;
|
|
||||||
console.log(2 * MULTIPLIER);
|
|
||||||
|
|
||||||
MULTIPLIER = 6; // error
|
|
||||||
var MULTIPLIER; // error
|
|
||||||
```
|
|
||||||
|
|
||||||
## Default parameters
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
function f(x, y = 12) {
|
|
||||||
// y is 12 if not passed (or passed as undefined)
|
|
||||||
return x + y;
|
|
||||||
}
|
|
||||||
f(3) == 15
|
|
||||||
```
|
|
||||||
|
|
||||||
## Destructuring
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
// list matching
|
|
||||||
var [a, , b] = [1,2,3];
|
|
||||||
|
|
||||||
// object matching
|
|
||||||
var { op: a, lhs: { op: b }, rhs: c } = getASTNode();
|
|
||||||
|
|
||||||
// object matching shorthand
|
|
||||||
// binds `op`, `lhs` and `rhs` in scope
|
|
||||||
var { op, lhs, rhs } = getASTNode();
|
|
||||||
|
|
||||||
// Can be used in parameter position
|
|
||||||
function g({ name: x }) {
|
|
||||||
console.log(x);
|
|
||||||
}
|
|
||||||
g({ name: 5 });
|
|
||||||
|
|
||||||
// Fail-soft destructuring
|
|
||||||
var [a] = [];
|
|
||||||
a === undefined;
|
|
||||||
```
|
|
||||||
|
|
||||||
## Exponentiation operator ([experimental](experimental.md)) ([spec](https://github.com/rwaldron/exponentiation-operator))
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var a = 2;
|
|
||||||
a **= 2;
|
|
||||||
|
|
||||||
var squared = 2 ** 2;
|
|
||||||
```
|
|
||||||
|
|
||||||
## For-of
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
for (var i of [1, 2, 3]) {
|
|
||||||
console.log(i * i);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Generators
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
function* fibonacci() {
|
|
||||||
var pre = 0, cur = 1;
|
|
||||||
for (;;) {
|
|
||||||
var temp = pre;
|
|
||||||
pre = cur;
|
|
||||||
cur += temp;
|
|
||||||
yield cur;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var n of fibonacci()) {
|
|
||||||
// truncate the sequence at 1000
|
|
||||||
if (n > 1000) break;
|
|
||||||
console.log(n);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Generator comprehensions ([experimental](experimental.md))
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var nums = [1, 2, 3, 4, 5, 6];
|
|
||||||
var multiples = (for (i of nums) if (i % 2) i * i);
|
|
||||||
assert.equal(multiples.next().value, 1);
|
|
||||||
assert.equal(multiples.next().value, 9);
|
|
||||||
assert.equal(multiples.next().value, 25);
|
|
||||||
```
|
|
||||||
|
|
||||||
## Let scoping
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
for (let i in arr) {
|
|
||||||
let v = arr[i];
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Modules
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
import "foo";
|
|
||||||
import foo from "foo";
|
|
||||||
import * as foo from "foo";
|
|
||||||
import {bar} from "foo";
|
|
||||||
import {foo as bar} from "foo";
|
|
||||||
|
|
||||||
export { test };
|
|
||||||
export var test = 5;
|
|
||||||
export function test() {}
|
|
||||||
|
|
||||||
export default test;
|
|
||||||
```
|
|
||||||
|
|
||||||
## Numeric literals
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
0b111110111 === 503; // true
|
|
||||||
0o767 === 503; // true
|
|
||||||
```
|
|
||||||
|
|
||||||
## Object spread/rest ([experimental](experimental.md)) ([spec](https://github.com/sebmarkbage/ecmascript-rest-spread))
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var n = { x, y, ...z };
|
|
||||||
var { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };
|
|
||||||
```
|
|
||||||
|
|
||||||
## Property method assignment
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var obj = {
|
|
||||||
foo() {
|
|
||||||
return "foobar";
|
|
||||||
},
|
|
||||||
|
|
||||||
get bar() {
|
|
||||||
return this._bar;
|
|
||||||
},
|
|
||||||
|
|
||||||
set bar(val) {
|
|
||||||
this._bar = val;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
## Property name shorthand
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
function f(x, y) {
|
|
||||||
return { x, y };
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Rest parameters
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
function f(x, ...y) {
|
|
||||||
// y is an Array
|
|
||||||
return x * y.length;
|
|
||||||
}
|
|
||||||
f(3, "hello", true) == 6
|
|
||||||
```
|
|
||||||
|
|
||||||
## Spread
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
function f(x, y, z) {
|
|
||||||
return x + y + z;
|
|
||||||
}
|
|
||||||
// Pass each elem of array as argument
|
|
||||||
f(...[1,2,3]) == 6
|
|
||||||
```
|
|
||||||
|
|
||||||
## Template literals
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var x = 5;
|
|
||||||
var y = 10;
|
|
||||||
console.log(`${x} + ${y} = ${x + y}`); // "5 + 10 = 15"
|
|
||||||
```
|
|
||||||
## Unicode regex
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var string = 'foo💩bar';
|
|
||||||
var match = string.match(/foo(.)bar/u);
|
|
||||||
console.log(match[1]);
|
|
||||||
```
|
|
||||||
63
doc/index.md
63
doc/index.md
@@ -1,62 +1 @@
|
|||||||
**6to5** turns ES6+ code into vanilla ES5, so you can use next generation features **today.**
|
See [6to5.github.io/docs](https://github.com/6to5/6to5.github.io/tree/master/docs).
|
||||||
|
|
||||||
- **Readable** - formatting is retained if possible so your generated code is as similar as possible.
|
|
||||||
- **Extensible** - with a large range of [plugins](plugins.md) and **browser support**.
|
|
||||||
- **Lossless** - **source map support** so you can debug your compiled code with ease.
|
|
||||||
- **Compact** - maps directly to the equivalent ES5 with **no runtime**[\*](caveats.md).
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
It's as easy as:
|
|
||||||
|
|
||||||
$ npm install -g 6to5
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
Once you've installed 6to5, there are multiple paths you can take depending on
|
|
||||||
how you want to use it.
|
|
||||||
|
|
||||||
6to5 will simply compile your ES6+ script to ES5 if you pass it as an argument
|
|
||||||
to the command-line tool `6to5`:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ 6to5 script.js
|
|
||||||
```
|
|
||||||
|
|
||||||
If you have a file written using ES6+ and you just want to run it, `6to5-node`
|
|
||||||
has you covered:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ 6to5-node script.js
|
|
||||||
```
|
|
||||||
|
|
||||||
And it doesn't end here! To see all the ways you can use 6to5, check out the
|
|
||||||
[Usage](http://6to5.github.io/usage.html) page.
|
|
||||||
|
|
||||||
## [Features](features.md)
|
|
||||||
|
|
||||||
- [Abstract references](features.md#abstract-references) ([experimental](experimental.md))
|
|
||||||
- [Array comprehension](features.md#array-comprehension) ([experimental](experimental.md))
|
|
||||||
- [Async functions](features.md#async-functions) ([experimental](experimental.md))
|
|
||||||
- [Async generator functions](features.md#async-generator-functions) ([experimental](experimental.md))
|
|
||||||
- [Arrow functions](features.md#arrow-functions)
|
|
||||||
- [Classes](features.md#classes)
|
|
||||||
- [Computed property names](features.md#computed-property-names)
|
|
||||||
- [Constants](features.md#constants)
|
|
||||||
- [Default parameters](features.md#default-parameters)
|
|
||||||
- [Destructuring](features.md#destructuring)
|
|
||||||
- [Exponentiation operator](features.md#exponentiation-operator) ([experimental](experimental.md))
|
|
||||||
- [For-of](features.md#for-of)
|
|
||||||
- [Generators](features.md#generators)
|
|
||||||
- [Generator comprehension](features.md#generator-comprehension) ([experimental](experimental.md))
|
|
||||||
- [Let scoping](features.md#let-scoping)
|
|
||||||
- [Modules](features.md#modules)
|
|
||||||
- [Numeric literals](features.md#numeric-literals)
|
|
||||||
- [Object rest/spread](features.md#object-rest-spread) ([experimental](experimental.md))
|
|
||||||
- [Property method assignment](features.md#property-method-assignment)
|
|
||||||
- [Property name shorthand](features.md#property-name-shorthand)
|
|
||||||
- [React/JSX](react.md)
|
|
||||||
- [Rest parameters](features.md#rest-parameters)
|
|
||||||
- [Spread](features.md#spread)
|
|
||||||
- [Template literals](features.md#template-literals)
|
|
||||||
- [Unicode regex](features.md#unicode-regex)
|
|
||||||
|
|||||||
257
doc/modules.md
257
doc/modules.md
@@ -1,257 +0,0 @@
|
|||||||
# Modules
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
### CLI
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ 6to5 --modules common script.js
|
|
||||||
```
|
|
||||||
|
|
||||||
### Node
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var to5 = require("6to5");
|
|
||||||
to5.transform('import "foo";', { modules: "common" });
|
|
||||||
```
|
|
||||||
|
|
||||||
## Formats
|
|
||||||
|
|
||||||
* [AMD](#amd)
|
|
||||||
* [Common (Default)](#common-default)
|
|
||||||
* [Ignore](#ignore)
|
|
||||||
* [System](#system)
|
|
||||||
* [UMD](#umd)
|
|
||||||
|
|
||||||
### Common
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ 6to5 --modules common
|
|
||||||
```
|
|
||||||
|
|
||||||
**In**
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
export default test;
|
|
||||||
|
|
||||||
export {test};
|
|
||||||
export var test = 5;
|
|
||||||
|
|
||||||
import "foo";
|
|
||||||
|
|
||||||
import foo from "foo";
|
|
||||||
import * as foo from "foo";
|
|
||||||
|
|
||||||
import {bar} from "foo";
|
|
||||||
import {foo as bar} from "foo";
|
|
||||||
```
|
|
||||||
|
|
||||||
**Out**
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var _interopRequire = function (obj) {
|
|
||||||
return obj && (obj["default"] || obj);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports = module.exports = test;
|
|
||||||
|
|
||||||
exports.test = test;
|
|
||||||
var test = exports.test = 5;
|
|
||||||
|
|
||||||
require("foo");
|
|
||||||
|
|
||||||
var foo = _interopRequire(require("foo"));
|
|
||||||
|
|
||||||
var foo = require("foo");
|
|
||||||
|
|
||||||
var bar = require("foo").bar;
|
|
||||||
var bar = require("foo").foo;
|
|
||||||
```
|
|
||||||
|
|
||||||
### AMD
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ 6to5 --modules amd
|
|
||||||
```
|
|
||||||
|
|
||||||
**In**
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
import foo from "foo";
|
|
||||||
|
|
||||||
export function bar() {
|
|
||||||
return foo("foobar");
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**Out**
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
define(["exports", "foo"], function (exports, _foo) {
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var _interopRequire = function (obj) {
|
|
||||||
return obj && (obj["default"] || obj);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.bar = bar;
|
|
||||||
var foo = _interopRequire(_foo);
|
|
||||||
|
|
||||||
function bar() {
|
|
||||||
return foo("foobar");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
You can optionally specify to include the module id (using the `--amd-module-id` argument):
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
define("filename", ["exports", "foo"], function (exports, _foo) {})
|
|
||||||
```
|
|
||||||
|
|
||||||
### UMD
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ 6to5 --modules umd
|
|
||||||
```
|
|
||||||
|
|
||||||
**In**
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
import foo from "foo";
|
|
||||||
|
|
||||||
export function bar() {
|
|
||||||
return foo("foobar");
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**Out**
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
(function (factory) {
|
|
||||||
if (typeof define === "function" && define.amd) {
|
|
||||||
define(["exports", "foo"], factory);
|
|
||||||
} else if (typeof exports !== "undefined") {
|
|
||||||
factory(exports, require("foo"));
|
|
||||||
}
|
|
||||||
})(function (exports, _foo) {
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var _interopRequire = function (obj) {
|
|
||||||
return obj && (obj["default"] || obj);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.bar = bar;
|
|
||||||
var foo = _interopRequire(_foo);
|
|
||||||
|
|
||||||
function bar() {
|
|
||||||
return foo("foobar");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
### Ignore
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ 6to5 --modules ignore
|
|
||||||
```
|
|
||||||
|
|
||||||
**In**
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
import foo from "foo";
|
|
||||||
|
|
||||||
export function bar() {
|
|
||||||
return foo("foobar");
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**Out**
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
function bar() {
|
|
||||||
return foo("foobar");
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### System
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ 6to5 --modules system
|
|
||||||
```
|
|
||||||
|
|
||||||
**In**
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
import foo from "foo";
|
|
||||||
|
|
||||||
export function bar() {
|
|
||||||
return foo("foobar");
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**Out**
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
System.register("bar", ["foo"], function (_export) {
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var __moduleName = "bar";
|
|
||||||
|
|
||||||
var foo;
|
|
||||||
function bar() {
|
|
||||||
return foo("foobar");
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
setters: [function (m) {
|
|
||||||
foo = m.default;
|
|
||||||
}],
|
|
||||||
execute: function () {
|
|
||||||
_export("bar", bar);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
## Custom
|
|
||||||
|
|
||||||
You can alternatively specify module names instead of one of the built-in types.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ 6to5 --modules custom-module-formatter
|
|
||||||
```
|
|
||||||
|
|
||||||
**node_modules/custom-module-formatter/index.js**
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
module.exports = ModuleFormatter;
|
|
||||||
|
|
||||||
function ModuleFormatter() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ModuleFormatter.prototype.transform = function (ast) {
|
|
||||||
// this is ran after all transformers have had their turn at modifying the ast
|
|
||||||
// feel free to modify this however
|
|
||||||
};
|
|
||||||
|
|
||||||
ModuleFormatter.prototype.importDeclaration = function (node, nodes) {
|
|
||||||
// node is an ImportDeclaration
|
|
||||||
};
|
|
||||||
|
|
||||||
ModuleFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
|
|
||||||
// specifier is an ImportSpecifier
|
|
||||||
// node is an ImportDeclaration
|
|
||||||
};
|
|
||||||
|
|
||||||
ModuleFormatter.prototype.exportDeclaration = function (node, nodes) {
|
|
||||||
// node is an ExportDeclaration
|
|
||||||
};
|
|
||||||
|
|
||||||
ModuleFormatter.prototype.exportSpecifier = function (specifier, node, nodes) {
|
|
||||||
// specifier is an ExportSpecifier
|
|
||||||
// node is an ExportDeclaration
|
|
||||||
};
|
|
||||||
```
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
# Optional runtime
|
|
||||||
|
|
||||||
6to5 has a few helper functions that'll be placed at the top of the generated
|
|
||||||
code if needed so it's not inlined multiple times throughout that file. This may
|
|
||||||
become an issue if you have multiple files, especially when you're sending them
|
|
||||||
to the browser. gzip alleviates most of this concern but it's still not ideal.
|
|
||||||
|
|
||||||
You can tell 6to5 to not place any declarations at the top of your files and
|
|
||||||
instead just point them to a reference contained within the runtime.
|
|
||||||
|
|
||||||
Simply use the following option if you're using the [Node API](usage.md#node):
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
{
|
|
||||||
runtime: true
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
or the following flag if you're using the [CLI](usage.md#cli):
|
|
||||||
|
|
||||||
```ssh
|
|
||||||
$ 6to5 --runtime
|
|
||||||
```
|
|
||||||
|
|
||||||
Then just include the runtime before your generated code.
|
|
||||||
|
|
||||||
## Getting the runtime
|
|
||||||
|
|
||||||
You can get the runtime via either:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ 6to5-runtime
|
|
||||||
```
|
|
||||||
|
|
||||||
or
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
require("6to5").runtime();
|
|
||||||
```
|
|
||||||
|
|
||||||
or from an npm release in `runtime.js` from the 6to5 directory.
|
|
||||||
|
|
||||||
## Customising namespace
|
|
||||||
|
|
||||||
You can also customise the runtime namespace by passing an optional namespace
|
|
||||||
argument:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
require("6to5").runtime("myCustomNamespace");
|
|
||||||
```
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ 6to5-runtime myCustomNamespace
|
|
||||||
```
|
|
||||||
|
|
||||||
See [Options - runtime](usage.md#options) for documentation on changing the
|
|
||||||
reference in generated code.
|
|
||||||
@@ -1,140 +0,0 @@
|
|||||||
# Playground
|
|
||||||
|
|
||||||
Playground is a proving ground for **possible** ES7 proposals.
|
|
||||||
|
|
||||||
**NOTE: These features are in no way endorsed by Ecma International and are not a part of ES6. They might become a part of ECMAScript in the future.**
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
$ 6to5 --playground
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
to5.transform("code", { playground: true });
|
|
||||||
```
|
|
||||||
|
|
||||||
**NOTE:** Enabling `playground` also enables [experimental support](experimental.md).
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
* [Memoization operator](#memoization-operator)
|
|
||||||
* [Method binding](#method-binding)
|
|
||||||
* [Method binding function shorthand](#method-binding-function-shorthand)
|
|
||||||
* [Object getter memoization](#object-getter-memoization)
|
|
||||||
* [This shorthand](#this-shorthand)
|
|
||||||
|
|
||||||
### Memoization assignment operator
|
|
||||||
|
|
||||||
The memoization assignment operator allows you to lazily set an object property.
|
|
||||||
It checks whether there's a property defined on the object and if there isn't then
|
|
||||||
the right hand value is set.
|
|
||||||
|
|
||||||
This means that `obj.x` in the following `var x = { x: undefined }; obj.x ?= 2;`
|
|
||||||
will still be `undefined` because it's already been defined on the object.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var obj = {};
|
|
||||||
obj.x ?= 2;
|
|
||||||
obj.x; // 2
|
|
||||||
|
|
||||||
obj = { x: 1 };
|
|
||||||
obj.x ?= 2;
|
|
||||||
obj.x; // 1
|
|
||||||
|
|
||||||
obj = { x: undefined }
|
|
||||||
obj.x ?= 2;
|
|
||||||
obj.x; // undefined
|
|
||||||
```
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var obj = {};
|
|
||||||
obj.x ?= 2;
|
|
||||||
```
|
|
||||||
|
|
||||||
equivalent to
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var obj = {};
|
|
||||||
if (!Object.prototype.hasOwnProperty.call(obj, "x")) obj.x = 2;
|
|
||||||
```
|
|
||||||
|
|
||||||
### Method binding
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var fn = obj#method;
|
|
||||||
var fn = obj#method("foob");
|
|
||||||
```
|
|
||||||
|
|
||||||
equivalent to
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var fn = obj.method.bind(obj);
|
|
||||||
var fn = obj.method.bind(obj, "foob");
|
|
||||||
```
|
|
||||||
|
|
||||||
### Method binding function shorthand
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
["foo", "bar"].map(#toUpperCase); // ["FOO", "BAR"]
|
|
||||||
[1.1234, 23.53245, 3].map(#toFixed(2)); // ["1.12", "23.53", "3.00"]
|
|
||||||
```
|
|
||||||
|
|
||||||
equivalent to
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
["foo", "bar"].map(function (val) { return val.toUpperCase(); });
|
|
||||||
[1.1234, 23.53245, 3].map(function (val) { return val.toFixed(2); });
|
|
||||||
```
|
|
||||||
|
|
||||||
### Object getter memoization
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var foo = {
|
|
||||||
memo bar() {
|
|
||||||
return complex();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class Foo {
|
|
||||||
memo bar() {
|
|
||||||
return complex();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
equivalent to
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var foo = {
|
|
||||||
get bar() {
|
|
||||||
return Object.defineProperty(this, "bar", {
|
|
||||||
value: complex(),
|
|
||||||
enumerable: true,
|
|
||||||
configurable: true,
|
|
||||||
writable: true
|
|
||||||
}).bar;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class Foo {
|
|
||||||
get bar() {
|
|
||||||
return Object.defineProperty(this, "bar", {
|
|
||||||
value: complex(),
|
|
||||||
enumerable: true,
|
|
||||||
configurable: true,
|
|
||||||
writable: true
|
|
||||||
}).bar;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### This shorthand
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
@foo
|
|
||||||
```
|
|
||||||
|
|
||||||
equivalent to
|
|
||||||
|
|
||||||
```javascirpt
|
|
||||||
this.foo
|
|
||||||
```
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
# Plugins
|
|
||||||
|
|
||||||
## Build systems
|
|
||||||
|
|
||||||
- [Broccoli](https://github.com/6to5/broccoli-6to5-transpiler)
|
|
||||||
- [Browserify](https://github.com/6to5/6to5ify)
|
|
||||||
- [Brunch](https://github.com/6to5/6to5-brunch)
|
|
||||||
- [Duo](https://github.com/6to5/duo6to5)
|
|
||||||
- [Gobble](https://github.com/6to5/gobble-6to5)
|
|
||||||
- [Gulp](https://github.com/6to5/gulp-6to5)
|
|
||||||
- [Grunt](https://github.com/6to5/grunt-6to5)
|
|
||||||
- [Sprockets](https://github.com/josh/sprockets-es6) or via [Browserify](https://github.com/6to5/6to5-rails)
|
|
||||||
- [webpack](https://github.com/6to5/6to5-loader)
|
|
||||||
|
|
||||||
## Integrations
|
|
||||||
|
|
||||||
- [Isparta](https://github.com/douglasduteil/isparta) - Code coverage with `karma` and `instanbul` using 6to5
|
|
||||||
- [JSXHint](https://github.com/STRML/JSXHint) - A wrapper around JSHint to allow linting of JSX files
|
|
||||||
|
|
||||||
## Bridges
|
|
||||||
|
|
||||||
- [Ruby](https://github.com/6to5/6to5-ruby)
|
|
||||||
|
|
||||||
## Testing
|
|
||||||
|
|
||||||
- [Jest](https://github.com/6to5/6to5-jest)
|
|
||||||
- [Karma](https://github.com/6to5/karma-6to5-preprocessor)
|
|
||||||
- [Mocha](https://github.com/6to5/6to5-mocha)
|
|
||||||
|
|
||||||
## Misc
|
|
||||||
|
|
||||||
- [Connect](https://github.com/6to5/6to5-connect)
|
|
||||||
- [Jade](https://github.com/6to5/jade-6to5)
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
# Polyfill
|
|
||||||
|
|
||||||
6to5 includes a polyfill that includes a custom
|
|
||||||
[regenerator runtime](https://github.com/facebook/regenerator/blob/master/runtime.js) and
|
|
||||||
[core.js](https://github.com/zloirock/core-js).
|
|
||||||
|
|
||||||
This will emulate a full ES6 environment. This polyfill is automatically loaded
|
|
||||||
when using [6to5-node](usage.md#node) and [6to5/register](usage.md#register-hook).
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
### Node/Browserify
|
|
||||||
|
|
||||||
You need to include the polyfill require at the top the **entry point** to your
|
|
||||||
application.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
require("6to5/polyfill");
|
|
||||||
```
|
|
||||||
|
|
||||||
Fortunately, this is automatically loaded when using:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
require("6to5/register");
|
|
||||||
```
|
|
||||||
|
|
||||||
### Browser
|
|
||||||
|
|
||||||
Available from the `browser-polyfill.js` file within the 6to5 directory of an
|
|
||||||
npm release. This needs to be included **before** all your compiled 6to5 code.
|
|
||||||
You can either prepend it to your compiled code or include it in a `<script>`
|
|
||||||
before it.
|
|
||||||
|
|
||||||
**NOTE:** Do not `require` this via browserify etc, use `6to5/polyfill`.
|
|
||||||
17
doc/react.md
17
doc/react.md
@@ -1,17 +0,0 @@
|
|||||||
# React/JSX
|
|
||||||
|
|
||||||
6to5 has built-in support for React v0.12. Tags are automatically transformed to
|
|
||||||
their equivalent `React.createElement(...)` and `displayName` is automatically
|
|
||||||
inferred and added to all `React.createClass` calls.
|
|
||||||
|
|
||||||
## Blacklist
|
|
||||||
|
|
||||||
To disable this behaviour add `react` to your blacklist:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
to5.transform("code", { blacklist: ["react"] });
|
|
||||||
```
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ 6to5 --blacklist react
|
|
||||||
```
|
|
||||||
259
doc/usage.md
259
doc/usage.md
@@ -1,259 +0,0 @@
|
|||||||
# Usage
|
|
||||||
|
|
||||||
## CLI
|
|
||||||
|
|
||||||
Compile the file `script.js` and output it to stdout.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ 6to5 script.js
|
|
||||||
```
|
|
||||||
|
|
||||||
Compile the file `script.js` and output it to `script-compiled.js`.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ 6to5 script.js --out-file script-compiled.js
|
|
||||||
```
|
|
||||||
|
|
||||||
Compile the file `script.js` and output it to `script-compiled.js` and save a
|
|
||||||
source map to `script-compiled.js.map`.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ 6to5 script.js --source-maps --out-file script-compiled.js
|
|
||||||
```
|
|
||||||
|
|
||||||
Compile the file `script.js` and output it to `script-compiled.js` with a source
|
|
||||||
map embedded in a comment at the bottom.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ 6to5 script.js --source-maps-inline --out-file script-compiled.js
|
|
||||||
```
|
|
||||||
|
|
||||||
Compile the entire `src` directory and output it to the `lib` directory.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ 6to5 src --out-dir lib
|
|
||||||
```
|
|
||||||
|
|
||||||
Compile the entire `src` directory and output it to the one concatenated file.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ 6to5 src --out-file script-compiled.js
|
|
||||||
```
|
|
||||||
|
|
||||||
Pipe a file in via stdin and output it to `script-compiled.js`
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ 6to5 --out-file script-compiled.js < script.js
|
|
||||||
```
|
|
||||||
|
|
||||||
### Node
|
|
||||||
|
|
||||||
Launch a repl.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ 6to5-node
|
|
||||||
```
|
|
||||||
|
|
||||||
Evaluate code.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ 6to5-node -e "class Test { }"
|
|
||||||
```
|
|
||||||
|
|
||||||
Compile and run `test.js`.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ 6to5-node test
|
|
||||||
```
|
|
||||||
|
|
||||||
## Node
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var to5 = require("6to5");
|
|
||||||
```
|
|
||||||
|
|
||||||
### to5.transform(code, [opts]);
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var result = to5.transform("code();", options);
|
|
||||||
result.code;
|
|
||||||
result.map;
|
|
||||||
result.ast;
|
|
||||||
```
|
|
||||||
|
|
||||||
### to5.transformFileSync(filename, [opts])
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
to5.transformFileSync("filename.js", options).code;
|
|
||||||
```
|
|
||||||
|
|
||||||
### to5.transformFile(filename, [opts], callback)
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
to5.transformFile("filename.js", options, function (err, result) {
|
|
||||||
result.code;
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
### to5.transform.fromAst(ast, [code], [opts])
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var result = to5.transform.fromAst(ast, "var a = 2;", opts);
|
|
||||||
result.code;
|
|
||||||
result.map;
|
|
||||||
result.ast;
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Options
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
{
|
|
||||||
// Filename for use in errors etc.
|
|
||||||
// Default: "unknown"
|
|
||||||
filename: "filename",
|
|
||||||
|
|
||||||
// Filename relative to `sourceRoot`
|
|
||||||
// Default: `filename` option.
|
|
||||||
filenameRelative: "",
|
|
||||||
|
|
||||||
// List of transformers to EXCLUDE.
|
|
||||||
// Run `6to5 --help` to see a full list of transformers.
|
|
||||||
blacklist: [],
|
|
||||||
|
|
||||||
// List of transformers to ONLY use.
|
|
||||||
// Run `6to5 --help` to see a full list of transformers.
|
|
||||||
whitelist: [],
|
|
||||||
|
|
||||||
// Module formatter to use
|
|
||||||
// Run `6to5 --help` to see a full list of module formatters.
|
|
||||||
// Default: "common"
|
|
||||||
modules: "common",
|
|
||||||
|
|
||||||
// If truthy, adds a `map` property to returned output.
|
|
||||||
// If set to "inline", a comment with a sourceMappingURL directive is added to
|
|
||||||
// the bottom of the returned code.
|
|
||||||
// Default: false
|
|
||||||
sourceMap: true,
|
|
||||||
|
|
||||||
// Set `file` on returned source map.
|
|
||||||
// Default: `filenameRelative` option.
|
|
||||||
sourceMapName: "filename",
|
|
||||||
|
|
||||||
// Set `sources[0]` on returned source map.
|
|
||||||
// Default: `filenameRelative` option.
|
|
||||||
sourceFileName: "filename",
|
|
||||||
|
|
||||||
// The root from which all sources are relative
|
|
||||||
// Default: `moduleRoot` option.
|
|
||||||
sourceRoot: "assets/scripts",
|
|
||||||
|
|
||||||
// Optional prefix for the AMD module formatter that will be prepend to the
|
|
||||||
// filename on module definitions
|
|
||||||
// Default: `sourceRoot` option.
|
|
||||||
moduleRoot: "my-app",
|
|
||||||
|
|
||||||
// If truthy, insert an explicit id for each defined AMD/System module.
|
|
||||||
// By default, AMD/System modules are anonymous.
|
|
||||||
// Default: false
|
|
||||||
moduleIds: true,
|
|
||||||
|
|
||||||
// Optionally replace all 6to5 helper declarations with a referenece to this
|
|
||||||
// variable. If set to `true` then the default namespace is used "to5Runtime".
|
|
||||||
// Default: false
|
|
||||||
runtime: true,
|
|
||||||
|
|
||||||
// Enable support for experimental ES7 features
|
|
||||||
// Default: false
|
|
||||||
experimental: true,
|
|
||||||
|
|
||||||
// Set this to `false` if you don't want the transformed AST in the returned
|
|
||||||
// result
|
|
||||||
// Default: true
|
|
||||||
ast: true,
|
|
||||||
|
|
||||||
// Set this to `false` if you don't want the transformed code in the returned
|
|
||||||
// result
|
|
||||||
// Default: true
|
|
||||||
code: true,
|
|
||||||
|
|
||||||
format: {
|
|
||||||
// Output comments in generated output
|
|
||||||
// Default: true
|
|
||||||
comments: true,
|
|
||||||
|
|
||||||
// Do not include superfluous whitespace characters and line terminators
|
|
||||||
// Default: false
|
|
||||||
compact: false,
|
|
||||||
|
|
||||||
indent: {
|
|
||||||
// Preserve parentheses in new expressions that have no arguments
|
|
||||||
// Default: true
|
|
||||||
parentheses: true,
|
|
||||||
|
|
||||||
// Adjust the indentation of multiline comments to keep asterisks vertically aligned
|
|
||||||
// Default: true
|
|
||||||
adjustMultilineComment: true,
|
|
||||||
|
|
||||||
// Indent string
|
|
||||||
// Default: " "
|
|
||||||
style: " ",
|
|
||||||
|
|
||||||
// Base indent level
|
|
||||||
// Default: 0
|
|
||||||
base: 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Require hook
|
|
||||||
|
|
||||||
All subsequent files required by node with the extensions `.es6`, `.es` and `.js` will
|
|
||||||
be transformed by 6to5. The polyfill specified in [Polyfill](polyfill.md) is
|
|
||||||
also required; but this is automatically loaded when using:
|
|
||||||
|
|
||||||
Source maps are automatically configured so if any errors a thrown then line
|
|
||||||
number info is mapped and you'll get the correct source location.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
require("6to5/register");
|
|
||||||
```
|
|
||||||
|
|
||||||
**NOTE:** By default all requires to `node_modules` will be ignored. You can
|
|
||||||
override this by passing an ignore regex via:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
require("6to5/register")({
|
|
||||||
// This will override `node_modules` ignoring - you can alternatively pass
|
|
||||||
// a regex
|
|
||||||
ignore: false
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
**NOTE:** Using 6to5-node or `require("6to5/register")`, 6to5 will check what features are available in the current environment and blacklists them if they're supported.
|
|
||||||
|
|
||||||
#### Options
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
require("6to5/register")({
|
|
||||||
// Optional ignore regex - if any filenames **do** match this regex then they
|
|
||||||
// aren't compiled
|
|
||||||
ignore: /regex/,
|
|
||||||
|
|
||||||
// Optional only regex - if any filenames **don't** match this regex then they
|
|
||||||
// aren't compiled
|
|
||||||
only: /my_es6_folder/,
|
|
||||||
|
|
||||||
// See options above for usage
|
|
||||||
whitelist: [],
|
|
||||||
blacklist: [],
|
|
||||||
|
|
||||||
// This will remove the currently hooked extensions of .es6 and .js so you'll
|
|
||||||
// have to add them back if you want them to be used again.
|
|
||||||
extensions: [".js", ".es6"],
|
|
||||||
|
|
||||||
// Enables `roadrunner` cache that will save to a `.roadrunner.json` file in your cwd
|
|
||||||
// Do not check this into git as it's user-specific
|
|
||||||
cache: true
|
|
||||||
});
|
|
||||||
```
|
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
var transform = module.exports = require("./transformation/transform");
|
var transform = module.exports = require("./transformation/transform");
|
||||||
|
|
||||||
|
transform.version = require("../../package").version;
|
||||||
|
|
||||||
transform.transform = transform;
|
transform.transform = transform;
|
||||||
|
|
||||||
transform.run = function (code, opts) {
|
transform.run = function (code, opts) {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
module.exports = File;
|
module.exports = File;
|
||||||
|
|
||||||
var SHEBANG_REGEX = /^\#\!.*/;
|
var SHEBANG_REGEX = /^\#\!.*/;
|
||||||
@@ -24,6 +26,7 @@ File.helpers = [
|
|||||||
"prototype-properties",
|
"prototype-properties",
|
||||||
"apply-constructor",
|
"apply-constructor",
|
||||||
"tagged-template-literal",
|
"tagged-template-literal",
|
||||||
|
"tagged-template-literal-loose",
|
||||||
"interop-require",
|
"interop-require",
|
||||||
"to-array",
|
"to-array",
|
||||||
"sliced-to-array",
|
"sliced-to-array",
|
||||||
@@ -35,32 +38,38 @@ File.helpers = [
|
|||||||
"async-to-generator",
|
"async-to-generator",
|
||||||
"interop-require-wildcard",
|
"interop-require-wildcard",
|
||||||
"typeof",
|
"typeof",
|
||||||
"exports-wildcard"
|
"extends",
|
||||||
|
"get"
|
||||||
];
|
];
|
||||||
|
|
||||||
File.excludeHelpersFromRuntime = [
|
File.excludeHelpersFromRuntime = [
|
||||||
"async-to-generator",
|
"async-to-generator",
|
||||||
"typeof"
|
"typeof",
|
||||||
|
"tagged-template-literal-loose"
|
||||||
];
|
];
|
||||||
|
|
||||||
File.normaliseOptions = function (opts) {
|
File.normaliseOptions = function (opts) {
|
||||||
opts = _.cloneDeep(opts || {});
|
opts = _.cloneDeep(opts || {});
|
||||||
|
|
||||||
_.defaults(opts, {
|
_.defaults(opts, {
|
||||||
experimental: false,
|
keepModuleIdExtensions: false,
|
||||||
playground: false,
|
includeRegenerator: false,
|
||||||
whitespace: true,
|
experimental: false,
|
||||||
moduleIds: opts.amdModuleIds || false,
|
reactCompat: false,
|
||||||
blacklist: [],
|
playground: false,
|
||||||
whitelist: [],
|
whitespace: true,
|
||||||
sourceMap: false,
|
moduleIds: opts.amdModuleIds || false,
|
||||||
optional: [],
|
blacklist: [],
|
||||||
comments: true,
|
whitelist: [],
|
||||||
filename: "unknown",
|
sourceMap: false,
|
||||||
modules: "common",
|
optional: [],
|
||||||
runtime: false,
|
comments: true,
|
||||||
code: true,
|
filename: "unknown",
|
||||||
ast: true
|
modules: "common",
|
||||||
|
runtime: false,
|
||||||
|
loose: [],
|
||||||
|
code: true,
|
||||||
|
ast: true
|
||||||
});
|
});
|
||||||
|
|
||||||
// normalise windows path separators to unix
|
// normalise windows path separators to unix
|
||||||
@@ -68,6 +77,23 @@ File.normaliseOptions = function (opts) {
|
|||||||
|
|
||||||
opts.blacklist = util.arrayify(opts.blacklist);
|
opts.blacklist = util.arrayify(opts.blacklist);
|
||||||
opts.whitelist = util.arrayify(opts.whitelist);
|
opts.whitelist = util.arrayify(opts.whitelist);
|
||||||
|
opts.optional = util.arrayify(opts.optional);
|
||||||
|
opts.loose = util.arrayify(opts.loose);
|
||||||
|
|
||||||
|
if (_.contains(opts.loose, "all")) {
|
||||||
|
opts.loose = Object.keys(transform.transformers);
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo: remove in 3.0.0
|
||||||
|
_.each({
|
||||||
|
fastForOf: "forOf",
|
||||||
|
classesFastSuper: "classes"
|
||||||
|
}, function (newTransformer, oldTransformer) {
|
||||||
|
if (_.contains(opts.optional, oldTransformer)) {
|
||||||
|
_.pull(opts.optional, oldTransformer);
|
||||||
|
opts.loose.push(newTransformer);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
_.defaults(opts, {
|
_.defaults(opts, {
|
||||||
moduleRoot: opts.sourceRoot
|
moduleRoot: opts.sourceRoot
|
||||||
@@ -97,10 +123,15 @@ File.normaliseOptions = function (opts) {
|
|||||||
transform._ensureTransformerNames("blacklist", opts.blacklist);
|
transform._ensureTransformerNames("blacklist", opts.blacklist);
|
||||||
transform._ensureTransformerNames("whitelist", opts.whitelist);
|
transform._ensureTransformerNames("whitelist", opts.whitelist);
|
||||||
transform._ensureTransformerNames("optional", opts.optional);
|
transform._ensureTransformerNames("optional", opts.optional);
|
||||||
|
transform._ensureTransformerNames("loose", opts.loose);
|
||||||
|
|
||||||
return opts;
|
return opts;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
File.prototype.isLoose = function (key) {
|
||||||
|
return _.contains(this.opts.loose, key);
|
||||||
|
};
|
||||||
|
|
||||||
File.prototype.getTransformers = function () {
|
File.prototype.getTransformers = function () {
|
||||||
var file = this;
|
var file = this;
|
||||||
var transformers = [];
|
var transformers = [];
|
||||||
@@ -300,7 +331,10 @@ File.prototype.generateUid = function (name, scope) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
File.prototype.generateUidIdentifier = function (name, scope) {
|
File.prototype.generateUidIdentifier = function (name, scope) {
|
||||||
return t.identifier(this.generateUid(name, scope));
|
scope = scope || this.scope;
|
||||||
|
var id = t.identifier(this.generateUid(name, scope));
|
||||||
|
scope.add(id);
|
||||||
|
return id;
|
||||||
};
|
};
|
||||||
|
|
||||||
File.prototype._generateUid = function (name) {
|
File.prototype._generateUid = function (name) {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
module.exports = Buffer;
|
module.exports = Buffer;
|
||||||
|
|
||||||
var util = require("../util");
|
var util = require("../util");
|
||||||
@@ -61,39 +63,63 @@ Buffer.prototype.space = function () {
|
|||||||
Buffer.prototype.removeLast = function (cha) {
|
Buffer.prototype.removeLast = function (cha) {
|
||||||
if (!this.isLast(cha)) return;
|
if (!this.isLast(cha)) return;
|
||||||
|
|
||||||
this.buf = this.buf.slice(0, -1);
|
this.buf = this.buf.substr(0, this.buf.length - 1);
|
||||||
this.position.unshift(cha);
|
this.position.unshift(cha);
|
||||||
};
|
};
|
||||||
|
|
||||||
Buffer.prototype.newline = function (i, removeLast) {
|
Buffer.prototype.newline = function (i, removeLast) {
|
||||||
if (this.format.compact) return;
|
if (this.format.compact) return;
|
||||||
|
removeLast = removeLast || false;
|
||||||
if (_.isBoolean(i)) {
|
|
||||||
removeLast = i;
|
|
||||||
i = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_.isNumber(i)) {
|
if (_.isNumber(i)) {
|
||||||
if (this.endsWith("{\n")) i--;
|
if (this.endsWith("{\n")) i--;
|
||||||
if (this.endsWith(util.repeat(i, "\n"))) return;
|
if (this.endsWith(util.repeat(i, "\n"))) return;
|
||||||
|
|
||||||
var self = this;
|
while (i--) {
|
||||||
_.times(i, function () {
|
this._newline(removeLast);
|
||||||
self.newline(null, removeLast);
|
}
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_.isBoolean(i)) {
|
||||||
|
removeLast = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._newline(removeLast);
|
||||||
|
};
|
||||||
|
|
||||||
|
Buffer.prototype._newline = function (removeLast) {
|
||||||
if (removeLast && this.isLast("\n")) this.removeLast("\n");
|
if (removeLast && this.isLast("\n")) this.removeLast("\n");
|
||||||
|
|
||||||
this.removeLast(" ");
|
this.removeLast(" ");
|
||||||
|
|
||||||
// remove whitespace if last character was a newline
|
// remove whitespace if last character was a newline
|
||||||
this.buf = this.buf.replace(/\n +$/, "\n");
|
this._removeSpacesAfterLastNewline();
|
||||||
|
|
||||||
this._push("\n");
|
this._push("\n");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If buffer ends with a newline and some spaces after it, trim those spaces.
|
||||||
|
*/
|
||||||
|
Buffer.prototype._removeSpacesAfterLastNewline = function () {
|
||||||
|
var lastNewlineIndex = this.buf.lastIndexOf('\n');
|
||||||
|
if (lastNewlineIndex === -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var index = this.buf.length - 1;
|
||||||
|
while (index > lastNewlineIndex) {
|
||||||
|
if (this.buf[index] !== ' ') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
index--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index === lastNewlineIndex) {
|
||||||
|
this.buf = this.buf.substring(0, index + 1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Buffer.prototype.push = function (str, noIndent) {
|
Buffer.prototype.push = function (str, noIndent) {
|
||||||
if (this._indent && !noIndent && str !== "\n") {
|
if (this._indent && !noIndent && str !== "\n") {
|
||||||
// we have an indent level and we aren't pushing a newline
|
// we have an indent level and we aren't pushing a newline
|
||||||
@@ -115,13 +141,18 @@ Buffer.prototype._push = function (str) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Buffer.prototype.endsWith = function (str) {
|
Buffer.prototype.endsWith = function (str) {
|
||||||
return this.buf.slice(-str.length) === str;
|
var d = this.buf.length - str.length;
|
||||||
|
return d >= 0 && this.buf.lastIndexOf(str) === d;
|
||||||
};
|
};
|
||||||
|
|
||||||
Buffer.prototype.isLast = function (cha, trimRight) {
|
Buffer.prototype.isLast = function (cha, trimRight) {
|
||||||
var buf = this.buf;
|
var buf = this.buf;
|
||||||
if (trimRight) buf = util.trimRight(buf);
|
if (trimRight) buf = util.trimRight(buf);
|
||||||
|
var last = buf[buf.length - 1];
|
||||||
|
|
||||||
var chars = [].concat(cha);
|
if (Array.isArray(cha)) {
|
||||||
return _.contains(chars, _.last(buf));
|
return _.contains(cha, last);
|
||||||
|
} else {
|
||||||
|
return cha === last;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
module.exports = function (ast, opts, code) {
|
module.exports = function (ast, opts, code) {
|
||||||
var gen = new CodeGenerator(ast, opts, code);
|
var gen = new CodeGenerator(ast, opts, code);
|
||||||
return gen.generate();
|
return gen.generate();
|
||||||
@@ -125,7 +127,7 @@ CodeGenerator.prototype.print = function (node, parent, opts) {
|
|||||||
|
|
||||||
var lines = 0;
|
var lines = 0;
|
||||||
|
|
||||||
if (node.start != null) {
|
if (node.start != null && !node._ignoreUserWhitespace) {
|
||||||
// user node
|
// user node
|
||||||
if (leading) {
|
if (leading) {
|
||||||
lines = self.whitespace.getNewlinesBefore(node);
|
lines = self.whitespace.getNewlinesBefore(node);
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
exports.File = function (node, print) {
|
exports.File = function (node, print) {
|
||||||
print(node.program);
|
print(node.program);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
exports.ClassExpression =
|
exports.ClassExpression =
|
||||||
exports.ClassDeclaration = function (node, print) {
|
exports.ClassDeclaration = function (node, print) {
|
||||||
this.push("class");
|
this.push("class");
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
exports.ComprehensionBlock = function (node, print) {
|
exports.ComprehensionBlock = function (node, print) {
|
||||||
this.keyword("for");
|
this.keyword("for");
|
||||||
this.push("(");
|
this.push("(");
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
var util = require("../../util");
|
var util = require("../../util");
|
||||||
var t = require("../../types");
|
var t = require("../../types");
|
||||||
var _ = require("lodash");
|
var _ = require("lodash");
|
||||||
@@ -57,8 +59,28 @@ exports.ThisExpression = function () {
|
|||||||
|
|
||||||
exports.CallExpression = function (node, print) {
|
exports.CallExpression = function (node, print) {
|
||||||
print(node.callee);
|
print(node.callee);
|
||||||
|
|
||||||
this.push("(");
|
this.push("(");
|
||||||
print.join(node.arguments, { separator: ", " });
|
|
||||||
|
var separator = ",";
|
||||||
|
|
||||||
|
if (node._prettyCall) {
|
||||||
|
separator += "\n";
|
||||||
|
this.newline();
|
||||||
|
this.indent();
|
||||||
|
} else {
|
||||||
|
separator += " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
print.join(node.arguments, {
|
||||||
|
separator: separator
|
||||||
|
});
|
||||||
|
|
||||||
|
if (node._prettyCall) {
|
||||||
|
this.newline();
|
||||||
|
this.dedent();
|
||||||
|
}
|
||||||
|
|
||||||
this.push(")");
|
this.push(")");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,35 @@
|
|||||||
exports.ClassProperty = function () {
|
"use strict";
|
||||||
throw new Error("not implemented");
|
|
||||||
|
exports.AnyTypeAnnotation =
|
||||||
|
exports.ArrayTypeAnnotation =
|
||||||
|
exports.BooleanTypeAnnotation =
|
||||||
|
exports.ClassProperty =
|
||||||
|
exports.DeclareClass =
|
||||||
|
exports.DeclareFunction =
|
||||||
|
exports.DeclareModule =
|
||||||
|
exports.DeclareVariable =
|
||||||
|
exports.FunctionTypeAnnotation =
|
||||||
|
exports.FunctionTypeParam =
|
||||||
|
exports.GenericTypeAnnotation =
|
||||||
|
exports.InterfaceExtends =
|
||||||
|
exports.InterfaceDeclaration =
|
||||||
|
exports.IntersectionTypeAnnotation =
|
||||||
|
exports.NullableTypeAnnotation =
|
||||||
|
exports.NumberTypeAnnotation =
|
||||||
|
exports.StringLiteralTypeAnnotation =
|
||||||
|
exports.StringTypeAnnotation =
|
||||||
|
exports.TupleTypeAnnotation =
|
||||||
|
exports.TypeofTypeAnnotation =
|
||||||
|
exports.TypeAlias =
|
||||||
|
exports.TypeAnnotation =
|
||||||
|
exports.TypeParameterDeclaration =
|
||||||
|
exports.TypeParameterInstantiation =
|
||||||
|
exports.ObjectTypeAnnotation =
|
||||||
|
exports.ObjectTypeCallProperty =
|
||||||
|
exports.ObjectTypeIndexer =
|
||||||
|
exports.ObjectTypeProperty =
|
||||||
|
exports.QualifiedTypeIdentifier =
|
||||||
|
exports.UnionTypeAnnotation =
|
||||||
|
exports.VoidTypeAnnotation = function () {
|
||||||
|
// todo: implement these once we have a `--keep-types` option
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
var t = require("../../types");
|
var t = require("../../types");
|
||||||
var _ = require("lodash");
|
var _ = require("lodash");
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
var t = require("../../types");
|
var t = require("../../types");
|
||||||
|
|
||||||
exports._params = function (node, print) {
|
exports._params = function (node, print) {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
var t = require("../../types");
|
var t = require("../../types");
|
||||||
var _ = require("lodash");
|
var _ = require("lodash");
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
var _ = require("lodash");
|
var _ = require("lodash");
|
||||||
|
|
||||||
_.each(["BindMemberExpression", "BindFunctionExpression"], function (type) {
|
_.each(["BindMemberExpression", "BindFunctionExpression"], function (type) {
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
var t = require("../../types");
|
"use strict";
|
||||||
|
|
||||||
|
var util = require("../../util");
|
||||||
|
var t = require("../../types");
|
||||||
|
|
||||||
exports.WithStatement = function (node, print) {
|
exports.WithStatement = function (node, print) {
|
||||||
this.keyword("with");
|
this.keyword("with");
|
||||||
@@ -106,7 +109,16 @@ exports.TryStatement = function (node, print) {
|
|||||||
this.keyword("try");
|
this.keyword("try");
|
||||||
print(node.block);
|
print(node.block);
|
||||||
this.space();
|
this.space();
|
||||||
print(node.handler);
|
|
||||||
|
// Esprima bug puts the catch clause in a `handlers` array.
|
||||||
|
// see https://code.google.com/p/esprima/issues/detail?id=433
|
||||||
|
// We run into this from regenerator generated ast.
|
||||||
|
if (node.handlers) {
|
||||||
|
print(node.handlers[0]);
|
||||||
|
} else {
|
||||||
|
print(node.handler);
|
||||||
|
}
|
||||||
|
|
||||||
if (node.finalizer) {
|
if (node.finalizer) {
|
||||||
this.space();
|
this.space();
|
||||||
this.push("finally ");
|
this.push("finally ");
|
||||||
@@ -157,7 +169,25 @@ exports.DebuggerStatement = function () {
|
|||||||
exports.VariableDeclaration = function (node, print, parent) {
|
exports.VariableDeclaration = function (node, print, parent) {
|
||||||
this.push(node.kind + " ");
|
this.push(node.kind + " ");
|
||||||
|
|
||||||
print.join(node.declarations, { separator: ", " });
|
var hasInits = false;
|
||||||
|
// don't add whitespace to loop heads
|
||||||
|
if (!t.isFor(parent)) {
|
||||||
|
for (var i = 0; i < node.declarations.length; i++) {
|
||||||
|
if (node.declarations[i].init) {
|
||||||
|
// has an init so let's split it up over multiple lines
|
||||||
|
hasInits = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var sep = ",";
|
||||||
|
if (hasInits) {
|
||||||
|
sep += "\n" + util.repeat(node.kind.length + 1);
|
||||||
|
} else {
|
||||||
|
sep += " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
print.join(node.declarations, { separator: sep });
|
||||||
|
|
||||||
if (!t.isFor(parent)) {
|
if (!t.isFor(parent)) {
|
||||||
this.semicolon();
|
this.semicolon();
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
var _ = require("lodash");
|
var _ = require("lodash");
|
||||||
|
|
||||||
exports.TaggedTemplateExpression = function (node, print) {
|
exports.TaggedTemplateExpression = function (node, print) {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
var _ = require("lodash");
|
var _ = require("lodash");
|
||||||
|
|
||||||
exports.Identifier = function (node) {
|
exports.Identifier = function (node) {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
module.exports = Node;
|
module.exports = Node;
|
||||||
|
|
||||||
var whitespace = require("./whitespace");
|
var whitespace = require("./whitespace");
|
||||||
@@ -6,14 +8,19 @@ var t = require("../../types");
|
|||||||
var _ = require("lodash");
|
var _ = require("lodash");
|
||||||
|
|
||||||
var find = function (obj, node, parent) {
|
var find = function (obj, node, parent) {
|
||||||
|
if (!obj) return;
|
||||||
var result;
|
var result;
|
||||||
|
|
||||||
_.each(obj, function (fn, type) {
|
var types = Object.keys(obj);
|
||||||
if (t["is" + type](node)) {
|
for (var i = 0; i < types.length; i++) {
|
||||||
|
var type = types[i];
|
||||||
|
|
||||||
|
if (t.is(type, node)) {
|
||||||
|
var fn = obj[type];
|
||||||
result = fn(node, parent);
|
result = fn(node, parent);
|
||||||
if (result != null) return false;
|
if (result != null) break;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
@@ -23,13 +30,11 @@ function Node(node, parent) {
|
|||||||
this.node = node;
|
this.node = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
Node.prototype.isUserWhitespacable = function () {
|
Node.isUserWhitespacable = function (node) {
|
||||||
return t.isUserWhitespacable(this.node);
|
return t.isUserWhitespacable(node);
|
||||||
};
|
};
|
||||||
|
|
||||||
Node.prototype.needsWhitespace = function (type) {
|
Node.needsWhitespace = function (node, parent, type) {
|
||||||
var parent = this.parent;
|
|
||||||
var node = this.node;
|
|
||||||
if (!node) return 0;
|
if (!node) return 0;
|
||||||
|
|
||||||
if (t.isExpressionStatement(node)) {
|
if (t.isExpressionStatement(node)) {
|
||||||
@@ -46,18 +51,15 @@ Node.prototype.needsWhitespace = function (type) {
|
|||||||
return lines || 0;
|
return lines || 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
Node.prototype.needsWhitespaceBefore = function () {
|
Node.needsWhitespaceBefore = function (node, parent) {
|
||||||
return this.needsWhitespace("before");
|
return Node.needsWhitespace(node, parent, "before");
|
||||||
};
|
};
|
||||||
|
|
||||||
Node.prototype.needsWhitespaceAfter = function () {
|
Node.needsWhitespaceAfter = function (node, parent) {
|
||||||
return this.needsWhitespace("after");
|
return Node.needsWhitespace(node, parent, "after");
|
||||||
};
|
};
|
||||||
|
|
||||||
Node.prototype.needsParens = function () {
|
Node.needsParens = function (node, parent) {
|
||||||
var parent = this.parent;
|
|
||||||
var node = this.node;
|
|
||||||
|
|
||||||
if (!parent) return false;
|
if (!parent) return false;
|
||||||
|
|
||||||
if (t.isNewExpression(parent) && parent.callee === node) {
|
if (t.isNewExpression(parent) && parent.callee === node) {
|
||||||
@@ -72,10 +74,7 @@ Node.prototype.needsParens = function () {
|
|||||||
return find(parens, node, parent);
|
return find(parens, node, parent);
|
||||||
};
|
};
|
||||||
|
|
||||||
Node.prototype.needsParensNoLineTerminator = function () {
|
Node.needsParensNoLineTerminator = function (node, parent) {
|
||||||
var parent = this.parent;
|
|
||||||
var node = this.node;
|
|
||||||
|
|
||||||
if (!parent) return false;
|
if (!parent) return false;
|
||||||
|
|
||||||
// no comments
|
// no comments
|
||||||
@@ -95,11 +94,18 @@ Node.prototype.needsParensNoLineTerminator = function () {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
_.each(Node.prototype, function (fn, key) {
|
_.each(Node, function (fn, key) {
|
||||||
Node[key] = function (node, parent) {
|
Node.prototype[key] = function () {
|
||||||
var n = new Node(node, parent);
|
// Avoid leaking arguments to prevent deoptimization
|
||||||
|
var args = new Array(arguments.length + 2);
|
||||||
|
|
||||||
var args = _.toArray(arguments).slice(2);
|
args[0] = this.node;
|
||||||
return n[key].apply(n, args);
|
args[1] = this.parent;
|
||||||
|
|
||||||
|
for (var i = 0; i < args.length; i++) {
|
||||||
|
args[i + 2] = arguments[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return Node[key].apply(null, args);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
var t = require("../../types");
|
var t = require("../../types");
|
||||||
var _ = require("lodash");
|
var _ = require("lodash");
|
||||||
|
|
||||||
@@ -21,6 +23,13 @@ _.each([
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
exports.UpdateExpression = function (node, parent) {
|
||||||
|
if (t.isMemberExpression(parent) && parent.object === node) {
|
||||||
|
// (foo++).test()
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
exports.ObjectExpression = function (node, parent) {
|
exports.ObjectExpression = function (node, parent) {
|
||||||
if (t.isExpressionStatement(parent)) {
|
if (t.isExpressionStatement(parent)) {
|
||||||
// ({ foo: "bar" });
|
// ({ foo: "bar" });
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
var _ = require("lodash");
|
var _ = require("lodash");
|
||||||
var t = require("../../types");
|
var t = require("../../types");
|
||||||
|
|
||||||
@@ -62,11 +64,15 @@ _.each({
|
|||||||
CallExpression: { after: 1 },
|
CallExpression: { after: 1 },
|
||||||
Literal: { after: 1 }
|
Literal: { after: 1 }
|
||||||
}, function (amounts, type) {
|
}, function (amounts, type) {
|
||||||
if (_.isNumber(amounts)) amounts = { after: amounts, before: amounts };
|
if (_.isNumber(amounts)) {
|
||||||
|
amounts = { after: amounts, before: amounts };
|
||||||
|
}
|
||||||
|
|
||||||
_.each(amounts, function (amount, key) {
|
_.each([type].concat(t.FLIPPED_ALIAS_KEYS[type] || []), function (type) {
|
||||||
exports[key].nodes[type] = function () {
|
_.each(amounts, function (amount, key) {
|
||||||
return amount;
|
exports[key].nodes[type] = function () {
|
||||||
};
|
return amount;
|
||||||
|
};
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
module.exports = Position;
|
"use strict";
|
||||||
|
|
||||||
var _ = require("lodash");
|
module.exports = Position;
|
||||||
|
|
||||||
function Position() {
|
function Position() {
|
||||||
this.line = 1;
|
this.line = 1;
|
||||||
@@ -8,26 +8,22 @@ function Position() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Position.prototype.push = function (str) {
|
Position.prototype.push = function (str) {
|
||||||
var self = this;
|
for (var i = 0; i < str.length; i++) {
|
||||||
|
if (str[i] === "\n") {
|
||||||
_.each(str, function (cha) {
|
this.line++;
|
||||||
if (cha === "\n") {
|
this.column = 0;
|
||||||
self.line++;
|
|
||||||
self.column = 0;
|
|
||||||
} else {
|
} else {
|
||||||
self.column++;
|
this.column++;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Position.prototype.unshift = function (str) {
|
Position.prototype.unshift = function (str) {
|
||||||
var self = this;
|
for (var i = 0; i < str.length; i++) {
|
||||||
|
if (str[i] === "\n") {
|
||||||
_.each(str, function (cha) {
|
this.line--;
|
||||||
if (cha === "\n") {
|
|
||||||
self.line--;
|
|
||||||
} else {
|
} else {
|
||||||
self.column--;
|
this.column--;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
module.exports = SourceMap;
|
module.exports = SourceMap;
|
||||||
|
|
||||||
var sourceMap = require("source-map");
|
var sourceMap = require("source-map");
|
||||||
|
|||||||
@@ -1,25 +1,62 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
module.exports = Whitespace;
|
module.exports = Whitespace;
|
||||||
|
|
||||||
var _ = require("lodash");
|
var _ = require("lodash");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns `i`th number from `base`, continuing from 0 when `max` is reached.
|
||||||
|
* Useful for shifting `for` loop by a fixed number but going over all items.
|
||||||
|
*
|
||||||
|
* @param {Number} i Current index in the loop
|
||||||
|
* @param {Number} base Start index for which to return 0
|
||||||
|
* @param {Number} max Array length
|
||||||
|
* @returns {Number} shiftedIndex
|
||||||
|
*/
|
||||||
|
function getLookupIndex(i, base, max) {
|
||||||
|
i += base;
|
||||||
|
|
||||||
|
if (i >= max)
|
||||||
|
i -= max;
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
function Whitespace(tokens, comments) {
|
function Whitespace(tokens, comments) {
|
||||||
this.tokens = _.sortBy(tokens.concat(comments), "start");
|
this.tokens = _.sortBy(tokens.concat(comments), "start");
|
||||||
this.used = [];
|
this.used = {};
|
||||||
|
|
||||||
|
// Profiling this code shows that while generator passes over it, indexes
|
||||||
|
// returned by `getNewlinesBefore` and `getNewlinesAfter` are always increasing.
|
||||||
|
|
||||||
|
// We use this implementation detail for an optimization: instead of always
|
||||||
|
// starting to look from `this.tokens[0]`, we will start `for` loops from the
|
||||||
|
// previous successful match. We will enumerate all tokens—but the common
|
||||||
|
// case will be much faster.
|
||||||
|
|
||||||
|
this._lastFoundIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Whitespace.prototype.getNewlinesBefore = function (node) {
|
Whitespace.prototype.getNewlinesBefore = function (node) {
|
||||||
var startToken;
|
var startToken;
|
||||||
var endToken;
|
var endToken;
|
||||||
var tokens = this.tokens;
|
var tokens = this.tokens;
|
||||||
|
var token;
|
||||||
|
|
||||||
|
for (var j = 0; j < tokens.length; j++) {
|
||||||
|
// optimize for forward traversal by shifting for loop index
|
||||||
|
var i = getLookupIndex(j, this._lastFoundIndex, this.tokens.length);
|
||||||
|
token = tokens[i];
|
||||||
|
|
||||||
_.each(tokens, function (token, i) {
|
|
||||||
// this is the token this node starts with
|
// this is the token this node starts with
|
||||||
if (node.start === token.start) {
|
if (node.start === token.start) {
|
||||||
startToken = tokens[i - 1];
|
startToken = tokens[i - 1];
|
||||||
endToken = token;
|
endToken = token;
|
||||||
return false;
|
|
||||||
|
this._lastFoundIndex = i;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
return this.getNewlinesBetween(startToken, endToken);
|
return this.getNewlinesBetween(startToken, endToken);
|
||||||
};
|
};
|
||||||
@@ -28,32 +65,44 @@ Whitespace.prototype.getNewlinesAfter = function (node) {
|
|||||||
var startToken;
|
var startToken;
|
||||||
var endToken;
|
var endToken;
|
||||||
var tokens = this.tokens;
|
var tokens = this.tokens;
|
||||||
|
var token;
|
||||||
|
|
||||||
|
for (var j = 0; j < tokens.length; j++) {
|
||||||
|
// optimize for forward traversal by shifting for loop index
|
||||||
|
var i = getLookupIndex(j, this._lastFoundIndex, this.tokens.length);
|
||||||
|
token = tokens[i];
|
||||||
|
|
||||||
_.each(tokens, function (token, i) {
|
|
||||||
// this is the token this node ends with
|
// this is the token this node ends with
|
||||||
if (node.end === token.end) {
|
if (node.end === token.end) {
|
||||||
startToken = token;
|
startToken = token;
|
||||||
endToken = tokens[i + 1];
|
endToken = tokens[i + 1];
|
||||||
return false;
|
|
||||||
|
this._lastFoundIndex = i;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
if (endToken.type.type === "eof") {
|
if (endToken.type.type === "eof") {
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
return this.getNewlinesBetween(startToken, endToken);
|
var lines = this.getNewlinesBetween(startToken, endToken);
|
||||||
|
if (node.type === "Line" && !lines) {
|
||||||
|
// line comment
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Whitespace.prototype.getNewlinesBetween = function (startToken, endToken) {
|
Whitespace.prototype.getNewlinesBetween = function (startToken, endToken) {
|
||||||
var start = startToken ? startToken.loc.end.line : 1;
|
var start = startToken ? startToken.loc.end.line : 1;
|
||||||
var end = endToken.loc.start.line;
|
var end = endToken.loc.start.line;
|
||||||
|
|
||||||
var lines = 0;
|
var lines = 0;
|
||||||
|
|
||||||
for (var line = start; line < end; line++) {
|
for (var line = start; line < end; line++) {
|
||||||
if (!_.contains(this.used, line)) {
|
if (typeof this.used[line] === 'undefined') {
|
||||||
this.used.push(line);
|
this.used[line] = true;
|
||||||
lines++;
|
lines++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
var transform = require("./transformation/transform");
|
var transform = require("./transformation/transform");
|
||||||
var util = require("./util");
|
var util = require("./util");
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var _ = require("lodash");
|
var _ = require("lodash");
|
||||||
|
|
||||||
|
exports.version = require("../../package").version;
|
||||||
|
|
||||||
exports.types = require("./types");
|
exports.types = require("./types");
|
||||||
|
|
||||||
exports.runtime = require("./runtime-generator");
|
exports.runtime = require("./runtime-generator");
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
var t = require("./types");
|
var t = require("./types");
|
||||||
var _ = require("lodash");
|
var _ = require("lodash");
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,4 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
require("core-js/shim");
|
require("core-js/shim");
|
||||||
require("regenerator/runtime");
|
require("regenerator/runtime");
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
// Required to safely use 6to5/register within a browserify codebase.
|
"use strict";
|
||||||
|
|
||||||
|
// required to safely use 6to5/register within a browserify codebase
|
||||||
|
|
||||||
module.exports = function () {};
|
module.exports = function () {};
|
||||||
|
|
||||||
require("./polyfill");
|
require("./polyfill");
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
require("./polyfill");
|
require("./polyfill");
|
||||||
|
|
||||||
var sourceMapSupport = require("source-map-support");
|
var sourceMapSupport = require("source-map-support");
|
||||||
@@ -21,51 +23,6 @@ sourceMapSupport.install({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
var blacklist = [];
|
|
||||||
|
|
||||||
var blacklistTest = function (transformer, code) {
|
|
||||||
try {
|
|
||||||
if (_.isFunction(code)) {
|
|
||||||
code();
|
|
||||||
} else {
|
|
||||||
new Function(code);
|
|
||||||
}
|
|
||||||
blacklist.push(transformer);
|
|
||||||
} catch (err) {
|
|
||||||
if (err.name !== "SyntaxError") throw err;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
blacklistTest("arrayComprehension", "var foo = [for (foo of bar) foo * foo];");
|
|
||||||
blacklistTest("generatorComprehension", "var foo = (for (foo of bar) foo * foo)");
|
|
||||||
blacklistTest("arrowFunctions", "var foo = x => x * x;");
|
|
||||||
blacklistTest("classes", "class Foo {}");
|
|
||||||
blacklistTest("computedPropertyNames", "var foo = { [foo]: bar };");
|
|
||||||
blacklistTest("constants", function () {
|
|
||||||
try {
|
|
||||||
new Function("const foo = 'foo';\nfoo = 'wow';");
|
|
||||||
} catch (err) {
|
|
||||||
return; // constants are supported
|
|
||||||
}
|
|
||||||
throw new SyntaxError;
|
|
||||||
});
|
|
||||||
blacklistTest("defaultParamaters", "var foo = function (bar = 0) {};");
|
|
||||||
blacklistTest("destructuring", "var { x, y } = { x: 0, y: 0 };");
|
|
||||||
blacklistTest("forOf", "for (var foo of bar) {}");
|
|
||||||
blacklistTest("generators", "function* foo() {}\nasync function bar() {}"); // generators/async functions delegated to same transformer
|
|
||||||
blacklistTest("letScoping", "let foo = 0;");
|
|
||||||
blacklistTest("modules", 'import foo from "from";');
|
|
||||||
blacklistTest("propertyMethodAssignment", "{ get foo() {} }");
|
|
||||||
blacklistTest("propertyNameShorthand", "var foo = { x, y };");
|
|
||||||
blacklistTest("restParameters", "function foo(...bar) {}");
|
|
||||||
blacklistTest("spread", "foo(...bar);");
|
|
||||||
blacklistTest("templateLiterals", "var foo = `foo`;");
|
|
||||||
blacklistTest("unicodeRegex", function () { new RegExp("foo", "u"); });
|
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
var transformOpts = {};
|
var transformOpts = {};
|
||||||
var ignoreRegex = /node_modules/;
|
var ignoreRegex = /node_modules/;
|
||||||
var onlyRegex;
|
var onlyRegex;
|
||||||
@@ -95,7 +52,6 @@ var loader = function (m, filename) {
|
|||||||
|
|
||||||
result = result || to5.transformFileSync(filename, _.extend({
|
result = result || to5.transformFileSync(filename, _.extend({
|
||||||
whitelist: whitelist,
|
whitelist: whitelist,
|
||||||
blacklist: blacklist,
|
|
||||||
sourceMap: true,
|
sourceMap: true,
|
||||||
ast: false
|
ast: false
|
||||||
}, transformOpts));
|
}, transformOpts));
|
||||||
@@ -123,7 +79,7 @@ var hookExtensions = function (_exts) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
hookExtensions([".es6", ".es", ".js"]);
|
hookExtensions(util.canCompile.EXTENSIONS);
|
||||||
|
|
||||||
module.exports = function (opts) {
|
module.exports = function (opts) {
|
||||||
// normalise options
|
// normalise options
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
var generator = require("./generation/generator");
|
var generator = require("./generation/generator");
|
||||||
var util = require("./util");
|
var util = require("./util");
|
||||||
var File = require("./file");
|
var File = require("./file");
|
||||||
@@ -20,7 +22,7 @@ module.exports = function (namespace) {
|
|||||||
|
|
||||||
_.each(File.helpers, function (name) {
|
_.each(File.helpers, function (name) {
|
||||||
if (_.contains(File.excludeHelpersFromRuntime, name)) {
|
if (_.contains(File.excludeHelpersFromRuntime, name)) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var key = t.identifier(t.toIdentifier(name));
|
var key = t.identifier(t.toIdentifier(name));
|
||||||
|
|||||||
17
lib/6to5/to-fast-properties.js
Normal file
17
lib/6to5/to-fast-properties.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A trick from Bluebird to force V8 to use fast properties for an object.
|
||||||
|
* Read more: http://stackoverflow.com/questions/24987896/
|
||||||
|
*
|
||||||
|
* Use %HasFastProperties(obj) and --allow-natives-syntax to check whether
|
||||||
|
* a particular object already has fast properties.
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports = function toFastProperties(obj) {
|
||||||
|
/*jshint -W027*/
|
||||||
|
function f() {}
|
||||||
|
f.prototype = obj;
|
||||||
|
return f;
|
||||||
|
eval(obj);
|
||||||
|
};
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
var explode = require("./explode-assignable-expression");
|
||||||
|
var t = require("../../types");
|
||||||
|
|
||||||
|
module.exports = function (exports, opts) {
|
||||||
|
var isAssignment = function (node) {
|
||||||
|
return node.operator === opts.operator + "=";
|
||||||
|
};
|
||||||
|
|
||||||
|
var buildAssignment = function (left, right) {
|
||||||
|
return t.assignmentExpression("=", left, right);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.ExpressionStatement = function (node, parent, scope, context, file) {
|
||||||
|
var expr = node.expression;
|
||||||
|
if (!isAssignment(expr)) return;
|
||||||
|
|
||||||
|
var nodes = [];
|
||||||
|
var exploded = explode(expr.left, nodes, file, scope, true);
|
||||||
|
|
||||||
|
nodes.push(t.expressionStatement(
|
||||||
|
buildAssignment(exploded.ref, opts.build(exploded.uid, expr.right))
|
||||||
|
));
|
||||||
|
|
||||||
|
return nodes;
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.AssignmentExpression = function (node, parent, scope, context, file) {
|
||||||
|
if (t.isExpressionStatement(parent)) return;
|
||||||
|
if (!isAssignment(node)) return;
|
||||||
|
|
||||||
|
var nodes = [];
|
||||||
|
var exploded = explode(node.left, nodes, file, scope);
|
||||||
|
nodes.push(opts.build(exploded.uid, node.right));
|
||||||
|
nodes.push(exploded.ref);
|
||||||
|
|
||||||
|
return t.toSequenceExpression(nodes, scope);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.BinaryExpression = function (node) {
|
||||||
|
if (node.operator !== opts.operator) return;
|
||||||
|
return opts.build(node.left, node.right);
|
||||||
|
};
|
||||||
|
};
|
||||||
25
lib/6to5/transformation/helpers/build-comprehension.js
Normal file
25
lib/6to5/transformation/helpers/build-comprehension.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
var t = require("../../types");
|
||||||
|
|
||||||
|
module.exports = function build(node, buildBody) {
|
||||||
|
var self = node.blocks.shift();
|
||||||
|
if (!self) return;
|
||||||
|
|
||||||
|
var child = build(node, buildBody);
|
||||||
|
if (!child) {
|
||||||
|
// last item
|
||||||
|
child = buildBody();
|
||||||
|
|
||||||
|
// add a filter as this is our final stop
|
||||||
|
if (node.filter) {
|
||||||
|
child = t.ifStatement(node.filter, t.blockStatement([child]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.forOfStatement(
|
||||||
|
t.variableDeclaration("let", [t.variableDeclarator(self.left)]),
|
||||||
|
self.right,
|
||||||
|
t.blockStatement([child])
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
var explode = require("./explode-assignable-expression");
|
||||||
|
var t = require("../../types");
|
||||||
|
|
||||||
|
module.exports = function (exports, opts) {
|
||||||
|
var buildAssignment = function (left, right) {
|
||||||
|
return t.assignmentExpression("=", left, right);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.ExpressionStatement = function (node, parent, scope, context, file) {
|
||||||
|
var expr = node.expression;
|
||||||
|
if (!opts.is(expr, file)) return;
|
||||||
|
|
||||||
|
var nodes = [];
|
||||||
|
|
||||||
|
var exploded = explode(expr.left, nodes, file, scope);
|
||||||
|
|
||||||
|
nodes.push(t.ifStatement(
|
||||||
|
opts.build(exploded.uid, file),
|
||||||
|
t.expressionStatement(buildAssignment(exploded.ref, expr.right))
|
||||||
|
));
|
||||||
|
|
||||||
|
return nodes;
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.AssignmentExpression = function (node, parent, scope, context, file) {
|
||||||
|
if (t.isExpressionStatement(parent)) return;
|
||||||
|
if (!opts.is(node, file)) return;
|
||||||
|
|
||||||
|
var nodes = [];
|
||||||
|
var exploded = explode(node.left, nodes, file, scope);
|
||||||
|
|
||||||
|
nodes.push(t.logicalExpression(
|
||||||
|
"&&",
|
||||||
|
opts.build(exploded.uid, file),
|
||||||
|
buildAssignment(exploded.ref, node.right)
|
||||||
|
));
|
||||||
|
|
||||||
|
// todo: duplicate expression node
|
||||||
|
nodes.push(exploded.ref);
|
||||||
|
|
||||||
|
return t.toSequenceExpression(nodes, scope);
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
var t = require("../../types");
|
||||||
|
|
||||||
|
var getObjRef = function (node, nodes, file, scope) {
|
||||||
|
var ref;
|
||||||
|
if (t.isIdentifier(node)) {
|
||||||
|
ref = node;
|
||||||
|
} else if (t.isMemberExpression(node)) {
|
||||||
|
ref = node.object;
|
||||||
|
} else {
|
||||||
|
throw new Error("We can't explode this node type " + node.type);
|
||||||
|
}
|
||||||
|
|
||||||
|
var temp = scope.generateUidBasedOnNode(ref, file);
|
||||||
|
nodes.push(t.variableDeclaration("var", [
|
||||||
|
t.variableDeclarator(temp, ref)
|
||||||
|
]));
|
||||||
|
return temp;
|
||||||
|
};
|
||||||
|
|
||||||
|
var getPropRef = function (node, nodes, file, scope) {
|
||||||
|
var prop = node.property;
|
||||||
|
var key = t.toComputedKey(node, prop);
|
||||||
|
if (t.isLiteral(key)) return key;
|
||||||
|
|
||||||
|
var temp = scope.generateUidBasedOnNode(prop, file);
|
||||||
|
nodes.push(t.variableDeclaration("var", [
|
||||||
|
t.variableDeclarator(temp, prop)
|
||||||
|
]));
|
||||||
|
return temp;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = function (node, nodes, file, scope, allowedSingleIdent) {
|
||||||
|
var obj;
|
||||||
|
if (t.isIdentifier(node) && allowedSingleIdent) {
|
||||||
|
obj = node;
|
||||||
|
} else {
|
||||||
|
obj = getObjRef(node, nodes, file, scope);
|
||||||
|
}
|
||||||
|
|
||||||
|
var ref, uid;
|
||||||
|
|
||||||
|
if (t.isIdentifier(node)) {
|
||||||
|
ref = node;
|
||||||
|
uid = obj;
|
||||||
|
} else {
|
||||||
|
var prop = getPropRef(node, nodes, file, scope);
|
||||||
|
var computed = node.computed || t.isLiteral(prop);
|
||||||
|
uid = ref = t.memberExpression(obj, prop, computed);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
uid: uid,
|
||||||
|
ref: ref
|
||||||
|
};
|
||||||
|
};
|
||||||
50
lib/6to5/transformation/helpers/name-method.js
Normal file
50
lib/6to5/transformation/helpers/name-method.js
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
var traverse = require("../../traverse");
|
||||||
|
var util = require("../../util");
|
||||||
|
var t = require("../../types");
|
||||||
|
|
||||||
|
var traverser = {
|
||||||
|
enter: function (node, parent, scope, context, state) {
|
||||||
|
// check if this node is an identifier that matches the same as our function id
|
||||||
|
if (!t.isIdentifier(node, { name: state.id })) return;
|
||||||
|
|
||||||
|
// check if this node is the one referenced
|
||||||
|
if (!t.isReferenced(node, parent)) return;
|
||||||
|
|
||||||
|
// check that we don't have a local variable declared as that removes the need
|
||||||
|
// for the wrapper
|
||||||
|
var localDeclar = scope.get(state.id, true);
|
||||||
|
if (localDeclar !== state.outerDeclar) return;
|
||||||
|
|
||||||
|
state.selfReference = true;
|
||||||
|
context.stop();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.property = function (node, file, scope) {
|
||||||
|
var key = t.toComputedKey(node, node.key);
|
||||||
|
if (!t.isLiteral(key)) return node; // we can't set a function id with this
|
||||||
|
|
||||||
|
var id = t.toIdentifier(key.value);
|
||||||
|
key = t.identifier(id);
|
||||||
|
|
||||||
|
var state = {
|
||||||
|
id: id,
|
||||||
|
selfReference: false,
|
||||||
|
outerDeclar: scope.get(id, true),
|
||||||
|
};
|
||||||
|
|
||||||
|
traverse(node, traverser, scope, state);
|
||||||
|
|
||||||
|
if (state.selfReference) {
|
||||||
|
node.value = util.template("property-method-assignment-wrapper", {
|
||||||
|
FUNCTION: node.value,
|
||||||
|
FUNCTION_ID: key,
|
||||||
|
FUNCTION_KEY: file.generateUidIdentifier(id, scope),
|
||||||
|
WRAPPER_KEY: file.generateUidIdentifier(id + "Wrapper", scope)
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
node.value.id = key;
|
||||||
|
}
|
||||||
|
};
|
||||||
31
lib/6to5/transformation/helpers/remap-async-to-generator.js
Normal file
31
lib/6to5/transformation/helpers/remap-async-to-generator.js
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
var traverse = require("../../traverse");
|
||||||
|
var t = require("../../types");
|
||||||
|
|
||||||
|
module.exports = function (node, callId) {
|
||||||
|
node.async = false;
|
||||||
|
node.generator = true;
|
||||||
|
|
||||||
|
traverse(node, {
|
||||||
|
enter: function (node, parent, scope, context) {
|
||||||
|
if (t.isFunction(node)) context.skip();
|
||||||
|
|
||||||
|
if (t.isAwaitExpression(node)) {
|
||||||
|
node.type = "YieldExpression";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var call = t.callExpression(callId, [node]);
|
||||||
|
|
||||||
|
if (t.isFunctionDeclaration(node)) {
|
||||||
|
var declar = t.variableDeclaration("var", [
|
||||||
|
t.variableDeclarator(node.id, call)
|
||||||
|
]);
|
||||||
|
declar._blockHoist = true;
|
||||||
|
return declar;
|
||||||
|
} else {
|
||||||
|
return call;
|
||||||
|
}
|
||||||
|
};
|
||||||
246
lib/6to5/transformation/helpers/replace-supers.js
Normal file
246
lib/6to5/transformation/helpers/replace-supers.js
Normal file
@@ -0,0 +1,246 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
module.exports = ReplaceSupers;
|
||||||
|
|
||||||
|
var traverse = require("../../traverse");
|
||||||
|
var t = require("../../types");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description
|
||||||
|
*
|
||||||
|
* @param {Object} methodNode
|
||||||
|
* @param {Object} className
|
||||||
|
* @param {Object} superName
|
||||||
|
* @param {Boolean} isLoose
|
||||||
|
* @param {File} file
|
||||||
|
*/
|
||||||
|
|
||||||
|
function ReplaceSupers(methodNode, className, superName, isLoose, file) {
|
||||||
|
this.topLevelThisReference = null;
|
||||||
|
this.methodNode = methodNode;
|
||||||
|
this.className = className;
|
||||||
|
this.superName = superName;
|
||||||
|
this.isLoose = isLoose;
|
||||||
|
this.file = file;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a node representing the super class value of the named property.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
*
|
||||||
|
* _get(Object.getPrototypeOf(CLASS.prototype), "METHOD", this)
|
||||||
|
*
|
||||||
|
* @param {Node} property
|
||||||
|
* @param {boolean} isStatic
|
||||||
|
* @param {boolean} isComputed
|
||||||
|
*
|
||||||
|
* @returns {Node}
|
||||||
|
*/
|
||||||
|
|
||||||
|
ReplaceSupers.prototype.superProperty = function (property, isStatic, isComputed, thisExpression) {
|
||||||
|
return t.callExpression(
|
||||||
|
this.file.addHelper("get"),
|
||||||
|
[
|
||||||
|
t.callExpression(
|
||||||
|
t.memberExpression(t.identifier("Object"), t.identifier("getPrototypeOf")),
|
||||||
|
[
|
||||||
|
isStatic ? this.className : t.memberExpression(this.className, t.identifier("prototype"))
|
||||||
|
]
|
||||||
|
),
|
||||||
|
isComputed ? property : t.literal(property.name),
|
||||||
|
thisExpression
|
||||||
|
]
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description
|
||||||
|
*
|
||||||
|
* @param {Object} node
|
||||||
|
* @param {Object} id
|
||||||
|
* @param {Object} parent
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
|
|
||||||
|
ReplaceSupers.prototype.looseSuperProperty = function (methodNode, id, parent) {
|
||||||
|
var methodName = methodNode.key;
|
||||||
|
var superName = this.superName || t.identifier("Function");
|
||||||
|
|
||||||
|
if (parent.property === id) {
|
||||||
|
return;
|
||||||
|
} else if (t.isCallExpression(parent, { callee: id })) {
|
||||||
|
// super(); -> ClassName.prototype.MethodName.call(this);
|
||||||
|
parent.arguments.unshift(t.thisExpression());
|
||||||
|
|
||||||
|
if (methodName.name === "constructor") {
|
||||||
|
// constructor() { super(); }
|
||||||
|
return t.memberExpression(superName, t.identifier("call"));
|
||||||
|
} else {
|
||||||
|
id = superName;
|
||||||
|
|
||||||
|
// foo() { super(); }
|
||||||
|
if (!methodNode.static) {
|
||||||
|
id = t.memberExpression(id, t.identifier("prototype"));
|
||||||
|
}
|
||||||
|
|
||||||
|
id = t.memberExpression(id, methodName, methodNode.computed);
|
||||||
|
return t.memberExpression(id, t.identifier("call"));
|
||||||
|
}
|
||||||
|
} else if (t.isMemberExpression(parent) && !methodNode.static) {
|
||||||
|
// super.test -> ClassName.prototype.test
|
||||||
|
return t.memberExpression(superName, t.identifier("prototype"));
|
||||||
|
} else {
|
||||||
|
return superName;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description
|
||||||
|
*/
|
||||||
|
|
||||||
|
ReplaceSupers.prototype.replace = function () {
|
||||||
|
this.traverseLevel(this.methodNode.value, true);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description
|
||||||
|
*
|
||||||
|
* @param {Object} node
|
||||||
|
* @param {Boolean} topLevel
|
||||||
|
*/
|
||||||
|
|
||||||
|
ReplaceSupers.prototype.traverseLevel = function (node, topLevel) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
traverse(node, {
|
||||||
|
enter: function (node, parent, scope, context) {
|
||||||
|
if (t.isFunction(node) && !t.isArrowFunctionExpression(node)) {
|
||||||
|
// we need to call traverseLevel again so we're context aware
|
||||||
|
self.traverseLevel(node, false);
|
||||||
|
return context.skip();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (t.isProperty(node, { method: true }) || t.isMethodDefinition(node)) {
|
||||||
|
// break on object methods
|
||||||
|
return context.skip();
|
||||||
|
}
|
||||||
|
|
||||||
|
var getThisReference = function () {
|
||||||
|
if (topLevel) {
|
||||||
|
// top level so `this` is the instance
|
||||||
|
return t.thisExpression();
|
||||||
|
} else {
|
||||||
|
// not in the top level so we need to create a reference
|
||||||
|
return self.getThisReference();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var callback = self.specHandle;
|
||||||
|
if (self.isLoose) callback = self.looseHandle;
|
||||||
|
return callback.call(self, getThisReference, node, parent);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description
|
||||||
|
*/
|
||||||
|
|
||||||
|
ReplaceSupers.prototype.getThisReference = function () {
|
||||||
|
if (this.topLevelThisReference) {
|
||||||
|
return this.topLevelThisReference;
|
||||||
|
} else {
|
||||||
|
var ref = this.topLevelThisReference = this.file.generateUidIdentifier("this");
|
||||||
|
this.methodNode.value.body.body.unshift(t.variableDeclaration("var", [
|
||||||
|
t.variableDeclarator(this.topLevelThisReference, t.thisExpression())
|
||||||
|
]));
|
||||||
|
return ref;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description
|
||||||
|
*
|
||||||
|
* @param {Function} getThisReference
|
||||||
|
* @param {Object} node
|
||||||
|
* @param {Object} parent
|
||||||
|
*/
|
||||||
|
|
||||||
|
ReplaceSupers.prototype.looseHandle = function (getThisReference, node, parent) {
|
||||||
|
if (t.isIdentifier(node, { name: "super" })) {
|
||||||
|
return this.looseSuperProperty(this.methodNode, node, parent);
|
||||||
|
} else if (t.isCallExpression(node)) {
|
||||||
|
var callee = node.callee;
|
||||||
|
if (!t.isMemberExpression(callee)) return;
|
||||||
|
if (callee.object.name !== "super") return;
|
||||||
|
|
||||||
|
// super.test(); -> ClassName.prototype.MethodName.call(this);
|
||||||
|
t.appendToMemberExpression(callee, t.identifier("call"));
|
||||||
|
node.arguments.unshift(getThisReference());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description
|
||||||
|
*
|
||||||
|
* @param {Function} getThisReference
|
||||||
|
* @param {Object} node
|
||||||
|
* @param {Object} parent
|
||||||
|
*/
|
||||||
|
|
||||||
|
ReplaceSupers.prototype.specHandle = function (getThisReference, node, parent) {
|
||||||
|
var methodNode = this.methodNode;
|
||||||
|
var property;
|
||||||
|
var computed;
|
||||||
|
var args;
|
||||||
|
|
||||||
|
if (t.isIdentifier(node, { name: "super" })) {
|
||||||
|
if (!(t.isMemberExpression(parent) && !parent.computed && parent.property === node)) {
|
||||||
|
throw this.file.errorWithNode(node, "illegal use of bare super");
|
||||||
|
}
|
||||||
|
} else if (t.isCallExpression(node)) {
|
||||||
|
var callee = node.callee;
|
||||||
|
if (t.isIdentifier(callee, { name: "super" })) {
|
||||||
|
// super(); -> _get(Object.getPrototypeOf(ClassName), "MethodName", this).call(this);
|
||||||
|
property = methodNode.key;
|
||||||
|
computed = methodNode.computed;
|
||||||
|
args = node.arguments;
|
||||||
|
} else {
|
||||||
|
if (!t.isMemberExpression(callee)) return;
|
||||||
|
if (callee.object.name !== "super") return;
|
||||||
|
|
||||||
|
// super.test(); -> _get(Object.getPrototypeOf(ClassName.prototype), "test", this).call(this);
|
||||||
|
property = callee.property;
|
||||||
|
computed = callee.computed;
|
||||||
|
args = node.arguments;
|
||||||
|
}
|
||||||
|
} else if (t.isMemberExpression(node)) {
|
||||||
|
if (!t.isIdentifier(node.object, { name: "super" })) return;
|
||||||
|
|
||||||
|
// super.name; -> _get(Object.getPrototypeOf(ClassName.prototype), "name", this);
|
||||||
|
property = node.property;
|
||||||
|
computed = node.computed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!property) return;
|
||||||
|
|
||||||
|
var thisReference = getThisReference();
|
||||||
|
var superProperty = this.superProperty(property, methodNode.static, computed, thisReference);
|
||||||
|
if (args) {
|
||||||
|
if (args.length === 1 && t.isSpreadElement(args[0])) {
|
||||||
|
// super(...arguments);
|
||||||
|
return t.callExpression(
|
||||||
|
t.memberExpression(superProperty, t.identifier("apply")),
|
||||||
|
[thisReference, args[0].argument]
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return t.callExpression(
|
||||||
|
t.memberExpression(superProperty, t.identifier("call")),
|
||||||
|
[thisReference].concat(args)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return superProperty;
|
||||||
|
}
|
||||||
|
};
|
||||||
21
lib/6to5/transformation/helpers/use-strict.js
Normal file
21
lib/6to5/transformation/helpers/use-strict.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
var t = require("../../types");
|
||||||
|
|
||||||
|
exports.has = function (node) {
|
||||||
|
var first = node.body[0];
|
||||||
|
return t.isExpressionStatement(first) && t.isLiteral(first.expression, { value: "use strict" });
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.wrap = function (node, callback) {
|
||||||
|
var useStrictNode;
|
||||||
|
if (exports.has(node)) {
|
||||||
|
useStrictNode = node.body.shift();
|
||||||
|
}
|
||||||
|
|
||||||
|
callback();
|
||||||
|
|
||||||
|
if (useStrictNode) {
|
||||||
|
node.body.unshift(useStrictNode);
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
module.exports = DefaultFormatter;
|
module.exports = DefaultFormatter;
|
||||||
|
|
||||||
var traverse = require("../../traverse");
|
var traverse = require("../../traverse");
|
||||||
@@ -9,24 +11,77 @@ function DefaultFormatter(file) {
|
|||||||
this.file = file;
|
this.file = file;
|
||||||
|
|
||||||
this.localExports = this.getLocalExports();
|
this.localExports = this.getLocalExports();
|
||||||
|
this.localImports = this.getLocalImports();
|
||||||
|
|
||||||
this.remapAssignments();
|
this.remapAssignments();
|
||||||
|
|
||||||
|
//this.checkCollisions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var exportsTraverser = {
|
||||||
|
enter: function (node, parent, scope, context, localExports) {
|
||||||
|
var declar = node && node.declaration;
|
||||||
|
if (t.isExportDeclaration(node) && declar && t.isStatement(declar)) {
|
||||||
|
_.extend(localExports, t.getIds(declar, true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
DefaultFormatter.prototype.getLocalExports = function () {
|
DefaultFormatter.prototype.getLocalExports = function () {
|
||||||
var localExports = {};
|
var localExports = {};
|
||||||
|
traverse(this.file.ast, exportsTraverser, null, localExports);
|
||||||
traverse(this.file.ast, {
|
|
||||||
enter: function (node) {
|
|
||||||
var declar = node && node.declaration;
|
|
||||||
if (t.isExportDeclaration(node) && declar && t.isStatement(declar)) {
|
|
||||||
_.extend(localExports, t.getIds(declar, true));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return localExports;
|
return localExports;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var importsTraverser = {
|
||||||
|
enter: function (node, parent, scope, context, localImports) {
|
||||||
|
if (t.isImportDeclaration(node)) {
|
||||||
|
_.extend(localImports, t.getIds(node, true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
DefaultFormatter.prototype.getLocalImports = function () {
|
||||||
|
var localImports = {};
|
||||||
|
traverse(this.file.ast, importsTraverser, null, localImports);
|
||||||
|
return localImports;
|
||||||
|
};
|
||||||
|
|
||||||
|
var collissionsTraverser = {
|
||||||
|
enter: function (node, parent, scope, context, check) {
|
||||||
|
if (t.isAssignmentExpression(node)) {
|
||||||
|
|
||||||
|
var left = node.left;
|
||||||
|
if (t.isMemberExpression(left)) {
|
||||||
|
while (left.object) left = left.object;
|
||||||
|
}
|
||||||
|
|
||||||
|
check(left);
|
||||||
|
} else if (t.isDeclaration(node)) {
|
||||||
|
_.each(t.getIds(node, true), check);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
DefaultFormatter.prototype.checkCollisions = function () {
|
||||||
|
// todo: all check export collissions
|
||||||
|
|
||||||
|
var localImports = this.localImports;
|
||||||
|
var file = this.file;
|
||||||
|
|
||||||
|
var isLocalReference = function (node) {
|
||||||
|
return t.isIdentifier(node) && _.has(localImports, node.name) && localImports[node.name] !== node;
|
||||||
|
};
|
||||||
|
|
||||||
|
var check = function (node) {
|
||||||
|
if (isLocalReference(node)) {
|
||||||
|
throw file.errorWithNode(node, "Illegal assignment of module import");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
traverse(file.ast, collissionsTraverser, null, check);
|
||||||
|
};
|
||||||
|
|
||||||
DefaultFormatter.prototype.remapExportAssignment = function (node) {
|
DefaultFormatter.prototype.remapExportAssignment = function (node) {
|
||||||
return t.assignmentExpression(
|
return t.assignmentExpression(
|
||||||
"=",
|
"=",
|
||||||
@@ -49,9 +104,9 @@ DefaultFormatter.prototype.remapAssignments = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
traverse(this.file.ast, {
|
traverse(this.file.ast, {
|
||||||
enter: function (node, parent, scope) {
|
enter: function (node, parent, scope, context, isLocalReference) {
|
||||||
if (t.isUpdateExpression(node) && isLocalReference(node.argument, scope)) {
|
if (t.isUpdateExpression(node) && isLocalReference(node.argument, scope)) {
|
||||||
this.skip();
|
context.skip();
|
||||||
|
|
||||||
// expand to long file assignment expression
|
// expand to long file assignment expression
|
||||||
var assign = t.assignmentExpression(node.operator[0] + "=", node.argument, t.literal(1));
|
var assign = t.assignmentExpression(node.operator[0] + "=", node.argument, t.literal(1));
|
||||||
@@ -79,11 +134,11 @@ DefaultFormatter.prototype.remapAssignments = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (t.isAssignmentExpression(node) && isLocalReference(node.left, scope)) {
|
if (t.isAssignmentExpression(node) && isLocalReference(node.left, scope)) {
|
||||||
this.skip();
|
context.skip();
|
||||||
return self.remapExportAssignment(node);
|
return self.remapExportAssignment(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}, null, isLocalReference);
|
||||||
};
|
};
|
||||||
|
|
||||||
DefaultFormatter.prototype.getModuleName = function () {
|
DefaultFormatter.prototype.getModuleName = function () {
|
||||||
@@ -105,11 +160,16 @@ DefaultFormatter.prototype.getModuleName = function () {
|
|||||||
filenameRelative = filenameRelative.replace(sourceRootRegEx, "");
|
filenameRelative = filenameRelative.replace(sourceRootRegEx, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove extension
|
if (!opts.keepModuleIdExtensions) {
|
||||||
filenameRelative = filenameRelative.replace(/\.(.*?)$/, "");
|
// remove extension
|
||||||
|
filenameRelative = filenameRelative.replace(/\.(.*?)$/, "");
|
||||||
|
}
|
||||||
|
|
||||||
moduleName += filenameRelative;
|
moduleName += filenameRelative;
|
||||||
|
|
||||||
|
// normalise path separators
|
||||||
|
moduleName = moduleName.replace(/\\/g, "/");
|
||||||
|
|
||||||
return moduleName;
|
return moduleName;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -142,10 +202,11 @@ DefaultFormatter.prototype._exportSpecifier = function (getRef, specifier, node,
|
|||||||
nodes.push(this._exportsWildcard(getRef(), node));
|
nodes.push(this._exportsWildcard(getRef(), node));
|
||||||
} else {
|
} else {
|
||||||
var ref;
|
var ref;
|
||||||
if (t.isSpecifierDefault(specifier.id) || this.noInteropRequire) {
|
if (t.isSpecifierDefault(specifier) && !this.noInteropRequire) {
|
||||||
ref = t.memberExpression(getRef(), specifier.id);
|
// importing a default so we need to normalise it
|
||||||
} else {
|
|
||||||
ref = t.callExpression(this.file.addHelper("interop-require"), [getRef()]);
|
ref = t.callExpression(this.file.addHelper("interop-require"), [getRef()]);
|
||||||
|
} else {
|
||||||
|
ref = t.memberExpression(getRef(), specifier.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// export { foo } from "test";
|
// export { foo } from "test";
|
||||||
@@ -162,7 +223,8 @@ DefaultFormatter.prototype._exportSpecifier = function (getRef, specifier, node,
|
|||||||
};
|
};
|
||||||
|
|
||||||
DefaultFormatter.prototype._exportsWildcard = function (objectIdentifier) {
|
DefaultFormatter.prototype._exportsWildcard = function (objectIdentifier) {
|
||||||
return t.expressionStatement(t.callExpression(this.file.addHelper("exports-wildcard"), [
|
return t.expressionStatement(t.callExpression(this.file.addHelper("defaults"), [
|
||||||
|
t.identifier("exports"),
|
||||||
t.callExpression(this.file.addHelper("interop-require-wildcard"), [objectIdentifier])
|
t.callExpression(this.file.addHelper("interop-require-wildcard"), [objectIdentifier])
|
||||||
]));
|
]));
|
||||||
};
|
};
|
||||||
@@ -186,13 +248,13 @@ DefaultFormatter.prototype.exportDeclaration = function (node, nodes) {
|
|||||||
var assign;
|
var assign;
|
||||||
|
|
||||||
if (t.isVariableDeclaration(declar)) {
|
if (t.isVariableDeclaration(declar)) {
|
||||||
for (var i in declar.declarations) {
|
for (var i = 0; i < declar.declarations.length; i++) {
|
||||||
var decl = declar.declarations[i];
|
var decl = declar.declarations[i];
|
||||||
|
|
||||||
decl.init = this._exportsAssign(decl.id, decl.init, node).expression;
|
decl.init = this._exportsAssign(decl.id, decl.init, node).expression;
|
||||||
|
|
||||||
var newDeclar = t.variableDeclaration(declar.kind, [decl]);
|
var newDeclar = t.variableDeclaration(declar.kind, [decl]);
|
||||||
if (i === "0") t.inherits(newDeclar, declar);
|
if (i === 0) t.inherits(newDeclar, declar);
|
||||||
nodes.push(newDeclar);
|
nodes.push(newDeclar);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
14
lib/6to5/transformation/modules/_strict.js
Normal file
14
lib/6to5/transformation/modules/_strict.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
var util = require("../../util");
|
||||||
|
|
||||||
|
module.exports = function (Parent) {
|
||||||
|
var Constructor = function () {
|
||||||
|
this.noInteropExport = true;
|
||||||
|
Parent.apply(this, arguments);
|
||||||
|
};
|
||||||
|
|
||||||
|
util.inherits(Constructor, Parent);
|
||||||
|
|
||||||
|
return Constructor;
|
||||||
|
};
|
||||||
3
lib/6to5/transformation/modules/amd-strict.js
Normal file
3
lib/6to5/transformation/modules/amd-strict.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
module.exports = require("./_strict")(require("./amd"));
|
||||||
@@ -1,13 +1,16 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
module.exports = AMDFormatter;
|
module.exports = AMDFormatter;
|
||||||
|
|
||||||
var DefaultFormatter = require("./_default");
|
var DefaultFormatter = require("./_default");
|
||||||
|
var CommonFormatter = require("./common");
|
||||||
var util = require("../../util");
|
var util = require("../../util");
|
||||||
var t = require("../../types");
|
var t = require("../../types");
|
||||||
var _ = require("lodash");
|
var _ = require("lodash");
|
||||||
|
|
||||||
function AMDFormatter() {
|
function AMDFormatter() {
|
||||||
DefaultFormatter.apply(this, arguments);
|
CommonFormatter.apply(this, arguments);
|
||||||
this.ids = {};
|
this.ids = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
util.inherits(AMDFormatter, DefaultFormatter);
|
util.inherits(AMDFormatter, DefaultFormatter);
|
||||||
@@ -30,12 +33,15 @@ AMDFormatter.prototype.transform = function (ast) {
|
|||||||
|
|
||||||
// build an array of module names
|
// build an array of module names
|
||||||
|
|
||||||
var names = [t.literal("exports")].concat(this.buildDependencyLiterals());
|
var names = [t.literal("exports")];
|
||||||
|
if (this.passModuleArg) names.push(t.literal("module"));
|
||||||
|
names = names.concat(this.buildDependencyLiterals());
|
||||||
names = t.arrayExpression(names);
|
names = t.arrayExpression(names);
|
||||||
|
|
||||||
// build up define container
|
// build up define container
|
||||||
|
|
||||||
var params = _.values(this.ids);
|
var params = _.values(this.ids);
|
||||||
|
if (this.passModuleArg) params.unshift(t.identifier("module"));
|
||||||
params.unshift(t.identifier("exports"));
|
params.unshift(t.identifier("exports"));
|
||||||
|
|
||||||
var container = t.functionExpression(null, params, t.blockStatement(body));
|
var container = t.functionExpression(null, params, t.blockStatement(body));
|
||||||
@@ -96,6 +102,14 @@ AMDFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
|
|||||||
]));
|
]));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
AMDFormatter.prototype.exportDeclaration = function (node) {
|
||||||
|
if (node.default && !this.noInteropExport) {
|
||||||
|
this.passModuleArg = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
CommonFormatter.prototype.exportDeclaration.apply(this, arguments);
|
||||||
|
};
|
||||||
|
|
||||||
AMDFormatter.prototype.exportSpecifier = function (specifier, node, nodes) {
|
AMDFormatter.prototype.exportSpecifier = function (specifier, node, nodes) {
|
||||||
var self = this;
|
var self = this;
|
||||||
return this._exportSpecifier(function () {
|
return this._exportSpecifier(function () {
|
||||||
|
|||||||
3
lib/6to5/transformation/modules/common-strict.js
Normal file
3
lib/6to5/transformation/modules/common-strict.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
module.exports = require("./_strict")(require("./common"));
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
module.exports = CommonJSFormatter;
|
module.exports = CommonJSFormatter;
|
||||||
|
|
||||||
var DefaultFormatter = require("./_default");
|
var DefaultFormatter = require("./_default");
|
||||||
@@ -61,7 +63,7 @@ CommonJSFormatter.prototype.importDeclaration = function (node, nodes) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
CommonJSFormatter.prototype.exportDeclaration = function (node, nodes) {
|
CommonJSFormatter.prototype.exportDeclaration = function (node, nodes) {
|
||||||
if (node.default) {
|
if (node.default && !this.noInteropRequire && !this.noInteropExport) {
|
||||||
var declar = node.declaration;
|
var declar = node.declaration;
|
||||||
var assign;
|
var assign;
|
||||||
|
|
||||||
@@ -83,10 +85,12 @@ CommonJSFormatter.prototype.exportDeclaration = function (node, nodes) {
|
|||||||
// this export isn't a function so we can't hoist it to the top so we need to set it
|
// this export isn't a function so we can't hoist it to the top so we need to set it
|
||||||
// at the very end of the file with something like:
|
// at the very end of the file with something like:
|
||||||
//
|
//
|
||||||
// module.exports = Object.assign(exports["default"], exports)
|
// module.exports = _extends(exports["default"], exports)
|
||||||
//
|
//
|
||||||
|
|
||||||
assign = util.template("common-export-default-assign", true);
|
assign = util.template("common-export-default-assign", {
|
||||||
|
EXTENDS_HELPER: this.file.addHelper("extends")
|
||||||
|
}, true);
|
||||||
assign._blockHoist = 0;
|
assign._blockHoist = 0;
|
||||||
|
|
||||||
nodes.push(assign);
|
nodes.push(assign);
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
module.exports = IgnoreFormatter;
|
module.exports = IgnoreFormatter;
|
||||||
|
|
||||||
var t = require("../../types");
|
var t = require("../../types");
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
module.exports = SystemFormatter;
|
module.exports = SystemFormatter;
|
||||||
|
|
||||||
var AMDFormatter = require("./amd");
|
var AMDFormatter = require("./amd");
|
||||||
var useStrict = require("../transformers/use-strict");
|
var useStrict = require("../helpers/use-strict");
|
||||||
var traverse = require("../../traverse");
|
var traverse = require("../../traverse");
|
||||||
var util = require("../../util");
|
var util = require("../../util");
|
||||||
var t = require("../../types");
|
var t = require("../../types");
|
||||||
@@ -63,28 +65,31 @@ SystemFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
|
|||||||
|
|
||||||
SystemFormatter.prototype.buildRunnerSetters = function (block, hoistDeclarators) {
|
SystemFormatter.prototype.buildRunnerSetters = function (block, hoistDeclarators) {
|
||||||
return t.arrayExpression(_.map(this.ids, function (uid, source) {
|
return t.arrayExpression(_.map(this.ids, function (uid, source) {
|
||||||
var nodes = [];
|
var state = {
|
||||||
|
nodes: [],
|
||||||
|
hoistDeclarators: hoistDeclarators
|
||||||
|
};
|
||||||
|
|
||||||
traverse(block, {
|
traverse(block, {
|
||||||
enter: function (node) {
|
enter: function (node, parent, scope, context, state) {
|
||||||
if (node._importSource === source) {
|
if (node._importSource === source) {
|
||||||
if (t.isVariableDeclaration(node)) {
|
if (t.isVariableDeclaration(node)) {
|
||||||
_.each(node.declarations, function (declar) {
|
_.each(node.declarations, function (declar) {
|
||||||
hoistDeclarators.push(t.variableDeclarator(declar.id));
|
state.hoistDeclarators.push(t.variableDeclarator(declar.id));
|
||||||
nodes.push(t.expressionStatement(
|
state.nodes.push(t.expressionStatement(
|
||||||
t.assignmentExpression("=", declar.id, declar.init)
|
t.assignmentExpression("=", declar.id, declar.init)
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
nodes.push(node);
|
state.nodes.push(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.remove();
|
context.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}, null, state);
|
||||||
|
|
||||||
return t.functionExpression(null, [uid], t.blockStatement(nodes));
|
return t.functionExpression(null, [uid], t.blockStatement(state.nodes));
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -112,10 +117,10 @@ SystemFormatter.prototype.transform = function (ast) {
|
|||||||
|
|
||||||
// hoist up all variable declarations
|
// hoist up all variable declarations
|
||||||
traverse(block, {
|
traverse(block, {
|
||||||
enter: function (node, parent, scope) {
|
enter: function (node, parent, scope, context, hoistDeclarators) {
|
||||||
if (t.isFunction(node)) {
|
if (t.isFunction(node)) {
|
||||||
// nothing inside is accessible
|
// nothing inside is accessible
|
||||||
return this.skip();
|
return context.skip();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t.isVariableDeclaration(node)) {
|
if (t.isVariableDeclaration(node)) {
|
||||||
@@ -150,7 +155,8 @@ SystemFormatter.prototype.transform = function (ast) {
|
|||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}, null, hoistDeclarators);
|
||||||
|
|
||||||
if (hoistDeclarators.length) {
|
if (hoistDeclarators.length) {
|
||||||
var hoistDeclar = t.variableDeclaration("var", hoistDeclarators);
|
var hoistDeclar = t.variableDeclaration("var", hoistDeclarators);
|
||||||
hoistDeclar._blockHoist = true;
|
hoistDeclar._blockHoist = true;
|
||||||
@@ -159,19 +165,19 @@ SystemFormatter.prototype.transform = function (ast) {
|
|||||||
|
|
||||||
// hoist up function declarations for circular references
|
// hoist up function declarations for circular references
|
||||||
traverse(block, {
|
traverse(block, {
|
||||||
enter: function (node) {
|
enter: function (node, parent, scope, context, handlerBody) {
|
||||||
if (t.isFunction(node)) this.skip();
|
if (t.isFunction(node)) context.skip();
|
||||||
|
|
||||||
if (t.isFunctionDeclaration(node) || node._blockHoist) {
|
if (t.isFunctionDeclaration(node) || node._blockHoist) {
|
||||||
handlerBody.push(node);
|
handlerBody.push(node);
|
||||||
this.remove();
|
context.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}, null, handlerBody);
|
||||||
|
|
||||||
handlerBody.push(returnStatement);
|
handlerBody.push(returnStatement);
|
||||||
|
|
||||||
if (useStrict._has(block)) {
|
if (useStrict.has(block)) {
|
||||||
handlerBody.unshift(block.body.shift());
|
handlerBody.unshift(block.body.shift());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
3
lib/6to5/transformation/modules/umd-strict.js
Normal file
3
lib/6to5/transformation/modules/umd-strict.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
module.exports = require("./_strict")(require("./umd"));
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
module.exports = UMDFormatter;
|
module.exports = UMDFormatter;
|
||||||
|
|
||||||
var AMDFormatter = require("./amd");
|
var AMDFormatter = require("./amd");
|
||||||
@@ -25,22 +27,44 @@ UMDFormatter.prototype.transform = function (ast) {
|
|||||||
// factory
|
// factory
|
||||||
|
|
||||||
var ids = _.values(this.ids);
|
var ids = _.values(this.ids);
|
||||||
var args = [t.identifier("exports")].concat(ids);
|
var args = [t.identifier("exports")];
|
||||||
|
if (this.passModuleArg) args.push(t.identifier("module"));
|
||||||
|
args = args.concat(ids);
|
||||||
|
|
||||||
var factory = t.functionExpression(null, args, t.blockStatement(body));
|
var factory = t.functionExpression(null, args, t.blockStatement(body));
|
||||||
|
|
||||||
// runner
|
// amd
|
||||||
|
|
||||||
|
var defineArgs = [t.literal("exports")];
|
||||||
|
if (this.passModuleArg) defineArgs.push(t.literal("module"));
|
||||||
|
defineArgs = defineArgs.concat(names);
|
||||||
|
defineArgs = [t.arrayExpression(defineArgs)];
|
||||||
|
|
||||||
|
// common
|
||||||
|
|
||||||
|
var testExports = util.template("test-exports");
|
||||||
|
var testModule = util.template("test-module");
|
||||||
|
var commonTests = this.passModuleArg ? t.logicalExpression("&&", testExports, testModule) : testExports;
|
||||||
|
|
||||||
|
var commonArgs = [t.identifier("exports")];
|
||||||
|
if (this.passModuleArg) commonArgs.push(t.identifier("module"));
|
||||||
|
commonArgs = commonArgs.concat(names.map(function (name) {
|
||||||
|
return t.callExpression(t.identifier("require"), [name]);
|
||||||
|
}));
|
||||||
|
|
||||||
|
// globals
|
||||||
|
|
||||||
|
//var umdArgs = [];
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
var defineArgs = [t.arrayExpression([t.literal("exports")].concat(names))];
|
|
||||||
var moduleName = this.getModuleName();
|
var moduleName = this.getModuleName();
|
||||||
if (moduleName) defineArgs.unshift(t.literal(moduleName));
|
if (moduleName) defineArgs.unshift(t.literal(moduleName));
|
||||||
|
|
||||||
var runner = util.template("umd-runner-body", {
|
var runner = util.template("umd-runner-body", {
|
||||||
AMD_ARGUMENTS: defineArgs,
|
AMD_ARGUMENTS: defineArgs,
|
||||||
|
COMMON_TEST: commonTests,
|
||||||
COMMON_ARGUMENTS: names.map(function (name) {
|
COMMON_ARGUMENTS: commonArgs
|
||||||
return t.callExpression(t.identifier("require"), [name]);
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
ARRAY.forEach(function (KEY) {
|
|
||||||
|
|
||||||
});
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
if (SUPER_NAME != null) {
|
||||||
|
SUPER_NAME.apply(this, arguments);
|
||||||
|
}
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
if (SUPER_NAME !== null) {
|
if (Object.getPrototypeOf(CLASS_NAME) !== null) {
|
||||||
SUPER_NAME.apply(this, arguments);
|
Object.getPrototypeOf(CLASS_NAME).apply(this, arguments);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
module.exports = Object.assign(exports["default"], exports);
|
module.exports = EXTENDS_HELPER(exports["default"], exports);
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
(function (obj) {
|
|
||||||
for (var i in obj) {
|
|
||||||
if (exports[i] !== undefined) {
|
|
||||||
exports[i] = obj[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
9
lib/6to5/transformation/templates/extends.js
Normal file
9
lib/6to5/transformation/templates/extends.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
(function (target) {
|
||||||
|
for (var i = 1; i < arguments.length; i++) {
|
||||||
|
var source = arguments[i];
|
||||||
|
for (var key in source) {
|
||||||
|
target[key] = source[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return target;
|
||||||
|
})
|
||||||
13
lib/6to5/transformation/templates/for-of-loose.js
Normal file
13
lib/6to5/transformation/templates/for-of-loose.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
for (var LOOP_OBJECT = OBJECT,
|
||||||
|
IS_ARRAY = Array.isArray(LOOP_OBJECT),
|
||||||
|
INDEX = 0,
|
||||||
|
LOOP_OBJECT = IS_ARRAY ? LOOP_OBJECT : LOOP_OBJECT[Symbol.iterator]();;) {
|
||||||
|
if (IS_ARRAY) {
|
||||||
|
if (INDEX >= LOOP_OBJECT.length) break;
|
||||||
|
ID = LOOP_OBJECT[INDEX++];
|
||||||
|
} else {
|
||||||
|
INDEX = LOOP_OBJECT.next();
|
||||||
|
if (INDEX.done) break;
|
||||||
|
ID = INDEX.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
23
lib/6to5/transformation/templates/get.js
Normal file
23
lib/6to5/transformation/templates/get.js
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
(function get(object, property, receiver) {
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(object, property);
|
||||||
|
|
||||||
|
if (desc === undefined) {
|
||||||
|
var parent = Object.getPrototypeOf(object);
|
||||||
|
|
||||||
|
if (parent === null) {
|
||||||
|
return undefined;
|
||||||
|
} else {
|
||||||
|
return get(parent, property, receiver);
|
||||||
|
}
|
||||||
|
} else if ("value" in desc && desc.writable) {
|
||||||
|
return desc.value;
|
||||||
|
} else {
|
||||||
|
var getter = desc.get;
|
||||||
|
|
||||||
|
if (getter === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getter.call(receiver);
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
(function (child, parent) {
|
(function (subClass, superClass) {
|
||||||
if (typeof parent !== "function" && parent !== null) {
|
if (typeof superClass !== "function" && superClass !== null) {
|
||||||
throw new TypeError("Super expression must either be null or a function, not " + typeof parent);
|
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
||||||
}
|
}
|
||||||
child.prototype = Object.create(parent && parent.prototype, {
|
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
||||||
constructor: {
|
constructor: {
|
||||||
value: child,
|
value: subClass,
|
||||||
enumerable: false,
|
enumerable: false,
|
||||||
writable: true,
|
writable: true,
|
||||||
configurable: true
|
configurable: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (parent) child.__proto__ = parent;
|
if (superClass) subClass.__proto__ = superClass;
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
|
|
||||||
(function (KEY) {
|
|
||||||
CONTENT;
|
|
||||||
return KEY;
|
|
||||||
})(OBJECT);
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
Object.defineProperties(OBJECT, PROPS);
|
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
for (var KEY = START; KEY < ARGUMENTS.length; KEY++) {
|
for (var LEN = ARGUMENTS.length, ARRAY = Array(ARRAY_LEN), KEY = START; KEY < LEN; KEY++) {
|
||||||
ARRAY[$__0] = ARGUMENTS[KEY];
|
ARRAY[ARRAY_KEY] = ARGUMENTS[KEY];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
(function (strings, raw) {
|
||||||
|
strings.raw = raw;
|
||||||
|
return strings;
|
||||||
|
});
|
||||||
1
lib/6to5/transformation/templates/test-exports.js
Normal file
1
lib/6to5/transformation/templates/test-exports.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
typeof exports !== "undefined"
|
||||||
1
lib/6to5/transformation/templates/test-module.js
Normal file
1
lib/6to5/transformation/templates/test-module.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
typeof module !== "undefined"
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
(function (factory) {
|
(function (factory) {
|
||||||
if (typeof define === "function" && define.amd) {
|
if (typeof define === "function" && define.amd) {
|
||||||
define(AMD_ARGUMENTS, factory);
|
define(AMD_ARGUMENTS, factory);
|
||||||
} else if (typeof exports !== "undefined") {
|
} else if (COMMON_TEST) {
|
||||||
factory(exports, COMMON_ARGUMENTS);
|
factory(COMMON_ARGUMENTS);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
module.exports = transform;
|
module.exports = transform;
|
||||||
|
|
||||||
var Transformer = require("./transformer");
|
var Transformer = require("./transformer");
|
||||||
@@ -20,7 +22,7 @@ transform.fromAst = function (ast, code, opts) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
transform._ensureTransformerNames = function (type, keys) {
|
transform._ensureTransformerNames = function (type, keys) {
|
||||||
for (var i in keys) {
|
for (var i = 0; i < keys.length; i++) {
|
||||||
var key = keys[i];
|
var key = keys[i];
|
||||||
if (!_.has(transform.transformers, key)) {
|
if (!_.has(transform.transformers, key)) {
|
||||||
throw new ReferenceError("unknown transformer " + key + " specified in " + type);
|
throw new ReferenceError("unknown transformer " + key + " specified in " + type);
|
||||||
@@ -31,19 +33,23 @@ transform._ensureTransformerNames = function (type, keys) {
|
|||||||
transform.transformers = {};
|
transform.transformers = {};
|
||||||
|
|
||||||
transform.moduleFormatters = {
|
transform.moduleFormatters = {
|
||||||
common: require("./modules/common"),
|
commonStrict: require("./modules/common-strict"),
|
||||||
system: require("./modules/system"),
|
umdStrict: require("./modules/umd-strict"),
|
||||||
ignore: require("./modules/ignore"),
|
amdStrict: require("./modules/amd-strict"),
|
||||||
amd: require("./modules/amd"),
|
common: require("./modules/common"),
|
||||||
umd: require("./modules/umd")
|
system: require("./modules/system"),
|
||||||
|
ignore: require("./modules/ignore"),
|
||||||
|
amd: require("./modules/amd"),
|
||||||
|
umd: require("./modules/umd")
|
||||||
};
|
};
|
||||||
|
|
||||||
_.each({
|
_.each({
|
||||||
// spec
|
|
||||||
specBlockHoistFunctions: require("./transformers/spec-block-hoist-functions"),
|
|
||||||
specNoForInOfAssignment: require("./transformers/spec-no-for-in-of-assignment"),
|
specNoForInOfAssignment: require("./transformers/spec-no-for-in-of-assignment"),
|
||||||
|
specSetters: require("./transformers/spec-setters"),
|
||||||
|
specBlockScopedFunctions: require("./transformers/spec-block-scoped-functions"),
|
||||||
|
|
||||||
// playground
|
// playground
|
||||||
|
malletOperator: require("./transformers/playground-mallet-operator"),
|
||||||
methodBinding: require("./transformers/playground-method-binding"),
|
methodBinding: require("./transformers/playground-method-binding"),
|
||||||
memoizationOperator: require("./transformers/playground-memoization-operator"),
|
memoizationOperator: require("./transformers/playground-memoization-operator"),
|
||||||
objectGetterMemoization: require("./transformers/playground-object-getter-memoization"),
|
objectGetterMemoization: require("./transformers/playground-object-getter-memoization"),
|
||||||
@@ -59,21 +65,21 @@ _.each({
|
|||||||
arrowFunctions: require("./transformers/es6-arrow-functions"),
|
arrowFunctions: require("./transformers/es6-arrow-functions"),
|
||||||
classes: require("./transformers/es6-classes"),
|
classes: require("./transformers/es6-classes"),
|
||||||
|
|
||||||
computedPropertyNames: require("./transformers/es6-computed-property-names"),
|
|
||||||
|
|
||||||
objectSpread: require("./transformers/es7-object-spread"),
|
objectSpread: require("./transformers/es7-object-spread"),
|
||||||
exponentiationOperator: require("./transformers/es7-exponentiation-operator"),
|
exponentiationOperator: require("./transformers/es7-exponentiation-operator"),
|
||||||
spread: require("./transformers/es6-spread"),
|
spread: require("./transformers/es6-spread"),
|
||||||
templateLiterals: require("./transformers/es6-template-literals"),
|
templateLiterals: require("./transformers/es6-template-literals"),
|
||||||
propertyMethodAssignment: require("./transformers/es6-property-method-assignment"),
|
propertyMethodAssignment: require("./transformers/es6-property-method-assignment"),
|
||||||
destructuring: require("./transformers/es6-destructuring"),
|
computedPropertyNames: require("./transformers/es6-computed-property-names"),
|
||||||
defaultParameters: require("./transformers/es6-default-parameters"),
|
defaultParameters: require("./transformers/es6-default-parameters"),
|
||||||
|
destructuring: require("./transformers/es6-destructuring"),
|
||||||
forOf: require("./transformers/es6-for-of"),
|
forOf: require("./transformers/es6-for-of"),
|
||||||
unicodeRegex: require("./transformers/es6-unicode-regex"),
|
unicodeRegex: require("./transformers/es6-unicode-regex"),
|
||||||
abstractReferences: require("./transformers/es7-abstract-references"),
|
abstractReferences: require("./transformers/es7-abstract-references"),
|
||||||
|
|
||||||
constants: require("./transformers/es6-constants"),
|
constants: require("./transformers/es6-constants"),
|
||||||
letScoping: require("./transformers/es6-let-scoping"),
|
letScoping: require("./transformers/es6-let-scoping"),
|
||||||
|
blockScopingTDZ: require("./transformers/optional-block-scoping-tdz"),
|
||||||
|
|
||||||
_blockHoist: require("./transformers/_block-hoist"),
|
_blockHoist: require("./transformers/_block-hoist"),
|
||||||
|
|
||||||
@@ -92,6 +98,7 @@ _.each({
|
|||||||
typeofSymbol: require("./transformers/optional-typeof-symbol"),
|
typeofSymbol: require("./transformers/optional-typeof-symbol"),
|
||||||
coreAliasing: require("./transformers/optional-core-aliasing"),
|
coreAliasing: require("./transformers/optional-core-aliasing"),
|
||||||
undefinedToVoid: require("./transformers/optional-undefined-to-void"),
|
undefinedToVoid: require("./transformers/optional-undefined-to-void"),
|
||||||
|
undeclaredVariableCheck: require("./transformers/optional-undeclared-variable-check"),
|
||||||
|
|
||||||
// spec
|
// spec
|
||||||
specPropertyLiterals: require("./transformers/spec-property-literals"),
|
specPropertyLiterals: require("./transformers/spec-property-literals"),
|
||||||
|
|||||||
@@ -1,9 +1,30 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
module.exports = Transformer;
|
module.exports = Transformer;
|
||||||
|
|
||||||
var traverse = require("../traverse");
|
var traverse = require("../traverse");
|
||||||
var t = require("../types");
|
var t = require("../types");
|
||||||
var _ = require("lodash");
|
var _ = require("lodash");
|
||||||
|
|
||||||
|
function noop() { }
|
||||||
|
|
||||||
|
function enter(node, parent, scope, context, args) {
|
||||||
|
var fns = args[1][node.type];
|
||||||
|
if (!fns) return;
|
||||||
|
return fns.enter(node, parent, scope, context, args[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function exit(node, parent, scope, context, args) {
|
||||||
|
var fns = args[1][node.type];
|
||||||
|
if (!fns) return;
|
||||||
|
return fns.exit(node, parent, scope, context, args[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
var traverseOpts = {
|
||||||
|
enter: enter,
|
||||||
|
exit: exit
|
||||||
|
};
|
||||||
|
|
||||||
function Transformer(key, transformer, opts) {
|
function Transformer(key, transformer, opts) {
|
||||||
this.manipulateOptions = transformer.manipulateOptions;
|
this.manipulateOptions = transformer.manipulateOptions;
|
||||||
this.experimental = !!transformer.experimental;
|
this.experimental = !!transformer.experimental;
|
||||||
@@ -32,6 +53,9 @@ Transformer.prototype.normalise = function (transformer) {
|
|||||||
|
|
||||||
if (!_.isObject(fns)) return;
|
if (!_.isObject(fns)) return;
|
||||||
|
|
||||||
|
if (!fns.enter) fns.enter = noop;
|
||||||
|
if (!fns.exit) fns.exit = noop;
|
||||||
|
|
||||||
transformer[type] = fns;
|
transformer[type] = fns;
|
||||||
|
|
||||||
var aliases = t.FLIPPED_ALIAS_KEYS[type];
|
var aliases = t.FLIPPED_ALIAS_KEYS[type];
|
||||||
@@ -54,28 +78,8 @@ Transformer.prototype.astRun = function (file, key) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Transformer.prototype.transform = function (file) {
|
Transformer.prototype.transform = function (file) {
|
||||||
var transformer = this.transformer;
|
|
||||||
|
|
||||||
var build = function (exit) {
|
|
||||||
return function (node, parent, scope) {
|
|
||||||
var fns = transformer[node.type];
|
|
||||||
if (!fns) return;
|
|
||||||
|
|
||||||
var fn = fns.enter;
|
|
||||||
if (exit) fn = fns.exit;
|
|
||||||
if (!fn) return;
|
|
||||||
|
|
||||||
return fn(node, parent, file, scope);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
this.astRun(file, "before");
|
this.astRun(file, "before");
|
||||||
|
traverse(file.ast, traverseOpts, null, [file, this.transformer]);
|
||||||
traverse(file.ast, {
|
|
||||||
enter: build(),
|
|
||||||
exit: build(true)
|
|
||||||
});
|
|
||||||
|
|
||||||
this.astRun(file, "after");
|
this.astRun(file, "after");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,57 +1,64 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
var traverse = require("../../traverse");
|
var traverse = require("../../traverse");
|
||||||
var t = require("../../types");
|
var t = require("../../types");
|
||||||
|
|
||||||
|
var functionChildrenTraverser = {
|
||||||
|
enter: function (node, parent, scope, context, state) {
|
||||||
|
if (t.isFunction(node) && !node._aliasFunction) {
|
||||||
|
return context.skip();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node._ignoreAliasFunctions) return context.skip();
|
||||||
|
|
||||||
|
var getId;
|
||||||
|
|
||||||
|
if (t.isIdentifier(node) && node.name === "arguments") {
|
||||||
|
getId = state.getArgumentsId;
|
||||||
|
} else if (t.isThisExpression(node)) {
|
||||||
|
getId = state.getThisId;
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (t.isReferenced(node, parent)) return getId();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var functionTraverser = {
|
||||||
|
enter: function (node, parent, scope, context, state) {
|
||||||
|
if (!node._aliasFunction) {
|
||||||
|
if (t.isFunction(node)) {
|
||||||
|
// stop traversal of this node as it'll be hit again by this transformer
|
||||||
|
return context.skip();
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// traverse all child nodes of this function and find `arguments` and `this`
|
||||||
|
traverse(node, functionChildrenTraverser, null, state);
|
||||||
|
|
||||||
|
return context.skip();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
var go = function (getBody, node, file, scope) {
|
var go = function (getBody, node, file, scope) {
|
||||||
var argumentsId;
|
var argumentsId;
|
||||||
var thisId;
|
var thisId;
|
||||||
|
|
||||||
var getArgumentsId = function () {
|
var state = {
|
||||||
return argumentsId = argumentsId || file.generateUidIdentifier("arguments", scope);
|
getArgumentsId: function () {
|
||||||
};
|
return argumentsId = argumentsId || file.generateUidIdentifier("arguments", scope);
|
||||||
|
},
|
||||||
var getThisId = function () {
|
getThisId: function () {
|
||||||
return thisId = thisId || file.generateUidIdentifier("this", scope);
|
return thisId = thisId || file.generateUidIdentifier("this", scope);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// traverse the function and find all alias functions so we can alias
|
// traverse the function and find all alias functions so we can alias
|
||||||
// `arguments` and `this` if necessary
|
// `arguments` and `this` if necessary
|
||||||
traverse(node, {
|
traverse(node, functionTraverser, null, state);
|
||||||
enter: function (node) {
|
|
||||||
if (!node._aliasFunction) {
|
|
||||||
if (t.isFunction(node)) {
|
|
||||||
// stop traversal of this node as it'll be hit again by this transformer
|
|
||||||
return this.skip();
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// traverse all child nodes of this function and find `arguments` and `this`
|
|
||||||
traverse(node, {
|
|
||||||
enter: function (node, parent) {
|
|
||||||
if (t.isFunction(node) && !node._aliasFunction) {
|
|
||||||
return this.skip();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node._ignoreAliasFunctions) return this.skip();
|
|
||||||
|
|
||||||
var getId;
|
|
||||||
|
|
||||||
if (t.isIdentifier(node) && node.name === "arguments") {
|
|
||||||
getId = getArgumentsId;
|
|
||||||
} else if (t.isThisExpression(node)) {
|
|
||||||
getId = getThisId;
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (t.isReferenced(node, parent)) return getId();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return this.skip();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var body;
|
var body;
|
||||||
|
|
||||||
@@ -71,14 +78,14 @@ var go = function (getBody, node, file, scope) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.Program = function (node, parent, file, scope) {
|
exports.Program = function (node, parent, scope, context, file) {
|
||||||
go(function () {
|
go(function () {
|
||||||
return node.body;
|
return node.body;
|
||||||
}, node, file, scope);
|
}, node, file, scope);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.FunctionDeclaration =
|
exports.FunctionDeclaration =
|
||||||
exports.FunctionExpression = function (node, parent, file, scope) {
|
exports.FunctionExpression = function (node, parent, scope, context, file) {
|
||||||
go(function () {
|
go(function () {
|
||||||
t.ensureBlock(node);
|
t.ensureBlock(node);
|
||||||
return node.body.body;
|
return node.body.body;
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
var useStrict = require("./use-strict");
|
"use strict";
|
||||||
|
|
||||||
|
var useStrict = require("../helpers/use-strict");
|
||||||
var _ = require("lodash");
|
var _ = require("lodash");
|
||||||
|
|
||||||
// Priority:
|
// Priority:
|
||||||
@@ -12,13 +14,13 @@ exports.BlockStatement =
|
|||||||
exports.Program = {
|
exports.Program = {
|
||||||
exit: function (node) {
|
exit: function (node) {
|
||||||
var hasChange = false;
|
var hasChange = false;
|
||||||
for (var i in node.body) {
|
for (var i = 0; i < node.body.length; i++) {
|
||||||
var bodyNode = node.body[i];
|
var bodyNode = node.body[i];
|
||||||
if (bodyNode && bodyNode._blockHoist != null) hasChange = true;
|
if (bodyNode && bodyNode._blockHoist != null) hasChange = true;
|
||||||
}
|
}
|
||||||
if (!hasChange) return;
|
if (!hasChange) return;
|
||||||
|
|
||||||
useStrict._wrap(node, function () {
|
useStrict.wrap(node, function () {
|
||||||
var nodePriorities = _.groupBy(node.body, function (bodyNode) {
|
var nodePriorities = _.groupBy(node.body, function (bodyNode) {
|
||||||
var priority = bodyNode._blockHoist;
|
var priority = bodyNode._blockHoist;
|
||||||
if (priority == null) priority = 1;
|
if (priority == null) priority = 1;
|
||||||
|
|||||||
@@ -1,14 +1,18 @@
|
|||||||
var useStrict = require("./use-strict");
|
"use strict";
|
||||||
|
|
||||||
|
var useStrict = require("../helpers/use-strict");
|
||||||
var t = require("../../types");
|
var t = require("../../types");
|
||||||
|
|
||||||
exports.secondPass = true;
|
exports.secondPass = true;
|
||||||
|
|
||||||
exports.BlockStatement =
|
exports.BlockStatement =
|
||||||
exports.Program = function (node) {
|
exports.Program = function (node) {
|
||||||
|
if (!node._declarations) return;
|
||||||
|
|
||||||
var kinds = {};
|
var kinds = {};
|
||||||
var kind;
|
var kind;
|
||||||
|
|
||||||
useStrict._wrap(node, function () {
|
useStrict.wrap(node, function () {
|
||||||
for (var i in node._declarations) {
|
for (var i in node._declarations) {
|
||||||
var declar = node._declarations[i];
|
var declar = node._declarations[i];
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
var transform = require("../transform");
|
var transform = require("../transform");
|
||||||
|
|
||||||
exports.ast = {
|
exports.ast = {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
var t = require("../../types");
|
var t = require("../../types");
|
||||||
|
|
||||||
exports.ArrowFunctionExpression = function (node) {
|
exports.ArrowFunctionExpression = function (node) {
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user