Compare commits
114 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b967ecf063 | ||
|
|
365b7285d2 | ||
|
|
a40d532b0e | ||
|
|
0487bf911d | ||
|
|
57c72d1cd0 | ||
|
|
335bdffec2 | ||
|
|
e1d76a1dfe | ||
|
|
a4845323a2 | ||
|
|
792951b489 | ||
|
|
5adda836af | ||
|
|
4c2c3098c3 | ||
|
|
087c714098 | ||
|
|
5a33e4fe05 | ||
|
|
5f8667eaa7 | ||
|
|
31b4468514 | ||
|
|
2be9678bbe | ||
|
|
b5210877cf | ||
|
|
658dde768e | ||
|
|
8df1d81ca4 | ||
|
|
a505e4a121 | ||
|
|
71eafdcac7 | ||
|
|
65060b0c97 | ||
|
|
09883962f1 | ||
|
|
1583262807 | ||
|
|
04c7cd5c0c | ||
|
|
3f6969f4f8 | ||
|
|
23db842cb8 | ||
|
|
41c82e00f9 | ||
|
|
766099e783 | ||
|
|
53bc54b3b2 | ||
|
|
bb70f37123 | ||
|
|
8a0317132e | ||
|
|
f598c70841 | ||
|
|
61b57ea055 | ||
|
|
a971ad7fd2 | ||
|
|
27b6f804ce | ||
|
|
8ab79f3a72 | ||
|
|
0c2bf2f5a2 | ||
|
|
7e1a4be085 | ||
|
|
bbc951dfe1 | ||
|
|
b3e4aefe12 | ||
|
|
26b5174dfa | ||
|
|
652d3c7320 | ||
|
|
edc2cd320c | ||
|
|
274a6e01dc | ||
|
|
3561efdb86 | ||
|
|
1a30f1aafc | ||
|
|
e362512af3 | ||
|
|
cf5d2429b4 | ||
|
|
72098036b2 | ||
|
|
7905f48280 | ||
|
|
aba2d1c23c | ||
|
|
5326e0543d | ||
|
|
1360c93e4b | ||
|
|
235cbc18cf | ||
|
|
98c5255b91 | ||
|
|
2a9777cc20 | ||
|
|
1cfca745a4 | ||
|
|
a3459deecf | ||
|
|
070152f6c1 | ||
|
|
719fdf5ca1 | ||
|
|
f2460c6173 | ||
|
|
155c640409 | ||
|
|
7de4718b27 | ||
|
|
4e6aed0408 | ||
|
|
3be8ccf68d | ||
|
|
704b31f44f | ||
|
|
1a9f193841 | ||
|
|
7ff67589a7 | ||
|
|
80f109efeb | ||
|
|
77c72bb5a6 | ||
|
|
6c5e0e6590 | ||
|
|
83324b977d | ||
|
|
5feab11d3f | ||
|
|
7b4172ce7b | ||
|
|
84439384c0 | ||
|
|
c9e7c306cc | ||
|
|
1e398e45ff | ||
|
|
475324c4b5 | ||
|
|
407daf4bac | ||
|
|
4155590cd8 | ||
|
|
0be6fd7abe | ||
|
|
cf51bf1395 | ||
|
|
06a31c419a | ||
|
|
da566110c0 | ||
|
|
c12c4a5c39 | ||
|
|
d114349890 | ||
|
|
8d6ae0e1eb | ||
|
|
cb8b47ee2f | ||
|
|
daf24c5c59 | ||
|
|
cdb2784e75 | ||
|
|
93feabb82e | ||
|
|
982c142bf6 | ||
|
|
de5520a94f | ||
|
|
c239d06f10 | ||
|
|
a5fed376d8 | ||
|
|
e99fd77d89 | ||
|
|
1374863b9c | ||
|
|
e88c28f88b | ||
|
|
7a0fd26f56 | ||
|
|
17583e4807 | ||
|
|
37dd5137ff | ||
|
|
24fced406e | ||
|
|
0ab1362893 | ||
|
|
96506f4249 | ||
|
|
ed747f88bd | ||
|
|
3987545b4f | ||
|
|
148aa3f96d | ||
|
|
0cb5a7c91e | ||
|
|
fc34d5a9b0 | ||
|
|
f8d56d9612 | ||
|
|
737be0e95e | ||
|
|
26e2b392e8 | ||
|
|
584532cc2c |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -11,6 +11,7 @@ test/core/tmp
|
||||
coverage
|
||||
dist
|
||||
.package.json
|
||||
packages/babel-runtime/core-js
|
||||
packages/babel-runtime/helpers/*.js
|
||||
packages/babel-runtime/regenerator/*.js
|
||||
lib
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
sudo: false
|
||||
language: node_js
|
||||
cache:
|
||||
directories:
|
||||
- node_modules
|
||||
node_js:
|
||||
- "0.12"
|
||||
- "iojs"
|
||||
|
||||
67
CHANGELOG.md
67
CHANGELOG.md
@@ -13,6 +13,73 @@ _Note: Gaps between patch versions are faulty/broken releases._
|
||||
|
||||
See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
|
||||
|
||||
## 5.1.5
|
||||
|
||||
* **Internal**
|
||||
* Bump `core-js` version.
|
||||
|
||||
## 5.1.4
|
||||
|
||||
* **Polish**
|
||||
* Add missing `Reflect` methods to runtime transformer.
|
||||
|
||||
## 5.1.3
|
||||
|
||||
* **Internal**
|
||||
* Switch entirely to vanilla regenerator.
|
||||
* Clean up and make the parsing of decorators stateless.
|
||||
* **Bug Fix**
|
||||
* Don't do TCO on generators and async functions.
|
||||
* Add missing `core-js` runtime definitions.
|
||||
|
||||
## 5.1.2
|
||||
|
||||
* **Bug Fix**
|
||||
* Add `getIterator` and `isIterable` to `babel-runtime` build script.
|
||||
|
||||
## 5.1.1
|
||||
|
||||
* **Bug Fix**
|
||||
* Add missing runtime symbol definitions.
|
||||
|
||||
## 5.1.0
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix super reference when using decorators.
|
||||
* Don't do array unpack optimisation when member expressions are present.
|
||||
* Add missing descriptors for undecorated class properties.
|
||||
* Don't consider `arguments` and `eval` valid function names when doing function name inferrence.
|
||||
* Fix scope tracking of constants in loop heads.
|
||||
* Parse `AwaitExpression` as a unary instead of an assignment.
|
||||
* Fix regex evaluation when attempting static evaluation.
|
||||
* Don't emit tokens when doing a lookahead.
|
||||
* Add missing `test` declaration to `utility.deadCodeElimination` transformer.
|
||||
* **Internal**
|
||||
* Upgrade `regenerator` to the latest and use my branch with the hope of eventually switching to vanilla regenerator.
|
||||
* Add support for the replacement of for loop `init`s with statements.
|
||||
* Upgrade dependencies.
|
||||
* **Polish**
|
||||
* When adding the scope IIFE when using default parameters, don't shadow the function expression, just `apply` `this` and `arguments` if necessary.
|
||||
* Use path basename as non-default import fallback.
|
||||
* **New Feature**
|
||||
* Add [trailing function comma proposal](https://github.com/jeffmo/es-trailing-function-commas). Thanks [@AluisioASG](https://github.com/AluisioASG)!
|
||||
* Add support for object literal decorators.
|
||||
* Make core-js modular when using the `runtime` transformer.
|
||||
|
||||
## 5.0.12
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix incorrect remapping of module references inside of a function id redirection container.
|
||||
|
||||
## 5.0.11
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix new `for...of` loops not properly inheriting their original loop.
|
||||
* **Internal**
|
||||
* Disable scope instance cache.
|
||||
* **Polish**
|
||||
* Allow comments in `.babelrc` JSON.
|
||||
|
||||
## 5.0.9
|
||||
|
||||
* **Polish**
|
||||
|
||||
@@ -35,13 +35,13 @@ This is mostly overkill and you can limit the tests to a select few by directly
|
||||
running them with `mocha`:
|
||||
|
||||
```sh
|
||||
$ mocha test/transformation.js
|
||||
$ mocha test/core/transformation.js
|
||||
```
|
||||
|
||||
Use mocha's `--grep` option to run a subset of tests by name:
|
||||
|
||||
```sh
|
||||
$ mocha test/transformation.js --grep es7
|
||||
$ mocha test/core/transformation.js --grep es7
|
||||
```
|
||||
|
||||
#### Workflow
|
||||
|
||||
1
Makefile
1
Makefile
@@ -109,6 +109,7 @@ publish-cli:
|
||||
npm publish
|
||||
|
||||
bootstrap:
|
||||
npm list --global --depth 1 babel >/dev/null 2>&1 && npm uninstall -g babel || true
|
||||
npm install
|
||||
npm link
|
||||
cd packages/babel-cli && npm install && npm link && npm link babel-core
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
For questions and support please visit the <a href="https://gitter.im/babel/babel">gitter room</a> or <a href="http://stackoverflow.com/questions/tagged/babeljs">StackOverflow</a>. The Babel issue tracker is <strong>exclusively</strong> for bug reports and future requests.
|
||||
For questions and support please visit the <a href="https://gitter.im/babel/babel">gitter room</a> or <a href="http://stackoverflow.com/questions/tagged/babeljs">StackOverflow</a>. The Babel issue tracker is <strong>exclusively</strong> for bug reports and feature requests.
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
|
||||
34
package.json
34
package.json
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "babel-core",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "5.0.9",
|
||||
"version": "5.1.5",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"repository": "babel/babel",
|
||||
@@ -29,44 +29,46 @@
|
||||
"dependencies": {
|
||||
"ast-types": "~0.7.0",
|
||||
"chalk": "^1.0.0",
|
||||
"convert-source-map": "^0.5.0",
|
||||
"core-js": "^0.8.1",
|
||||
"convert-source-map": "^1.0.0",
|
||||
"core-js": "^0.8.3",
|
||||
"debug": "^2.1.1",
|
||||
"detect-indent": "^3.0.0",
|
||||
"estraverse": "^1.9.1",
|
||||
"esutils": "^1.1.6",
|
||||
"estraverse": "^3.0.0",
|
||||
"esutils": "^2.0.0",
|
||||
"fs-readdir-recursive": "^0.1.0",
|
||||
"globals": "^6.2.0",
|
||||
"globals": "^6.4.0",
|
||||
"is-integer": "^1.0.4",
|
||||
"js-tokens": "1.0.0",
|
||||
"leven": "^1.0.1",
|
||||
"line-numbers": "0.2.0",
|
||||
"lodash": "^3.2.0",
|
||||
"lodash": "^3.6.0",
|
||||
"minimatch": "^2.0.3",
|
||||
"output-file-sync": "^1.1.0",
|
||||
"path-is-absolute": "^1.0.0",
|
||||
"private": "^0.1.6",
|
||||
"regenerator-babel": "0.8.13-2",
|
||||
"regenerator": "^0.8.20",
|
||||
"regexpu": "^1.1.2",
|
||||
"repeating": "^1.1.2",
|
||||
"shebang-regex": "^1.0.0",
|
||||
"slash": "^1.0.0",
|
||||
"source-map": "^0.4.0",
|
||||
"source-map-support": "^0.2.9",
|
||||
"source-map-support": "^0.2.10",
|
||||
"strip-json-comments": "^1.0.2",
|
||||
"to-fast-properties": "^1.0.0",
|
||||
"trim-right": "^1.0.0"
|
||||
"trim-right": "^1.0.0",
|
||||
"user-home": "^1.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel": "4.7.13",
|
||||
"browserify": "^9.0.3",
|
||||
"chai": "^2.0.0",
|
||||
"eslint": "^0.15.1",
|
||||
"babel-eslint": "^1.0.1",
|
||||
"browserify": "^9.0.8",
|
||||
"chai": "^2.2.0",
|
||||
"eslint": "^0.18.0",
|
||||
"babel-eslint": "^2.0.0",
|
||||
"esvalid": "^1.1.0",
|
||||
"istanbul": "^0.3.5",
|
||||
"matcha": "^0.6.0",
|
||||
"mocha": "^2.1.0",
|
||||
"rimraf": "^2.2.8",
|
||||
"mocha": "2.2.0",
|
||||
"rimraf": "^2.3.2",
|
||||
"uglify-js": "^2.4.16"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
{
|
||||
"name": "babel",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "5.0.8",
|
||||
"version": "5.1.4",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"repository": "babel/babel",
|
||||
"preferGlobal": true,
|
||||
"dependencies": {
|
||||
"chokidar": "^0.12.6",
|
||||
"babel-core": "^5.0.8",
|
||||
"babel-core": "^5.1.4",
|
||||
"chokidar": "^1.0.0",
|
||||
"commander": "^2.6.0",
|
||||
"fs-readdir-recursive": "^0.1.0",
|
||||
"output-file-sync": "^1.1.0",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "babel-runtime",
|
||||
"description": "babel selfContained runtime",
|
||||
"version": "5.0.8",
|
||||
"version": "5.1.4",
|
||||
"repository": "babel/babel",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"dependencies": {
|
||||
|
||||
@@ -13,16 +13,20 @@ function relative(filename) {
|
||||
return __dirname + "/babel-runtime/" + filename;
|
||||
}
|
||||
|
||||
function readFile(filename, defaultify) {
|
||||
function readFile(filename, shouldDefaultify) {
|
||||
var file = fs.readFileSync(require.resolve(filename), "utf8");
|
||||
|
||||
if (defaultify) {
|
||||
file += '\nmodule.exports = { "default": module.exports, __esModule: true };\n';
|
||||
if (shouldDefaultify) {
|
||||
file += "\n" + defaultify("module.exports") + "\n";
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
function defaultify(name) {
|
||||
return 'module.exports = { "default": ' + name + ', __esModule: true };';
|
||||
}
|
||||
|
||||
function updatePackage() {
|
||||
var pkgLoc = relative("package.json");
|
||||
var pkg = require(pkgLoc);
|
||||
@@ -69,4 +73,26 @@ each(File.helpers, function (helperName) {
|
||||
writeFile("regenerator/index.js", readFile("regenerator-babel/runtime-module", true));
|
||||
writeFile("regenerator/runtime.js", selfContainify(readFile("regenerator-babel/runtime")));
|
||||
|
||||
//
|
||||
|
||||
var coreDefinitions = require("../lib/babel/transformation/transformers/other/runtime/definitions");
|
||||
|
||||
var paths = ["is-iterable", "get-iterator"];
|
||||
|
||||
each(coreDefinitions.builtins, function (path) {
|
||||
paths.push(path);
|
||||
});
|
||||
|
||||
each(coreDefinitions.methods, function (props) {
|
||||
each(props, function (path) {
|
||||
paths.push(path);
|
||||
});
|
||||
});
|
||||
|
||||
each(paths, function (path) {
|
||||
writeFile("core-js/" + path + ".js", defaultify('require("core-js/library/fn/' + path + '")'));
|
||||
});
|
||||
|
||||
//
|
||||
|
||||
updatePackage();
|
||||
|
||||
@@ -93,13 +93,15 @@ pp.parseMaybeAssign = function(noIn, refShorthandDefaultPos, afterLeftParse) {
|
||||
failOnShorthandAssign = false
|
||||
}
|
||||
let start = this.markPosition()
|
||||
if (this.type == tt.parenL || this.type == tt.name)
|
||||
this.potentialArrowAt = this.start
|
||||
let left = this.parseMaybeConditional(noIn, refShorthandDefaultPos)
|
||||
if (afterLeftParse) left = afterLeftParse.call(this, left, start)
|
||||
if (this.type.isAssign) {
|
||||
let node = this.startNodeAt(start)
|
||||
node.operator = this.value
|
||||
node.left = this.type === tt.eq ? this.toAssignable(left) : left
|
||||
refShorthandDefaultPos.start = 0; // reset because shorthand default was used correctly
|
||||
refShorthandDefaultPos.start = 0 // reset because shorthand default was used correctly
|
||||
this.checkLVal(left)
|
||||
if (left.parenthesizedExpression) {
|
||||
if (left.type === "ObjectPattern") {
|
||||
@@ -224,7 +226,7 @@ pp.parseSubscripts = function(base, start, noCalls) {
|
||||
} else if (!noCalls && this.eat(tt.parenL)) {
|
||||
let node = this.startNodeAt(start)
|
||||
node.callee = base
|
||||
node.arguments = this.parseExprList(tt.parenR, false)
|
||||
node.arguments = this.parseExprList(tt.parenR, this.options.features["es7.trailingFunctionCommas"])
|
||||
return this.parseSubscripts(this.finishNode(node, "CallExpression"), start, noCalls)
|
||||
} else if (this.type === tt.backQuote) {
|
||||
let node = this.startNodeAt(start)
|
||||
@@ -240,7 +242,7 @@ pp.parseSubscripts = function(base, start, noCalls) {
|
||||
// or `{}`.
|
||||
|
||||
pp.parseExprAtom = function(refShorthandDefaultPos) {
|
||||
let node
|
||||
let node, canBeArrow = this.potentialArrowAt == this.start
|
||||
switch (this.type) {
|
||||
case tt._this:
|
||||
case tt._super:
|
||||
@@ -271,7 +273,7 @@ pp.parseExprAtom = function(refShorthandDefaultPos) {
|
||||
if (id.name === "async") {
|
||||
// arrow functions
|
||||
if (this.type === tt.parenL) {
|
||||
let expr = this.parseParenAndDistinguishExpression(start, true)
|
||||
let expr = this.parseParenAndDistinguishExpression(start, true, true)
|
||||
if (expr && expr.type === "ArrowFunctionExpression") {
|
||||
return expr
|
||||
} else {
|
||||
@@ -302,9 +304,8 @@ pp.parseExprAtom = function(refShorthandDefaultPos) {
|
||||
}
|
||||
//
|
||||
|
||||
if (!this.canInsertSemicolon() && this.eat(tt.arrow)) {
|
||||
if (canBeArrow && !this.canInsertSemicolon() && this.eat(tt.arrow))
|
||||
return this.parseArrowExpression(this.startNodeAt(start), [id])
|
||||
}
|
||||
return id
|
||||
|
||||
case tt.regexp:
|
||||
@@ -324,7 +325,7 @@ pp.parseExprAtom = function(refShorthandDefaultPos) {
|
||||
return this.finishNode(node, "Literal")
|
||||
|
||||
case tt.parenL:
|
||||
return this.parseParenAndDistinguishExpression()
|
||||
return this.parseParenAndDistinguishExpression(null, null, canBeArrow)
|
||||
|
||||
case tt.bracketL:
|
||||
node = this.startNode()
|
||||
@@ -378,7 +379,7 @@ pp.parseParenExpression = function() {
|
||||
return val
|
||||
}
|
||||
|
||||
pp.parseParenAndDistinguishExpression = function(start, isAsync) {
|
||||
pp.parseParenAndDistinguishExpression = function(start, isAsync, canBeArrow) {
|
||||
start = start || this.markPosition()
|
||||
let val
|
||||
if (this.options.ecmaVersion >= 6) {
|
||||
@@ -407,7 +408,7 @@ pp.parseParenAndDistinguishExpression = function(start, isAsync) {
|
||||
let innerEnd = this.markPosition()
|
||||
this.expect(tt.parenR)
|
||||
|
||||
if (!this.canInsertSemicolon() && this.eat(tt.arrow)) {
|
||||
if (canBeArrow && !this.canInsertSemicolon() && this.eat(tt.arrow)) {
|
||||
if (innerParenStart) this.unexpected(innerParenStart)
|
||||
return this.parseParenArrowList(start, exprList, isAsync)
|
||||
}
|
||||
@@ -508,14 +509,21 @@ pp.parseTemplate = function() {
|
||||
pp.parseObj = function(isPattern, refShorthandDefaultPos) {
|
||||
let node = this.startNode(), first = true, propHash = {}
|
||||
node.properties = []
|
||||
let decorators = []
|
||||
this.next()
|
||||
while (!this.eat(tt.braceR)) {
|
||||
if (!first) {
|
||||
this.expect(tt.comma)
|
||||
if (this.afterTrailingComma(tt.braceR)) break
|
||||
} else first = false
|
||||
|
||||
while (this.type === tt.at) {
|
||||
decorators.push(this.parseDecorator())
|
||||
}
|
||||
let prop = this.startNode(), isGenerator = false, isAsync = false, start
|
||||
if (decorators.length) {
|
||||
prop.decorators = decorators
|
||||
decorators = []
|
||||
}
|
||||
if (this.options.features["es7.objectRestSpread"] && this.type === tt.ellipsis) {
|
||||
prop = this.parseSpread()
|
||||
prop.type = "SpreadProperty"
|
||||
@@ -546,6 +554,9 @@ pp.parseObj = function(isPattern, refShorthandDefaultPos) {
|
||||
this.checkPropClash(prop, propHash)
|
||||
node.properties.push(this.finishNode(prop, "Property"))
|
||||
}
|
||||
if (decorators.length) {
|
||||
this.raise(this.start, "You have trailing decorators with no property");
|
||||
}
|
||||
return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
|
||||
}
|
||||
|
||||
@@ -726,7 +737,7 @@ pp.parseAwait = function (node) {
|
||||
this.unexpected()
|
||||
}
|
||||
node.all = this.eat(tt.star)
|
||||
node.argument = this.parseMaybeAssign(true)
|
||||
node.argument = this.parseMaybeUnary()
|
||||
return this.finishNode(node, "AwaitExpression")
|
||||
};
|
||||
|
||||
|
||||
@@ -18,17 +18,19 @@ var STATE_KEYS = [
|
||||
];
|
||||
|
||||
pp.getState = function () {
|
||||
var state = {};
|
||||
var state = {}
|
||||
for (var i = 0; i < STATE_KEYS.length; i++) {
|
||||
var key = STATE_KEYS[i];
|
||||
state[key] = this[key];
|
||||
var key = STATE_KEYS[i]
|
||||
state[key] = this[key]
|
||||
}
|
||||
return state;
|
||||
return state
|
||||
};
|
||||
|
||||
pp.lookahead = function() {
|
||||
var old = this.getState();
|
||||
this.next();
|
||||
this.isLookahead = true
|
||||
this.next()
|
||||
this.isLookahead = false
|
||||
var curr = this.getState();
|
||||
for (var key in old) this[key] = old[key];
|
||||
return curr;
|
||||
|
||||
@@ -46,6 +46,9 @@ export function Parser(options, input, startPos) {
|
||||
this.inModule = this.options.sourceType === "module"
|
||||
this.strict = this.options.strictMode === false ? false : this.inModule
|
||||
|
||||
// Used to signify the start of a potential arrow function
|
||||
this.potentialArrowAt = -1
|
||||
|
||||
// Flags to track whether we are in a function, a generator.
|
||||
this.inFunction = this.inGenerator = false
|
||||
// Labels in scope.
|
||||
|
||||
@@ -458,7 +458,7 @@ pp.parseFunction = function(node, isStatement, allowExpressionBody, isAsync) {
|
||||
|
||||
pp.parseFunctionParams = function(node) {
|
||||
this.expect(tt.parenL)
|
||||
node.params = this.parseBindingList(tt.parenR, false, false)
|
||||
node.params = this.parseBindingList(tt.parenR, false, this.options.features["es7.trailingFunctionCommas"])
|
||||
}
|
||||
|
||||
// Parse a class declaration or literal (depending on the
|
||||
@@ -471,14 +471,18 @@ pp.parseClass = function(node, isStatement) {
|
||||
var classBody = this.startNode()
|
||||
classBody.body = []
|
||||
this.expect(tt.braceL)
|
||||
let decorators = []
|
||||
while (!this.eat(tt.braceR)) {
|
||||
if (this.eat(tt.semi)) continue
|
||||
if (this.type === tt.at) {
|
||||
this.decorators.push(this.parseDecorator())
|
||||
continue;
|
||||
decorators.push(this.parseDecorator())
|
||||
continue
|
||||
}
|
||||
var method = this.startNode()
|
||||
this.takeDecorators(method)
|
||||
if (decorators.length) {
|
||||
method.decorators = decorators
|
||||
decorators = []
|
||||
}
|
||||
var isGenerator = this.eat(tt.star), isAsync = false
|
||||
this.parsePropertyName(method)
|
||||
if (this.type !== tt.parenL && !method.computed && method.key.type === "Identifier" &&
|
||||
@@ -517,7 +521,7 @@ pp.parseClass = function(node, isStatement) {
|
||||
}
|
||||
this.parseClassMethod(classBody, method, isGenerator, isAsync)
|
||||
}
|
||||
if (this.decorators.length) {
|
||||
if (decorators.length) {
|
||||
this.raise(this.start, "You have trailing decorators with no method");
|
||||
}
|
||||
node.body = this.finishNode(classBody, "ClassBody")
|
||||
|
||||
@@ -28,7 +28,7 @@ const pp = Parser.prototype
|
||||
// Move to the next token
|
||||
|
||||
pp.next = function() {
|
||||
if (this.options.onToken)
|
||||
if (this.options.onToken && !this.isLookahead)
|
||||
this.options.onToken(new Token(this))
|
||||
|
||||
this.lastTokEnd = this.end
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import path from "path";
|
||||
import os from "os";
|
||||
import fs from "fs";
|
||||
import userHome from "user-home";
|
||||
|
||||
function getUserHome() {
|
||||
return process.env.HOME || process.env.USERPROFILE;
|
||||
}
|
||||
|
||||
const FILENAME = process.env.BABEL_CACHE_PATH || path.join(getUserHome() || os.tmpdir(), ".babel.json");
|
||||
const FILENAME = process.env.BABEL_CACHE_PATH || path.join(userHome || os.tmpdir(), ".babel.json");
|
||||
var data = {};
|
||||
|
||||
export function save() {
|
||||
|
||||
@@ -169,4 +169,8 @@ export function MemberExpression(node, print) {
|
||||
}
|
||||
}
|
||||
|
||||
export { MemberExpression as MetaProperty };
|
||||
export function MetaProperty(node, print) {
|
||||
print(node.meta);
|
||||
this.push(".");
|
||||
print(node.property);
|
||||
}
|
||||
|
||||
@@ -75,5 +75,16 @@ export function ArrowFunctionExpression(node, print) {
|
||||
}
|
||||
|
||||
this.push(" => ");
|
||||
|
||||
const bodyNeedsParens = t.isObjectExpression(node.body);
|
||||
|
||||
if (bodyNeedsParens) {
|
||||
this.push("(");
|
||||
}
|
||||
|
||||
print(node.body);
|
||||
|
||||
if (bodyNeedsParens) {
|
||||
this.push(")");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,15 +7,15 @@ import * as t from "./types";
|
||||
|
||||
extend(estraverse.VisitorKeys, t.VISITOR_KEYS);
|
||||
|
||||
// regenerator-babel/ast-types
|
||||
// regenerator/ast-types
|
||||
|
||||
var def = types.Type.def;
|
||||
var or = types.Type.or;
|
||||
|
||||
def("File")
|
||||
.bases("Node")
|
||||
.build("program")
|
||||
.field("program", def("Program"));
|
||||
//def("File")
|
||||
// .bases("Node")
|
||||
// .build("program")
|
||||
// .field("program", def("Program"));
|
||||
|
||||
def("AssignmentPattern")
|
||||
.bases("Pattern")
|
||||
|
||||
@@ -4,4 +4,4 @@ if (global._babelPolyfill) {
|
||||
global._babelPolyfill = true;
|
||||
|
||||
import "core-js/shim";
|
||||
import "regenerator-babel/runtime";
|
||||
import "regenerator/runtime";
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import stripJsonComments from "strip-json-comments";
|
||||
import merge from "lodash/object/merge";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
@@ -24,7 +25,7 @@ export default function (loc, opts = {}) {
|
||||
var json;
|
||||
|
||||
try {
|
||||
json = jsons[content] ||= JSON.parse(content);
|
||||
json = jsons[content] ||= JSON.parse(stripJsonComments(content));
|
||||
} catch (err) {
|
||||
err.message = `${file}: ${err.message}`;
|
||||
throw err;
|
||||
|
||||
@@ -36,10 +36,9 @@ function checkNode(stack, node, scope) {
|
||||
|
||||
export default class File {
|
||||
constructor(opts = {}) {
|
||||
this.dynamicImportedNoDefault = [];
|
||||
this.dynamicImportIds = {};
|
||||
this.dynamicImported = [];
|
||||
this.dynamicImports = [];
|
||||
this.dynamicImportAbsoluteDefaults = [];
|
||||
this.dynamicImportIds = {};
|
||||
this.dynamicImports = [];
|
||||
|
||||
this.usedHelpers = {};
|
||||
this.dynamicData = {};
|
||||
@@ -59,6 +58,7 @@ export default class File {
|
||||
"defaults",
|
||||
"create-class",
|
||||
"create-decorated-class",
|
||||
"create-decorated-object",
|
||||
"tagged-template-literal",
|
||||
"tagged-template-literal-loose",
|
||||
"interop-require",
|
||||
@@ -85,6 +85,8 @@ export default class File {
|
||||
"default-props"
|
||||
];
|
||||
|
||||
static soloHelpers = [];
|
||||
|
||||
static options = require("./options");
|
||||
|
||||
normalizeOptions(opts: Object) {
|
||||
@@ -267,7 +269,7 @@ export default class File {
|
||||
|
||||
// validate Transformer instance
|
||||
if (!plugin.buildPass || plugin.constructor.name !== "Transformer") {
|
||||
throw new TypeError(`Plugin ${JSON.stringify(name)} didn't export default a Transformer instance`);
|
||||
throw new TypeError(`Plugin ${JSON.stringify(name)} didn't export a default Transformer instance`);
|
||||
}
|
||||
|
||||
// build!
|
||||
@@ -332,7 +334,7 @@ export default class File {
|
||||
return source;
|
||||
}
|
||||
|
||||
addImport(source: string, name?: string, noDefault?: boolean): Object {
|
||||
addImport(source: string, name?: string, absoluteDefault?: boolean): Object {
|
||||
name ||= source;
|
||||
var id = this.dynamicImportIds[name];
|
||||
|
||||
@@ -343,9 +345,7 @@ export default class File {
|
||||
var specifiers = [t.importDefaultSpecifier(id)];
|
||||
var declar = t.importDeclaration(specifiers, t.literal(source));
|
||||
declar._blockHoist = 3;
|
||||
|
||||
this.dynamicImported.push(declar);
|
||||
if (noDefault) this.dynamicImportedNoDefault.push(declar);
|
||||
if (absoluteDefault) this.dynamicImportAbsoluteDefaults.push(declar);
|
||||
|
||||
if (this.transformers["es6.modules"].canTransform()) {
|
||||
this.moduleFormatter.importSpecifier(specifiers[0], declar, this.dynamicImports);
|
||||
@@ -375,7 +375,9 @@ export default class File {
|
||||
}
|
||||
|
||||
addHelper(name: string): Object {
|
||||
if (!includes(File.helpers, name)) {
|
||||
var isSolo = includes(File.soloHelpers, name);
|
||||
|
||||
if (!isSolo && !includes(File.helpers, name)) {
|
||||
throw new ReferenceError(`Unknown helper ${name}`);
|
||||
}
|
||||
|
||||
@@ -386,24 +388,26 @@ export default class File {
|
||||
|
||||
this.usedHelpers[name] = true;
|
||||
|
||||
var generator = this.get("helperGenerator");
|
||||
var runtime = this.get("helpersNamespace");
|
||||
if (generator) {
|
||||
return generator(name);
|
||||
} else if (runtime) {
|
||||
var id = t.identifier(t.toIdentifier(name));
|
||||
return t.memberExpression(runtime, id);
|
||||
} else {
|
||||
var ref = util.template("helper-" + name);
|
||||
ref._compact = true;
|
||||
var uid = this.scope.generateUidIdentifier(name);
|
||||
this.scope.push({
|
||||
key: name,
|
||||
id: uid,
|
||||
init: ref
|
||||
});
|
||||
return uid;
|
||||
if (!isSolo) {
|
||||
var generator = this.get("helperGenerator");
|
||||
var runtime = this.get("helpersNamespace");
|
||||
if (generator) {
|
||||
return generator(name);
|
||||
} else if (runtime) {
|
||||
var id = t.identifier(t.toIdentifier(name));
|
||||
return t.memberExpression(runtime, id);
|
||||
}
|
||||
}
|
||||
|
||||
var ref = util.template("helper-" + name);
|
||||
ref._compact = true;
|
||||
var uid = this.scope.generateUidIdentifier(name);
|
||||
this.scope.push({
|
||||
key: name,
|
||||
id: uid,
|
||||
init: ref
|
||||
});
|
||||
return uid;
|
||||
}
|
||||
|
||||
errorWithNode(node, msg, Error = SyntaxError) {
|
||||
|
||||
@@ -19,7 +19,7 @@ export default function (exports, opts) {
|
||||
exports.JSXIdentifier = function (node, parent) {
|
||||
if (node.name === "this" && t.isReferenced(node, parent)) {
|
||||
return t.thisExpression();
|
||||
} else if (esutils.keyword.isIdentifierName(node.name)) {
|
||||
} else if (esutils.keyword.isIdentifierNameES6(node.name)) {
|
||||
node.type = "Identifier";
|
||||
} else {
|
||||
return t.literal(node.name);
|
||||
|
||||
@@ -1,10 +1,33 @@
|
||||
import traverse from "../../traversal";
|
||||
import * as t from "../../types";
|
||||
|
||||
export default function (node) {
|
||||
var container = t.functionExpression(null, [], node.body, node.generator, node.async);
|
||||
container.shadow = true;
|
||||
var visitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (this.isThisExpression() || this.isReferencedIdentifier({ name: "arguments" })) {
|
||||
state.found = true;
|
||||
this.stop();
|
||||
}
|
||||
|
||||
var call = t.callExpression(container, []);
|
||||
if (this.isFunction()) {
|
||||
this.skip();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default function (node, scope) {
|
||||
var container = t.functionExpression(null, [], node.body, node.generator, node.async);
|
||||
|
||||
var callee = container;
|
||||
var args = [];
|
||||
|
||||
var state = { found: false };
|
||||
scope.traverse(node, visitor, state);
|
||||
if (state.found) {
|
||||
callee = t.memberExpression(container, t.identifier("apply"));
|
||||
args = [t.thisExpression(), t.identifier("arguments")];
|
||||
}
|
||||
|
||||
var call = t.callExpression(callee, args);
|
||||
if (node.generator) call = t.yieldExpression(call, true);
|
||||
|
||||
return t.returnStatement(call);
|
||||
|
||||
@@ -4,17 +4,45 @@ import each from "lodash/collection/each";
|
||||
import has from "lodash/object/has";
|
||||
import * as t from "../../types";
|
||||
|
||||
export function push(mutatorMap, key, kind, computed, value) {
|
||||
var alias = t.toKeyAlias({ computed }, key);
|
||||
export function push(mutatorMap, node, kind, file) {
|
||||
var alias = t.toKeyAlias(node);
|
||||
|
||||
//
|
||||
|
||||
var map = {};
|
||||
if (has(mutatorMap, alias)) map = mutatorMap[alias];
|
||||
mutatorMap[alias] = map;
|
||||
|
||||
map._key = key;
|
||||
if (computed) map._computed = true;
|
||||
//
|
||||
|
||||
map[kind] = value;
|
||||
map._inherits ||= [];
|
||||
map._inherits.push(node);
|
||||
|
||||
map._key = node.key;
|
||||
|
||||
if (node.computed) {
|
||||
map._computed = true;
|
||||
}
|
||||
|
||||
if (node.decorators) {
|
||||
var decorators = map.decorators ||= t.arrayExpression([]);
|
||||
decorators.elements = decorators.elements.concat(node.decorators.map(dec => dec.expression));
|
||||
}
|
||||
|
||||
if (map.value || map.initializer) {
|
||||
throw file.errorWithNode(node, "Key conflict with sibling node");
|
||||
}
|
||||
|
||||
if (node.value) {
|
||||
if (node.kind === "init") kind = "value";
|
||||
if (node.kind === "get") kind = "get";
|
||||
if (node.kind === "set") kind = "set";
|
||||
|
||||
t.inheritsComments(node.value, node);
|
||||
map[kind] = node.value;
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
export function hasComputed(mutatorMap) {
|
||||
|
||||
@@ -27,6 +27,7 @@ var wrap = function (state, method, id, scope) {
|
||||
FUNCTION_ID: id,
|
||||
FUNCTION_KEY: scope.generateUidIdentifier(id.name)
|
||||
});
|
||||
template.callee._skipModulesRemap = true;
|
||||
|
||||
// shim in dummy params to retain function arity, if you try to read the
|
||||
// source then you'll get the original since it's proxied so it's all good
|
||||
@@ -98,6 +99,7 @@ export function property(node, file, scope) {
|
||||
if (!t.isLiteral(key)) return node; // we can't set a function id with this
|
||||
|
||||
var name = t.toIdentifier(key.value);
|
||||
if (name === "eval" || name === "arguments") name = "_" + name;
|
||||
var id = t.identifier(name);
|
||||
|
||||
var method = node.value;
|
||||
|
||||
@@ -46,7 +46,11 @@ var remapVisitor = {
|
||||
}
|
||||
}
|
||||
|
||||
if (t.isAssignmentExpression(node)) {
|
||||
if (node._skipModulesRemap) {
|
||||
return this.skip();
|
||||
}
|
||||
|
||||
if (t.isAssignmentExpression(node) && !node._ignoreModulesRemap) {
|
||||
var exported = formatter.getExport(node.left, scope);
|
||||
if (exported) {
|
||||
this.skip();
|
||||
|
||||
@@ -80,9 +80,10 @@ export default class AMDFormatter extends DefaultFormatter {
|
||||
this.defaultIds[key] = specifier.local;
|
||||
}
|
||||
|
||||
if (includes(this.file.dynamicImportedNoDefault, node)) {
|
||||
// Prevent unnecessary renaming of dynamic imports.
|
||||
if (includes(this.file.dynamicImportAbsoluteDefaults, node)) {
|
||||
// prevent unnecessary renaming of dynamic imports
|
||||
this.ids[node.source.value] = ref;
|
||||
ref = t.memberExpression(ref, t.identifier("default"));
|
||||
} else if (t.isImportNamespaceSpecifier(specifier)) {
|
||||
// import * as bar from "foo";
|
||||
} else if (!includes(this.file.dynamicImported, node) && t.isSpecifierDefault(specifier) && !this.noInteropRequireImport) {
|
||||
|
||||
@@ -45,20 +45,18 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
||||
|
||||
// import foo from "foo";
|
||||
if (t.isSpecifierDefault(specifier)) {
|
||||
if (includes(this.file.dynamicImportedNoDefault, node)) {
|
||||
if (includes(this.file.dynamicImportAbsoluteDefaults, node)) {
|
||||
this.internalRemap[variableName.name] = ref;
|
||||
} else if (this.noInteropRequireImport) {
|
||||
this.internalRemap[variableName.name] = t.memberExpression(ref, t.identifier("default"));
|
||||
} else {
|
||||
if (this.noInteropRequireImport) {
|
||||
this.internalRemap[variableName.name] = t.memberExpression(ref, t.identifier("default"));
|
||||
} else if (!includes(this.file.dynamicImported, node)) {
|
||||
var uid = this.scope.generateUidBasedOnNode(node, "import");
|
||||
var uid = this.scope.generateUidBasedOnNode(node, "import");
|
||||
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(uid, t.callExpression(this.file.addHelper("interop-require-wildcard"), [ref]))
|
||||
]));
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(uid, t.callExpression(this.file.addHelper("interop-require-wildcard"), [ref]))
|
||||
]));
|
||||
|
||||
this.internalRemap[variableName.name] = t.memberExpression(uid, t.identifier("default"));
|
||||
}
|
||||
this.internalRemap[variableName.name] = t.memberExpression(uid, t.identifier("default"));
|
||||
}
|
||||
} else {
|
||||
if (t.isImportNamespaceSpecifier(specifier)) {
|
||||
@@ -106,7 +104,7 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
||||
var call = t.callExpression(t.identifier("require"), [node.source]);
|
||||
var uid;
|
||||
|
||||
if (includes(this.file.dynamicImported, node) && !includes(this.file.dynamicImportedNoDefault, node)) {
|
||||
if (includes(this.file.dynamicImportAbsoluteDefaults, node)) {
|
||||
call = t.memberExpression(call, t.identifier("default"));
|
||||
uid = node.specifiers[0].local;
|
||||
} else {
|
||||
|
||||
@@ -6,12 +6,8 @@ import each from "lodash/collection/each";
|
||||
import map from "lodash/collection/map";
|
||||
import * as t from "../../types";
|
||||
|
||||
var canHoist = function (node, file) {
|
||||
return node._blockHoist && !file.transformers.runtime.canTransform();
|
||||
}
|
||||
|
||||
var hoistVariablesVisitor = {
|
||||
enter(node, parent, scope, hoistDeclarators) {
|
||||
enter(node, parent, scope, state) {
|
||||
if (t.isFunction(node)) {
|
||||
// nothing inside is accessible
|
||||
return this.skip();
|
||||
@@ -24,13 +20,13 @@ var hoistVariablesVisitor = {
|
||||
}
|
||||
|
||||
// ignore block hoisted nodes as these can be left in
|
||||
if (canHoist(node, scope.file)) return;
|
||||
if (state.formatter.canHoist(node)) return;
|
||||
|
||||
var nodes = [];
|
||||
|
||||
for (var i = 0; i < node.declarations.length; i++) {
|
||||
var declar = node.declarations[i];
|
||||
hoistDeclarators.push(t.variableDeclarator(declar.id));
|
||||
state.hoistDeclarators.push(t.variableDeclarator(declar.id));
|
||||
if (declar.init) {
|
||||
// no initializer so we can just hoist it as-is
|
||||
var assign = t.expressionStatement(t.assignmentExpression("=", declar.id, declar.init));
|
||||
@@ -40,14 +36,8 @@ var hoistVariablesVisitor = {
|
||||
|
||||
// for (var i in test)
|
||||
// for (var i = 0;;)
|
||||
if (t.isFor(parent)) {
|
||||
if (parent.left === node) {
|
||||
return node.declarations[0].id;
|
||||
}
|
||||
|
||||
if (parent.init === node) {
|
||||
return nodes;
|
||||
}
|
||||
if (t.isFor(parent) && parent.left === node) {
|
||||
return node.declarations[0].id;
|
||||
}
|
||||
|
||||
return nodes;
|
||||
@@ -56,11 +46,11 @@ var hoistVariablesVisitor = {
|
||||
};
|
||||
|
||||
var hoistFunctionsVisitor = {
|
||||
enter(node, parent, scope, handlerBody) {
|
||||
enter(node, parent, scope, state) {
|
||||
if (t.isFunction(node)) this.skip();
|
||||
|
||||
if (t.isFunctionDeclaration(node) || canHoist(node, scope.file)) {
|
||||
handlerBody.push(node);
|
||||
if (t.isFunctionDeclaration(node) || state.formatter.canHoist(node)) {
|
||||
state.handlerBody.push(node);
|
||||
this.remove();
|
||||
}
|
||||
}
|
||||
@@ -174,6 +164,10 @@ export default class SystemFormatter extends AMDFormatter {
|
||||
}));
|
||||
}
|
||||
|
||||
canHoist(node) {
|
||||
return node._blockHoist && !this.file.dynamicImports.length;
|
||||
}
|
||||
|
||||
transform(program) {
|
||||
DefaultFormatter.prototype.transform.apply(this, arguments);
|
||||
|
||||
@@ -197,7 +191,10 @@ export default class SystemFormatter extends AMDFormatter {
|
||||
var returnStatement = handlerBody.pop();
|
||||
|
||||
// hoist up all variable declarations
|
||||
this.file.scope.traverse(block, hoistVariablesVisitor, hoistDeclarators);
|
||||
this.file.scope.traverse(block, hoistVariablesVisitor, {
|
||||
formatter: this,
|
||||
hoistDeclarators: hoistDeclarators
|
||||
});
|
||||
|
||||
if (hoistDeclarators.length) {
|
||||
var hoistDeclar = t.variableDeclaration("var", hoistDeclarators);
|
||||
@@ -206,7 +203,10 @@ export default class SystemFormatter extends AMDFormatter {
|
||||
}
|
||||
|
||||
// hoist up function declarations for circular references
|
||||
this.file.scope.traverse(block, hoistFunctionsVisitor, handlerBody);
|
||||
this.file.scope.traverse(block, hoistFunctionsVisitor, {
|
||||
formatter: this,
|
||||
handlerBody: handlerBody
|
||||
});
|
||||
|
||||
handlerBody.push(returnStatement);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import DefaultFormatter from "./_default";
|
||||
import AMDFormatter from "./amd";
|
||||
import values from "lodash/object/values";
|
||||
import path from "path";
|
||||
import * as util from "../../util";
|
||||
import * as t from "../../types";
|
||||
|
||||
@@ -51,7 +52,7 @@ export default class UMDFormatter extends AMDFormatter {
|
||||
if (this.passModuleArg) browserArgs.push(t.identifier("mod"));
|
||||
|
||||
for (let name in this.ids) {
|
||||
var id = this.defaultIds[name] || t.identifier(t.toIdentifier(name));
|
||||
var id = this.defaultIds[name] || t.identifier(t.toIdentifier(path.basename(name, path.extname(name))));
|
||||
browserArgs.push(t.memberExpression(t.identifier("global"), id));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"blacklist": ["useStrict", "es6.blockScoping", "regenerator"],
|
||||
"blacklist": ["useStrict", "es6.blockScoping", "regenerator", "es6.spread"],
|
||||
"loose": ["es6.modules"]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
if (SUPER_NAME != null) {
|
||||
var NATIVE_REF = new SUPER_NAME(...arguments);
|
||||
NATIVE_REF.__proto__ = CLASS_NAME.prototype;
|
||||
return NATIVE_REF;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
CORE_ID.isIterable(VALUE);
|
||||
@@ -1 +0,0 @@
|
||||
CORE_ID.getIterator(VALUE);
|
||||
@@ -0,0 +1,33 @@
|
||||
(function (descriptors) {
|
||||
var target = {};
|
||||
|
||||
for (var i = 0; i < descriptors.length; i ++) {
|
||||
var descriptor = descriptors[i];
|
||||
var decorators = descriptor.decorators;
|
||||
var key = descriptor.key;
|
||||
|
||||
// don't want to expose these to userland since i know people will rely on them
|
||||
// and think it's spec behaviour
|
||||
delete descriptor.key;
|
||||
delete descriptor.decorators;
|
||||
|
||||
descriptor.enumerable = true;
|
||||
descriptor.configurable = true;
|
||||
if ("value" in descriptor) descriptor.writable = true;
|
||||
|
||||
if (decorators) {
|
||||
for (var f = 0; f < decorators.length; f++) {
|
||||
var decorator = decorators[f];
|
||||
if (typeof decorator === "function") {
|
||||
descriptor = decorator(target, key, descriptor) || descriptor;
|
||||
} else {
|
||||
throw new TypeError("The decorator for method " + descriptor.key + " is of the invalid type " + typeof decorator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Object.defineProperty(target, key, descriptor);
|
||||
}
|
||||
|
||||
return target;
|
||||
})
|
||||
@@ -5,14 +5,14 @@ export function check(node) {
|
||||
return t.isProperty(node) && (node.kind === "get" || node.kind === "set");
|
||||
}
|
||||
|
||||
export function ObjectExpression(node) {
|
||||
export function ObjectExpression(node, parent, scope, file) {
|
||||
var mutatorMap = {};
|
||||
var hasAny = false;
|
||||
|
||||
node.properties = node.properties.filter(function (prop) {
|
||||
if (prop.kind === "get" || prop.kind === "set") {
|
||||
hasAny = true;
|
||||
defineMap.push(mutatorMap, prop.key, prop.kind, prop.computed, prop.value);
|
||||
defineMap.push(mutatorMap, prop, prop.kind, file);
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
|
||||
@@ -30,7 +30,7 @@ var collectPropertyReferencesVisitor = {
|
||||
}
|
||||
|
||||
if (this.isReferenced() && scope.getBinding(node.name) === state.scope.getBinding(node.name)) {
|
||||
state.references[node.name] = true;;
|
||||
state.references[node.name] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,6 +79,10 @@ var verifyConstructorVisitor = traverse.explode({
|
||||
if (state.hasSuper && !state.hasBareSuper) {
|
||||
throw this.errorWithNode("'this' is not allowed before super()");
|
||||
}
|
||||
|
||||
if (state.isNativeSuper) {
|
||||
return state.nativeSuperRef;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -133,6 +137,15 @@ class ClassTransformer {
|
||||
|
||||
//
|
||||
|
||||
var superClass = this.node.superClass;
|
||||
this.isNativeSuper = superClass && t.isIdentifier(superClass) && t.NATIVE_TYPE_NAMES.indexOf(superClass.name) >= 0;
|
||||
|
||||
if (this.isNativeSuper) {
|
||||
this.nativeSuperRef = this.scope.generateUidIdentifier("this");
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
var body = this.body;
|
||||
|
||||
//
|
||||
@@ -155,7 +168,6 @@ class ClassTransformer {
|
||||
var closureArgs = [];
|
||||
|
||||
//
|
||||
|
||||
if (this.hasSuper) {
|
||||
closureArgs.push(superName);
|
||||
|
||||
@@ -167,27 +179,50 @@ class ClassTransformer {
|
||||
}
|
||||
|
||||
//
|
||||
var decorators = this.node.decorators;
|
||||
if (decorators) {
|
||||
// create a class reference to use later on
|
||||
this.classRef = this.scope.generateUidIdentifier(classRef);
|
||||
|
||||
// this is so super calls and the decorators have access to the raw function
|
||||
body.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(this.classRef, classRef)
|
||||
]));
|
||||
}
|
||||
|
||||
//
|
||||
this.buildBody();
|
||||
|
||||
// make sure this class isn't directly called
|
||||
constructorBody.body.unshift(t.expressionStatement(t.callExpression(file.addHelper("class-call-check"), [
|
||||
t.thisExpression(),
|
||||
classRef
|
||||
this.classRef
|
||||
])));
|
||||
|
||||
//
|
||||
|
||||
var decorators = this.node.decorators;
|
||||
if (decorators) {
|
||||
// reverse the decorators so we execute them in the right order
|
||||
decorators = decorators.reverse();
|
||||
|
||||
for (var i = 0; i < decorators.length; i++) {
|
||||
var decorator = decorators[i];
|
||||
body.push(util.template("class-decorator", {
|
||||
|
||||
var decoratorNode = util.template("class-decorator", {
|
||||
DECORATOR: decorator.expression,
|
||||
CLASS_REF: classRef
|
||||
}, true));
|
||||
}, true);
|
||||
decoratorNode.expression._ignoreModulesRemap = true;
|
||||
body.push(decoratorNode);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.isNativeSuper) {
|
||||
// we've determined this is inheriting from a native class so return the constructed
|
||||
// instance
|
||||
constructorBody.body.push(t.returnStatement(this.nativeSuperRef));
|
||||
}
|
||||
|
||||
if (this.className) {
|
||||
// named class with only a constructor
|
||||
if (body.length === 1) return t.toExpression(body[0]);
|
||||
@@ -228,44 +263,15 @@ class ClassTransformer {
|
||||
mutatorMap = this.instanceMutatorMap;
|
||||
}
|
||||
|
||||
var alias = t.toKeyAlias(node);
|
||||
|
||||
//
|
||||
|
||||
var map = {};
|
||||
if (has(mutatorMap, alias)) map = mutatorMap[alias];
|
||||
mutatorMap[alias] = map;
|
||||
|
||||
//
|
||||
|
||||
map._inherits ||= [];
|
||||
map._inherits.push(node);
|
||||
|
||||
map._key = node.key;
|
||||
var map = defineMap.push(mutatorMap, node, kind, this.file);
|
||||
|
||||
if (enumerable) {
|
||||
map.enumerable = t.literal(true)
|
||||
}
|
||||
|
||||
if (node.computed) {
|
||||
map._computed = true;
|
||||
}
|
||||
|
||||
if (node.decorators) {
|
||||
if (map.decorators) {
|
||||
this.hasDecorators = true;
|
||||
var decorators = map.decorators ||= t.arrayExpression([]);
|
||||
decorators.elements = decorators.elements.concat(node.decorators.map(dec => dec.expression));
|
||||
}
|
||||
|
||||
if (map.value || map.initializer) {
|
||||
throw this.file.errorWithNode(node, "Key conflict with sibling node");
|
||||
}
|
||||
|
||||
if (node.kind === "get") kind = "get";
|
||||
if (node.kind === "set") kind = "set";
|
||||
|
||||
t.inheritsComments(node.value, node);
|
||||
map[kind] = node.value;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -317,7 +323,9 @@ class ClassTransformer {
|
||||
if (!this.hasConstructor && this.hasSuper) {
|
||||
var helperName = "class-super-constructor-call";
|
||||
if (this.isLoose) helperName += "-loose";
|
||||
if (this.isNativeSuper) helperName = "class-super-native-constructor-call";
|
||||
constructorBody.body.push(util.template(helperName, {
|
||||
NATIVE_REF: this.nativeSuperRef,
|
||||
CLASS_NAME: className,
|
||||
SUPER_NAME: this.superName
|
||||
}, true));
|
||||
@@ -446,10 +454,12 @@ class ClassTransformer {
|
||||
|
||||
verifyConstructor(path: TraversalPath) {
|
||||
var state = {
|
||||
hasBareSuper: false,
|
||||
bareSuper: null,
|
||||
hasSuper: this.hasSuper,
|
||||
file: this.file
|
||||
nativeSuperRef: this.nativeSuperRef,
|
||||
isNativeSuper: this.isNativeSuper,
|
||||
hasBareSuper: false,
|
||||
bareSuper: null,
|
||||
hasSuper: this.hasSuper,
|
||||
file: this.file
|
||||
};
|
||||
|
||||
path.get("value").traverse(verifyConstructorVisitor, state);
|
||||
@@ -459,6 +469,21 @@ class ClassTransformer {
|
||||
if (!state.hasBareSuper && this.hasSuper) {
|
||||
throw path.errorWithNode("Derived constructor must call super()");
|
||||
}
|
||||
|
||||
if (this.isNativeSuper && this.bareSuper) {
|
||||
this.bareSuper.replaceWithMultiple([
|
||||
t.variableDeclaration("var", [
|
||||
t.variableDeclarator(this.nativeSuperRef, t.newExpression(this.superName, this.bareSuper.node.arguments))
|
||||
]),
|
||||
|
||||
t.expressionStatement(t.assignmentExpression(
|
||||
"=",
|
||||
t.memberExpression(this.nativeSuperRef, t.identifier("__proto__")),
|
||||
t.memberExpression(this.classRef, t.identifier("prototype"))
|
||||
)),
|
||||
t.expressionStatement(this.nativeSuperRef)
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -495,8 +520,6 @@ class ClassTransformer {
|
||||
*/
|
||||
|
||||
pushProperty(node: { type: "ClassProperty" }) {
|
||||
if (!node.value && !node.decorators) return;
|
||||
|
||||
var key;
|
||||
|
||||
this.scope.traverse(node, collectPropertyReferencesVisitor, {
|
||||
@@ -523,16 +546,17 @@ class ClassTransformer {
|
||||
}, true));
|
||||
}
|
||||
} else {
|
||||
if (node.static) {
|
||||
// can just be added to the static map
|
||||
this.pushToMap(node, true);
|
||||
} else {
|
||||
if (!node.static && node.value) {
|
||||
// add this to the instancePropBody which will be added after the super call in a derived constructor
|
||||
// or at the start of a constructor for a non-derived constructor
|
||||
this.instancePropBody.push(t.expressionStatement(
|
||||
t.assignmentExpression("=", t.memberExpression(t.thisExpression(), node.key), node.value)
|
||||
));
|
||||
node.value = t.identifier("undefined");
|
||||
}
|
||||
|
||||
// can just be added to the static map
|
||||
this.pushToMap(node, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -126,10 +126,11 @@ export function AssignmentExpression(node, parent, scope, file) {
|
||||
if (!t.isPattern(node.left)) return;
|
||||
|
||||
var ref = scope.generateUidIdentifier("temp");
|
||||
scope.push({ id: ref });
|
||||
|
||||
var nodes = [];
|
||||
nodes.push(t.expressionStatement(t.assignmentExpression("=", ref, node.right)));
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(ref, node.right)
|
||||
]));
|
||||
|
||||
var destructuring = new DestructuringTransformer({
|
||||
operator: node.operator,
|
||||
@@ -137,6 +138,11 @@ export function AssignmentExpression(node, parent, scope, file) {
|
||||
scope: scope,
|
||||
nodes: nodes
|
||||
});
|
||||
|
||||
if (t.isArrayExpression(node.right)) {
|
||||
destructuring.arrays[ref.name] = true;
|
||||
}
|
||||
|
||||
destructuring.init(node.left, ref);
|
||||
|
||||
nodes.push(t.expressionStatement(ref));
|
||||
@@ -397,9 +403,14 @@ class DestructuringTransformer {
|
||||
if (pattern.elements.length > arr.elements.length) return;
|
||||
if (pattern.elements.length < arr.elements.length && !hasRest(pattern)) return false;
|
||||
|
||||
// deopt on holes
|
||||
for (var i = 0; i < pattern.elements.length; i++) {
|
||||
if (!pattern.elements[i]) return false;
|
||||
var elem = pattern.elements[i];
|
||||
|
||||
// deopt on holes
|
||||
if (!elem) return false;
|
||||
|
||||
// deopt on member expressions
|
||||
if (t.isMemberExpression(elem)) return false;
|
||||
}
|
||||
|
||||
// deopt on reference to left side identifiers
|
||||
|
||||
@@ -17,9 +17,6 @@ export function ForOfStatement(node, parent, scope, file) {
|
||||
var loop = build.loop;
|
||||
var block = loop.body;
|
||||
|
||||
// inherit comments from the original loop
|
||||
t.inheritsComments(loop, node);
|
||||
|
||||
// ensure that it's a block so we can take all its statements
|
||||
t.ensureBlock(node);
|
||||
|
||||
@@ -32,6 +29,7 @@ export function ForOfStatement(node, parent, scope, file) {
|
||||
block.body = block.body.concat(node.body.body);
|
||||
|
||||
t.inherits(loop, node);
|
||||
t.inherits(loop.body, node.body);
|
||||
|
||||
if (build.replaceParent) {
|
||||
this.parentPath.replaceWithMultiple(build.node);
|
||||
|
||||
@@ -92,7 +92,7 @@ exports.Function = function (node, parent, scope, file) {
|
||||
node.params = node.params.slice(0, lastNonDefaultParam);
|
||||
|
||||
if (state.iife) {
|
||||
body.push(callDelegate(node));
|
||||
body.push(callDelegate(node, scope));
|
||||
node.body = t.blockStatement(body);
|
||||
} else {
|
||||
node.body.body = body.concat(node.body.body);
|
||||
|
||||
@@ -6,6 +6,7 @@ import map from "lodash/collection/map";
|
||||
import * as t from "../../../types";
|
||||
|
||||
exports.Function = function (node, parent, scope, file) {
|
||||
if (node.generator || node.async) return;
|
||||
var tailCall = new TailCallTransformer(this, scope, file);
|
||||
tailCall.run();
|
||||
};
|
||||
@@ -179,7 +180,7 @@ class TailCallTransformer {
|
||||
if (this.vars.length > 0) {
|
||||
var declarations = flatten(map(this.vars, function (decl) {
|
||||
return decl.declarations;
|
||||
}, this));
|
||||
}));
|
||||
var assignment = reduceRight(declarations, function (expr, decl) {
|
||||
return t.assignmentExpression("=", decl.id, expr);
|
||||
}, t.identifier("undefined"));
|
||||
|
||||
@@ -1,4 +1,33 @@
|
||||
import * as defineMap from "../../helpers/define-map";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
optional: true,
|
||||
stage: 1
|
||||
};
|
||||
|
||||
export function check(node) {
|
||||
return !!node.decorators;
|
||||
}
|
||||
|
||||
export function ObjectExpression(node, parent, scope, file) {
|
||||
var hasDecorators = false;
|
||||
for (var i = 0; i < node.properties.length; i++) {
|
||||
var prop = node.properties[i];
|
||||
if (prop.decorators) {
|
||||
hasDecorators = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!hasDecorators) return;
|
||||
|
||||
var mutatorMap = {};
|
||||
|
||||
for (var i = 0; i < node.properties.length; i++) {
|
||||
defineMap.push(mutatorMap, node.properties[i], null, file);
|
||||
}
|
||||
|
||||
var obj = defineMap.toClassObject(mutatorMap);
|
||||
obj = defineMap.toComputedObjectFromClass(obj);
|
||||
return t.callExpression(file.addHelper("create-decorated-object"), [obj]);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
export var metadata = {
|
||||
stage: 1
|
||||
};
|
||||
|
||||
export function check() {
|
||||
return false;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
export default {
|
||||
"es7.classProperties": require("./es7/class-properties"),
|
||||
"es7.trailingFunctionCommas": require("./es7/trailing-function-commas"),
|
||||
"es7.asyncFunctions": require("./es7/async-functions"),
|
||||
"es7.decorators": require("./es7/decorators"),
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ exports.Function = function (node, parent, scope, file) {
|
||||
|
||||
return remapAsyncToGenerator(
|
||||
node,
|
||||
t.memberExpression(file.addImport("bluebird", null, true), t.identifier("coroutine")),
|
||||
t.memberExpression(file.addImport("bluebird"), t.identifier("coroutine")),
|
||||
scope
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import regenerator from "regenerator-babel";
|
||||
import regenerator from "regenerator";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export function check(node) {
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
import core from "core-js/library";
|
||||
import includes from "lodash/collection/includes";
|
||||
import * as util from "../../../util";
|
||||
import has from "lodash/object/has";
|
||||
import * as t from "../../../types";
|
||||
|
||||
var isSymbolIterator = t.buildMatchMemberExpression("Symbol.iterator");
|
||||
|
||||
var ALIASABLE_CONSTRUCTORS = [
|
||||
"Symbol",
|
||||
"Promise",
|
||||
"Map",
|
||||
"WeakMap",
|
||||
"Set",
|
||||
"WeakSet"
|
||||
];
|
||||
|
||||
function coreHas(node) {
|
||||
return node.name !== "_" && has(core, node.name);
|
||||
}
|
||||
|
||||
var astVisitor = {
|
||||
enter(node, parent, scope, file) {
|
||||
var prop;
|
||||
|
||||
if (this.isMemberExpression() && this.isReferenced()) {
|
||||
// Array.from -> _core.Array.from
|
||||
var obj = node.object;
|
||||
prop = node.property;
|
||||
|
||||
if (!t.isReferenced(obj, node)) return;
|
||||
|
||||
if (!node.computed && coreHas(obj) && has(core[obj.name], prop.name) && !scope.getBindingIdentifier(obj.name)) {
|
||||
this.skip();
|
||||
return t.prependToMemberExpression(node, file.get("coreIdentifier"));
|
||||
}
|
||||
} else if (this.isReferencedIdentifier() && !t.isMemberExpression(parent) && includes(ALIASABLE_CONSTRUCTORS, node.name) && !scope.getBindingIdentifier(node.name)) {
|
||||
// Symbol() -> _core.Symbol(); new Promise -> new _core.Promise
|
||||
return t.memberExpression(file.get("coreIdentifier"), node);
|
||||
} else if (this.isCallExpression()) {
|
||||
// arr[Symbol.iterator]() -> _core.$for.getIterator(arr)
|
||||
|
||||
var callee = node.callee;
|
||||
if (node.arguments.length) return false;
|
||||
|
||||
if (!t.isMemberExpression(callee)) return false;
|
||||
if (!callee.computed) return false;
|
||||
|
||||
prop = callee.property;
|
||||
if (!isSymbolIterator(prop)) return false;
|
||||
|
||||
return util.template("corejs-iterator", {
|
||||
CORE_ID: file.get("coreIdentifier"),
|
||||
VALUE: callee.object
|
||||
});
|
||||
} else if (this.isBinaryExpression()) {
|
||||
// Symbol.iterator in arr -> core.$for.isIterable(arr)
|
||||
|
||||
if (node.operator !== "in") return;
|
||||
|
||||
var left = node.left;
|
||||
if (!isSymbolIterator(left)) return;
|
||||
|
||||
return util.template("corejs-is-iterator", {
|
||||
CORE_ID: file.get("coreIdentifier"),
|
||||
VALUE: node.right
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.metadata = {
|
||||
optional: true
|
||||
};
|
||||
|
||||
exports.Program = function (node, parent, scope, file) {
|
||||
this.traverse(astVisitor, file);
|
||||
};
|
||||
|
||||
exports.pre = function (file) {
|
||||
file.set("helperGenerator", function (name) {
|
||||
return file.addImport(`babel-runtime/helpers/${name}`, name);
|
||||
});
|
||||
|
||||
file.setDynamic("coreIdentifier", function () {
|
||||
return file.addImport("babel-runtime/core-js", "core");
|
||||
});
|
||||
|
||||
file.setDynamic("regeneratorIdentifier", function () {
|
||||
return file.addImport("babel-runtime/regenerator", "regeneratorRuntime");
|
||||
});
|
||||
};
|
||||
|
||||
exports.Identifier = function (node, parent, scope, file) {
|
||||
if (this.isReferencedIdentifier({ name: "regeneratorRuntime" })) {
|
||||
return file.get("regeneratorIdentifier");
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,165 @@
|
||||
{
|
||||
"builtins": {
|
||||
"Symbol": "symbol",
|
||||
"Promise": "promise",
|
||||
"Map": "map",
|
||||
"WeakMap": "weak-map",
|
||||
"Set": "set",
|
||||
"WeakSet": "weak-set"
|
||||
},
|
||||
|
||||
"methods": {
|
||||
"Array": {
|
||||
"concat": "array/concat",
|
||||
"copyWithin": "array/copy-within",
|
||||
"entries": "array/entries",
|
||||
"every": "array/every",
|
||||
"fill": "array/fill",
|
||||
"filter": "array/filter",
|
||||
"findIndex": "array/find-index",
|
||||
"find": "array/find",
|
||||
"forEach": "array/for-each",
|
||||
"from": "array/from",
|
||||
"includes": "array/includes",
|
||||
"indexOf": "array/index-of",
|
||||
"join": "array/join",
|
||||
"keys": "array/keys",
|
||||
"lastIndexOf": "array/last-index-of",
|
||||
"map": "array/map",
|
||||
"of": "array/of",
|
||||
"pop": "array/pop",
|
||||
"push": "array/push",
|
||||
"reduceRight": "array/reduce-right",
|
||||
"reduce": "array/reduce",
|
||||
"reverse": "array/reverse",
|
||||
"shift": "array/shift",
|
||||
"slice": "array/slice",
|
||||
"some": "array/some",
|
||||
"sort": "array/sort",
|
||||
"splice": "array/splice",
|
||||
"turn": "array/turn",
|
||||
"unshift": "array/unshift",
|
||||
"values": "array/values"
|
||||
},
|
||||
|
||||
"Object": {
|
||||
"assign": "object/assign",
|
||||
"classof": "object/classof",
|
||||
"define": "object/define",
|
||||
"entries": "object/entries",
|
||||
"freeze": "object/freeze",
|
||||
"getOwnPropertyDescriptor": "object/get-own-property-descriptor",
|
||||
"getOwnPropertyDescriptors": "object/get-own-property-descriptors",
|
||||
"getOwnPropertyNames": "object/get-own-property-names",
|
||||
"getOwnPropertySymbols": "object/get-own-property-symbols",
|
||||
"getPrototypePf": "object/get-prototype-of",
|
||||
"index": "object/index",
|
||||
"isExtensible": "object/is-extensible",
|
||||
"isFrozen": "object/is-frozen",
|
||||
"isObject": "object/is-object",
|
||||
"isSealed": "object/is-sealed",
|
||||
"is": "object/is",
|
||||
"keys": "object/keys",
|
||||
"make": "object/make",
|
||||
"preventExtensions": "object/prevent-extensions",
|
||||
"seal": "object/seal",
|
||||
"setPrototypeOf": "object/set-prototype-of",
|
||||
"values": "object/values"
|
||||
},
|
||||
|
||||
"RegExp": {
|
||||
"escape": "regexp/escape"
|
||||
},
|
||||
|
||||
"Function": {
|
||||
"only": "function/only",
|
||||
"part": "function/part"
|
||||
},
|
||||
|
||||
"Math": {
|
||||
"acosh": "math/acosh",
|
||||
"asinh": "math/asinh",
|
||||
"atanh": "math/atanh",
|
||||
"cbrt": "math/cbrt",
|
||||
"clz32": "math/clz32",
|
||||
"cosh": "math/cosh",
|
||||
"expm1": "math/expm1",
|
||||
"fround": "math/fround",
|
||||
"hypot": "math/hypot",
|
||||
"pot": "math/pot",
|
||||
"imul": "math/imul",
|
||||
"log10": "math/log10",
|
||||
"log1p": "math/log1p",
|
||||
"log2": "math/log2",
|
||||
"sign": "math/sign",
|
||||
"sinh": "math/sinh",
|
||||
"tanh": "math/tanh",
|
||||
"trunc": "math/trunc"
|
||||
},
|
||||
|
||||
"Date": {
|
||||
"addLocale": "date/add-locale",
|
||||
"formatUTC": "date/format-utc",
|
||||
"format": "date/format"
|
||||
},
|
||||
|
||||
"Symbol": {
|
||||
"for": "symbol/for",
|
||||
"hasInstance": "symbol/for-instance",
|
||||
"is-concat-spreadable": "symbol/is-concat-spreadable",
|
||||
"iterator": "symbol/iterator",
|
||||
"keyFor": "symbol/key-for",
|
||||
"match": "symbol/match",
|
||||
"replace": "symbol/replace",
|
||||
"search": "symbol/search",
|
||||
"species": "symbol/species",
|
||||
"split": "symbol/split",
|
||||
"toPrimitive": "symbol/to-primitive",
|
||||
"toStringTag": "symbol/to-string-tag",
|
||||
"unscopables": "symbol/unscopables"
|
||||
},
|
||||
|
||||
"String": {
|
||||
"at": "string/at",
|
||||
"codePointAt": "string/code-point-at",
|
||||
"endsWith": "string/ends-with",
|
||||
"escapeHTML": "string/escape-html",
|
||||
"fromCodePoint": "string/from-code-point",
|
||||
"includes": "string/includes",
|
||||
"raw": "string/raw",
|
||||
"repeat": "string/repeat",
|
||||
"startsWith": "string/starts-with",
|
||||
"unescapeHTML": "string/unescape-html"
|
||||
},
|
||||
|
||||
"Number": {
|
||||
"EPSILON": "number/epsilon",
|
||||
"isFinite": "number/is-finite",
|
||||
"isInteger": "number/is-integer",
|
||||
"isNaN": "number/is-nan",
|
||||
"isSafeInteger": "number/is-safe-integer",
|
||||
"MAX_SAFE_INTEGER": "number/max-safe-integer",
|
||||
"MIN_SAFE_INTEGER": "number/min-safe-integer",
|
||||
"parseFloat": "number/parse-float",
|
||||
"parseInt": "number/parse-int",
|
||||
"random": "number/random"
|
||||
},
|
||||
|
||||
"Reflect": {
|
||||
"apply": "reflect/apply",
|
||||
"construct": "reflect/construct",
|
||||
"defineProperty": "reflect/define-property",
|
||||
"deleteProperty": "reflect/delete-property",
|
||||
"enumerate": "reflect/enumerate",
|
||||
"getOwnPropertyDescriptor": "reflect/get-own-property-descriptor",
|
||||
"getPrototypeOf": "reflect/get-prototype-of",
|
||||
"get": "reflect/get",
|
||||
"has": "reflect/has",
|
||||
"isExtensible": "reflect/is-extensible",
|
||||
"ownKeys": "reflect/own-keys",
|
||||
"preventExtensions": "reflect/prevent-extensions",
|
||||
"setPrototypeOf": "reflect/set-prototype-of",
|
||||
"set": "reflect/set"
|
||||
}
|
||||
}
|
||||
}
|
||||
116
src/babel/transformation/transformers/other/runtime/index.js
Normal file
116
src/babel/transformation/transformers/other/runtime/index.js
Normal file
@@ -0,0 +1,116 @@
|
||||
import includes from "lodash/collection/includes";
|
||||
import traverse from "../../../../traversal";
|
||||
import * as util from "../../../../util";
|
||||
import has from "lodash/object/has";
|
||||
import * as t from "../../../../types";
|
||||
import definitions from "./definitions";
|
||||
|
||||
var isSymbolIterator = t.buildMatchMemberExpression("Symbol.iterator");
|
||||
|
||||
const RUNTIME_MODULE_NAME = "babel-runtime";
|
||||
|
||||
var astVisitor = traverse.explode({
|
||||
Identifier(node, parent, scope, file) {
|
||||
if (!this.isReferenced()) return;
|
||||
if (t.isMemberExpression(parent)) return;
|
||||
if (!has(definitions.builtins, node.name)) return;
|
||||
if (scope.getBindingIdentifier(node.name)) return;
|
||||
|
||||
// Symbol() -> _core.Symbol(); new Promise -> new _core.Promise
|
||||
var modulePath = definitions.builtins[node.name];
|
||||
return file.addImport(`${RUNTIME_MODULE_NAME}/core-js/${modulePath}`, node.name, true);
|
||||
},
|
||||
|
||||
CallExpression(node, parent, scope, file) {
|
||||
// arr[Symbol.iterator]() -> _core.$for.getIterator(arr)
|
||||
|
||||
var callee = node.callee;
|
||||
if (node.arguments.length) return;
|
||||
|
||||
if (!t.isMemberExpression(callee)) return;
|
||||
if (!callee.computed) return;
|
||||
|
||||
var prop = callee.property;
|
||||
if (!isSymbolIterator(prop)) return;
|
||||
|
||||
return t.callExpression(file.addImport(`${RUNTIME_MODULE_NAME}/core-js/get-iterator`, "getIterator", true), [callee.object]);
|
||||
},
|
||||
|
||||
BinaryExpression(node, parent, scope, file) {
|
||||
// Symbol.iterator in arr -> core.$for.isIterable(arr)
|
||||
|
||||
if (node.operator !== "in") return;
|
||||
|
||||
var left = node.left;
|
||||
if (!isSymbolIterator(left)) return;
|
||||
|
||||
return t.callExpression(
|
||||
file.addImport(`${RUNTIME_MODULE_NAME}/core-js/is-iterable`, "isIterable", true),
|
||||
[node.right]
|
||||
);
|
||||
},
|
||||
|
||||
MemberExpression: {
|
||||
enter(node, parent, scope, file) {
|
||||
// Array.from -> _core.Array.from
|
||||
|
||||
if (!this.isReferenced()) return;
|
||||
|
||||
var obj = node.object;
|
||||
var prop = node.property;
|
||||
|
||||
if (!t.isReferenced(obj, node)) return;
|
||||
|
||||
if (node.computed) return;
|
||||
|
||||
if (!has(definitions.methods, obj.name)) return;
|
||||
|
||||
var methods = definitions.methods[obj.name];
|
||||
if (!has(methods, prop.name)) return;
|
||||
|
||||
if (scope.getBindingIdentifier(obj.name)) return;
|
||||
|
||||
var modulePath = methods[prop.name];
|
||||
return file.addImport(`${RUNTIME_MODULE_NAME}/core-js/${modulePath}`, `${obj.name}$${prop.name}`, true);
|
||||
},
|
||||
|
||||
exit(node, parent, scope, file) {
|
||||
if (!this.isReferenced()) return;
|
||||
|
||||
var prop = node.property;
|
||||
var obj = node.object;
|
||||
|
||||
if (!has(definitions.builtins, obj.name)) return;
|
||||
|
||||
var modulePath = definitions.builtins[obj.name];
|
||||
return t.memberExpression(
|
||||
file.addImport(`${RUNTIME_MODULE_NAME}/core-js/${modulePath}`, `${obj.name}`, true),
|
||||
prop
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
exports.metadata = {
|
||||
optional: true
|
||||
};
|
||||
|
||||
exports.Program = function (node, parent, scope, file) {
|
||||
this.traverse(astVisitor, file);
|
||||
};
|
||||
|
||||
exports.pre = function (file) {
|
||||
file.set("helperGenerator", function (name) {
|
||||
return file.addImport(`${RUNTIME_MODULE_NAME}/helpers/${name}`, name, true);
|
||||
});
|
||||
|
||||
file.setDynamic("regeneratorIdentifier", function () {
|
||||
return file.addImport(`${RUNTIME_MODULE_NAME}/regenerator`, "regeneratorRuntime", true);
|
||||
});
|
||||
};
|
||||
|
||||
exports.Identifier = function (node, parent, scope, file) {
|
||||
if (this.isReferencedIdentifier({ name: "regeneratorRuntime" })) {
|
||||
return file.get("regeneratorIdentifier");
|
||||
}
|
||||
};
|
||||
@@ -34,6 +34,7 @@ export var IfStatement = {
|
||||
exit(node, parent, scope) {
|
||||
var consequent = node.consequent;
|
||||
var alternate = node.alternate;
|
||||
var test = node.test;
|
||||
|
||||
var evaluateTest = this.get("test").evaluateTruthy();
|
||||
|
||||
|
||||
@@ -78,6 +78,9 @@ traverse.removeProperties = function (tree) {
|
||||
traverse.explode = function (obj) {
|
||||
for (var type in obj) {
|
||||
var fns = obj[type];
|
||||
if (typeof fns === "function") {
|
||||
obj[type] = fns = { enter: fns };
|
||||
}
|
||||
|
||||
var aliases = t.FLIPPED_ALIAS_KEYS[type];
|
||||
if (aliases) {
|
||||
|
||||
@@ -57,7 +57,7 @@ export function evaluate(): { confident: boolean; value: any } {
|
||||
}
|
||||
|
||||
if (path.isLiteral()) {
|
||||
if (node.regex && node.value === null) {
|
||||
if (node.regex) {
|
||||
// we have a regex and we can't represent it natively
|
||||
} else {
|
||||
return node.value;
|
||||
|
||||
@@ -91,6 +91,9 @@ export default class TraversalPath {
|
||||
|
||||
if (this.parentPath.isExpressionStatement() || this.parentPath.isLabeledStatement()) {
|
||||
return this.parentPath.insertBefore(nodes);
|
||||
} else if (this.isPreviousType("Expression") || (this.parentPath.isForStatement() && this.key === "init")) {
|
||||
if (this.node) nodes.push(this.node);
|
||||
this.replaceExpressionWithStatements(nodes);
|
||||
} else if (this.isPreviousType("Statement")) {
|
||||
this._maybePopFromStatements(nodes);
|
||||
if (Array.isArray(this.container)) {
|
||||
@@ -101,15 +104,11 @@ export default class TraversalPath {
|
||||
} else {
|
||||
throw new Error("We don't know what to do with this node type. We were previously a Statement but we can't fit in here?");
|
||||
}
|
||||
} else if (this.isPreviousType("Expression")) {
|
||||
if (this.node) nodes.push(this.node);
|
||||
this.replaceExpressionWithStatements(nodes);
|
||||
} else {
|
||||
throw new Error("No clue what to do with this node type.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_containerInsert(from, nodes) {
|
||||
this.updateSiblingKeys(from, nodes.length);
|
||||
|
||||
@@ -133,11 +132,24 @@ export default class TraversalPath {
|
||||
|
||||
_maybePopFromStatements(nodes) {
|
||||
var last = nodes[nodes.length - 1];
|
||||
if (t.isExpressionStatement(last) && t.isIdentifier(last.expression)) {
|
||||
if (t.isExpressionStatement(last) && t.isIdentifier(last.expression) && !this.isCompletionRecord()) {
|
||||
nodes.pop();
|
||||
}
|
||||
}
|
||||
|
||||
isCompletionRecord() {
|
||||
var path = this;
|
||||
|
||||
do {
|
||||
var container = path.container;
|
||||
if (Array.isArray(container) && path.key !== container.length - 1) {
|
||||
return false;
|
||||
}
|
||||
} while (path = path.parentPath && !path.isProgram());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
isStatementOrBlock() {
|
||||
if (t.isLabeledStatement(this.parent) || t.isBlockStatement(this.container)) {
|
||||
return false;
|
||||
@@ -152,6 +164,13 @@ export default class TraversalPath {
|
||||
|
||||
if (this.parentPath.isExpressionStatement() || this.parentPath.isLabeledStatement()) {
|
||||
return this.parentPath.insertAfter(nodes);
|
||||
} else if (this.isPreviousType("Expression") || (this.parentPath.isForStatement() && this.key === "init")) {
|
||||
if (this.node) {
|
||||
var temp = this.scope.generateTemp();
|
||||
nodes.unshift(t.expressionStatement(t.assignmentExpression("=", temp, this.node)));
|
||||
nodes.push(t.expressionStatement(temp));
|
||||
}
|
||||
this.replaceExpressionWithStatements(nodes);
|
||||
} else if (this.isPreviousType("Statement")) {
|
||||
this._maybePopFromStatements(nodes);
|
||||
if (Array.isArray(this.container)) {
|
||||
@@ -159,16 +178,10 @@ export default class TraversalPath {
|
||||
} else if (this.isStatementOrBlock()) {
|
||||
if (this.node) nodes.unshift(this.node);
|
||||
this.container[this.key] = t.blockStatement(nodes);
|
||||
this.replaceExpressionWithStatements(nodes);
|
||||
} else {
|
||||
throw new Error("We don't know what to do with this node type. We were previously a Statement but we can't fit in here?");
|
||||
}
|
||||
} else if (this.isPreviousType("Expression")) {
|
||||
if (this.node) {
|
||||
var temp = this.scope.generateTemp();
|
||||
nodes.unshift(t.expressionStatement(t.assignmentExpression("=", temp, this.node)));
|
||||
nodes.push(t.expressionStatement(temp));
|
||||
}
|
||||
this.replaceExpressionWithStatements(nodes);
|
||||
} else {
|
||||
throw new Error("No clue what to do with this node type.");
|
||||
}
|
||||
@@ -700,6 +713,11 @@ export default class TraversalPath {
|
||||
var search = [this.node];
|
||||
var i = 0;
|
||||
|
||||
function matches(name) {
|
||||
var part = parts[i];
|
||||
return part === "*" || name === part;
|
||||
}
|
||||
|
||||
while (search.length) {
|
||||
var node = search.shift();
|
||||
|
||||
@@ -709,10 +727,10 @@ export default class TraversalPath {
|
||||
|
||||
if (t.isIdentifier(node)) {
|
||||
// this part doesn't match
|
||||
if (parts[i] !== node.name) return false;
|
||||
if (!matches(node.name)) return false;
|
||||
} else if (t.isLiteral(node)) {
|
||||
// this part doesn't match
|
||||
if (parts[i] !== node.value) return false;
|
||||
if (!matches(node.value)) return false;
|
||||
} else if (t.isMemberExpression(node)) {
|
||||
if (node.computed && !t.isLiteral(node.property)) {
|
||||
// we can't deal with this
|
||||
|
||||
@@ -80,7 +80,7 @@ export default class Scope {
|
||||
if (cached && cached.parent === parent) {
|
||||
return cached;
|
||||
} else {
|
||||
path.setData("scope", this);
|
||||
//path.setData("scope", this);
|
||||
}
|
||||
|
||||
this.parent = parent;
|
||||
@@ -449,7 +449,7 @@ export default class Scope {
|
||||
if (path.isLoop()) {
|
||||
for (let i = 0; i < t.FOR_INIT_KEYS.length; i++) {
|
||||
var node = path.get(t.FOR_INIT_KEYS[i]);
|
||||
if (node.isBlockScoped()) this.registerBinding("let", node);
|
||||
if (node.isBlockScoped()) this.registerBinding(node.node.kind, node);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,8 @@
|
||||
"id": null,
|
||||
"params": null,
|
||||
"body": null,
|
||||
"generator": false
|
||||
"generator": false,
|
||||
"async": false
|
||||
},
|
||||
|
||||
"GenericTypeAnnotation": {
|
||||
|
||||
@@ -115,7 +115,8 @@ export function isReferencedIdentifier(node: Object, parent: Object, opts?: Obje
|
||||
*/
|
||||
|
||||
export function isValidIdentifier(name: string): boolean {
|
||||
return isString(name) && esutils.keyword.isIdentifierName(name) && !esutils.keyword.isReservedWordES6(name, true);
|
||||
if (!isString(name) || esutils.keyword.isReservedWordES6(name, true)) return false;
|
||||
return esutils.keyword.isIdentifierNameES6(name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
"CallExpression": ["callee", "arguments"],
|
||||
"CatchClause": ["param", "body"],
|
||||
"ClassBody": ["body"],
|
||||
"ClassDeclaration": ["id", "body", "superClass", "typeParameters", "superTypeParameters", "implements"],
|
||||
"ClassExpression": ["id", "body", "superClass", "typeParameters", "superTypeParameters", "implements"],
|
||||
"ClassDeclaration": ["id", "body", "superClass", "typeParameters", "superTypeParameters", "implements", "decorators"],
|
||||
"ClassExpression": ["id", "body", "superClass", "typeParameters", "superTypeParameters", "implements", "decorators"],
|
||||
"ComprehensionBlock": ["left", "right", "body"],
|
||||
"ComprehensionExpression": ["filter", "blocks", "body"],
|
||||
"ConditionalExpression": ["test", "consequent", "alternate"],
|
||||
@@ -40,12 +40,12 @@
|
||||
"LogicalExpression": ["left", "right"],
|
||||
"MemberExpression": ["object", "property"],
|
||||
"MetaProperty": ["meta", "property"],
|
||||
"MethodDefinition": ["key", "value"],
|
||||
"MethodDefinition": ["key", "value", "decorators"],
|
||||
"NewExpression": ["callee", "arguments"],
|
||||
"ObjectExpression": ["properties"],
|
||||
"ObjectPattern": ["properties", "typeAnnotation"],
|
||||
"Program": ["body"],
|
||||
"Property": ["key", "value"],
|
||||
"Property": ["key", "value", "decorators"],
|
||||
"RestElement": ["argument", "typeAnnotation"],
|
||||
"ReturnStatement": ["argument"],
|
||||
"SequenceExpression": ["expressions"],
|
||||
|
||||
@@ -2461,6 +2461,166 @@ test("class Foo { @foo @bar bar() {} }", {
|
||||
features: { "es7.decorators": true }
|
||||
});
|
||||
|
||||
test('@foo({ @bar foo: "bar" }) @bar class Foo {}', {
|
||||
"start": 0,
|
||||
"body": [{
|
||||
"start": 31,
|
||||
"decorators": [{
|
||||
"start": 0,
|
||||
"expression": {
|
||||
"start": 1,
|
||||
"callee": {
|
||||
"start": 1,
|
||||
"name": "foo",
|
||||
"type": "Identifier",
|
||||
"end": 4
|
||||
},
|
||||
"arguments": [{
|
||||
"start": 5,
|
||||
"properties": [{
|
||||
"start": 12,
|
||||
"decorators": [{
|
||||
"start": 7,
|
||||
"expression": {
|
||||
"start": 8,
|
||||
"name": "bar",
|
||||
"type": "Identifier",
|
||||
"end": 11
|
||||
},
|
||||
"type": "Decorator",
|
||||
"end": 11
|
||||
}],
|
||||
"method": false,
|
||||
"shorthand": false,
|
||||
"computed": false,
|
||||
"key": {
|
||||
"start": 12,
|
||||
"name": "foo",
|
||||
"type": "Identifier",
|
||||
"end": 15
|
||||
},
|
||||
"value": {
|
||||
"start": 17,
|
||||
"value": "bar",
|
||||
"raw": "\"bar\"",
|
||||
"type": "Literal",
|
||||
"end": 22
|
||||
},
|
||||
"kind": "init",
|
||||
"type": "Property",
|
||||
"end": 22
|
||||
}],
|
||||
"type": "ObjectExpression",
|
||||
"end": 24
|
||||
}],
|
||||
"type": "CallExpression",
|
||||
"end": 25
|
||||
},
|
||||
"type": "Decorator",
|
||||
"end": 25
|
||||
},
|
||||
{
|
||||
"start": 26,
|
||||
"expression": {
|
||||
"start": 27,
|
||||
"name": "bar",
|
||||
"type": "Identifier",
|
||||
"end": 30
|
||||
},
|
||||
"type": "Decorator",
|
||||
"end": 30
|
||||
}],
|
||||
"id": {
|
||||
"start": 37,
|
||||
"name": "Foo",
|
||||
"type": "Identifier",
|
||||
"end": 40
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"start": 41,
|
||||
"body": [],
|
||||
"type": "ClassBody",
|
||||
"end": 43
|
||||
},
|
||||
"type": "ClassDeclaration",
|
||||
"end": 43
|
||||
}],
|
||||
"sourceType": "script",
|
||||
"type": "Program",
|
||||
"end": 43
|
||||
}, {
|
||||
ecmaVersion: 6,
|
||||
features: { "es7.decorators": true }
|
||||
});
|
||||
|
||||
test('@bar class Foo extends @foo class Bar {} {}', {
|
||||
"start": 0,
|
||||
"body": [{
|
||||
"start": 5,
|
||||
"decorators": [{
|
||||
"start": 0,
|
||||
"expression": {
|
||||
"start": 1,
|
||||
"name": "bar",
|
||||
"type": "Identifier",
|
||||
"end": 4
|
||||
},
|
||||
"type": "Decorator",
|
||||
"end": 4
|
||||
}],
|
||||
"id": {
|
||||
"start": 11,
|
||||
"name": "Foo",
|
||||
"type": "Identifier",
|
||||
"end": 14
|
||||
},
|
||||
"superClass": {
|
||||
"start": 28,
|
||||
"decorators": [{
|
||||
"start": 23,
|
||||
"expression": {
|
||||
"start": 24,
|
||||
"name": "foo",
|
||||
"type": "Identifier",
|
||||
"end": 27
|
||||
},
|
||||
"type": "Decorator",
|
||||
"end": 27
|
||||
}],
|
||||
"id": {
|
||||
"start": 34,
|
||||
"name": "Bar",
|
||||
"type": "Identifier",
|
||||
"end": 37
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"start": 38,
|
||||
"body": [],
|
||||
"type": "ClassBody",
|
||||
"end": 40
|
||||
},
|
||||
"type": "ClassExpression",
|
||||
"end": 40
|
||||
},
|
||||
"body": {
|
||||
"start": 41,
|
||||
"body": [],
|
||||
"type": "ClassBody",
|
||||
"end": 43
|
||||
},
|
||||
"type": "ClassDeclaration",
|
||||
"end": 43
|
||||
}],
|
||||
"sourceType": "script",
|
||||
"type": "Program",
|
||||
"end": 43
|
||||
}, {
|
||||
ecmaVersion: 6,
|
||||
features: { "es7.decorators": true }
|
||||
});
|
||||
|
||||
testFail("@foo function bar() {}", "Leading decorators must be attached to a class declaration (1:5)", {
|
||||
ecmaVersion: 6,
|
||||
features: { "es7.decorators": true }
|
||||
@@ -2787,6 +2947,66 @@ test('class Foo { @bar static foo = "bar"; }', {
|
||||
features: { "es7.classProperties": true, "es7.decorators": true }
|
||||
});
|
||||
|
||||
test("var obj = { @foo bar: 'wow' };", {
|
||||
"start": 0,
|
||||
"body": [{
|
||||
"start": 0,
|
||||
"declarations": [{
|
||||
"start": 4,
|
||||
"id": {
|
||||
"start": 4,
|
||||
"name": "obj",
|
||||
"type": "Identifier",
|
||||
"end": 7
|
||||
},
|
||||
"init": {
|
||||
"start": 10,
|
||||
"properties": [{
|
||||
"start": 17,
|
||||
"key": {
|
||||
"start": 17,
|
||||
"name": "bar",
|
||||
"type": "Identifier",
|
||||
"end": 20
|
||||
},
|
||||
"value": {
|
||||
"start": 22,
|
||||
"value": "wow",
|
||||
"raw": "'wow'",
|
||||
"type": "Literal",
|
||||
"end": 27
|
||||
},
|
||||
"kind": "init",
|
||||
"decorators": [{
|
||||
"start": 12,
|
||||
"expression": {
|
||||
"start": 13,
|
||||
"name": "foo",
|
||||
"type": "Identifier",
|
||||
"end": 16
|
||||
},
|
||||
"type": "Decorator",
|
||||
"end": 16
|
||||
}],
|
||||
"type": "Property",
|
||||
"end": 27
|
||||
}],
|
||||
"type": "ObjectExpression",
|
||||
"end": 29
|
||||
},
|
||||
"type": "VariableDeclarator",
|
||||
"end": 29
|
||||
}],
|
||||
"kind": "var",
|
||||
"type": "VariableDeclaration",
|
||||
"end": 30
|
||||
}],
|
||||
"type": "Program",
|
||||
"end": 30
|
||||
}, {
|
||||
features: { "es7.decorators": true }
|
||||
});
|
||||
|
||||
// ES7 export extensions - https://github.com/leebyron/ecmascript-more-export-from
|
||||
|
||||
test('export foo, { bar } from "bar";', {
|
||||
@@ -2940,3 +3160,99 @@ test('export * as foo from "bar";', {
|
||||
sourceType: "module",
|
||||
features: { "es7.exportExtensions": true }
|
||||
});
|
||||
|
||||
// ES7: Trailing Function Commas
|
||||
|
||||
test("log(n, '=', 2,);", {
|
||||
type: "Program",
|
||||
start: 0,
|
||||
end: 16,
|
||||
body: [{
|
||||
type: "ExpressionStatement",
|
||||
start: 0,
|
||||
end: 16,
|
||||
expression: {
|
||||
type: "CallExpression",
|
||||
callee: {
|
||||
type: "Identifier",
|
||||
name: "log",
|
||||
start: 0,
|
||||
end: 3
|
||||
},
|
||||
arguments: [{
|
||||
type: "Identifier",
|
||||
name: "n",
|
||||
start: 4,
|
||||
end: 5
|
||||
}, {
|
||||
type: "Literal",
|
||||
value: "=",
|
||||
raw: "'='",
|
||||
start: 7,
|
||||
end: 10
|
||||
}, {
|
||||
type: "Literal",
|
||||
raw: "2",
|
||||
value: 2,
|
||||
start: 12,
|
||||
end: 13
|
||||
}]
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
ecmaVersion: 7,
|
||||
features: { "es7.trailingFunctionCommas": true }
|
||||
});
|
||||
|
||||
test("function log(n, op, val,) { }", {
|
||||
type: "Program",
|
||||
start: 0,
|
||||
end: 29,
|
||||
body: [{
|
||||
type: "FunctionDeclaration",
|
||||
id: {
|
||||
type: "Identifier",
|
||||
name: "log",
|
||||
start: 9,
|
||||
end: 12
|
||||
},
|
||||
start: 0,
|
||||
end: 29,
|
||||
expression: false,
|
||||
params: [{
|
||||
type: "Identifier",
|
||||
name: "n",
|
||||
start: 13,
|
||||
end: 14
|
||||
}, {
|
||||
type: "Identifier",
|
||||
name: "op",
|
||||
start: 16,
|
||||
end: 18
|
||||
}, {
|
||||
type: "Identifier",
|
||||
name: "val",
|
||||
start: 20,
|
||||
end: 23
|
||||
}],
|
||||
body: {
|
||||
type: "BlockStatement",
|
||||
start: 26,
|
||||
end: 29,
|
||||
body: []
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
ecmaVersion: 7,
|
||||
features: { "es7.trailingFunctionCommas": true }
|
||||
});
|
||||
|
||||
testFail("log(,);", "Unexpected token (1:4)", {
|
||||
ecmaVersion: 7,
|
||||
features: { "es7.trailingFunctionCommas": true }
|
||||
});
|
||||
|
||||
testFail("function log(,) { }", "Unexpected token (1:13)", {
|
||||
ecmaVersion: 7,
|
||||
features: { "es7.trailingFunctionCommas": true }
|
||||
});
|
||||
|
||||
@@ -1714,6 +1714,8 @@ test("([a, , b]) => 42", {
|
||||
|
||||
testFail("([a.a]) => 42", "Assigning to rvalue (1:2)", {ecmaVersion: 6});
|
||||
|
||||
testFail("console.log(typeof () => {});", "Unexpected token (1:20)", {ecmaVersion: 6});
|
||||
|
||||
test("(x=1) => x * x", {
|
||||
type: "Program",
|
||||
body: [{
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
var foo = arr.map(v => ({
|
||||
x: v.bar,
|
||||
y: v.bar*2
|
||||
}));
|
||||
@@ -0,0 +1,4 @@
|
||||
var foo = arr.map(v => ({
|
||||
x: v.bar,
|
||||
y: v.bar * 2
|
||||
}));
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
var _bluebird2 = require("bluebird");
|
||||
|
||||
var _bluebird3 = babelHelpers.interopRequireWildcard(_bluebird2);
|
||||
|
||||
var Foo = (function () {
|
||||
function Foo() {
|
||||
babelHelpers.classCallCheck(this, Foo);
|
||||
@@ -9,7 +11,7 @@ var Foo = (function () {
|
||||
|
||||
babelHelpers.createClass(Foo, [{
|
||||
key: "foo",
|
||||
value: _bluebird2.coroutine(function* () {
|
||||
value: _bluebird3["default"].coroutine(function* () {
|
||||
var wat = yield bar();
|
||||
})
|
||||
}]);
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
var _bluebird2 = require("bluebird");
|
||||
|
||||
var foo = _bluebird2.coroutine(function* () {
|
||||
var _bluebird3 = _interopRequireWildcard(_bluebird2);
|
||||
|
||||
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { "default": obj }; };
|
||||
|
||||
var foo = _bluebird3["default"].coroutine(function* () {
|
||||
var wat = yield bar();
|
||||
});
|
||||
|
||||
@@ -2,9 +2,13 @@
|
||||
|
||||
var _bluebird2 = require("bluebird");
|
||||
|
||||
var _bluebird3 = _interopRequireWildcard(_bluebird2);
|
||||
|
||||
var _bar;
|
||||
|
||||
var foo = _bar = _bluebird2.coroutine(function* () {
|
||||
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { "default": obj }; };
|
||||
|
||||
var foo = _bar = _bluebird3["default"].coroutine(function* () {
|
||||
console.log(_bar);
|
||||
});
|
||||
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
var _bluebird2 = require("bluebird");
|
||||
|
||||
var foo = _bluebird2.coroutine(function* () {
|
||||
var _bluebird3 = _interopRequireWildcard(_bluebird2);
|
||||
|
||||
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { "default": obj }; };
|
||||
|
||||
var foo = _bluebird3["default"].coroutine(function* () {
|
||||
var wat = yield bar();
|
||||
});
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
class Foo extends Array {
|
||||
|
||||
}
|
||||
|
||||
class Bar extends Array {
|
||||
constructor() {
|
||||
super();
|
||||
this.foo = "bar";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
class Foo extends Array {
|
||||
|
||||
}
|
||||
|
||||
class Bar extends Array {
|
||||
constructor() {
|
||||
super();
|
||||
this.foo = "bar";
|
||||
}
|
||||
}
|
||||
|
||||
var foo = new Foo;
|
||||
assert.ok(Array.isArray(foo));
|
||||
foo.push(1);
|
||||
foo.push(2);
|
||||
assert.equal(foo[0], 1);
|
||||
assert.equal(foo[1], 2);
|
||||
assert.equal(foo.length, 2);
|
||||
|
||||
var bar = new Bar;
|
||||
assert.ok(Array.isArray(bar));
|
||||
assert.equal(bar.foo, "bar");
|
||||
bar.push(1);
|
||||
bar.push(2);
|
||||
assert.equal(bar[0], 1);
|
||||
assert.equal(bar[1], 2);
|
||||
assert.equal(bar.length, 2);
|
||||
@@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
|
||||
var Foo = (function (_Array) {
|
||||
function Foo() {
|
||||
babelHelpers.classCallCheck(this, Foo);
|
||||
|
||||
if (_Array != null) {
|
||||
var _this = new (babelHelpers.bind.apply(_Array, [null].concat(babelHelpers.slice.call(arguments))))();
|
||||
|
||||
_this.__proto__ = Foo.prototype;
|
||||
return _this;
|
||||
}
|
||||
|
||||
return _this;
|
||||
}
|
||||
|
||||
babelHelpers.inherits(Foo, _Array);
|
||||
return Foo;
|
||||
})(Array);
|
||||
|
||||
var Bar = (function (_Array2) {
|
||||
function Bar() {
|
||||
babelHelpers.classCallCheck(this, Bar);
|
||||
|
||||
var _this2 = new _Array2();
|
||||
|
||||
_this2.__proto__ = Bar.prototype;
|
||||
|
||||
_this2.foo = "bar";
|
||||
return _this2;
|
||||
}
|
||||
|
||||
babelHelpers.inherits(Bar, _Array2);
|
||||
return Bar;
|
||||
})(Array);
|
||||
@@ -0,0 +1,3 @@
|
||||
for (const i = 0; i < 3; i = i + 1) {
|
||||
console.log(i);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "\"i\" is read-only"
|
||||
}
|
||||
@@ -8,3 +8,4 @@ var [[a, b, ...c]] = [[1, 2, 3, 4]];
|
||||
var [a, b] = [1, 2, 3];
|
||||
var [[a, b]] = [[1, 2, 3]];
|
||||
var [a, b] = [a, b];
|
||||
[a[0], a[1]] = [a[1], a[0]];
|
||||
|
||||
@@ -22,3 +22,7 @@ var b = _ref2[1];
|
||||
var _ref3 = [a, b];
|
||||
var a = _ref3[0];
|
||||
var b = _ref3[1];
|
||||
var _temp = [a[1], a[0]];
|
||||
a[0] = _temp[0];
|
||||
a[1] = _temp[1];
|
||||
_temp;
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
var x, y;
|
||||
[x, y] = [1, 2];
|
||||
@@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
var x, y;
|
||||
var _temp = [1, 2];
|
||||
x = _temp[0];
|
||||
y = _temp[1];
|
||||
_temp;
|
||||
@@ -1,5 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
var _temp, _temp2;
|
||||
var _temp;
|
||||
|
||||
console.log((_temp = [123], _temp2 = babelHelpers.slicedToArray(_temp, 1), x = _temp2[0], _temp));
|
||||
console.log((_temp = [123], x = _temp[0], _temp));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
foo.foo = 1;
|
||||
foo.bar = 2;
|
||||
var _ref = [1, 2];
|
||||
foo.foo = _ref[0];
|
||||
foo.bar = _ref[1];
|
||||
|
||||
;
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
var mod = {
|
||||
exports: {}
|
||||
};
|
||||
factory(mod.exports, global.foo, global.fooBar, global.directoryFooBar);
|
||||
factory(mod.exports, global.foo, global.fooBar, global.fooBar);
|
||||
global.actual = mod.exports;
|
||||
}
|
||||
})(this, function (exports, _foo, _fooBar, _directoryFooBar) {
|
||||
"use strict";
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
import { render } from "./lib/render";
|
||||
@@ -0,0 +1,15 @@
|
||||
(function (global, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define(["exports", "./lib/render"], factory);
|
||||
} else if (typeof exports !== "undefined") {
|
||||
factory(exports, require("./lib/render"));
|
||||
} else {
|
||||
var mod = {
|
||||
exports: {}
|
||||
};
|
||||
factory(mod.exports, global.render);
|
||||
global.actual = mod.exports;
|
||||
}
|
||||
})(this, function (exports, _libRender) {
|
||||
"use strict";
|
||||
});
|
||||
@@ -7,7 +7,7 @@
|
||||
var mod = {
|
||||
exports: {}
|
||||
};
|
||||
factory(mod.exports, global.foo2, global.fooBar, global.directoryFooBar);
|
||||
factory(mod.exports, global.foo2, global.fooBar, global.fooBar);
|
||||
global.actual = mod.exports;
|
||||
}
|
||||
})(this, function (exports, _foo, _fooBar, _directoryFooBar) {
|
||||
@@ -29,4 +29,4 @@
|
||||
|
||||
_foo.bar;
|
||||
_foo.foo;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
const bar = true;
|
||||
|
||||
function foo(a = bar, ...b) {
|
||||
const bar = false;
|
||||
assert.equal(b[0], 2);
|
||||
assert.equal(b[1], 3);
|
||||
}
|
||||
|
||||
foo(1, 2, 3);
|
||||
@@ -12,10 +12,14 @@ var Foo = (function () {
|
||||
}
|
||||
|
||||
babelHelpers.createClass(Foo, [{
|
||||
key: "bar",
|
||||
value: undefined,
|
||||
enumerable: true
|
||||
}, {
|
||||
key: "__initializeProperties",
|
||||
value: function __initializeProperties() {
|
||||
this.bar = foo;
|
||||
}
|
||||
}]);
|
||||
return Foo;
|
||||
})();
|
||||
})();
|
||||
@@ -12,5 +12,10 @@ var Foo = (function (_Bar) {
|
||||
}
|
||||
|
||||
babelHelpers.inherits(Foo, _Bar);
|
||||
babelHelpers.createClass(Foo, [{
|
||||
key: "bar",
|
||||
value: undefined,
|
||||
enumerable: true
|
||||
}]);
|
||||
return Foo;
|
||||
})(Bar);
|
||||
})(Bar);
|
||||
@@ -1,6 +1,15 @@
|
||||
"use strict";
|
||||
|
||||
var Foo = function Foo() {
|
||||
babelHelpers.classCallCheck(this, Foo);
|
||||
this.bar = "foo";
|
||||
};
|
||||
var Foo = (function () {
|
||||
function Foo() {
|
||||
babelHelpers.classCallCheck(this, Foo);
|
||||
this.bar = "foo";
|
||||
}
|
||||
|
||||
babelHelpers.createClass(Foo, [{
|
||||
key: "bar",
|
||||
value: undefined,
|
||||
enumerable: true
|
||||
}]);
|
||||
return Foo;
|
||||
})();
|
||||
@@ -7,8 +7,8 @@ var Foo = (function () {
|
||||
|
||||
babelHelpers.createClass(Foo, null, [{
|
||||
key: "bar",
|
||||
enumerable: true,
|
||||
value: "foo"
|
||||
value: "foo",
|
||||
enumerable: true
|
||||
}]);
|
||||
return Foo;
|
||||
})();
|
||||
|
||||
@@ -10,5 +10,10 @@ var Foo = (function (_Bar) {
|
||||
}
|
||||
|
||||
babelHelpers.inherits(Foo, _Bar);
|
||||
babelHelpers.createClass(Foo, [{
|
||||
key: "bar",
|
||||
value: undefined,
|
||||
enumerable: true
|
||||
}]);
|
||||
return Foo;
|
||||
})(Bar);
|
||||
})(Bar);
|
||||
@@ -9,5 +9,10 @@ var Foo = (function (_Bar) {
|
||||
}
|
||||
|
||||
babelHelpers.inherits(Foo, _Bar);
|
||||
babelHelpers.createClass(Foo, [{
|
||||
key: "bar",
|
||||
value: undefined,
|
||||
enumerable: true
|
||||
}]);
|
||||
return Foo;
|
||||
})(Bar);
|
||||
})(Bar);
|
||||
@@ -10,11 +10,11 @@ var Foo = (function () {
|
||||
|
||||
babelHelpers.createDecoratedClass(Foo, [{
|
||||
key: "foo",
|
||||
enumerable: true,
|
||||
decorators: [bar],
|
||||
initializer: function () {
|
||||
return "Bar";
|
||||
}
|
||||
},
|
||||
enumerable: true
|
||||
}], null, _instanceInitializers);
|
||||
return Foo;
|
||||
})();
|
||||
})();
|
||||
|
||||
@@ -9,12 +9,12 @@ var Foo = (function () {
|
||||
|
||||
babelHelpers.createDecoratedClass(Foo, null, [{
|
||||
key: "foo",
|
||||
enumerable: true,
|
||||
decorators: [bar],
|
||||
initializer: function () {
|
||||
return "Bar";
|
||||
}
|
||||
},
|
||||
enumerable: true
|
||||
}], null, _staticInitializers);
|
||||
Foo.foo = _staticInitializers.foo.call(Foo);
|
||||
return Foo;
|
||||
})();
|
||||
})();
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import foo from "foo";
|
||||
|
||||
@foo
|
||||
export default class Foo {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _foo = require("foo");
|
||||
|
||||
var _foo2 = babelHelpers.interopRequireWildcard(_foo);
|
||||
|
||||
var Foo = (function () {
|
||||
function Foo() {
|
||||
babelHelpers.classCallCheck(this, _Foo);
|
||||
}
|
||||
|
||||
var _Foo = Foo;
|
||||
Foo = _foo2["default"](Foo) || Foo;
|
||||
return Foo;
|
||||
})();
|
||||
|
||||
exports["default"] = Foo;
|
||||
module.exports = exports["default"];
|
||||
@@ -10,9 +10,9 @@ var Foo = (function () {
|
||||
|
||||
babelHelpers.createDecoratedClass(Foo, [{
|
||||
key: "foo",
|
||||
enumerable: true,
|
||||
decorators: [bar],
|
||||
initializer: function () {}
|
||||
initializer: function () {},
|
||||
enumerable: true
|
||||
}], null, _instanceInitializers);
|
||||
return Foo;
|
||||
})();
|
||||
})();
|
||||
|
||||
@@ -9,10 +9,10 @@ var Foo = (function () {
|
||||
|
||||
babelHelpers.createDecoratedClass(Foo, null, [{
|
||||
key: "foo",
|
||||
enumerable: true,
|
||||
decorators: [bar],
|
||||
initializer: function () {}
|
||||
initializer: function () {},
|
||||
enumerable: true
|
||||
}], null, _staticInitializers);
|
||||
Foo.foo = _staticInitializers.foo.call(Foo);
|
||||
return Foo;
|
||||
})();
|
||||
})();
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
@bar
|
||||
class Foo extends Bar {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
var Foo2 = @bar class extends Bar {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
|
||||
var Foo = (function (_Bar) {
|
||||
function Foo() {
|
||||
babelHelpers.classCallCheck(this, _Foo);
|
||||
|
||||
babelHelpers.get(Object.getPrototypeOf(_Foo.prototype), "constructor", this).call(this);
|
||||
}
|
||||
|
||||
babelHelpers.inherits(Foo, _Bar);
|
||||
var _Foo = Foo;
|
||||
Foo = bar(Foo) || Foo;
|
||||
return Foo;
|
||||
})(Bar);
|
||||
|
||||
var Foo2 = (function (_Bar2) {
|
||||
var _class = function Foo2() {
|
||||
babelHelpers.classCallCheck(this, _class2);
|
||||
|
||||
babelHelpers.get(Object.getPrototypeOf(_class2.prototype), "constructor", this).call(this);
|
||||
};
|
||||
|
||||
babelHelpers.inherits(_class, _Bar2);
|
||||
var _class2 = _class;
|
||||
_class = bar(_class) || _class;
|
||||
return _class;
|
||||
})(Bar);
|
||||
@@ -12,3 +12,10 @@ var Foo2 = @bar class Foo {
|
||||
var Bar2 = @foo @bar class Bar {
|
||||
|
||||
};
|
||||
|
||||
@foo
|
||||
class Baz{
|
||||
constructor(baz) {
|
||||
this.baz = baz;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,38 +2,54 @@
|
||||
|
||||
var Foo = (function () {
|
||||
function Foo() {
|
||||
babelHelpers.classCallCheck(this, Foo);
|
||||
babelHelpers.classCallCheck(this, _Foo);
|
||||
}
|
||||
|
||||
var _Foo = Foo;
|
||||
Foo = foo(Foo) || Foo;
|
||||
return Foo;
|
||||
})();
|
||||
|
||||
var Bar = (function () {
|
||||
function Bar() {
|
||||
babelHelpers.classCallCheck(this, Bar);
|
||||
babelHelpers.classCallCheck(this, _Bar);
|
||||
}
|
||||
|
||||
Bar = foo(Bar) || Bar;
|
||||
var _Bar = Bar;
|
||||
Bar = bar(Bar) || Bar;
|
||||
Bar = foo(Bar) || Bar;
|
||||
return Bar;
|
||||
})();
|
||||
|
||||
var Foo2 = (function () {
|
||||
function Foo() {
|
||||
babelHelpers.classCallCheck(this, Foo);
|
||||
babelHelpers.classCallCheck(this, _Foo2);
|
||||
}
|
||||
|
||||
var _Foo2 = Foo;
|
||||
Foo = bar(Foo) || Foo;
|
||||
return Foo;
|
||||
})();
|
||||
|
||||
var Bar2 = (function () {
|
||||
function Bar() {
|
||||
babelHelpers.classCallCheck(this, Bar);
|
||||
babelHelpers.classCallCheck(this, _Bar2);
|
||||
}
|
||||
|
||||
Bar = foo(Bar) || Bar;
|
||||
var _Bar2 = Bar;
|
||||
Bar = bar(Bar) || Bar;
|
||||
Bar = foo(Bar) || Bar;
|
||||
return Bar;
|
||||
})();
|
||||
})();
|
||||
|
||||
var Baz = (function () {
|
||||
function Baz(baz) {
|
||||
babelHelpers.classCallCheck(this, _Baz);
|
||||
|
||||
this.baz = baz;
|
||||
}
|
||||
|
||||
var _Baz = Baz;
|
||||
Baz = foo(Baz) || Baz;
|
||||
return Baz;
|
||||
})();
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
var autobind = function (target, name, descriptor) {
|
||||
var fn = descriptor.value;
|
||||
delete descriptor.value;
|
||||
delete descriptor.writable;
|
||||
descriptor.get = function () {
|
||||
return fn.bind(this);
|
||||
};
|
||||
};
|
||||
|
||||
var person = {
|
||||
first: "Sebastian",
|
||||
last: "McKenzie",
|
||||
|
||||
@autobind
|
||||
getName() {
|
||||
return `${this.first} ${this.last}`;
|
||||
}
|
||||
}
|
||||
|
||||
assert.equal(person.getName.call(null), "Sebastian McKenzie")
|
||||
@@ -0,0 +1,11 @@
|
||||
var obj = {
|
||||
@foo
|
||||
get foo() {
|
||||
|
||||
},
|
||||
|
||||
@foo
|
||||
set foo() {
|
||||
|
||||
}
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user