Compare commits
193 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2f61754a24 | ||
|
|
3910d18bc9 | ||
|
|
583111ebfb | ||
|
|
1b15481460 | ||
|
|
fd9c98ff86 | ||
|
|
41b5607ef3 | ||
|
|
ae77ea807f | ||
|
|
ad44190c6b | ||
|
|
024e4454a1 | ||
|
|
14dddcda36 | ||
|
|
d4fb924b6a | ||
|
|
b02c97af60 | ||
|
|
cc611cb71c | ||
|
|
b8a01a9919 | ||
|
|
55c99661be | ||
|
|
1563b216df | ||
|
|
a9d4b485d9 | ||
|
|
360daa6267 | ||
|
|
724bf52929 | ||
|
|
7407b37bd9 | ||
|
|
da765cc4c1 | ||
|
|
4f862eee6e | ||
|
|
e05d7cf49a | ||
|
|
fd8e94a90f | ||
|
|
a6cf28c5b5 | ||
|
|
6b07b13a8e | ||
|
|
561c4dcc25 | ||
|
|
b516ea596a | ||
|
|
248758eee3 | ||
|
|
a808602ae0 | ||
|
|
40e3436e95 | ||
|
|
f704770b26 | ||
|
|
330665f150 | ||
|
|
af41899d74 | ||
|
|
d12f4d0bc8 | ||
|
|
97680e9dfd | ||
|
|
51341ca6c3 | ||
|
|
ab54bfa50e | ||
|
|
60aa933fb6 | ||
|
|
1a299b2bcc | ||
|
|
37f662d790 | ||
|
|
b0317f9bab | ||
|
|
be2dfaf081 | ||
|
|
2c8437ae92 | ||
|
|
2a0bcfd086 | ||
|
|
2cf41afac3 | ||
|
|
e318f5f3be | ||
|
|
939decb86c | ||
|
|
1baa0df948 | ||
|
|
e8956a8c44 | ||
|
|
2f0fdbbc26 | ||
|
|
5f931525bc | ||
|
|
b86545a320 | ||
|
|
06e75c42bf | ||
|
|
05dd65244d | ||
|
|
c4ebfeb0fa | ||
|
|
1aa0bbfac9 | ||
|
|
58f1e6cbc6 | ||
|
|
83e0be3038 | ||
|
|
5fc242e4ec | ||
|
|
dc101adad3 | ||
|
|
faade72787 | ||
|
|
2a78ae9889 | ||
|
|
9840639843 | ||
|
|
82c21a901e | ||
|
|
e1c83144c1 | ||
|
|
ef2ac73215 | ||
|
|
735d8955bf | ||
|
|
3abee0a4fa | ||
|
|
b6f18b4f2b | ||
|
|
85cd0465fa | ||
|
|
0452e0fdd2 | ||
|
|
462ff572b3 | ||
|
|
d11099bb2b | ||
|
|
f5c4684d3e | ||
|
|
876a22578b | ||
|
|
9f5e8b296b | ||
|
|
d9deb02edc | ||
|
|
a402d0cdeb | ||
|
|
683fb62505 | ||
|
|
941474983d | ||
|
|
2b42773e01 | ||
|
|
8277a532f4 | ||
|
|
539784b640 | ||
|
|
f373f8f003 | ||
|
|
8605e835eb | ||
|
|
b4ace2043a | ||
|
|
444a64e934 | ||
|
|
8ea2ae924d | ||
|
|
4ceb1d6f5e | ||
|
|
3c81899ca7 | ||
|
|
ab59fd08e5 | ||
|
|
19b05b5e61 | ||
|
|
65a44a1e13 | ||
|
|
d38f18af40 | ||
|
|
2744b9f31f | ||
|
|
4deed35212 | ||
|
|
bc9ae5ea8b | ||
|
|
87d879e236 | ||
|
|
f657598c72 | ||
|
|
2a5cb9d21b | ||
|
|
cf7d6b655e | ||
|
|
6d2723eec5 | ||
|
|
6834cc5b46 | ||
|
|
9b949e574f | ||
|
|
a75af0a5d2 | ||
|
|
080b26769c | ||
|
|
e037ae7bc9 | ||
|
|
c60ad89937 | ||
|
|
4194857086 | ||
|
|
1179c44c5b | ||
|
|
f6d9b270c9 | ||
|
|
1be0159b01 | ||
|
|
61ba8ad997 | ||
|
|
89e31085d2 | ||
|
|
920c84a1f2 | ||
|
|
ed56fecd04 | ||
|
|
f0bfdfb699 | ||
|
|
b02a1112bc | ||
|
|
590a165776 | ||
|
|
2fd1b2a484 | ||
|
|
8f9d02d689 | ||
|
|
b376b6b33b | ||
|
|
8292d6d8ad | ||
|
|
d6a5c39079 | ||
|
|
2a9a59f784 | ||
|
|
abf4a5495a | ||
|
|
f8b8723bef | ||
|
|
6b9686f2dd | ||
|
|
4a439d8c8e | ||
|
|
c526a3eb04 | ||
|
|
ba516901af | ||
|
|
8f52229a86 | ||
|
|
5b793f8882 | ||
|
|
b31c14c52a | ||
|
|
78b72512cb | ||
|
|
2fbb3cad9f | ||
|
|
2621081a13 | ||
|
|
8daf95bf59 | ||
|
|
6e8ab16b25 | ||
|
|
a5cda5caa7 | ||
|
|
13a6c69668 | ||
|
|
380293d030 | ||
|
|
0b15a97013 | ||
|
|
11af066956 | ||
|
|
d7b4d342c3 | ||
|
|
77aeebe2a8 | ||
|
|
c3a08d413f | ||
|
|
23ac2319af | ||
|
|
a1bc0704ab | ||
|
|
0bbfd427af | ||
|
|
f17b268a71 | ||
|
|
9ffc265bea | ||
|
|
6f664ca64e | ||
|
|
8a4a76000d | ||
|
|
e83daf87d4 | ||
|
|
8ed90d3af2 | ||
|
|
0bb311f8ce | ||
|
|
53f0f0302b | ||
|
|
c25a5d2480 | ||
|
|
fc8540d88a | ||
|
|
31a4195c81 | ||
|
|
bf0e4ede00 | ||
|
|
3757bc6b9a | ||
|
|
2e01f220da | ||
|
|
8ae4e1fdf2 | ||
|
|
f6219ec15a | ||
|
|
6a82eb5a5c | ||
|
|
a241300ff1 | ||
|
|
d5548a6ff9 | ||
|
|
ba6cb112c3 | ||
|
|
8f1bb84930 | ||
|
|
235726eee6 | ||
|
|
08183ef490 | ||
|
|
dc6fc3b30a | ||
|
|
76f2eb5684 | ||
|
|
4f33687957 | ||
|
|
74f37fe0a3 | ||
|
|
cc5e4bce52 | ||
|
|
f441a7cae8 | ||
|
|
fc2be81c43 | ||
|
|
1277a8f67f | ||
|
|
86c6d4e769 | ||
|
|
bf2d527cfe | ||
|
|
6b59ea8eac | ||
|
|
72e3cb9243 | ||
|
|
5e5ede6058 | ||
|
|
d25944ea1f | ||
|
|
fce2aa8fa3 | ||
|
|
0112c63779 | ||
|
|
6a4e93bf0f | ||
|
|
4328e920d2 | ||
|
|
6491018c21 |
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -1,6 +1,3 @@
|
||||
[submodule "vendor/traceur"]
|
||||
path = vendor/traceur
|
||||
url = https://github.com/google/traceur-compiler
|
||||
[submodule "vendor/compat-table"]
|
||||
path = vendor/compat-table
|
||||
url = https://github.com/kangax/compat-table
|
||||
|
||||
102
CHANGELOG.md
102
CHANGELOG.md
@@ -13,6 +13,108 @@ _Note: Gaps between patch versions are faulty/broken releases._
|
||||
|
||||
See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
|
||||
|
||||
## 5.4.0
|
||||
|
||||
* **New Feature**
|
||||
* Added [function bind syntax](https://github.com/zenparsing/es-function-bind) behind stage 0. Thanks [@RReverser](https://github.com/rreverser)!
|
||||
* Added `env` option. Especially handy when using the `.babelrc`.
|
||||
* **Bug Fix**
|
||||
* Fix files not properly being ignored when `babel.transform` ignores them when using `$ babel`.
|
||||
* Fix scope tracking registering loop head bindings to their `VariableDeclaration` instead of `VariableDeclarator`.
|
||||
* **Polish**
|
||||
* Normalise path separators for souce map paths when using `$ babel`.
|
||||
* Rework `PathHoister` to ignore global references and to not deopt on reassignments to referenced bindings, instead it tries to hoist to the highest scope.
|
||||
* Added missing exponential operator inlining. Thanks [@nkt](https://github.com/nkt)!
|
||||
* Optimise `regenerator` transformer. Thanks [@benjamn](https://github.com/benjamn)!
|
||||
|
||||
## 5.3.3
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix `minification.deadCodeElimination` transformer incorrectly trying to inline import declarations.
|
||||
* Fix `minification.inlineExpression` transformer getting into an infinite loop.
|
||||
|
||||
## 5.3.2
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix patterns not being considered when hoisting variables in the `es6.blockScoping` transformer.
|
||||
|
||||
## 5.3.1
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix unique export specifiers not being cloned when exploding class and function exports,
|
||||
* **Polish**
|
||||
* Turn import remaps to sequence expressions to remove their context and improve performance.
|
||||
|
||||
## 5.3.0
|
||||
|
||||
**Speeeeeeed**
|
||||
|
||||

|
||||
|
||||
* **Spec Compliancy**
|
||||
* Allow trailing param commas for methods when using the `es7.trailingCommas` transformer.
|
||||
* **Bug Fix**
|
||||
* Fix `es6.blockScoping` transformer not properly ignoring `break` in `SwitchCase`.
|
||||
* Fix lookahead context saving to avoid weird tokenizer state.
|
||||
* Explode duplicate identifiers in export/import specifiers and property shorthand to create unique objects.
|
||||
* Skip loose mode for class methods when they have decorators.
|
||||
* When removing nodes, share their comments with their siblings.
|
||||
* Properly hoist temp param declarations when doing TCO.
|
||||
* **Internal**
|
||||
* Add `--harmony_generators` flag to `$ babel-node`.
|
||||
* Internal AST traversals have been minimised **drastically**. Transformers have been grouped together which means entire tree traversals are much fewer. Visiting nodes is now also skipped if the traversal context can detect that the handler is a noop. This sames precious cycles as it avoids constructing traversal paths and creating a new traversal context. See issues [#1472](https://github.com/babel/babel/issues/1472) and [#1486](https://github.com/babel/babel/issues/1486) for related discussion.
|
||||
* **Polish**
|
||||
* Move many `utility` transformers to `minification`.
|
||||
|
||||
## 5.2.17
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix auxiliary comments not properly being attached to function declaration helpers.
|
||||
* Add `Super` node type to `ast-types` patch.
|
||||
* Ignore parameter bindings when attempting to inline them in the `minification.deadCodeElimination` transformer.
|
||||
* Correct `extensions` arguments when using the Babel CLI.
|
||||
|
||||
## 5.2.16
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix plugins being disabled when using the whitelist.
|
||||
* Fix correct function scope being passed to `nameMethod.property` when inferring the function name for class methods.
|
||||
* Fix incorrect extensions reference causing weird issues when using the Babel CLI.
|
||||
* Fix destructuring param reference replacements not inheriting from their original param.
|
||||
* **Spec Compliancy**
|
||||
* Fix order that method decorators are ran in.
|
||||
|
||||
## 5.2.15
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix initializer descriptor add attempt if it doesn't exist.
|
||||
|
||||
## 5.2.14
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix bug with initializer decorators where the descriptors weren't being defined if there was no `initializer` property.
|
||||
* **Internal**
|
||||
* Expose `retainLines` option to CLI.
|
||||
* Fix `retainLines` option not being taken into consideration when doing multiple variable declaration declarators generation.
|
||||
* Expose minified and unminified copies of dist scripts.
|
||||
|
||||
## 5.2.13
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix `ExportDeclaration`s being incorrectly removed when using the `utility.deadCodeElimination` transformer.
|
||||
* Fix position of `utility` transformers.
|
||||
* **New Feature**
|
||||
* Add built-in `esquery` support.
|
||||
* **Internal**
|
||||
* Consolidate notion of "virtual types".
|
||||
|
||||
## 5.2.12
|
||||
|
||||
* **Polish**
|
||||
* Make UID generation based on module declarations **much** nicer.
|
||||
* **Internal**
|
||||
* Remove internal check for traversal path replacement of self. This is a pattern that **could** come up in the wild and it could lead to pretty nasty code and may lead to internal regressions as the test coverage isn't 100% :( Instead, just put it in the fast path.
|
||||
|
||||
## 5.2.11
|
||||
|
||||
* **Internal**
|
||||
|
||||
15
Makefile
15
Makefile
@@ -82,9 +82,15 @@ publish:
|
||||
npm version $$version --message "v%s"
|
||||
|
||||
make build
|
||||
cp dist/babel.min.js browser.js
|
||||
cp dist/polyfill.min.js browser-polyfill.js
|
||||
cp dist/external-helpers.min.js external-helpers.js
|
||||
|
||||
cp dist/babel.js browser.js
|
||||
cp dist/babel.min.js browser.min.js
|
||||
|
||||
cp dist/polyfill.js browser-polyfill.js
|
||||
cp dist/polyfill.min.js browser-polyfill.min.js
|
||||
|
||||
cp dist/external-helpers.js external-helpers.js
|
||||
cp dist/external-helpers.min.js external-helpers.min.js
|
||||
|
||||
node tools/cache-templates
|
||||
test -f templates.json
|
||||
@@ -96,7 +102,7 @@ publish:
|
||||
make publish-cli
|
||||
make publish-runtime
|
||||
|
||||
rm -rf templates.json browser.js browser-polyfill.js external-helpers.js
|
||||
rm -rf templates.json browser.js browser.min.js browser-polyfill.js browser-polyfill.min.js external-helpers.js external-helpers.min.js
|
||||
|
||||
publish-runtime:
|
||||
cd packages; \
|
||||
@@ -116,5 +122,4 @@ bootstrap:
|
||||
npm link
|
||||
cd packages/babel-cli && npm install && npm link && npm link babel-core
|
||||
git submodule update --init
|
||||
cd vendor/compat-table && npm install object-assign
|
||||
make build
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
{
|
||||
"name": "babel-core",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "5.2.12",
|
||||
"version": "5.4.0",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"license": "MIT",
|
||||
"repository": "babel/babel",
|
||||
"main": "lib/babel/api/node.js",
|
||||
"browser": {
|
||||
@@ -35,7 +36,8 @@
|
||||
"core-js": "^0.9.0",
|
||||
"debug": "^2.1.1",
|
||||
"detect-indent": "^3.0.0",
|
||||
"estraverse": "^3.0.0",
|
||||
"esquery": "^0.4.0",
|
||||
"estraverse": "^4.0.0",
|
||||
"esutils": "^2.0.0",
|
||||
"fs-readdir-recursive": "^0.1.0",
|
||||
"globals": "^6.4.0",
|
||||
@@ -62,7 +64,7 @@
|
||||
"user-home": "^1.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel": "5.1.13",
|
||||
"babel": "5.3.1",
|
||||
"browserify": "^9.0.8",
|
||||
"chai": "^2.2.0",
|
||||
"eslint": "^0.18.0",
|
||||
|
||||
@@ -55,6 +55,8 @@ babelArgs.forEach(function(arg){
|
||||
case "--harmony_classes":
|
||||
case "--harmony_object_literals":
|
||||
case "--harmony_templates":
|
||||
case "--harmony_rest_parameters":
|
||||
case "--harmony_generators":
|
||||
case "--compiled_keyed_generic_loads":
|
||||
case "--pretenuring_call_new":
|
||||
case "--allocation_site_pretenuring":
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
var outputFileSync = require("output-file-sync");
|
||||
var chokidar = require("chokidar");
|
||||
var slash = require("slash");
|
||||
var path = require("path");
|
||||
var util = require("./util");
|
||||
var fs = require("fs");
|
||||
@@ -13,8 +14,9 @@ module.exports = function (commander, filenames, opts) {
|
||||
var dest = path.join(commander.outDir, relative);
|
||||
|
||||
var data = util.compile(src, {
|
||||
sourceFileName: path.relative(dest + "/..", src)
|
||||
sourceFileName: slash(path.relative(dest + "/..", src))
|
||||
});
|
||||
if (data.ignored) return;
|
||||
|
||||
if (commander.sourceMaps && commander.sourceMaps !== "inline") {
|
||||
var mapLoc = dest + ".map";
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
var convertSourceMap = require("convert-source-map");
|
||||
var sourceMap = require("source-map");
|
||||
var chokidar = require("chokidar");
|
||||
var slash = require("slash");
|
||||
var path = require("path");
|
||||
var util = require("./util");
|
||||
var fs = require("fs");
|
||||
@@ -15,7 +16,7 @@ module.exports = function (commander, filenames, opts) {
|
||||
|
||||
var buildResult = function () {
|
||||
var map = new sourceMap.SourceMapGenerator({
|
||||
file: commander.outFile || "stdout"
|
||||
file: slash(commander.outFile || "stdout")
|
||||
});
|
||||
|
||||
var code = "";
|
||||
@@ -27,11 +28,12 @@ module.exports = function (commander, filenames, opts) {
|
||||
|
||||
if (result.map) {
|
||||
var consumer = new sourceMap.SourceMapConsumer(result.map);
|
||||
var sourceFilename = filename;
|
||||
|
||||
var sourceFilename = filename;
|
||||
if (commander.outFile) {
|
||||
sourceFilename = path.relative(path.dirname(commander.outFile), sourceFilename);
|
||||
}
|
||||
sourceFilename = slash(sourceFilename);
|
||||
|
||||
map._sources.add(sourceFilename);
|
||||
map.setSourceContent(sourceFilename, result.actual);
|
||||
@@ -114,7 +116,9 @@ module.exports = function (commander, filenames, opts) {
|
||||
_.each(_filenames, function (filename) {
|
||||
if (util.shouldIgnore(filename)) return;
|
||||
|
||||
results.push(util.compile(filename));
|
||||
var data = util.compile(filename);
|
||||
if (data.ignored) return;
|
||||
results.push(data);
|
||||
});
|
||||
|
||||
output();
|
||||
|
||||
@@ -70,6 +70,12 @@ commander.parse(process.argv);
|
||||
|
||||
//
|
||||
|
||||
if (commander.extensions) {
|
||||
commander.extensions = util.arrayify(commander.extensions);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
var errors = [];
|
||||
|
||||
var filenames = commander.args.reduce(function (globbed, input) {
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
{
|
||||
"name": "babel",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "5.2.11",
|
||||
"version": "5.3.3",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"license": "MIT",
|
||||
"repository": "babel/babel",
|
||||
"preferGlobal": true,
|
||||
"dependencies": {
|
||||
"babel-core": "^5.2.11",
|
||||
"babel-core": "^5.3.3",
|
||||
"chokidar": "^1.0.0",
|
||||
"commander": "^2.6.0",
|
||||
"convert-source-map": "^1.1.0",
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
{
|
||||
"name": "babel-runtime",
|
||||
"description": "babel selfContained runtime",
|
||||
"version": "5.2.11",
|
||||
"version": "5.3.3",
|
||||
"license": "MIT",
|
||||
"repository": "babel/babel",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"dependencies": {
|
||||
|
||||
48
sebmck-bjs.nfo
Normal file
48
sebmck-bjs.nfo
Normal file
@@ -0,0 +1,48 @@
|
||||
|
||||
====== ==========M=
|
||||
============= == ======O= ======= MM ==
|
||||
M==+=== ==M === ==== == === ==
|
||||
=D === === ====MM ==M ==M ==M ===
|
||||
===M ====M ==== =D ===M === === ==
|
||||
==7 ====M ==M == ======== =========M ==M
|
||||
=========== ======M ===MMM === ==M ==
|
||||
=======MM==========MM== ==M ==M=== ==
|
||||
==M === M== ==M == === === =D =
|
||||
==M ===+ == == == ==$M =========== ============M
|
||||
=== ====M == ==M ===M== ====?MMMM M M
|
||||
== ===== ==M == ==MM M
|
||||
==M===M=M =M =MM M M
|
||||
==MM=M ==
|
||||
MMM =M
|
||||
M
|
||||
|
||||
> ú B ú A ú B ú E ú L ú <
|
||||
ÕÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÑÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͸
|
||||
³ SOFTWARE .. : JavaScript Compiler ³ COMPANY ... : N/A ³
|
||||
³ SUPPLIER .. : N/A ³ CRACKER ... : Sebastian McKenzie ³
|
||||
³ RATING .... : depends.. ³ PACKAGER .. : Sebastian McKenzie ³
|
||||
³ ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ³
|
||||
³ GRAFIX .... : - ³ SOUND ..... : - ³
|
||||
ÔÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÏÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ;
|
||||
|
||||
Babel is a JavaScript compiler and transformation platform for writing NeXt
|
||||
GeNeRaTiOn JavaScript.
|
||||
|
||||
ÆÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÏÍÍÍÍÍÍÍÍÍÍÍÍÍÍÏÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÏÍÍÍÍÍÍÍÏÍÍÍÍÍÍÍÍÍÍÍ͵
|
||||
³ :: Greets :: ³
|
||||
³ ³
|
||||
³ sebmck, thejameskyle, RReverser, zloirock, monsanto, gaearon, zertosh, ³
|
||||
³ stefanpenner, eventualbuddha, AluisioASG, Apoxx, Couto, dominicbarnes, ³
|
||||
³ es128, gordonkristan, hkjels, jmeas, josh, loganfsmyth, nightire, ³
|
||||
³ Rich-Harris, shinnn, shuhei, sindresorhus, tricknotes ³
|
||||
³ ³
|
||||
ÔÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ;
|
||||
|
||||
-*- JavaScripts for all , All for JavaScripts ! -*-
|
||||
|
||||
ÕÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͸
|
||||
³ If you want to Contact us, call 555-720-4228, Use the Handle "BABEL" w/ ³
|
||||
³ password : VISITOR and leave a mail to Sebastian or James. ³
|
||||
ÔÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ;
|
||||
|
||||
-=- We LoVe fun Too! -=-
|
||||
@@ -153,10 +153,15 @@ pp.flow_parseTypeAlias = function (node) {
|
||||
node.typeParameters = null
|
||||
}
|
||||
|
||||
var oldInType = this.inType;
|
||||
this.inType = true;
|
||||
|
||||
this.expect(tt.eq)
|
||||
|
||||
node.right = this.flow_parseType()
|
||||
|
||||
this.inType = oldInType;
|
||||
|
||||
this.semicolon()
|
||||
|
||||
return this.finishNode(node, "TypeAlias")
|
||||
|
||||
@@ -214,7 +214,12 @@ pp.parseExprSubscripts = function(refShorthandDefaultPos) {
|
||||
}
|
||||
|
||||
pp.parseSubscripts = function(base, start, noCalls) {
|
||||
if (this.eat(tt.dot)) {
|
||||
if (!noCalls && this.eat(tt.doubleColon)) {
|
||||
let node = this.startNodeAt(start)
|
||||
node.object = base
|
||||
node.callee = this.parseNoCallExpr()
|
||||
return this.parseSubscripts(this.finishNode(node, "BindExpression"), start, noCalls)
|
||||
} else if (this.eat(tt.dot)) {
|
||||
let node = this.startNodeAt(start)
|
||||
node.object = base
|
||||
node.property = this.parseIdent(true)
|
||||
@@ -240,6 +245,13 @@ pp.parseSubscripts = function(base, start, noCalls) {
|
||||
} return base
|
||||
}
|
||||
|
||||
// Parse a no-call expression (like argument of `new` or `::` operators).
|
||||
|
||||
pp.parseNoCallExpr = function() {
|
||||
let start = this.markPosition()
|
||||
return this.parseSubscripts(this.parseExprAtom(), start, true)
|
||||
}
|
||||
|
||||
// Parse an atomic expression — either a single token that is an
|
||||
// expression, an expression started by a keyword like `function` or
|
||||
// `new`, or an expression wrapped in punctuation like `()`, `[]`,
|
||||
@@ -363,6 +375,15 @@ pp.parseExprAtom = function(refShorthandDefaultPos) {
|
||||
case tt.backQuote:
|
||||
return this.parseTemplate()
|
||||
|
||||
case tt.doubleColon:
|
||||
node = this.startNode()
|
||||
this.next()
|
||||
node.object = null
|
||||
let callee = node.callee = this.parseNoCallExpr()
|
||||
if (callee.type !== "MemberExpression")
|
||||
this.raise(callee.start, "Binding should be performed on object property.")
|
||||
return this.finishNode(node, "BindExpression")
|
||||
|
||||
default:
|
||||
this.unexpected()
|
||||
}
|
||||
@@ -472,9 +493,11 @@ pp.parseNew = function() {
|
||||
this.raise(node.property.start, "The only valid meta property for new is new.target")
|
||||
return this.finishNode(node, "MetaProperty")
|
||||
}
|
||||
let start = this.markPosition()
|
||||
node.callee = this.parseSubscripts(this.parseExprAtom(), start, true)
|
||||
if (this.eat(tt.parenL)) node.arguments = this.parseExprList(tt.parenR, false)
|
||||
node.callee = this.parseNoCallExpr()
|
||||
if (this.eat(tt.parenL)) node.arguments = this.parseExprList(
|
||||
tt.parenR,
|
||||
this.options.features["es7.trailingFunctionCommas"]
|
||||
)
|
||||
else node.arguments = empty
|
||||
return this.finishNode(node, "NewExpression")
|
||||
}
|
||||
@@ -632,7 +655,7 @@ pp.parseMethod = function(isGenerator, isAsync) {
|
||||
let node = this.startNode()
|
||||
this.initFunction(node, isAsync)
|
||||
this.expect(tt.parenL)
|
||||
node.params = this.parseBindingList(tt.parenR, false, false)
|
||||
node.params = this.parseBindingList(tt.parenR, false, this.options.features["es7.trailingFunctionCommas"])
|
||||
if (this.options.ecmaVersion >= 6) {
|
||||
node.generator = isGenerator
|
||||
}
|
||||
|
||||
@@ -14,7 +14,11 @@ var STATE_KEYS = [
|
||||
"pos",
|
||||
"end",
|
||||
"type",
|
||||
"value"
|
||||
"value",
|
||||
"exprAllowed",
|
||||
"potentialArrowAt",
|
||||
"currLine",
|
||||
"input"
|
||||
];
|
||||
|
||||
pp.getState = function () {
|
||||
@@ -23,6 +27,7 @@ pp.getState = function () {
|
||||
var key = STATE_KEYS[i]
|
||||
state[key] = this[key]
|
||||
}
|
||||
state.context = this.context.slice()
|
||||
return state
|
||||
};
|
||||
|
||||
|
||||
@@ -504,7 +504,7 @@ pp.parseClass = function(node, isStatement) {
|
||||
this.parsePropertyName(method)
|
||||
}
|
||||
method.kind = "method"
|
||||
if (!method.computed && !isGenerator) {
|
||||
if (!method.computed && !isGenerator && !isAsync) {
|
||||
if (method.key.type === "Identifier") {
|
||||
if (this.type !== tt.parenL && (method.key.name === "get" || method.key.name === "set")) {
|
||||
method.kind = method.key.name
|
||||
|
||||
@@ -283,7 +283,7 @@ pp.readToken_lt_gt = function(code) { // '<>'
|
||||
}
|
||||
if (next == 33 && code == 60 && this.input.charCodeAt(this.pos + 2) == 45 &&
|
||||
this.input.charCodeAt(this.pos + 3) == 45) {
|
||||
if (this.inModule) unexpected()
|
||||
if (this.inModule) this.unexpected()
|
||||
// `<!--`, an XML-style comment that should be interpreted as a line comment
|
||||
this.skipLineComment(4)
|
||||
this.skipSpace()
|
||||
@@ -320,7 +320,13 @@ pp.getTokenFromCode = function(code) {
|
||||
case 93: ++this.pos; return this.finishToken(tt.bracketR)
|
||||
case 123: ++this.pos; return this.finishToken(tt.braceL)
|
||||
case 125: ++this.pos; return this.finishToken(tt.braceR)
|
||||
case 58: ++this.pos; return this.finishToken(tt.colon)
|
||||
|
||||
case 58:
|
||||
if (this.options.features["es7.functionBind"] && this.input.charCodeAt(this.pos + 1) === 58)
|
||||
return this.finishOp(tt.doubleColon, 2)
|
||||
++this.pos
|
||||
return this.finishToken(tt.colon)
|
||||
|
||||
case 63: ++this.pos; return this.finishToken(tt.question)
|
||||
case 64: ++this.pos; return this.finishToken(tt.at)
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ export const types = {
|
||||
comma: new TokenType(",", beforeExpr),
|
||||
semi: new TokenType(";", beforeExpr),
|
||||
colon: new TokenType(":", beforeExpr),
|
||||
doubleColon: new TokenType("::", beforeExpr),
|
||||
dot: new TokenType("."),
|
||||
question: new TokenType("?", beforeExpr),
|
||||
arrow: new TokenType("=>", beforeExpr),
|
||||
|
||||
@@ -133,6 +133,12 @@ export function AssignmentExpression(node, print) {
|
||||
print(node.right);
|
||||
}
|
||||
|
||||
export function BindExpression(node, print) {
|
||||
print(node.object);
|
||||
this.push("::");
|
||||
print(node.callee);
|
||||
}
|
||||
|
||||
export {
|
||||
AssignmentExpression as BinaryExpression,
|
||||
AssignmentExpression as LogicalExpression,
|
||||
|
||||
@@ -43,13 +43,13 @@ export function JSXElement(node, print) {
|
||||
if (open.selfClosing) return;
|
||||
|
||||
this.indent();
|
||||
each(node.children, (child) => {
|
||||
for (var child of (node.children: Array)) {
|
||||
if (t.isLiteral(child)) {
|
||||
this.push(child.value, true);
|
||||
} else {
|
||||
print(child);
|
||||
}
|
||||
});
|
||||
}
|
||||
this.dedent();
|
||||
|
||||
print(node.closingElement);
|
||||
|
||||
@@ -3,7 +3,7 @@ import * as t from "../../types";
|
||||
|
||||
export function ImportSpecifier(node, print) {
|
||||
print(node.imported);
|
||||
if (node.local && node.local !== node.imported) {
|
||||
if (node.local && node.local.name !== node.imported.name) {
|
||||
this.push(" as ");
|
||||
print(node.local);
|
||||
}
|
||||
@@ -19,7 +19,7 @@ export function ExportDefaultSpecifier(node, print) {
|
||||
|
||||
export function ExportSpecifier(node, print) {
|
||||
print(node.local);
|
||||
if (node.exported && node.local !== node.exported) {
|
||||
if (node.exported && node.local.name !== node.exported.name) {
|
||||
this.push(" as ");
|
||||
print(node.exported);
|
||||
}
|
||||
|
||||
@@ -182,8 +182,8 @@ export function VariableDeclaration(node, print, parent) {
|
||||
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) {
|
||||
for (var declar of (node.declarations: Array)) {
|
||||
if (declar.init) {
|
||||
// has an init so let's split it up over multiple lines
|
||||
hasInits = true;
|
||||
}
|
||||
@@ -191,7 +191,7 @@ export function VariableDeclaration(node, print, parent) {
|
||||
}
|
||||
|
||||
var sep = ",";
|
||||
if (!this.format.compact && hasInits) {
|
||||
if (!this.format.compact && !this.format.concise && hasInits && !this.format.retainLines) {
|
||||
sep += `\n${repeating(" ", node.kind.length + 1)}`;
|
||||
} else {
|
||||
sep += " ";
|
||||
|
||||
@@ -15,15 +15,15 @@ export function TemplateLiteral(node, print) {
|
||||
var quasis = node.quasis;
|
||||
var len = quasis.length;
|
||||
|
||||
each(quasis, (quasi, i) => {
|
||||
print(quasi);
|
||||
for (var i = 0; i < len; i++) {
|
||||
print(quasis[i]);
|
||||
|
||||
if (i + 1 < len) {
|
||||
this.push("${ ");
|
||||
print(node.expressions[i]);
|
||||
this.push(" }");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this._push("`");
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import each from "lodash/collection/each";
|
||||
import * as t from "../../types";
|
||||
|
||||
export function Identifier(node) {
|
||||
this.push(node.name);
|
||||
@@ -39,7 +40,14 @@ export function Property(node, print) {
|
||||
this.push("]");
|
||||
} else {
|
||||
print(node.key);
|
||||
if (node.shorthand) return;
|
||||
|
||||
// shorthand!
|
||||
if (node.shorthand &&
|
||||
(t.isIdentifier(node.key) &&
|
||||
t.isIdentifier(node.value) &&
|
||||
node.key.name === node.value.name)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.push(":");
|
||||
@@ -54,7 +62,8 @@ export function ArrayExpression(node, print) {
|
||||
|
||||
this.push("[");
|
||||
|
||||
each(elems, (elem, i) => {
|
||||
for (var i = 0; i < elems.length; i++) {
|
||||
var elem = elems[i];
|
||||
if (!elem) {
|
||||
// If the array expression ends with a hole, that hole
|
||||
// will be ignored by the interpreter, but if it ends with
|
||||
@@ -67,7 +76,7 @@ export function ArrayExpression(node, print) {
|
||||
print(elem);
|
||||
if (i < len - 1) this.push(",");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.push("]");
|
||||
}
|
||||
|
||||
@@ -105,11 +105,13 @@ class CodeGenerator {
|
||||
|
||||
this.print(ast);
|
||||
|
||||
var comments = [];
|
||||
each(ast.comments, function (comment) {
|
||||
if (!comment._displayed) comments.push(comment);
|
||||
});
|
||||
this._printComments(comments);
|
||||
if (ast.comments) {
|
||||
var comments = [];
|
||||
for (var comment of (ast.comments: Array)) {
|
||||
if (!comment._displayed) comments.push(comment);
|
||||
}
|
||||
this._printComments(comments);
|
||||
}
|
||||
|
||||
return {
|
||||
map: this.map.get(),
|
||||
@@ -249,7 +251,8 @@ class CodeGenerator {
|
||||
|
||||
if (opts.indent) this.indent();
|
||||
|
||||
each(nodes, (node, i) => {
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
var node = nodes[i];
|
||||
print(node, {
|
||||
statement: opts.statement,
|
||||
addNewlines: opts.addNewlines,
|
||||
@@ -263,7 +266,7 @@ class CodeGenerator {
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (opts.indent) this.dedent();
|
||||
}
|
||||
@@ -314,9 +317,9 @@ class CodeGenerator {
|
||||
nodes.push(node.argument);
|
||||
}
|
||||
|
||||
each(nodes, (node) => {
|
||||
for (var node of (nodes: Array)) {
|
||||
comments = comments.concat(this._getComments(key, node));
|
||||
});
|
||||
}
|
||||
|
||||
return comments;
|
||||
}
|
||||
@@ -331,19 +334,21 @@ class CodeGenerator {
|
||||
if (!this.format.comments) return;
|
||||
if (!comments || !comments.length) return;
|
||||
|
||||
each(comments, (comment) => {
|
||||
for (var comment of (comments: Array)) {
|
||||
var skip = false;
|
||||
|
||||
// find the original comment in the ast and set it as displayed
|
||||
each(this.ast.comments, function (origComment) {
|
||||
if (origComment.start === comment.start) {
|
||||
// comment has already been output
|
||||
if (origComment._displayed) skip = true;
|
||||
if (this.ast.comments) {
|
||||
// find the original comment in the ast and set it as displayed
|
||||
for (var origComment of (this.ast.comments: Array)) {
|
||||
if (origComment.start === comment.start) {
|
||||
// comment has already been output
|
||||
if (origComment._displayed) skip = true;
|
||||
|
||||
origComment._displayed = true;
|
||||
return false;
|
||||
origComment._displayed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (skip) return;
|
||||
|
||||
@@ -387,7 +392,7 @@ class CodeGenerator {
|
||||
|
||||
// whitespace after
|
||||
this.newline(this.whitespace.getNewlinesAfter(comment));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
17
src/babel/helpers/merge.js
Normal file
17
src/babel/helpers/merge.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import merge from "lodash/object/merge";
|
||||
|
||||
export default function (dest, src) {
|
||||
if (!dest || !src) return;
|
||||
|
||||
return merge(dest, src, function(a, b) {
|
||||
if (Array.isArray(a)) {
|
||||
var c = a.slice(0);
|
||||
for (var v of b) {
|
||||
if (a.indexOf(v) < 0) {
|
||||
c.push(v);
|
||||
}
|
||||
}
|
||||
return c;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -18,15 +18,15 @@ export const MESSAGES = {
|
||||
modulesIllegalExportName: "Illegal export $1",
|
||||
unknownForHead: "Unknown node type $1 in ForStatement",
|
||||
didYouMean: "Did you mean $1?",
|
||||
evalInStrictMode: "eval is not allowed in strict mode",
|
||||
codeGeneratorDeopt: "Note: The code generator has deoptimised the styling of $1 as it exceeds the max of $2.",
|
||||
missingTemplatesDirectory: "no templates directory - this is most likely the result of a broken `npm publish`. Please report to https://github.com/babel/babel/issues",
|
||||
unsupportedOutputType: "Unsupported output type $1",
|
||||
illegalMethodName: "Illegal method name $1",
|
||||
|
||||
traverseNeedsParent: "Must pass a scope and parentPath unless traversing a Program/File got a $1 node",
|
||||
traverseVerifyRootFunction: "You passed `traverse()` a function when it expected a visitor object, are you sure you didn't mean `{ enter: Function }`?",
|
||||
traverseVerifyVisitorFunction: "Hey! You passed \`traverse()\` a visitor object with the key $1 that's a straight up `Function` instead of `{ enter: Function }`. You need to normalise it with `traverse.explode(visitor)`.",
|
||||
traverseVerifyVisitorProperty: "You passed `traverse()` a visitor object with the property $1 that has the invalid property $2",
|
||||
traverseVerifyNodeType: "You gave us a visitor for the node type $1 but it's not a valid type",
|
||||
|
||||
pluginIllegalKind: "Illegal kind $1 for plugin $2",
|
||||
pluginIllegalPosition: "Illegal position $1 for plugin $2",
|
||||
|
||||
@@ -33,6 +33,9 @@ def("DoExpression")
|
||||
.build("body")
|
||||
.field("body", [def("Statement")]);
|
||||
|
||||
def("Super")
|
||||
.bases("Expression");
|
||||
|
||||
def("ExportDefaultDeclaration")
|
||||
.bases("Declaration")
|
||||
.build("declaration")
|
||||
@@ -69,4 +72,10 @@ def("ExportAllDeclaration")
|
||||
.field("exported", def("Identifier"))
|
||||
.field("source", def("Literal"));
|
||||
|
||||
def("BindExpression")
|
||||
.bases("Expression")
|
||||
.build("object", "callee")
|
||||
.field("object", or(def("Expression"), null))
|
||||
.field("callee", def("Expression"));
|
||||
|
||||
types.finalize();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import stripJsonComments from "strip-json-comments";
|
||||
import merge from "lodash/object/merge";
|
||||
import merge from "../helpers/merge";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
|
||||
@@ -42,17 +42,7 @@ export default function (loc, opts = {}) {
|
||||
opts.babelrc.push(file);
|
||||
|
||||
if (json.breakConfig) return;
|
||||
merge(opts, json, function(a, b) {
|
||||
if (Array.isArray(a)) {
|
||||
var c = a.slice(0);
|
||||
for (var v of b) {
|
||||
if (a.indexOf(v) < 0) {
|
||||
c.push(v);
|
||||
}
|
||||
}
|
||||
return c;
|
||||
}
|
||||
});
|
||||
merge(opts, json);
|
||||
}
|
||||
|
||||
var up = path.dirname(start);
|
||||
|
||||
@@ -4,6 +4,7 @@ import moduleFormatters from "../modules";
|
||||
import PluginManager from "./plugin-manager";
|
||||
import shebangRegex from "shebang-regex";
|
||||
import TraversalPath from "../../traversal/path";
|
||||
import Transformer from "../transformer";
|
||||
import isFunction from "lodash/lang/isFunction";
|
||||
import isAbsolute from "path-is-absolute";
|
||||
import resolveRc from "../../tools/resolve-rc";
|
||||
@@ -18,29 +19,18 @@ import assign from "lodash/object/assign";
|
||||
import Logger from "./logger";
|
||||
import parse from "../../helpers/parse";
|
||||
import Scope from "../../traversal/scope";
|
||||
import merge from "../../helpers/merge";
|
||||
import slash from "slash";
|
||||
import clone from "lodash/lang/clone";
|
||||
import * as util from "../../util";
|
||||
import * as api from "../../api/node";
|
||||
import path from "path";
|
||||
import each from "lodash/collection/each";
|
||||
import * as t from "../../types";
|
||||
|
||||
var checkTransformerVisitor = {
|
||||
exit(node, parent, scope, state) {
|
||||
checkPath(state.stack, this);
|
||||
}
|
||||
};
|
||||
|
||||
function checkPath(stack, path) {
|
||||
each(stack, function (pass) {
|
||||
if (pass.shouldRun || pass.ran) return;
|
||||
pass.checkPath(path);
|
||||
});
|
||||
}
|
||||
|
||||
export default class File {
|
||||
constructor(opts = {}, pipeline) {
|
||||
this.transformerDependencies = {};
|
||||
|
||||
this.dynamicImportTypes = {};
|
||||
this.dynamicImportIds = {};
|
||||
this.dynamicImports = [];
|
||||
@@ -48,8 +38,8 @@ export default class File {
|
||||
this.declarations = {};
|
||||
this.usedHelpers = {};
|
||||
this.dynamicData = {};
|
||||
this.metadata = {};
|
||||
this.data = {};
|
||||
this.uids = {};
|
||||
|
||||
this.pipeline = pipeline;
|
||||
this.log = new Logger(this, opts.filename || "unknown");
|
||||
@@ -96,10 +86,7 @@ export default class File {
|
||||
"interop-require",
|
||||
];
|
||||
|
||||
static soloHelpers = [
|
||||
"ludicrous-proxy-create",
|
||||
"ludicrous-proxy-directory"
|
||||
];
|
||||
static soloHelpers = [];
|
||||
|
||||
static options = require("./options");
|
||||
|
||||
@@ -121,6 +108,9 @@ export default class File {
|
||||
if (!option) this.log.error(`Unknown option: ${key}`, ReferenceError);
|
||||
}
|
||||
|
||||
var envKey = process.env.BABEL_ENV || process.env.NODE_ENV || "development";
|
||||
if (opts.env) merge(opts, opts.env[envKey]);
|
||||
|
||||
for (let key in File.options) {
|
||||
let option = File.options[key];
|
||||
|
||||
@@ -203,7 +193,8 @@ export default class File {
|
||||
var stack = [];
|
||||
|
||||
// build internal transformers
|
||||
each(this.pipeline.transformers, function (transformer, key) {
|
||||
for (var key in this.pipeline.transformers) {
|
||||
var transformer = this.pipeline.transformers[key];
|
||||
var pass = transformers[key] = transformer.buildPass(file);
|
||||
|
||||
if (pass.canTransform()) {
|
||||
@@ -217,7 +208,7 @@ export default class File {
|
||||
transformer.manipulateOptions(file.opts, file);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// init plugins!
|
||||
var beforePlugins = [];
|
||||
@@ -233,8 +224,55 @@ export default class File {
|
||||
}
|
||||
stack = beforePlugins.concat(stack, afterPlugins);
|
||||
|
||||
// register
|
||||
this.transformerStack = stack.concat(secondaryStack);
|
||||
// build transformer stack
|
||||
this.uncollapsedTransformerStack = stack = stack.concat(secondaryStack);
|
||||
|
||||
// build dependency graph
|
||||
for (var pass of (stack: Array)) {
|
||||
for (var dep of (pass.transformer.dependencies: Array)) {
|
||||
this.transformerDependencies[dep] = pass.key;
|
||||
}
|
||||
}
|
||||
|
||||
// collapse stack categories
|
||||
this.transformerStack = this.collapseStack(stack);
|
||||
}
|
||||
|
||||
collapseStack(_stack) {
|
||||
var stack = [];
|
||||
var ignore = [];
|
||||
|
||||
for (let pass of (_stack: Array)) {
|
||||
// been merged
|
||||
if (ignore.indexOf(pass) >= 0) continue;
|
||||
|
||||
var group = pass.transformer.metadata.group;
|
||||
|
||||
// can't merge
|
||||
if (!pass.canTransform() || !group) {
|
||||
stack.push(pass);
|
||||
continue;
|
||||
}
|
||||
|
||||
var mergeStack = [];
|
||||
for (let pass of (_stack: Array)) {
|
||||
if (pass.transformer.metadata.group === group) {
|
||||
mergeStack.push(pass);
|
||||
ignore.push(pass);
|
||||
}
|
||||
}
|
||||
|
||||
var visitors = [];
|
||||
for (let pass of (mergeStack: Array)) {
|
||||
visitors.push(pass.handlers);
|
||||
}
|
||||
var visitor = traverse.visitors.merge(visitors);
|
||||
var mergeTransformer = new Transformer(group, visitor);
|
||||
//console.log(mergeTransformer);
|
||||
stack.push(mergeTransformer.buildPass(this));
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
set(key: string, val): any {
|
||||
@@ -337,6 +375,7 @@ export default class File {
|
||||
ref._generated = true;
|
||||
ref.id = uid;
|
||||
ref.type = "FunctionDeclaration";
|
||||
this.attachAuxiliaryComment(ref);
|
||||
this.path.unshiftContainer("body", ref);
|
||||
} else {
|
||||
ref._compact = true;
|
||||
@@ -357,23 +396,6 @@ export default class File {
|
||||
return err;
|
||||
}
|
||||
|
||||
checkPath(path) {
|
||||
if (Array.isArray(path)) {
|
||||
for (var i = 0; i < path.length; i++) {
|
||||
this.checkPath(path[i]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var stack = this.transformerStack;
|
||||
|
||||
checkPath(stack, path);
|
||||
|
||||
path.traverse(checkTransformerVisitor, {
|
||||
stack: stack
|
||||
});
|
||||
}
|
||||
|
||||
mergeSourceMap(map: Object) {
|
||||
var opts = this.opts;
|
||||
|
||||
@@ -444,16 +466,6 @@ export default class File {
|
||||
this.path = TraversalPath.get(null, null, ast, ast, "program", this);
|
||||
this.scope = this.path.scope;
|
||||
this.ast = ast;
|
||||
|
||||
this.path.traverse({
|
||||
enter(node, parent, scope) {
|
||||
if (this.isScope()) {
|
||||
for (var key in scope.bindings) {
|
||||
scope.bindings[key].setTypeAnnotation();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
addAst(ast) {
|
||||
@@ -461,10 +473,6 @@ export default class File {
|
||||
this._addAst(ast);
|
||||
this.log.debug("End set AST");
|
||||
|
||||
this.log.debug("Start prepass");
|
||||
this.checkPath(this.path);
|
||||
this.log.debug("End prepass");
|
||||
|
||||
this.log.debug("Start module formatter init");
|
||||
var modFormatter = this.moduleFormatter = this.getModuleFormatter(this.opts.modules);
|
||||
if (modFormatter.init && this.transformers["es6.modules"].canTransform()) {
|
||||
@@ -473,9 +481,9 @@ export default class File {
|
||||
this.log.debug("End module formatter init");
|
||||
|
||||
this.call("pre");
|
||||
each(this.transformerStack, function (pass) {
|
||||
for (var pass of (this.transformerStack: Array)) {
|
||||
pass.transform();
|
||||
});
|
||||
}
|
||||
this.call("post");
|
||||
}
|
||||
|
||||
@@ -485,7 +493,8 @@ export default class File {
|
||||
try {
|
||||
if (this.shouldIgnore()) {
|
||||
return {
|
||||
metadata: {},
|
||||
metadata: this.metadata,
|
||||
ignored: true,
|
||||
code: code,
|
||||
map: null,
|
||||
ast: null
|
||||
@@ -540,10 +549,8 @@ export default class File {
|
||||
}
|
||||
|
||||
call(key: string) {
|
||||
var stack = this.transformerStack;
|
||||
for (var i = 0; i < stack.length; i++) {
|
||||
var transformer = stack[i].transformer;
|
||||
var fn = transformer[key];
|
||||
for (var pass of (this.uncollapsedTransformerStack: Array)) {
|
||||
var fn = pass.transformer[key];
|
||||
if (fn) fn(this);
|
||||
}
|
||||
}
|
||||
@@ -580,7 +587,7 @@ export default class File {
|
||||
var ast = this.ast;
|
||||
|
||||
var result = {
|
||||
metadata: {},
|
||||
metadata: this.metadata,
|
||||
code: "",
|
||||
map: null,
|
||||
ast: null
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import * as util from "../../util";
|
||||
import buildDebug from "debug/node";
|
||||
|
||||
var verboseDebug = buildDebug("babel:verbose");
|
||||
var generalDebug = buildDebug("babel");
|
||||
|
||||
export default class Logger {
|
||||
constructor(file: File, filename: string) {
|
||||
@@ -22,11 +25,15 @@ export default class Logger {
|
||||
}
|
||||
}
|
||||
|
||||
verbose(msg: string) {
|
||||
if (verboseDebug.enabled) verboseDebug(this._buildMessage(msg));
|
||||
}
|
||||
|
||||
debug(msg: string) {
|
||||
util.debug(this._buildMessage(msg));
|
||||
if (generalDebug.enabled) generalDebug(this._buildMessage(msg));
|
||||
}
|
||||
|
||||
deopt(node: Object, msg: string) {
|
||||
util.debug(this._buildMessage(msg));
|
||||
this.debug(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,11 @@
|
||||
"default": {}
|
||||
},
|
||||
|
||||
"env": {
|
||||
"hidden": true,
|
||||
"default": {}
|
||||
},
|
||||
|
||||
"moduleId": {
|
||||
"description": "specify a custom name for module ids",
|
||||
"type": "string"
|
||||
@@ -30,7 +35,6 @@
|
||||
},
|
||||
|
||||
"retainLines": {
|
||||
"hidden": true,
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "retain line numbers - will result in really ugly code"
|
||||
|
||||
@@ -57,6 +57,9 @@ export default class PluginManager {
|
||||
if (!plugin.buildPass || plugin.constructor.name !== "Transformer") {
|
||||
throw new TypeError(messages.get("pluginNotTransformer", name));
|
||||
}
|
||||
|
||||
// register as a plugin
|
||||
plugin.metadata.plugin = true;
|
||||
}
|
||||
|
||||
add(name) {
|
||||
@@ -65,7 +68,7 @@ export default class PluginManager {
|
||||
|
||||
if (name) {
|
||||
if (typeof name === "object" && name.transformer) {
|
||||
({ plugin: name, position } = name);
|
||||
({ transformer: plugin, position } = name);
|
||||
} else if (typeof name !== "string") {
|
||||
// not a string so we'll just assume that it's a direct Transformer instance, if not then
|
||||
// the checks later on will complain
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import explode from "./explode-assignable-expression";
|
||||
import * as t from "../../types";
|
||||
|
||||
export default function (exports, opts) {
|
||||
export default function (opts) {
|
||||
var exports = {};
|
||||
|
||||
var isAssignment = function (node) {
|
||||
return node.operator === opts.operator + "=";
|
||||
};
|
||||
@@ -10,10 +12,6 @@ export default function (exports, opts) {
|
||||
return t.assignmentExpression("=", left, right);
|
||||
};
|
||||
|
||||
exports.shouldVisit = function (node) {
|
||||
return node.operator && (node.operator === opts.operator || node.operator === opts.operator + "=");
|
||||
};
|
||||
|
||||
exports.ExpressionStatement = function (node, parent, scope, file) {
|
||||
// hit the `AssignmentExpression` one below
|
||||
if (this.isCompletionRecord()) return;
|
||||
@@ -44,4 +42,6 @@ export default function (exports, opts) {
|
||||
if (node.operator !== opts.operator) return;
|
||||
return opts.build(node.left, node.right);
|
||||
};
|
||||
|
||||
return exports;
|
||||
};
|
||||
|
||||
@@ -10,14 +10,8 @@ import * as react from "./react";
|
||||
import * as t from "../../types";
|
||||
|
||||
export default function (exports, opts) {
|
||||
exports.check = function (node) {
|
||||
if (t.isJSX(node)) return true;
|
||||
if (react.isCreateClass(node)) return true;
|
||||
return false;
|
||||
};
|
||||
|
||||
exports.JSXIdentifier = function (node, parent) {
|
||||
if (node.name === "this" && t.isReferenced(node, parent)) {
|
||||
if (node.name === "this" && this.isReferenced()) {
|
||||
return t.thisExpression();
|
||||
} else if (esutils.keyword.isIdentifierNameES6(node.name)) {
|
||||
node.type = "Identifier";
|
||||
|
||||
@@ -26,7 +26,7 @@ export function push(mutatorMap, node, kind, file) {
|
||||
|
||||
if (node.decorators) {
|
||||
var decorators = map.decorators = map.decorators || t.arrayExpression([]);
|
||||
decorators.elements = decorators.elements.concat(node.decorators.map(dec => dec.expression));
|
||||
decorators.elements = decorators.elements.concat(node.decorators.map(dec => dec.expression).reverse());
|
||||
}
|
||||
|
||||
if (map.value || map.initializer) {
|
||||
|
||||
@@ -26,7 +26,7 @@ var getObjRef = function (node, nodes, file, scope) {
|
||||
throw new Error(`We can't explode this node type ${node.type}`);
|
||||
}
|
||||
|
||||
var temp = scope.generateUidBasedOnNode(ref);
|
||||
var temp = scope.generateUidIdentifierBasedOnNode(ref);
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(temp, ref)
|
||||
]));
|
||||
@@ -38,7 +38,7 @@ var getPropRef = function (node, nodes, file, scope) {
|
||||
var key = t.toComputedKey(node, prop);
|
||||
if (t.isLiteral(key)) return key;
|
||||
|
||||
var temp = scope.generateUidBasedOnNode(prop);
|
||||
var temp = scope.generateUidIdentifierBasedOnNode(prop);
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(temp, prop)
|
||||
]));
|
||||
|
||||
@@ -6,7 +6,7 @@ export default function (decorators, scope) {
|
||||
var expression = decorator.expression;
|
||||
if (!t.isMemberExpression(expression)) continue;
|
||||
|
||||
var temp = scope.generateMemoisedReference(expression.object);
|
||||
var temp = scope.maybeGenerateMemoised(expression.object);
|
||||
var ref;
|
||||
|
||||
var nodes = [];
|
||||
|
||||
@@ -19,7 +19,7 @@ var awaitVisitor = {
|
||||
var referenceVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
var name = state.id.name;
|
||||
if (t.isReferencedIdentifier(node, parent, { name: name }) && scope.bindingIdentifierEquals(name, state.id)) {
|
||||
if (this.isReferencedIdentifier({ name: name }) && scope.bindingIdentifierEquals(name, state.id)) {
|
||||
return state.ref = state.ref || scope.generateUidIdentifier(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,13 @@ var pipeline = new Pipeline;
|
||||
//
|
||||
|
||||
import transformers from "./transformers";
|
||||
|
||||
for (var key in transformers) {
|
||||
var transformer = transformers[key];
|
||||
var metadata = transformer.metadata = transformer.metadata || {};
|
||||
metadata.group = metadata.group || "builtin-basic";
|
||||
}
|
||||
|
||||
pipeline.addTransformers(transformers);
|
||||
|
||||
//
|
||||
|
||||
@@ -7,58 +7,65 @@ import * as t from "../../types";
|
||||
|
||||
var remapVisitor = {
|
||||
enter(node, parent, scope, formatter) {
|
||||
var remap = formatter.internalRemap[node.name];
|
||||
|
||||
if (this.isReferencedIdentifier() && remap && node !== remap) {
|
||||
if (!scope.hasBinding(node.name) || scope.bindingIdentifierEquals(node.name, formatter.localImports[node.name])) {
|
||||
return remap;
|
||||
}
|
||||
}
|
||||
|
||||
if (t.isUpdateExpression(node)) {
|
||||
var exported = formatter.getExport(node.argument, scope);
|
||||
|
||||
if (exported) {
|
||||
this.skip();
|
||||
|
||||
// expand to long file assignment expression
|
||||
var assign = t.assignmentExpression(node.operator[0] + "=", node.argument, t.literal(1));
|
||||
|
||||
// remap this assignment expression
|
||||
var remapped = formatter.remapExportAssignment(assign, exported);
|
||||
|
||||
// we don't need to change the result
|
||||
if (t.isExpressionStatement(parent) || node.prefix) {
|
||||
return remapped;
|
||||
}
|
||||
|
||||
var nodes = [];
|
||||
nodes.push(remapped);
|
||||
|
||||
var operator;
|
||||
if (node.operator === "--") {
|
||||
operator = "+";
|
||||
} else { // "++"
|
||||
operator = "-";
|
||||
}
|
||||
nodes.push(t.binaryExpression(operator, node.argument, t.literal(1)));
|
||||
|
||||
return t.sequenceExpression(nodes);
|
||||
}
|
||||
}
|
||||
|
||||
if (node._skipModulesRemap) {
|
||||
return this.skip();
|
||||
}
|
||||
},
|
||||
|
||||
exit(node, parent, scope, formatter) {
|
||||
if (t.isAssignmentExpression(node) && !node._ignoreModulesRemap) {
|
||||
var exported = formatter.getExport(node.left, scope);
|
||||
if (exported) {
|
||||
return formatter.remapExportAssignment(node, exported);
|
||||
ReferencedIdentifier(node, parent, scope, formatter) {
|
||||
var remap = formatter.internalRemap[node.name];
|
||||
|
||||
if (remap && node !== remap) {
|
||||
if (!scope.hasBinding(node.name) || scope.bindingIdentifierEquals(node.name, formatter.localImports[node.name])) {
|
||||
if (this.key === "callee" && this.parentPath.isCallExpression()) {
|
||||
return t.sequenceExpression([t.literal(0), remap]);
|
||||
} else {
|
||||
return remap;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
AssignmentExpression: {
|
||||
exit(node, parent, scope, formatter) {
|
||||
if (!node._ignoreModulesRemap) {
|
||||
var exported = formatter.getExport(node.left, scope);
|
||||
if (exported) {
|
||||
return formatter.remapExportAssignment(node, exported);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
UpdateExpression(node, parent, scope, formatter) {
|
||||
var exported = formatter.getExport(node.argument, scope);
|
||||
if (!exported) return;
|
||||
|
||||
this.skip();
|
||||
|
||||
// expand to long file assignment expression
|
||||
var assign = t.assignmentExpression(node.operator[0] + "=", node.argument, t.literal(1));
|
||||
|
||||
// remap this assignment expression
|
||||
var remapped = formatter.remapExportAssignment(assign, exported);
|
||||
|
||||
// we don't need to change the result
|
||||
if (t.isExpressionStatement(parent) || node.prefix) {
|
||||
return remapped;
|
||||
}
|
||||
|
||||
var nodes = [];
|
||||
nodes.push(remapped);
|
||||
|
||||
var operator;
|
||||
if (node.operator === "--") {
|
||||
operator = "+";
|
||||
} else { // "++"
|
||||
operator = "-";
|
||||
}
|
||||
nodes.push(t.binaryExpression(operator, node.argument, t.literal(1)));
|
||||
|
||||
return t.sequenceExpression(nodes);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -71,7 +78,7 @@ var importsVisitor = {
|
||||
}
|
||||
};
|
||||
|
||||
var exportsVisitor = traverse.explode({
|
||||
var exportsVisitor = {
|
||||
ExportDeclaration: {
|
||||
enter(node, parent, scope, formatter) {
|
||||
formatter.hasLocalExports = true;
|
||||
@@ -103,7 +110,7 @@ var exportsVisitor = traverse.explode({
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export default class DefaultFormatter {
|
||||
constructor(file) {
|
||||
|
||||
@@ -52,7 +52,7 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
||||
} else if (this.noInteropRequireImport) {
|
||||
this.internalRemap[variableName.name] = t.memberExpression(ref, t.identifier("default"));
|
||||
} else {
|
||||
var uid = this.scope.generateUidBasedOnNode(node, "import");
|
||||
var uid = this.scope.generateUidIdentifierBasedOnNode(node, "import");
|
||||
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(uid, t.callExpression(this.file.addHelper("interop-require-default"), [ref]))
|
||||
@@ -111,7 +111,7 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
||||
} else if (this.isModuleType(node, "absoluteDefault")) {
|
||||
call = t.memberExpression(call, t.identifier("default"));
|
||||
} else {
|
||||
uid = this.scope.generateUidBasedOnNode(node, "import");
|
||||
uid = this.scope.generateUidIdentifierBasedOnNode(node, "import");
|
||||
}
|
||||
|
||||
uid = uid || node.specifiers[0].local;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import DefaultFormatter from "./_default";
|
||||
import AMDFormatter from "./amd";
|
||||
import object from "../../helpers/object";
|
||||
import * as util from "../../util";
|
||||
import last from "lodash/array/last";
|
||||
import each from "lodash/collection/each";
|
||||
@@ -20,7 +21,7 @@ var hoistVariablesVisitor = {
|
||||
}
|
||||
|
||||
// ignore block hoisted nodes as these can be left in
|
||||
if (state.formatter.canHoist(node)) return;
|
||||
if (state.formatter._canHoist(node)) return;
|
||||
|
||||
var nodes = [];
|
||||
|
||||
@@ -49,7 +50,7 @@ var hoistFunctionsVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (t.isFunction(node)) this.skip();
|
||||
|
||||
if (t.isFunctionDeclaration(node) || state.formatter.canHoist(node)) {
|
||||
if (t.isFunctionDeclaration(node) || state.formatter._canHoist(node)) {
|
||||
state.handlerBody.push(node);
|
||||
this.remove();
|
||||
}
|
||||
@@ -60,12 +61,12 @@ var runnerSettersVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (node._importSource === state.source) {
|
||||
if (t.isVariableDeclaration(node)) {
|
||||
each(node.declarations, function (declar) {
|
||||
for (var declar of (node.declarations: Array)) {
|
||||
state.hoistDeclarators.push(t.variableDeclarator(declar.id));
|
||||
state.nodes.push(t.expressionStatement(
|
||||
t.assignmentExpression("=", declar.id, declar.init)
|
||||
));
|
||||
});
|
||||
}
|
||||
} else {
|
||||
state.nodes.push(node);
|
||||
}
|
||||
@@ -100,14 +101,14 @@ export default class SystemFormatter extends AMDFormatter {
|
||||
var right = objectIdentifier;
|
||||
|
||||
var block = t.blockStatement([
|
||||
t.expressionStatement(this.buildExportCall(leftIdentifier, valIdentifier))
|
||||
t.expressionStatement(this._buildExportCall(leftIdentifier, valIdentifier))
|
||||
]);
|
||||
|
||||
return this._addImportSource(t.forInStatement(left, right, block), node);
|
||||
}
|
||||
|
||||
buildExportsAssignment(id, init, node) {
|
||||
var call = this.buildExportCall(t.literal(id.name), init, true);
|
||||
var call = this._buildExportCall(t.literal(id.name), init, true);
|
||||
return this._addImportSource(call, node);
|
||||
}
|
||||
|
||||
@@ -119,13 +120,13 @@ export default class SystemFormatter extends AMDFormatter {
|
||||
var assign = node;
|
||||
|
||||
for (var i = 0; i < exported.length; i++) {
|
||||
assign = this.buildExportCall(t.literal(exported[i].name), assign);
|
||||
assign = this._buildExportCall(t.literal(exported[i].name), assign);
|
||||
}
|
||||
|
||||
return assign;
|
||||
}
|
||||
|
||||
buildExportCall(id, init, isStatement) {
|
||||
_buildExportCall(id, init, isStatement) {
|
||||
var call = t.callExpression(this.exportIdentifier, [id, init]);
|
||||
if (isStatement) {
|
||||
return t.expressionStatement(call);
|
||||
@@ -143,12 +144,12 @@ export default class SystemFormatter extends AMDFormatter {
|
||||
]));
|
||||
}
|
||||
|
||||
this.internalRemap = {};
|
||||
this.internalRemap = object();
|
||||
|
||||
this._addImportSource(last(nodes), node);
|
||||
}
|
||||
|
||||
buildRunnerSetters(block, hoistDeclarators) {
|
||||
_buildRunnerSetters(block, hoistDeclarators) {
|
||||
var scope = this.file.scope;
|
||||
|
||||
return t.arrayExpression(map(this.ids, function (uid, source) {
|
||||
@@ -164,7 +165,7 @@ export default class SystemFormatter extends AMDFormatter {
|
||||
}));
|
||||
}
|
||||
|
||||
canHoist(node) {
|
||||
_canHoist(node) {
|
||||
return node._blockHoist && !this.file.dynamicImports.length;
|
||||
}
|
||||
|
||||
@@ -181,7 +182,7 @@ export default class SystemFormatter extends AMDFormatter {
|
||||
MODULE_DEPENDENCIES: t.arrayExpression(this.buildDependencyLiterals()),
|
||||
EXPORT_IDENTIFIER: this.exportIdentifier,
|
||||
MODULE_NAME: moduleNameLiteral,
|
||||
SETTERS: this.buildRunnerSetters(block, hoistDeclarators),
|
||||
SETTERS: this._buildRunnerSetters(block, hoistDeclarators),
|
||||
EXECUTE: t.functionExpression(null, [], block)
|
||||
}, true);
|
||||
|
||||
|
||||
@@ -28,8 +28,9 @@
|
||||
|
||||
if (descriptor.initializer) {
|
||||
descriptor.value = descriptor.initializer.call(target);
|
||||
Object.defineProperty(target, key, descriptor);
|
||||
}
|
||||
|
||||
Object.defineProperty(target, key, descriptor);
|
||||
}
|
||||
|
||||
return target;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
(function (target, key, descriptors) {
|
||||
var _descriptor = descriptors[key];
|
||||
if (!_descriptor) return;
|
||||
|
||||
// clone it
|
||||
var descriptor = {};
|
||||
for (var _key in _descriptor) descriptor[_key] = _descriptor[_key];
|
||||
|
||||
// initialize it
|
||||
if (!descriptor.initializer) return;
|
||||
descriptor.value = descriptor.initializer.call(target);
|
||||
|
||||
Object.defineProperty(target, key, descriptor);
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
Object(RIGHT)[LEFT] !== undefined;
|
||||
@@ -1,4 +0,0 @@
|
||||
(function (proxy, directory) {
|
||||
directory.push(proxy);
|
||||
return proxy;
|
||||
})
|
||||
@@ -1 +0,0 @@
|
||||
[];
|
||||
@@ -1,3 +1,3 @@
|
||||
for (var LEN = ARGUMENTS.length, ARRAY = Array(ARRAY_LEN), KEY = START; KEY < LEN; KEY++) {
|
||||
for (var LEN = ARGUMENTS.length, ARRAY: ARRAY_TYPE = Array(ARRAY_LEN), KEY = START; KEY < LEN; KEY++) {
|
||||
ARRAY[ARRAY_KEY] = ARGUMENTS[KEY];
|
||||
}
|
||||
|
||||
@@ -8,34 +8,26 @@ import traverse from "../traversal";
|
||||
|
||||
export default class TransformerPass {
|
||||
constructor(file: File, transformer: Transformer) {
|
||||
this.shouldTransform = !transformer.shouldVisit;
|
||||
this.transformer = transformer;
|
||||
this.handlers = transformer.handlers;
|
||||
this.skipKey = transformer.skipKey;
|
||||
this.file = file;
|
||||
this.ran = false;
|
||||
this.transformer = transformer;
|
||||
this.handlers = transformer.handlers;
|
||||
this.file = file;
|
||||
this.ran = false;
|
||||
this.key = transformer.key;
|
||||
}
|
||||
|
||||
canTransform(): boolean {
|
||||
return this.file.pipeline.canTransform(this.transformer, this.file.opts);
|
||||
}
|
||||
|
||||
checkPath(path: TraversalPath): boolean {
|
||||
if (this.shouldTransform || this.ran) return;
|
||||
|
||||
this.shouldTransform = this.transformer.shouldVisit(path.node);
|
||||
return this.file.transformerDependencies[this.key] ||
|
||||
this.file.pipeline.canTransform(this.transformer, this.file.opts);
|
||||
}
|
||||
|
||||
transform() {
|
||||
if (!this.shouldTransform) return;
|
||||
|
||||
var file = this.file;
|
||||
|
||||
file.log.debug(`Start transformer ${this.transformer.key}`);
|
||||
file.log.debug(`Start transformer ${this.key}`);
|
||||
|
||||
traverse(file.ast, this.handlers, file.scope, file);
|
||||
|
||||
file.log.debug(`Finish transformer ${this.transformer.key}`);
|
||||
file.log.debug(`Finish transformer ${this.key}`);
|
||||
|
||||
this.ran = true;
|
||||
}
|
||||
|
||||
@@ -47,6 +47,8 @@ export default class TransformerPipeline {
|
||||
}
|
||||
|
||||
canTransform(transformer, fileOpts) {
|
||||
if (transformer.metadata.plugin) return true;
|
||||
|
||||
for (var filter of (this.filters: Array)) {
|
||||
var result = filter(transformer, fileOpts);
|
||||
if (result != null) return result;
|
||||
|
||||
@@ -25,8 +25,8 @@ export default class Transformer {
|
||||
};
|
||||
|
||||
this.manipulateOptions = take("manipulateOptions");
|
||||
this.shouldVisit = take("shouldVisit");
|
||||
this.metadata = take("metadata") || {};
|
||||
this.dependencies = this.metadata.dependencies || [];
|
||||
this.parser = take("parser");
|
||||
this.post = take("post");
|
||||
this.pre = take("pre");
|
||||
@@ -41,18 +41,6 @@ export default class Transformer {
|
||||
|
||||
this.handlers = this.normalize(transformer);
|
||||
this.key = transformerKey;
|
||||
|
||||
//
|
||||
|
||||
if (!this.shouldVisit) {
|
||||
var types = Object.keys(this.handlers);
|
||||
this.shouldVisit = function (node) {
|
||||
for (var i = 0; i < types.length; i++) {
|
||||
if (node.type === types[i]) return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
normalize(transformer: Object): Object {
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
"es6.symbols": "es6.spec.symbols",
|
||||
"es6.blockScopingTDZ": "es6.spec.blockScoping",
|
||||
|
||||
"utility.inlineExpressions": "minification.inlineExpressions",
|
||||
"utility.deadCodeElimination": "minification.deadCodeElimination",
|
||||
"minification.removeConsoleCalls": "utility.removeConsole",
|
||||
"minification.removeDebugger": "utility.removeDebugger"
|
||||
"utility.removeConsoleCalls": "minification.removeConsole",
|
||||
"utility.removeDebugger": "minification.removeDebugger"
|
||||
}
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export function MemberExpression(node) {
|
||||
var prop = node.property;
|
||||
if (!node.computed && t.isIdentifier(prop) && !t.isValidIdentifier(prop.name)) {
|
||||
// foo.default -> foo["default"]
|
||||
node.property = t.literal(prop.name);
|
||||
node.computed = true;
|
||||
export var metadata = {
|
||||
group: "builtin-trailing"
|
||||
};
|
||||
|
||||
export var MemberExpression = {
|
||||
exit(node) {
|
||||
var prop = node.property;
|
||||
if (!node.computed && t.isIdentifier(prop) && !t.isValidIdentifier(prop.name)) {
|
||||
// foo.default -> foo["default"]
|
||||
node.property = t.literal(prop.name);
|
||||
node.computed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export function Property(node) {
|
||||
var key = node.key;
|
||||
if (!node.computed && t.isIdentifier(key) && !t.isValidIdentifier(key.name)) {
|
||||
// default: "bar" -> "default": "bar"
|
||||
node.key = t.literal(key.name);
|
||||
export var metadata = {
|
||||
group: "builtin-trailing"
|
||||
};
|
||||
|
||||
export var Property = {
|
||||
exit(node) {
|
||||
var key = node.key;
|
||||
if (!node.computed && t.isIdentifier(key) && !t.isValidIdentifier(key.name)) {
|
||||
// default: "bar" -> "default": "bar"
|
||||
node.key = t.literal(key.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import * as defineMap from "../../helpers/define-map";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export function shouldVisit(node) {
|
||||
return t.isProperty(node) && (node.kind === "get" || node.kind === "set");
|
||||
}
|
||||
|
||||
export function ObjectExpression(node, parent, scope, file) {
|
||||
var mutatorMap = {};
|
||||
var hasAny = false;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var shouldVisit = t.isArrowFunctionExpression;
|
||||
|
||||
export function ArrowFunctionExpression(node) {
|
||||
t.ensureBlock(node);
|
||||
|
||||
|
||||
@@ -32,14 +32,14 @@ function isVar(node, parent) {
|
||||
}
|
||||
|
||||
function standardizeLets(declars) {
|
||||
for (var i = 0; i < declars.length; i++) {
|
||||
delete declars[i]._let;
|
||||
for (var declar of (declars: Array)) {
|
||||
delete declar._let;
|
||||
}
|
||||
}
|
||||
|
||||
export function shouldVisit(node) {
|
||||
return t.isVariableDeclaration(node) && (node.kind === "let" || node.kind === "const");
|
||||
}
|
||||
export var metadata = {
|
||||
group: "builtin-advanced"
|
||||
};
|
||||
|
||||
export function VariableDeclaration(node, parent, scope, file) {
|
||||
if (!isLet(node, parent)) return;
|
||||
@@ -109,19 +109,14 @@ function traverseReplace(node, parent, scope, remaps) {
|
||||
}
|
||||
|
||||
var letReferenceBlockVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (this.isFunction()) {
|
||||
this.traverse(letReferenceFunctionVisitor, state);
|
||||
return this.skip();
|
||||
}
|
||||
Function(node, parent, scope, state) {
|
||||
this.traverse(letReferenceFunctionVisitor, state);
|
||||
return this.skip();
|
||||
}
|
||||
};
|
||||
|
||||
var letReferenceFunctionVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
// not a direct reference
|
||||
if (!this.isReferencedIdentifier()) return;
|
||||
|
||||
ReferencedIdentifier(node, parent, scope, state) {
|
||||
var ref = state.letReferences[node.name];
|
||||
|
||||
// not a part of our scope
|
||||
@@ -159,10 +154,8 @@ var hoistVarDeclarationsVisitor = {
|
||||
};
|
||||
|
||||
var loopLabelVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (this.isLabeledStatement()) {
|
||||
state.innerLabels.push(node.label.name);
|
||||
}
|
||||
LabeledStatement(node, parent, scope, state) {
|
||||
state.innerLabels.push(node.label.name);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -187,19 +180,28 @@ var loopNodeTo = function (node) {
|
||||
};
|
||||
|
||||
var loopVisitor = {
|
||||
Loop(node, parent, scope, state) {
|
||||
var oldIgnoreLabeless = state.ignoreLabeless;
|
||||
state.ignoreLabeless = true;
|
||||
this.traverse(loopVisitor, state);
|
||||
state.ignoreLabeless = oldIgnoreLabeless;
|
||||
this.skip();
|
||||
},
|
||||
|
||||
Function() {
|
||||
this.skip();
|
||||
},
|
||||
|
||||
SwitchCase(node, parent, scope, state) {
|
||||
var oldInSwitchCase = state.inSwitchCase;
|
||||
state.inSwitchCase = true;
|
||||
this.traverse(loopVisitor, state);
|
||||
state.inSwitchCase = oldInSwitchCase;
|
||||
this.skip();
|
||||
},
|
||||
|
||||
enter(node, parent, scope, state) {
|
||||
var replace;
|
||||
|
||||
if (this.isLoop()) {
|
||||
state.ignoreLabeless = true;
|
||||
this.traverse(loopVisitor, state);
|
||||
state.ignoreLabeless = false;
|
||||
}
|
||||
|
||||
if (this.isFunction() || this.isLoop()) {
|
||||
return this.skip();
|
||||
}
|
||||
|
||||
var loopText = loopNodeTo(node);
|
||||
|
||||
if (loopText) {
|
||||
@@ -215,6 +217,9 @@ var loopVisitor = {
|
||||
// they don't refer to the actual loop we're scopifying
|
||||
if (state.ignoreLabeless) return;
|
||||
|
||||
//
|
||||
if (state.inSwitchCase) return;
|
||||
|
||||
// break statements mean something different in this context
|
||||
if (t.isBreakStatement(node) && t.isSwitchCase(parent)) return;
|
||||
}
|
||||
@@ -233,6 +238,7 @@ var loopVisitor = {
|
||||
|
||||
if (replace) {
|
||||
replace = t.returnStatement(replace);
|
||||
this.skip();
|
||||
return t.inherits(replace, node);
|
||||
}
|
||||
}
|
||||
@@ -467,18 +473,17 @@ class BlockScoping {
|
||||
var block = this.block;
|
||||
|
||||
var declarators = block._letDeclarators || [];
|
||||
var declar;
|
||||
|
||||
//
|
||||
for (let i = 0; i < declarators.length; i++) {
|
||||
declar = declarators[i];
|
||||
let declar = declarators[i];
|
||||
extend(this.outsideLetReferences, t.getBindingIdentifiers(declar));
|
||||
}
|
||||
|
||||
//
|
||||
if (block.body) {
|
||||
for (let i = 0; i < block.body.length; i++) {
|
||||
declar = block.body[i];
|
||||
let declar = block.body[i];
|
||||
if (isLet(declar, block)) {
|
||||
declarators = declarators.concat(declar.declarations);
|
||||
}
|
||||
@@ -487,7 +492,7 @@ class BlockScoping {
|
||||
|
||||
//
|
||||
for (let i = 0; i < declarators.length; i++) {
|
||||
declar = declarators[i];
|
||||
let declar = declarators[i];
|
||||
var keys = t.getBindingIdentifiers(declar);
|
||||
extend(this.letReferences, keys);
|
||||
this.hasLetReferences = true;
|
||||
@@ -524,6 +529,7 @@ class BlockScoping {
|
||||
var state = {
|
||||
hasBreakContinue: false,
|
||||
ignoreLabeless: false,
|
||||
inSwitchCase: false,
|
||||
innerLabels: [],
|
||||
hasReturn: false,
|
||||
isLoop: !!this.loop,
|
||||
@@ -551,9 +557,13 @@ class BlockScoping {
|
||||
*/
|
||||
|
||||
pushDeclar(node: { type: "VariableDeclaration" }): Array<Object> {
|
||||
this.body.push(t.variableDeclaration(node.kind, node.declarations.map(function (declar) {
|
||||
return t.variableDeclarator(declar.id);
|
||||
})));
|
||||
var declars = [];
|
||||
var names = t.getBindingIdentifiers(node);
|
||||
for (var name in names) {
|
||||
declars.push(t.variableDeclarator(names[name]));
|
||||
}
|
||||
|
||||
this.body.push(t.variableDeclaration(node.kind, declars));
|
||||
|
||||
var replace = [];
|
||||
|
||||
|
||||
@@ -11,8 +11,6 @@ import * as t from "../../../types";
|
||||
|
||||
const PROPERTY_COLLISION_METHOD_NAME = "__initializeProperties";
|
||||
|
||||
export var shouldVisit = t.isClass;
|
||||
|
||||
export function ClassDeclaration(node, parent, scope, file) {
|
||||
return t.variableDeclaration("let", [
|
||||
t.variableDeclarator(node.id, t.toExpression(node))
|
||||
@@ -37,7 +35,7 @@ var collectPropertyReferencesVisitor = {
|
||||
}
|
||||
};
|
||||
|
||||
var constructorVisitor = traverse.explode({
|
||||
var constructorVisitor = {
|
||||
ThisExpression: {
|
||||
enter(node, parent, scope, ref) {
|
||||
return ref;
|
||||
@@ -51,9 +49,9 @@ var constructorVisitor = traverse.explode({
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var verifyConstructorVisitor = traverse.explode({
|
||||
var verifyConstructorVisitor = {
|
||||
MethodDefinition: {
|
||||
enter() {
|
||||
this.skip();
|
||||
@@ -98,7 +96,7 @@ var verifyConstructorVisitor = traverse.explode({
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
class ClassTransformer {
|
||||
|
||||
@@ -175,7 +173,7 @@ class ClassTransformer {
|
||||
if (this.hasSuper) {
|
||||
closureArgs.push(superName);
|
||||
|
||||
superName = this.scope.generateUidBasedOnNode(superName);
|
||||
superName = this.scope.generateUidIdentifierBasedOnNode(superName);
|
||||
closureParams.push(superName);
|
||||
|
||||
this.superName = superName;
|
||||
@@ -314,7 +312,7 @@ class ClassTransformer {
|
||||
if (isConstructor) {
|
||||
this.pushConstructor(node, path);
|
||||
} else {
|
||||
this.pushMethod(node);
|
||||
this.pushMethod(node, path);
|
||||
}
|
||||
} else if (t.isClassProperty(node)) {
|
||||
this.pushProperty(node);
|
||||
@@ -412,7 +410,7 @@ class ClassTransformer {
|
||||
this.pushMethod(t.methodDefinition(
|
||||
t.identifier(PROPERTY_COLLISION_METHOD_NAME),
|
||||
t.functionExpression(null, [], t.blockStatement(body))
|
||||
), true);
|
||||
), null, true);
|
||||
|
||||
if (this.hasSuper) {
|
||||
this.bareSuper.insertAfter(call);
|
||||
@@ -473,15 +471,15 @@ class ClassTransformer {
|
||||
* Push a method to its respective mutatorMap.
|
||||
*/
|
||||
|
||||
pushMethod(node: { type: "MethodDefinition" }, allowedIllegal?) {
|
||||
pushMethod(node: { type: "MethodDefinition" }, path?: TraversalPath, allowedIllegal?) {
|
||||
if (!allowedIllegal && t.isLiteral(t.toComputedKey(node), { value: PROPERTY_COLLISION_METHOD_NAME })) {
|
||||
throw this.file.errorWithNode(node, messages.get("illegalMethodName", PROPERTY_COLLISION_METHOD_NAME));
|
||||
}
|
||||
|
||||
if (node.kind === "method") {
|
||||
nameMethod.property(node, this.file, this.scope);
|
||||
nameMethod.property(node, this.file, path ? path.get("value").scope : this.scope);
|
||||
|
||||
if (this.isLoose) {
|
||||
if (this.isLoose && !node.decorators) {
|
||||
// use assignments instead of define properties for loose classes
|
||||
|
||||
var classRef = this.classRef;
|
||||
|
||||
@@ -1,48 +1,31 @@
|
||||
import * as messages from "../../../messages";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export function shouldVisit(node) {
|
||||
return t.isVariableDeclaration(node, { kind: "const" }) || t.isImportDeclaration(node);
|
||||
}
|
||||
export function AssignmentExpression(node, parent, scope, file) {
|
||||
var ids = this.getBindingIdentifiers();
|
||||
|
||||
var visitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (this.isAssignmentExpression() || this.isUpdateExpression()) {
|
||||
var ids = this.getBindingIdentifiers();
|
||||
for (var name in ids) {
|
||||
var id = ids[name];
|
||||
|
||||
for (var name in ids) {
|
||||
var id = ids[name];
|
||||
var binding = scope.getBinding(name);
|
||||
|
||||
var constant = state.constants[name];
|
||||
// no binding exists
|
||||
if (!binding) continue;
|
||||
|
||||
// no constant exists
|
||||
if (!constant) continue;
|
||||
// not a constant
|
||||
if (binding.kind !== "const" && binding.kind !== "module") continue;
|
||||
|
||||
var constantIdentifier = constant.identifier;
|
||||
// check if the assignment id matches the constant declaration id
|
||||
// if it does then it was the id used to initially declare the
|
||||
// constant so we can just ignore it
|
||||
if (binding.identifier === id) continue;
|
||||
|
||||
// check if the assignment id matches the constant declaration id
|
||||
// if it does then it was the id used to initially declare the
|
||||
// constant so we can just ignore it
|
||||
if (id === constantIdentifier) continue;
|
||||
|
||||
// check if there's been a local binding that shadows this constant
|
||||
if (!scope.bindingIdentifierEquals(name, constantIdentifier)) continue;
|
||||
|
||||
throw state.file.errorWithNode(id, messages.get("readOnly", name));
|
||||
}
|
||||
} else if (this.isScope()) {
|
||||
this.skip();
|
||||
}
|
||||
throw file.errorWithNode(id, messages.get("readOnly", name));
|
||||
}
|
||||
};
|
||||
|
||||
export function Scopable(node, parent, scope, file) {
|
||||
this.traverse(visitor, {
|
||||
constants: scope.getAllBindingsOfKind("const", "module"),
|
||||
file: file
|
||||
});
|
||||
}
|
||||
|
||||
export { AssignmentExpression as UpdateExpression };
|
||||
|
||||
export function VariableDeclaration(node) {
|
||||
if (node.kind === "const") node.kind = "let";
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import * as messages from "../../../messages";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var shouldVisit = t.isPattern;
|
||||
export var metadata = {
|
||||
group: "builtin-advanced"
|
||||
};
|
||||
|
||||
export function ForOfStatement(node, parent, scope, file) {
|
||||
var left = node.left;
|
||||
@@ -53,7 +55,7 @@ export function ForOfStatement(node, parent, scope, file) {
|
||||
|
||||
export { ForOfStatement as ForInStatement };
|
||||
|
||||
exports.Function = function (node, parent, scope, file) {
|
||||
export function Func/*tion*/(node, parent, scope, file) {
|
||||
var nodes = [];
|
||||
|
||||
var hasDestructuring = false;
|
||||
@@ -63,6 +65,7 @@ exports.Function = function (node, parent, scope, file) {
|
||||
|
||||
hasDestructuring = true;
|
||||
var ref = scope.generateUidIdentifier("ref");
|
||||
t.inherits(ref, pattern);
|
||||
|
||||
var destructuring = new DestructuringTransformer({
|
||||
blockHoist: node.params.length - i,
|
||||
@@ -82,8 +85,7 @@ exports.Function = function (node, parent, scope, file) {
|
||||
|
||||
var block = node.body;
|
||||
block.body = nodes.concat(block.body);
|
||||
this.checkSelf();
|
||||
};
|
||||
}
|
||||
|
||||
export function CatchClause(node, parent, scope, file) {
|
||||
var pattern = node.param;
|
||||
@@ -103,8 +105,6 @@ export function CatchClause(node, parent, scope, file) {
|
||||
destructuring.init(pattern, ref);
|
||||
|
||||
node.body.body = nodes.concat(node.body.body);
|
||||
|
||||
this.checkSelf();
|
||||
}
|
||||
|
||||
export function ExpressionStatement(node, parent, scope, file) {
|
||||
@@ -179,7 +179,7 @@ export function VariableDeclaration(node, parent, scope, file) {
|
||||
file: file
|
||||
});
|
||||
|
||||
if (t.isPattern(pattern) && patternId) {
|
||||
if (t.isPattern(pattern)) {
|
||||
destructuring.init(pattern, patternId);
|
||||
|
||||
if (+i !== node.declarations.length - 1) {
|
||||
@@ -295,7 +295,7 @@ class DestructuringTransformer {
|
||||
// we need to assign the current value of the assignment to avoid evaluating
|
||||
// it more than once
|
||||
|
||||
var tempValueRef = this.scope.generateUidBasedOnNode(valueRef);
|
||||
var tempValueRef = this.scope.generateUidIdentifierBasedOnNode(valueRef);
|
||||
|
||||
var declar = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(tempValueRef, valueRef)
|
||||
@@ -377,7 +377,7 @@ class DestructuringTransformer {
|
||||
// only evaluated once
|
||||
|
||||
if (pattern.properties.length > 1 && t.isMemberExpression(objRef)) {
|
||||
var temp = this.scope.generateUidBasedOnNode(objRef, this.file);
|
||||
var temp = this.scope.generateUidIdentifierBasedOnNode(objRef, this.file);
|
||||
this.nodes.push(this.buildVariableDeclaration(temp, objRef));
|
||||
objRef = temp;
|
||||
}
|
||||
@@ -461,7 +461,7 @@ class DestructuringTransformer {
|
||||
// array
|
||||
arrayRef = toArray;
|
||||
} else {
|
||||
arrayRef = this.scope.generateUidBasedOnNode(arrayRef);
|
||||
arrayRef = this.scope.generateUidIdentifierBasedOnNode(arrayRef);
|
||||
this.arrays[arrayRef.name] = true;
|
||||
this.nodes.push(this.buildVariableDeclaration(arrayRef, toArray));
|
||||
}
|
||||
@@ -500,7 +500,7 @@ class DestructuringTransformer {
|
||||
|
||||
var shouldMemoise = true;
|
||||
if (!t.isArrayExpression(ref) && !t.isMemberExpression(ref)) {
|
||||
var memo = this.scope.generateMemoisedReference(ref, true);
|
||||
var memo = this.scope.maybeGenerateMemoised(ref, true);
|
||||
if (memo) {
|
||||
this.nodes.push(this.buildVariableDeclaration(memo, ref));
|
||||
ref = memo;
|
||||
|
||||
@@ -2,8 +2,6 @@ import * as messages from "../../../messages";
|
||||
import * as util from "../../../util";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var shouldVisit = t.isForOfStatement;
|
||||
|
||||
export function ForOfStatement(node, parent, scope, file) {
|
||||
if (this.get("right").isArrayExpression()) {
|
||||
return _ForOfStatementArray.call(this, node, scope, file);
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export { check } from "../internal/modules";
|
||||
|
||||
function keepBlockHoist(node, nodes) {
|
||||
if (node._blockHoist) {
|
||||
for (let i = 0; i < nodes.length; i++) {
|
||||
@@ -10,6 +8,10 @@ function keepBlockHoist(node, nodes) {
|
||||
}
|
||||
}
|
||||
|
||||
export var metadata = {
|
||||
group: "builtin-modules"
|
||||
};
|
||||
|
||||
export function ImportDeclaration(node, parent, scope, file) {
|
||||
// flow type
|
||||
if (node.isType) return;
|
||||
|
||||
@@ -1,33 +1,20 @@
|
||||
import ReplaceSupers from "../../helpers/replace-supers";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var shouldVisit = t.isSuper;
|
||||
|
||||
function Property(path, node, scope, getObjectRef, file) {
|
||||
if (!node.method) return;
|
||||
|
||||
var value = node.value;
|
||||
var thisExpr = scope.generateUidIdentifier("this");
|
||||
if (!node.method && node.kind === "init") return;
|
||||
if (!t.isFunction(node.value)) return;
|
||||
|
||||
var replaceSupers = new ReplaceSupers({
|
||||
topLevelThisReference: thisExpr,
|
||||
getObjectRef: getObjectRef,
|
||||
methodNode: node,
|
||||
methodPath: path,
|
||||
isStatic: true,
|
||||
scope: scope,
|
||||
file: file
|
||||
getObjectRef: getObjectRef,
|
||||
methodNode: node,
|
||||
methodPath: path,
|
||||
isStatic: true,
|
||||
scope: scope,
|
||||
file: file
|
||||
});
|
||||
|
||||
replaceSupers.replace();
|
||||
|
||||
if (replaceSupers.hasSuper) {
|
||||
value.body.body.unshift(
|
||||
t.variableDeclaration("var", [
|
||||
t.variableDeclarator(thisExpr, t.thisExpression())
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function ObjectExpression(node, parent, scope, file) {
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import callDelegate from "../../helpers/call-delegate";
|
||||
import * as util from "../../../util";
|
||||
import traverse from "../../../traversal";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export function shouldVisit(node) {
|
||||
return t.isFunction(node) && hasDefaults(node);
|
||||
}
|
||||
|
||||
var hasDefaults = function (node) {
|
||||
for (var i = 0; i < node.params.length; i++) {
|
||||
if (!t.isIdentifier(node.params[i])) return true;
|
||||
@@ -14,17 +11,18 @@ var hasDefaults = function (node) {
|
||||
};
|
||||
|
||||
var iifeVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (!this.isReferencedIdentifier()) return;
|
||||
if (!state.scope.hasOwnBinding(node.name)) return;
|
||||
if (state.scope.bindingIdentifierEquals(node.name, node)) return;
|
||||
ReferencedIdentifier(node, parent, scope, state) {
|
||||
if (node.name !== "eval") {
|
||||
if (!state.scope.hasOwnBinding(node.name)) return;
|
||||
if (state.scope.bindingIdentifierEquals(node.name, node)) return;
|
||||
}
|
||||
|
||||
state.iife = true;
|
||||
this.stop();
|
||||
}
|
||||
};
|
||||
|
||||
exports.Function = function (node, parent, scope, file) {
|
||||
export function Func/*tion*/(node, parent, scope, file) {
|
||||
if (!hasDefaults(node)) return;
|
||||
|
||||
t.ensureBlock(node);
|
||||
@@ -96,6 +94,4 @@ exports.Function = function (node, parent, scope, file) {
|
||||
} else {
|
||||
node.body.body = body.concat(node.body.body);
|
||||
}
|
||||
|
||||
this.checkSelf();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@ import isNumber from "lodash/lang/isNumber";
|
||||
import * as util from "../../../util";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var shouldVisit = t.isRestElement;
|
||||
|
||||
var memberExpressionOptimisationVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
// check if this scope has a local binding that will shadow the rest parameter
|
||||
@@ -55,10 +53,11 @@ var hasRest = function (node) {
|
||||
return t.isRestElement(node.params[node.params.length - 1]);
|
||||
};
|
||||
|
||||
exports.Function = function (node, parent, scope, file) {
|
||||
export function Func/*tion*/(node, parent, scope, file) {
|
||||
if (!hasRest(node)) return;
|
||||
|
||||
var rest = node.params.pop().argument;
|
||||
var restParam = node.params.pop();
|
||||
var rest = restParam.argument;
|
||||
|
||||
var argsId = t.identifier("arguments");
|
||||
|
||||
@@ -96,7 +95,6 @@ exports.Function = function (node, parent, scope, file) {
|
||||
candidate.replaceWith(argsId);
|
||||
optimizeMemberExpression(candidate.parent, node.params.length);
|
||||
}
|
||||
this.checkSelf();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -128,15 +126,15 @@ exports.Function = function (node, parent, scope, file) {
|
||||
}
|
||||
|
||||
var loop = util.template("rest", {
|
||||
ARGUMENTS: argsId,
|
||||
ARRAY_KEY: arrKey,
|
||||
ARRAY_LEN: arrLen,
|
||||
START: start,
|
||||
ARRAY: rest,
|
||||
KEY: key,
|
||||
LEN: len
|
||||
ARRAY_TYPE: restParam.typeAnnotation,
|
||||
ARGUMENTS: argsId,
|
||||
ARRAY_KEY: arrKey,
|
||||
ARRAY_LEN: arrLen,
|
||||
START: start,
|
||||
ARRAY: rest,
|
||||
KEY: key,
|
||||
LEN: len
|
||||
});
|
||||
loop._blockHoist = node.params.length + 1;
|
||||
node.body.body.unshift(loop);
|
||||
this.checkSelf();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -63,42 +63,40 @@ function spec(node, body, objId, initProps, file) {
|
||||
}
|
||||
}
|
||||
|
||||
export function shouldVisit(node) {
|
||||
return t.isProperty(node) && node.computed;
|
||||
}
|
||||
export var ObjectExpression = {
|
||||
exit(node, parent, scope, file) {
|
||||
var hasComputed = false;
|
||||
|
||||
export function ObjectExpression(node, parent, scope, file) {
|
||||
var hasComputed = false;
|
||||
for (var prop of (node.properties: Array)) {
|
||||
hasComputed = t.isProperty(prop, { computed: true, kind: "init" });
|
||||
if (hasComputed) break;
|
||||
}
|
||||
|
||||
for (var i = 0; i < node.properties.length; i++) {
|
||||
hasComputed = t.isProperty(node.properties[i], { computed: true, kind: "init" });
|
||||
if (hasComputed) break;
|
||||
if (!hasComputed) return;
|
||||
|
||||
var initProps = [];
|
||||
var objId = scope.generateUidIdentifierBasedOnNode(parent);
|
||||
|
||||
//
|
||||
|
||||
var body = [];
|
||||
|
||||
//
|
||||
|
||||
var callback = spec;
|
||||
if (file.isLoose("es6.properties.computed")) callback = loose;
|
||||
|
||||
var result = callback(node, body, objId, initProps, file);
|
||||
if (result) return result;
|
||||
|
||||
//
|
||||
|
||||
body.unshift(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(objId, t.objectExpression(initProps))
|
||||
]));
|
||||
|
||||
body.push(t.expressionStatement(objId));
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
if (!hasComputed) return;
|
||||
|
||||
var initProps = [];
|
||||
var objId = scope.generateUidBasedOnNode(parent);
|
||||
|
||||
//
|
||||
|
||||
var body = [];
|
||||
|
||||
//
|
||||
|
||||
var callback = spec;
|
||||
if (file.isLoose("es6.properties.computed")) callback = loose;
|
||||
|
||||
var result = callback(node, body, objId, initProps, file);
|
||||
if (result) return result;
|
||||
|
||||
//
|
||||
|
||||
body.unshift(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(objId, t.objectExpression(initProps))
|
||||
]));
|
||||
|
||||
body.push(t.expressionStatement(objId));
|
||||
|
||||
return body;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,9 +1,3 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export function shouldVisit(node) {
|
||||
return t.isProperty(node) && (node.method || node.shorthand);
|
||||
}
|
||||
|
||||
export function Property(node) {
|
||||
if (node.method) {
|
||||
node.method = false;
|
||||
@@ -11,6 +5,5 @@ export function Property(node) {
|
||||
|
||||
if (node.shorthand) {
|
||||
node.shorthand = false;
|
||||
node.key = t.removeComments(t.clone(node.key));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import * as regex from "../../helpers/regex";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export function shouldVisit(node) {
|
||||
return regex.is(node, "y");
|
||||
}
|
||||
|
||||
export function Literal(node) {
|
||||
if (!regex.is(node, "y")) return;
|
||||
return t.newExpression(t.identifier("RegExp"), [
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import rewritePattern from "regexpu/rewrite-pattern";
|
||||
import * as regex from "../../helpers/regex";
|
||||
|
||||
export function shouldVisit(node) {
|
||||
return regex.is(node, "u");
|
||||
}
|
||||
|
||||
export function Literal(node) {
|
||||
if (!regex.is(node, "u")) return;
|
||||
node.regex.pattern = rewritePattern(node.regex.pattern, node.regex.flags);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import traverse from "../../../traversal";
|
||||
import * as t from "../../../types";
|
||||
|
||||
var visitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (!this.isReferencedIdentifier()) return;
|
||||
ReferencedIdentifier(node, parent, scope, state) {
|
||||
if (t.isFor(parent) && parent.left === node) return;
|
||||
|
||||
var declared = state.letRefs[node.name];
|
||||
@@ -28,17 +28,20 @@ var visitor = {
|
||||
};
|
||||
|
||||
export var metadata = {
|
||||
optional: true
|
||||
optional: true,
|
||||
group: "builtin-advanced"
|
||||
};
|
||||
|
||||
export function BlockStatement(node, parent, scope, file) {
|
||||
var letRefs = node._letReferences;
|
||||
if (!letRefs) return;
|
||||
export var BlockStatement = {
|
||||
exit(node, parent, scope, file) {
|
||||
var letRefs = node._letReferences;
|
||||
if (!letRefs) return;
|
||||
|
||||
this.traverse(visitor, {
|
||||
letRefs: letRefs,
|
||||
file: file
|
||||
});
|
||||
}
|
||||
this.traverse(visitor, {
|
||||
letRefs: letRefs,
|
||||
file: file
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export { BlockStatement as Program, BlockStatement as Loop };
|
||||
|
||||
@@ -44,8 +44,6 @@ function build(props, scope) {
|
||||
return nodes;
|
||||
}
|
||||
|
||||
export var shouldVisit = t.isSpreadElement;
|
||||
|
||||
export function ArrayExpression(node, parent, scope) {
|
||||
var elements = node.elements;
|
||||
if (!hasSpread(elements)) return;
|
||||
@@ -86,7 +84,7 @@ export function CallExpression(node, parent, scope) {
|
||||
var callee = node.callee;
|
||||
|
||||
if (this.get("callee").isMemberExpression()) {
|
||||
var temp = scope.generateMemoisedReference(callee.object);
|
||||
var temp = scope.maybeGenerateMemoised(callee.object);
|
||||
if (temp) {
|
||||
callee.object = t.assignmentExpression("=", temp, callee.object);
|
||||
contextLiteral = temp;
|
||||
|
||||
@@ -1,78 +1,57 @@
|
||||
import reduceRight from "lodash/collection/reduceRight";
|
||||
import * as messages from "../../../messages";
|
||||
import flatten from "lodash/array/flatten";
|
||||
import traverse from "../../../traversal";
|
||||
import * as util from "../../../util";
|
||||
import map from "lodash/collection/map";
|
||||
import * as t from "../../../types";
|
||||
|
||||
exports.Function = function (node, parent, scope, file) {
|
||||
export var metadata = {
|
||||
group: "builtin-trailing"
|
||||
};
|
||||
|
||||
export function Func/*tion*/(node, parent, scope, file) {
|
||||
if (node.generator || node.async) return;
|
||||
var tailCall = new TailCallTransformer(this, scope, file);
|
||||
tailCall.run();
|
||||
};
|
||||
}
|
||||
|
||||
function returnBlock(expr) {
|
||||
return t.blockStatement([t.returnStatement(expr)]);
|
||||
}
|
||||
|
||||
// looks for and replaces tail recursion calls
|
||||
var firstPass = {
|
||||
var visitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (this.isReturnStatement()) {
|
||||
this.skip();
|
||||
return state.subTransform(node.argument);
|
||||
} else if (t.isTryStatement(parent)) {
|
||||
if (t.isTryStatement(parent)) {
|
||||
if (node === parent.block) {
|
||||
this.skip();
|
||||
} else if (parent.finalizer && node !== parent.finalizer) {
|
||||
this.skip();
|
||||
}
|
||||
} else if (this.isFunction()) {
|
||||
this.skip();
|
||||
} else if (this.isVariableDeclaration()) {
|
||||
this.skip();
|
||||
state.vars.push(node);
|
||||
}
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
// hoists up function declarations, replaces `this` and `arguments` and marks
|
||||
// them as needed
|
||||
var secondPass = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (this.isThisExpression()) {
|
||||
state.needsThis = true;
|
||||
return state.getThisId();
|
||||
} else if (this.isReferencedIdentifier({ name: "arguments" })) {
|
||||
ReturnStatement(node, parent, scope, state) {
|
||||
return state.subTransform(node.argument);
|
||||
},
|
||||
|
||||
Function(node, parent, scope, state) {
|
||||
this.skip();
|
||||
},
|
||||
|
||||
VariableDeclaration(node, parent, scope, state) {
|
||||
state.vars.push(node);
|
||||
},
|
||||
|
||||
ThisExpression(node, parent, scope, state) {
|
||||
state.needsThis = true;
|
||||
state.thisPaths.push(this);
|
||||
},
|
||||
|
||||
ReferencedIdentifier(node, parent, scope, state) {
|
||||
if (node.name === "arguments") {
|
||||
state.needsArguments = true;
|
||||
return state.getArgumentsId();
|
||||
} else if (this.isFunction()) {
|
||||
this.skip();
|
||||
if (this.isFunctionDeclaration()) {
|
||||
node = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(node.id, t.toExpression(node))
|
||||
]);
|
||||
node._blockHoist = 2;
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// optimizes recursion by removing `this` and `arguments` if they aren't used
|
||||
var thirdPass = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (!this.isExpressionStatement()) return;
|
||||
|
||||
var expr = node.expression;
|
||||
if (!t.isAssignmentExpression(expr)) return;
|
||||
|
||||
if (!state.needsThis && expr.left === state.getThisId()) {
|
||||
this.remove();
|
||||
} else if (!state.needsArguments && expr.left === state.getArgumentsId() && t.isArrayExpression(expr.right)) {
|
||||
return map(expr.right.elements, function (elem) {
|
||||
return t.expressionStatement(elem);
|
||||
});
|
||||
state.argumentsPaths.push(this);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -80,11 +59,16 @@ var thirdPass = {
|
||||
class TailCallTransformer {
|
||||
constructor(path, scope, file) {
|
||||
this.hasTailRecursion = false;
|
||||
this.needsArguments = false;
|
||||
this.setsArguments = false;
|
||||
this.needsThis = false;
|
||||
this.ownerId = path.node.id;
|
||||
this.vars = [];
|
||||
|
||||
this.needsArguments = false;
|
||||
this.argumentsPaths = [];
|
||||
this.setsArguments = false;
|
||||
|
||||
this.needsThis = false;
|
||||
this.thisPaths = [];
|
||||
|
||||
this.ownerId = path.node.id;
|
||||
this.vars = [];
|
||||
|
||||
this.scope = scope;
|
||||
this.path = path;
|
||||
@@ -150,10 +134,12 @@ class TailCallTransformer {
|
||||
if (!ownerId) return;
|
||||
|
||||
// traverse the function and look for tail recursion
|
||||
this.path.traverse(firstPass, this);
|
||||
this.path.traverse(visitor, this);
|
||||
|
||||
// has no tail call recursion
|
||||
if (!this.hasTailRecursion) return;
|
||||
|
||||
// the function binding isn't constant so we can't be sure that it's the same function :(
|
||||
if (this.hasDeopt()) {
|
||||
this.file.log.deopt(node, messages.get("tailCallReassignmentDeopt"));
|
||||
return;
|
||||
@@ -161,21 +147,27 @@ class TailCallTransformer {
|
||||
|
||||
//
|
||||
|
||||
this.path.traverse(secondPass, this);
|
||||
|
||||
if (!this.needsThis || !this.needsArguments) {
|
||||
this.path.traverse(thirdPass, this);
|
||||
}
|
||||
|
||||
var body = t.ensureBlock(node).body;
|
||||
|
||||
for (var i = 0; i < body.length; i++) {
|
||||
var bodyNode = body[i];
|
||||
if (!t.isFunctionDeclaration(bodyNode)) continue;
|
||||
|
||||
bodyNode = body[i] = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(bodyNode.id, t.toExpression(bodyNode))
|
||||
]);
|
||||
bodyNode._blockHoist = 2;
|
||||
}
|
||||
|
||||
if (this.vars.length > 0) {
|
||||
var declarations = flatten(map(this.vars, function (decl) {
|
||||
return decl.declarations;
|
||||
}));
|
||||
|
||||
var assignment = reduceRight(declarations, function (expr, decl) {
|
||||
return t.assignmentExpression("=", decl.id, expr);
|
||||
}, t.identifier("undefined"));
|
||||
|
||||
var statement = t.expressionStatement(assignment);
|
||||
statement._blockHoist = Infinity;
|
||||
body.unshift(statement);
|
||||
@@ -183,7 +175,9 @@ class TailCallTransformer {
|
||||
|
||||
var paramDecls = this.paramDecls;
|
||||
if (paramDecls.length > 0) {
|
||||
body.unshift(t.variableDeclaration("var", paramDecls));
|
||||
var paramDecl = t.variableDeclaration("var", paramDecls);
|
||||
paramDecl._blockHoist = Infinity;
|
||||
body.unshift(paramDecl);
|
||||
}
|
||||
|
||||
body.unshift(t.expressionStatement(
|
||||
@@ -191,22 +185,28 @@ class TailCallTransformer {
|
||||
);
|
||||
|
||||
node.body = util.template("tail-call-body", {
|
||||
AGAIN_ID: this.getAgainId(),
|
||||
THIS_ID: this.thisId,
|
||||
ARGUMENTS_ID: this.argumentsId,
|
||||
FUNCTION_ID: this.getFunctionId(),
|
||||
BLOCK: node.body
|
||||
FUNCTION_ID: this.getFunctionId(),
|
||||
AGAIN_ID: this.getAgainId(),
|
||||
BLOCK: node.body
|
||||
});
|
||||
|
||||
var topVars = [];
|
||||
|
||||
if (this.needsThis) {
|
||||
for (var path of (this.thisPaths: Array)) {
|
||||
path.replaceWith(this.getThisId());
|
||||
}
|
||||
|
||||
topVars.push(t.variableDeclarator(this.getThisId(), t.thisExpression()));
|
||||
}
|
||||
|
||||
if (this.needsArguments || this.setsArguments) {
|
||||
var decl = t.variableDeclarator(this.getArgumentsId());
|
||||
if (this.needsArguments) {
|
||||
for (var path of (this.argumentsPaths: Array)) {
|
||||
path.replaceWith(this.argumentsId);
|
||||
}
|
||||
|
||||
var decl = t.variableDeclarator(this.argumentsId);
|
||||
if (this.argumentsId) {
|
||||
decl.init = t.identifier("arguments");
|
||||
}
|
||||
topVars.push(decl);
|
||||
@@ -319,7 +319,7 @@ class TailCallTransformer {
|
||||
|
||||
var body = [];
|
||||
|
||||
if (!t.isThisExpression(thisBinding)) {
|
||||
if (this.needsThis && !t.isThisExpression(thisBinding)) {
|
||||
body.push(t.expressionStatement(t.assignmentExpression(
|
||||
"=",
|
||||
this.getThisId(),
|
||||
@@ -332,29 +332,35 @@ class TailCallTransformer {
|
||||
}
|
||||
|
||||
var argumentsId = this.getArgumentsId();
|
||||
var params = this.getParams();
|
||||
var params = this.getParams();
|
||||
|
||||
body.push(t.expressionStatement(t.assignmentExpression(
|
||||
"=",
|
||||
argumentsId,
|
||||
args
|
||||
)));
|
||||
|
||||
var i, param;
|
||||
if (this.needsArguments) {
|
||||
body.push(t.expressionStatement(t.assignmentExpression(
|
||||
"=",
|
||||
argumentsId,
|
||||
args
|
||||
)));
|
||||
}
|
||||
|
||||
if (t.isArrayExpression(args)) {
|
||||
var elems = args.elements;
|
||||
for (i = 0; i < elems.length && i < params.length; i++) {
|
||||
param = params[i];
|
||||
for (let i = 0; i < elems.length && i < params.length; i++) {
|
||||
let param = params[i];
|
||||
var elem = elems[i] || (elems[i] = t.identifier("undefined"));
|
||||
if (!param._isDefaultPlaceholder) {
|
||||
elems[i] = t.assignmentExpression("=", param, elem);
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.needsArguments) {
|
||||
for (var elem of (elems: Array)) {
|
||||
body.push(t.expressionStatement(elem));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.setsArguments = true;
|
||||
for (i = 0; i < params.length; i++) {
|
||||
param = params[i];
|
||||
for (let i = 0; i < params.length; i++) {
|
||||
let param = params[i];
|
||||
if (!param._isDefaultPlaceholder) {
|
||||
body.push(t.expressionStatement(t.assignmentExpression(
|
||||
"=",
|
||||
@@ -368,6 +374,7 @@ class TailCallTransformer {
|
||||
body.push(t.expressionStatement(
|
||||
t.assignmentExpression("=", this.getAgainId(), t.literal(true))
|
||||
));
|
||||
|
||||
body.push(t.continueStatement(this.getFunctionId()));
|
||||
|
||||
return body;
|
||||
|
||||
@@ -4,10 +4,6 @@ var buildBinaryExpression = function (left, right) {
|
||||
return t.binaryExpression("+", left, right);
|
||||
};
|
||||
|
||||
export function shouldVisit(node) {
|
||||
return t.isTemplateLiteral(node) || t.isTaggedTemplateExpression(node);
|
||||
}
|
||||
|
||||
export function TaggedTemplateExpression(node, parent, scope, file) {
|
||||
var quasi = node.quasi;
|
||||
var args = [];
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
export var metadata = {
|
||||
stage: 1
|
||||
};
|
||||
|
||||
export function shouldVisit() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
export var metadata = {
|
||||
stage: 0
|
||||
stage: 0,
|
||||
dependencies: ["es6.classes"]
|
||||
};
|
||||
|
||||
export function shouldVisit() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ function generator(node) {
|
||||
}
|
||||
|
||||
function array(node, parent, scope, file) {
|
||||
var uid = scope.generateUidBasedOnNode(parent);
|
||||
var uid = scope.generateUidIdentifierBasedOnNode(parent);
|
||||
|
||||
var container = util.template("array-comprehension-container", {
|
||||
KEY: uid
|
||||
|
||||
@@ -3,14 +3,11 @@ import * as defineMap from "../../helpers/define-map";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
dependencies: ["es6.classes"],
|
||||
optional: true,
|
||||
stage: 1
|
||||
};
|
||||
|
||||
export function shouldVisit(node) {
|
||||
return !!node.decorators;
|
||||
}
|
||||
|
||||
export function ObjectExpression(node, parent, scope, file) {
|
||||
var hasDecorators = false;
|
||||
for (var i = 0; i < node.properties.length; i++) {
|
||||
|
||||
@@ -5,8 +5,6 @@ export var metadata = {
|
||||
stage: 0
|
||||
};
|
||||
|
||||
export var shouldVisit = t.isDoExpression;
|
||||
|
||||
export function DoExpression(node) {
|
||||
var body = node.body.body;
|
||||
if (body.length) {
|
||||
|
||||
@@ -9,10 +9,20 @@ export var metadata = {
|
||||
|
||||
var MATH_POW = t.memberExpression(t.identifier("Math"), t.identifier("pow"));
|
||||
|
||||
build(exports, {
|
||||
var {
|
||||
ExpressionStatement,
|
||||
AssignmentExpression,
|
||||
BinaryExpression
|
||||
} = build({
|
||||
operator: "**",
|
||||
|
||||
build(left, right) {
|
||||
return t.callExpression(MATH_POW, [left, right]);
|
||||
}
|
||||
});
|
||||
|
||||
export {
|
||||
ExpressionStatement,
|
||||
AssignmentExpression,
|
||||
BinaryExpression
|
||||
};
|
||||
|
||||
@@ -6,10 +6,6 @@ export var metadata = {
|
||||
stage: 1
|
||||
};
|
||||
|
||||
export function shouldVisit(node) {
|
||||
return t.isExportDefaultSpecifier(node) || t.isExportNamespaceSpecifier(node);
|
||||
}
|
||||
|
||||
function build(node, nodes, scope) {
|
||||
var first = node.specifiers[0];
|
||||
if (!t.isExportNamespaceSpecifier(first) && !t.isExportDefaultSpecifier(first)) return;
|
||||
|
||||
51
src/babel/transformation/transformers/es7/function-bind.js
Normal file
51
src/babel/transformation/transformers/es7/function-bind.js
Normal file
@@ -0,0 +1,51 @@
|
||||
// https://github.com/zenparsing/es-function-bind
|
||||
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
optional: true,
|
||||
stage: 0
|
||||
};
|
||||
|
||||
function getTempId(scope) {
|
||||
var id = scope.path.getData("functionBind");
|
||||
if (id) return id;
|
||||
|
||||
id = scope.generateDeclaredUidIdentifier("context");
|
||||
return scope.path.setData("functionBind", id);
|
||||
}
|
||||
|
||||
function getStaticContext(bind, scope) {
|
||||
var object = bind.object || bind.callee.object;
|
||||
return scope.isStatic(object) && object;
|
||||
}
|
||||
|
||||
function inferBindContext(bind, scope) {
|
||||
var staticContext = getStaticContext(bind, scope);
|
||||
if (staticContext) return staticContext;
|
||||
|
||||
var tempId = getTempId(scope);
|
||||
if (bind.object) {
|
||||
bind.callee = t.sequenceExpression([
|
||||
t.assignmentExpression("=", tempId, bind.object),
|
||||
bind.callee
|
||||
]);
|
||||
} else {
|
||||
bind.callee.object = t.assignmentExpression("=", tempId, bind.callee.object);
|
||||
}
|
||||
return tempId;
|
||||
}
|
||||
|
||||
export function CallExpression(node, parent, scope, file) {
|
||||
var bind = node.callee;
|
||||
if (!t.isBindExpression(bind)) return;
|
||||
|
||||
var context = inferBindContext(bind, scope);
|
||||
node.callee = t.memberExpression(bind.callee, t.identifier("call"));
|
||||
node.arguments.unshift(context);
|
||||
}
|
||||
|
||||
export function BindExpression(node, parent, scope, file) {
|
||||
var context = inferBindContext(node, scope);
|
||||
return t.callExpression(t.memberExpression(node.callee, t.identifier("bind")), [context]);
|
||||
}
|
||||
@@ -3,13 +3,10 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
stage: 1
|
||||
stage: 1,
|
||||
dependencies: ["es6.destructuring"]
|
||||
};
|
||||
|
||||
export function manipulateOptions(opts) {
|
||||
if (opts.whitelist) opts.whitelist.push("es6.destructuring");
|
||||
}
|
||||
|
||||
var hasSpread = function (node) {
|
||||
for (var i = 0; i < node.properties.length; i++) {
|
||||
if (t.isSpreadProperty(node.properties[i])) {
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
export var metadata = {
|
||||
stage: 1
|
||||
};
|
||||
|
||||
export function shouldVisit() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,123 +1,86 @@
|
||||
export default {
|
||||
_modules: require("./internal/modules"),
|
||||
//- builtin-setup
|
||||
strict: require("./other/strict"),
|
||||
_explode: require("./internal/explode"),
|
||||
_validation: require("./internal/validation"),
|
||||
_hoistDirectives: require("./internal/hoist-directives"),
|
||||
"minification.removeDebugger": require("./minification/remove-debugger"),
|
||||
"minification.removeConsole": require("./minification/remove-console"),
|
||||
"utility.inlineEnvironmentVariables": require("./utility/inline-environment-variables"),
|
||||
"minification.inlineExpressions": require("./minification/inline-expressions"),
|
||||
"minification.deadCodeElimination": require("./minification/dead-code-elimination"),
|
||||
_modules: require("./internal/modules"),
|
||||
"spec.functionName": require("./spec/function-name"),
|
||||
|
||||
//- builtin-basic
|
||||
// this is where the bulk of the ES6 transformations take place, none of them require traversal state
|
||||
// so they can all be concatenated together for performance
|
||||
"es7.classProperties": require("./es7/class-properties"),
|
||||
"es7.trailingFunctionCommas": require("./es7/trailing-function-commas"),
|
||||
"es7.asyncFunctions": require("./es7/async-functions"),
|
||||
"es7.decorators": require("./es7/decorators"),
|
||||
|
||||
strict: require("./other/strict"),
|
||||
|
||||
_validation: require("./internal/validation"),
|
||||
|
||||
"validation.undeclaredVariableCheck": require("./validation/undeclared-variable-check"),
|
||||
"validation.react": require("./validation/react"),
|
||||
|
||||
// this goes at the start so we only transform the original user code
|
||||
"spec.functionName": require("./spec/function-name"),
|
||||
|
||||
// needs to be before `_shadowFunctions`
|
||||
"es6.arrowFunctions": require("./es6/arrow-functions"),
|
||||
|
||||
"spec.blockScopedFunctions": require("./spec/block-scoped-functions"),
|
||||
|
||||
"optimisation.react.constantElements": require("./optimisation/react.constant-elements"),
|
||||
"optimisation.react.inlineElements": require("./optimisation/react.inline-elements"),
|
||||
reactCompat: require("./other/react-compat"),
|
||||
react: require("./other/react"),
|
||||
|
||||
// needs to be before `regenerator` due to generator comprehensions
|
||||
// needs to be before `_shadowFunctions`
|
||||
"es7.comprehensions": require("./es7/comprehensions"),
|
||||
|
||||
"es6.classes": require("./es6/classes"),
|
||||
|
||||
asyncToGenerator: require("./other/async-to-generator"),
|
||||
bluebirdCoroutines: require("./other/bluebird-coroutines"),
|
||||
|
||||
"es6.objectSuper": require("./es6/object-super"),
|
||||
"es7.objectRestSpread": require("./es7/object-rest-spread"),
|
||||
"es7.exponentiationOperator": require("./es7/exponentiation-operator"),
|
||||
|
||||
"es6.spec.templateLiterals": require("./es6/spec.template-literals"),
|
||||
"es6.templateLiterals": require("./es6/template-literals"),
|
||||
|
||||
"es5.properties.mutators": require("./es5/properties.mutators"),
|
||||
"es6.properties.shorthand": require("./es6/properties.shorthand"),
|
||||
|
||||
// needs to be before `_shadowFunctions` due to define property closure
|
||||
"es6.properties.computed": require("./es6/properties.computed"),
|
||||
|
||||
"optimisation.flow.forOf": require("./optimisation/flow.for-of"),
|
||||
"es6.forOf": require("./es6/for-of"),
|
||||
|
||||
"es6.regex.sticky": require("./es6/regex.sticky"),
|
||||
"es6.regex.unicode": require("./es6/regex.unicode"),
|
||||
|
||||
"es6.constants": require("./es6/constants"),
|
||||
|
||||
// needs to be before `es6.parameters.default` as default parameters will destroy the rest param
|
||||
"es6.parameters.rest": require("./es6/parameters.rest"),
|
||||
|
||||
// needs to be after `es6.parameters.rest` as we use `toArray` and avoid turning an already known array into one
|
||||
"es6.spread": require("./es6/spread"),
|
||||
|
||||
// needs to be before `es6.blockScoping` as default parameters have a TDZ
|
||||
"es6.parameters.default": require("./es6/parameters.default"),
|
||||
"es7.exportExtensions": require("./es7/export-extensions"),
|
||||
"spec.protoToAssign": require("./spec/proto-to-assign"),
|
||||
"es7.doExpressions": require("./es7/do-expressions"),
|
||||
"es6.spec.symbols": require("./es6/spec.symbols"),
|
||||
"es7.functionBind": require("./es7/function-bind"),
|
||||
"spec.undefinedToVoid": require("./spec/undefined-to-void"),
|
||||
jscript: require("./other/jscript"),
|
||||
flow: require("./other/flow"),
|
||||
|
||||
// needs to be before `es6.blockScoping` as let variables may be produced
|
||||
//- builtin-advanced
|
||||
"es6.destructuring": require("./es6/destructuring"),
|
||||
|
||||
// needs to be before `_shadowFunctions` due to block scopes sometimes being wrapped in a
|
||||
// closure
|
||||
"es6.blockScoping": require("./es6/block-scoping"),
|
||||
|
||||
// needs to be after `es6.blockScoping` due to needing `letReferences` set on blocks
|
||||
"es6.spec.blockScoping": require("./es6/spec.block-scoping"),
|
||||
reactCompat: require("./other/react-compat"),
|
||||
react: require("./other/react"),
|
||||
|
||||
// needs to be after `es6.parameters.*` and `es6.blockScoping` due to needing pure
|
||||
// identifiers in parameters and variable declarators
|
||||
"es6.tailCall": require("./es6/tail-call"),
|
||||
// es6 syntax transformation is **forbidden** past this point since regenerator will chuck a massive
|
||||
// hissy fit
|
||||
|
||||
//- regenerator
|
||||
regenerator: require("./other/regenerator"),
|
||||
|
||||
// needs to be after `regenerator` due to needing `regeneratorRuntime` references
|
||||
// needs to be after `es6.forOf` due to needing `Symbol.iterator` references
|
||||
// needs to be before `es6.modules` due to dynamic imports
|
||||
runtime: require("./other/runtime"),
|
||||
|
||||
// needs to be before `_blockHoist` due to function hoisting etc
|
||||
"es7.exportExtensions": require("./es7/export-extensions"),
|
||||
//- builtin-modules
|
||||
runtime: require("./other/runtime"),
|
||||
"es6.modules": require("./es6/modules"),
|
||||
|
||||
_blockHoist: require("./internal/block-hoist"),
|
||||
|
||||
"spec.protoToAssign": require("./spec/proto-to-assign"),
|
||||
|
||||
_shadowFunctions: require("./internal/shadow-functions"),
|
||||
|
||||
"es7.doExpressions": require("./es7/do-expressions"),
|
||||
|
||||
"es6.spec.symbols": require("./es6/spec.symbols"),
|
||||
ludicrous: require("./other/ludicrous"),
|
||||
"spec.undefinedToVoid": require("./spec/undefined-to-void"),
|
||||
|
||||
_strict: require("./internal/strict"),
|
||||
_moduleFormatter: require("./internal/module-formatter"),
|
||||
|
||||
//- builtin-trailing
|
||||
// these clean up the output and do finishing up transformations, it's important to note that by this
|
||||
// stage you can't import any new modules or insert new ES6 as all those transformers have already
|
||||
// been ran
|
||||
"es6.tailCall": require("./es6/tail-call"),
|
||||
_shadowFunctions: require("./internal/shadow-functions"),
|
||||
"es3.propertyLiterals": require("./es3/property-literals"),
|
||||
"es3.memberExpressionLiterals": require("./es3/member-expression-literals"),
|
||||
|
||||
"utility.removeDebugger": require("./utility/remove-debugger"),
|
||||
"utility.removeConsole": require("./utility/remove-console"),
|
||||
|
||||
"utility.inlineEnvironmentVariables": require("./utility/inline-environment-variables"),
|
||||
"utility.inlineExpressions": require("./utility/inline-expressions"),
|
||||
|
||||
"minification.memberExpressionLiterals": require("./minification/member-expression-literals"),
|
||||
"minification.propertyLiterals": require("./minification/property-literals"),
|
||||
|
||||
jscript: require("./other/jscript"),
|
||||
flow: require("./other/flow")
|
||||
_blockHoist: require("./internal/block-hoist"),
|
||||
};
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import sortBy from "lodash/collection/sortBy";
|
||||
|
||||
export var metadata = {
|
||||
group: "builtin-trailing"
|
||||
};
|
||||
|
||||
// Priority:
|
||||
//
|
||||
// - 0 We want this to be at the **very** bottom
|
||||
|
||||
30
src/babel/transformation/transformers/internal/explode.js
Normal file
30
src/babel/transformation/transformers/internal/explode.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import clone from "lodash/lang/clone";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
group: "builtin-setup"
|
||||
};
|
||||
|
||||
function buildClone(bindingKey, refKey) {
|
||||
return function (node) {
|
||||
if (node[bindingKey] === node[refKey]) {
|
||||
node[refKey] = t.removeComments(clone(node[refKey]));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function buildListClone(listKey, bindingKey, refKey) {
|
||||
var clone = buildClone(bindingKey, refKey);
|
||||
|
||||
return function (node) {
|
||||
if (!node[listKey]) return;
|
||||
|
||||
for (var subNode of (node[listKey]: Array)) {
|
||||
clone(subNode);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export var Property = buildClone("value", "key");
|
||||
export var ExportDeclaration = buildListClone("specifiers", "local", "exported");
|
||||
export var ImportDeclaration = buildListClone("specifiers", "local", "imported");
|
||||
@@ -0,0 +1,20 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
group: "builtin-setup"
|
||||
};
|
||||
|
||||
export var BlockStatement = {
|
||||
exit(node) {
|
||||
for (var i = 0; i < node.body.length; i++) {
|
||||
var bodyNode = node.body[i];
|
||||
if (t.isExpressionStatement(bodyNode) && t.isLiteral(bodyNode.expression)) {
|
||||
bodyNode._blockHoist = Infinity;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export { BlockStatement as Program };
|
||||
@@ -1,15 +1,24 @@
|
||||
import * as strict from "../../helpers/strict";
|
||||
|
||||
export function Program(program, parent, scope, file) {
|
||||
this.stop();
|
||||
export var metadata = {
|
||||
group: "builtin-modules"
|
||||
};
|
||||
|
||||
strict.wrap(program, function () {
|
||||
program.body = file.dynamicImports.concat(program.body);
|
||||
});
|
||||
export var Program = {
|
||||
exit(program, parent, scope, file) {
|
||||
strict.wrap(program, function () {
|
||||
// ensure that these are at the top, just like normal imports
|
||||
for (var node of (file.dynamicImports: Array)) {
|
||||
node._blockHoist = 3;
|
||||
}
|
||||
|
||||
if (!file.transformers["es6.modules"].canTransform()) return;
|
||||
program.body = file.dynamicImports.concat(program.body);
|
||||
});
|
||||
|
||||
if (file.moduleFormatter.transform) {
|
||||
file.moduleFormatter.transform(program);
|
||||
if (!file.transformers["es6.modules"].canTransform()) return;
|
||||
|
||||
if (file.moduleFormatter.transform) {
|
||||
file.moduleFormatter.transform(program);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -4,11 +4,12 @@
|
||||
// a generator function as a default then regenerator will destroy the export
|
||||
// declaration and leave a variable declaration in it's place... yeah, handy.
|
||||
|
||||
import clone from "lodash/lang/clone";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export function shouldVisit(node) {
|
||||
return t.isImportDeclaration(node) || t.isExportDeclaration(node);
|
||||
}
|
||||
export var metadata = {
|
||||
group: "builtin-setup"
|
||||
};
|
||||
|
||||
export function ImportDeclaration(node, parent, scope, file) {
|
||||
if (node.source) {
|
||||
@@ -48,6 +49,10 @@ export function ExportDefaultDeclaration(node, parent, scope) {
|
||||
}
|
||||
}
|
||||
|
||||
function buildExportSpecifier(id) {
|
||||
return t.exportSpecifier(clone(id), clone(id));
|
||||
}
|
||||
|
||||
export function ExportNamedDeclaration(node, parent, scope) {
|
||||
ImportDeclaration.apply(this, arguments);
|
||||
|
||||
@@ -60,12 +65,12 @@ export function ExportNamedDeclaration(node, parent, scope) {
|
||||
|
||||
if (t.isClassDeclaration(declar)) {
|
||||
// export class Foo {}
|
||||
node.specifiers = [t.exportSpecifier(declar.id, declar.id)];
|
||||
node.specifiers = [buildExportSpecifier(declar.id)];
|
||||
node.declaration = null;
|
||||
return [getDeclar(), node];
|
||||
} else if (t.isFunctionDeclaration(declar)) {
|
||||
// export function Foo() {}
|
||||
node.specifiers = [t.exportSpecifier(declar.id, declar.id)];
|
||||
node.specifiers = [buildExportSpecifier(declar.id)];
|
||||
node.declaration = null;
|
||||
node._blockHoist = 2;
|
||||
return [getDeclar(), node];
|
||||
@@ -74,8 +79,7 @@ export function ExportNamedDeclaration(node, parent, scope) {
|
||||
var specifiers = [];
|
||||
var bindings = this.get("declaration").getBindingIdentifiers();
|
||||
for (var key in bindings) {
|
||||
var id = bindings[key];
|
||||
specifiers.push(t.exportSpecifier(id, id));
|
||||
specifiers.push(buildExportSpecifier(bindings[key]));
|
||||
}
|
||||
return [declar, t.exportNamedDeclaration(null, specifiers)];
|
||||
}
|
||||
|
||||
@@ -1,102 +1,33 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
var functionChildrenVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (this.isClass(node)) {
|
||||
return this.skip();
|
||||
}
|
||||
|
||||
if (this.isFunction() && !node.shadow) {
|
||||
return this.skip();
|
||||
}
|
||||
|
||||
if (node._shadowedFunctionLiteral) return this.skip();
|
||||
|
||||
var getId;
|
||||
|
||||
if (this.isIdentifier() && node.name === "arguments") {
|
||||
getId = state.getArgumentsId;
|
||||
} else if (this.isThisExpression()) {
|
||||
getId = state.getThisId;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isReferenced()) return getId();
|
||||
}
|
||||
export var metadata = {
|
||||
group: "builtin-trailing"
|
||||
};
|
||||
|
||||
var functionVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (!node.shadow) {
|
||||
if (this.isFunction()) {
|
||||
// stop traversal of this node as it'll be hit again by this transformer
|
||||
return this.skip();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
function remap(path, key, create) {
|
||||
// ensure that we're shadowed
|
||||
if (!path.inShadow()) return;
|
||||
|
||||
// traverse all child nodes of this function and find `arguments` and `this`
|
||||
this.traverse(functionChildrenVisitor, state);
|
||||
var fnPath = path.findParent((node, path) => !node.shadow && (path.isFunction() || path.isProgram()));
|
||||
|
||||
node.shadow = false;
|
||||
var cached = fnPath.getData(key);
|
||||
if (cached) return cached;
|
||||
|
||||
return this.skip();
|
||||
}
|
||||
};
|
||||
var init = create();
|
||||
var id = path.scope.generateUidIdentifier(key);
|
||||
|
||||
function aliasFunction(getBody, path, scope) {
|
||||
var argumentsId;
|
||||
var thisId;
|
||||
fnPath.setData(key, id);
|
||||
fnPath.scope.push({ id, init });
|
||||
|
||||
var state = {
|
||||
getArgumentsId() {
|
||||
return argumentsId = argumentsId || scope.generateUidIdentifier("arguments");
|
||||
},
|
||||
|
||||
getThisId() {
|
||||
return thisId = thisId || scope.generateUidIdentifier("this");
|
||||
}
|
||||
};
|
||||
|
||||
// traverse the function and find all alias functions so we can alias
|
||||
// `arguments` and `this` if necessary
|
||||
path.traverse(functionVisitor, state);
|
||||
|
||||
var body;
|
||||
|
||||
var pushDeclaration = function (id, init) {
|
||||
body = body || getBody();
|
||||
body.unshift(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(id, init)
|
||||
]));
|
||||
};
|
||||
|
||||
if (argumentsId) {
|
||||
pushDeclaration(argumentsId, t.identifier("arguments"));
|
||||
}
|
||||
|
||||
if (thisId) {
|
||||
pushDeclaration(thisId, t.thisExpression());
|
||||
}
|
||||
};
|
||||
|
||||
export function shouldVisit(node) {
|
||||
return true;
|
||||
return id;
|
||||
}
|
||||
|
||||
export function Program(node, parent, scope) {
|
||||
aliasFunction(function () {
|
||||
return node.body;
|
||||
}, this, scope);
|
||||
};
|
||||
|
||||
export function FunctionDeclaration(node, parent, scope) {
|
||||
aliasFunction(function () {
|
||||
t.ensureBlock(node);
|
||||
return node.body.body;
|
||||
}, this, scope);
|
||||
export function ThisExpression() {
|
||||
return remap(this, "this", () => t.thisExpression());
|
||||
}
|
||||
|
||||
export { FunctionDeclaration as FunctionExpression };
|
||||
export function ReferencedIdentifier(node) {
|
||||
if (node.name === "arguments" && !node._shadowedFunctionLiteral) {
|
||||
return remap(this, "arguments", () => t.identifier("arguments"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export function Program(program, parent, scope, file) {
|
||||
if (file.transformers.strict.canTransform()) {
|
||||
var directive = file.get("existingStrictDirective");
|
||||
|
||||
if (!directive) {
|
||||
directive = t.expressionStatement(t.literal("use strict"));
|
||||
var first = program.body[0];
|
||||
if (first) {
|
||||
directive.leadingComments = first.leadingComments;
|
||||
first.leadingComments = [];
|
||||
}
|
||||
}
|
||||
|
||||
this.unshiftContainer("body", [directive]);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import * as messages from "../../../messages";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
readOnly: true
|
||||
group: "builtin-setup"
|
||||
};
|
||||
|
||||
export function ForOfStatement(node, parent, scope, file) {
|
||||
@@ -43,16 +43,3 @@ export function Property(node, parent, scope, file) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function BlockStatement(node) {
|
||||
for (var i = 0; i < node.body.length; i++) {
|
||||
var bodyNode = node.body[i];
|
||||
if (t.isExpressionStatement(bodyNode) && t.isLiteral(bodyNode.expression)) {
|
||||
bodyNode._blockHoist = Infinity;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { BlockStatement as Program };
|
||||
|
||||
@@ -18,23 +18,23 @@ function toStatements(node) {
|
||||
}
|
||||
|
||||
export var metadata = {
|
||||
optional: true
|
||||
optional: true,
|
||||
group: "builtin-setup"
|
||||
};
|
||||
|
||||
export function Identifier(node, parent, scope) {
|
||||
if (!this.isReferenced()) return;
|
||||
|
||||
export function ReferencedIdentifier(node, parent, scope) {
|
||||
var binding = scope.getBinding(node.name);
|
||||
if (!binding || binding.references > 1 || !binding.constant) return;
|
||||
if (binding.kind === "param" || binding.kind === "module") return;
|
||||
|
||||
var replacement = binding.path.node;
|
||||
if (t.isVariableDeclarator(replacement)) {
|
||||
replacement = replacement.init;
|
||||
}
|
||||
if (!replacement) return;
|
||||
|
||||
t.toExpression(replacement);
|
||||
|
||||
scope.removeBinding(node.name);
|
||||
|
||||
binding.path.remove();
|
||||
return replacement;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
optional: true,
|
||||
group: "builtin-setup"
|
||||
};
|
||||
|
||||
export var Expression = {
|
||||
exit(node, parent, scope) {
|
||||
var res = this.evaluate();
|
||||
if (res.confident) return t.valueToNode(res.value);
|
||||
}
|
||||
};
|
||||
|
||||
export function Identifier() {
|
||||
// override Expression
|
||||
}
|
||||
@@ -1,14 +1,17 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
optional: true
|
||||
optional: true,
|
||||
group: "builtin-trailing"
|
||||
};
|
||||
|
||||
export function MemberExpression(node) {
|
||||
var prop = node.property;
|
||||
if (node.computed && t.isLiteral(prop) && t.isValidIdentifier(prop.value)) {
|
||||
// foo["bar"] => foo.bar
|
||||
node.property = t.identifier(prop.value);
|
||||
node.computed = false;
|
||||
export var MemberExpression = {
|
||||
exit(node) {
|
||||
var prop = node.property;
|
||||
if (node.computed && t.isLiteral(prop) && t.isValidIdentifier(prop.value)) {
|
||||
// foo["bar"] => foo.bar
|
||||
node.property = t.identifier(prop.value);
|
||||
node.computed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
optional: true
|
||||
optional: true,
|
||||
group: "builtin-trailing"
|
||||
};
|
||||
|
||||
export function Property(node) {
|
||||
var key = node.key;
|
||||
if (t.isLiteral(key) && t.isValidIdentifier(key.value)) {
|
||||
// "foo": "bar" -> foo: "bar"
|
||||
node.key = t.identifier(key.value);
|
||||
node.computed = false;
|
||||
export var Property = {
|
||||
exit(node) {
|
||||
var key = node.key;
|
||||
if (t.isLiteral(key) && t.isValidIdentifier(key.value)) {
|
||||
// "foo": "bar" -> foo: "bar"
|
||||
node.key = t.identifier(key.value);
|
||||
node.computed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
optional: true
|
||||
optional: true,
|
||||
group: "builtin-setup"
|
||||
};
|
||||
|
||||
export function CallExpression(node, parent) {
|
||||
@@ -1,7 +1,8 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
optional: true
|
||||
optional: true,
|
||||
group: "builtin-setup"
|
||||
};
|
||||
|
||||
export function ExpressionStatement(node) {
|
||||
@@ -1,8 +1,9 @@
|
||||
import { _ForOfStatementArray } from "../es6/for-of";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var shouldVisit = t.isForOfStatement;
|
||||
export var optional = true;
|
||||
export var metadata = {
|
||||
optional: true
|
||||
};
|
||||
|
||||
export function ForOfStatement(node, parent, scope, file) {
|
||||
if (this.get("right").isTypeGeneric("Array")) {
|
||||
|
||||
@@ -35,9 +35,8 @@ export function JSXElement(node, parent, scope, file) {
|
||||
this.traverse(immutabilityVisitor, state);
|
||||
|
||||
if (state.isImmutable) {
|
||||
this.hoist();
|
||||
this.skip();
|
||||
return this.hoist();
|
||||
} else {
|
||||
node._hoisted = true;
|
||||
}
|
||||
|
||||
node._hoisted = true;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user