Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4845323a2 | ||
|
|
792951b489 | ||
|
|
5adda836af | ||
|
|
4c2c3098c3 | ||
|
|
087c714098 | ||
|
|
5a33e4fe05 | ||
|
|
5f8667eaa7 | ||
|
|
31b4468514 | ||
|
|
2be9678bbe | ||
|
|
b5210877cf | ||
|
|
658dde768e | ||
|
|
8df1d81ca4 | ||
|
|
a505e4a121 | ||
|
|
71eafdcac7 |
@@ -1,5 +1,8 @@
|
||||
sudo: false
|
||||
language: node_js
|
||||
cache:
|
||||
directories:
|
||||
- node_modules
|
||||
node_js:
|
||||
- "0.12"
|
||||
- "iojs"
|
||||
|
||||
14
CHANGELOG.md
14
CHANGELOG.md
@@ -13,6 +13,20 @@ _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.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**
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "babel-core",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "5.1.1",
|
||||
"version": "5.1.3",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"repository": "babel/babel",
|
||||
@@ -46,7 +46,7 @@
|
||||
"output-file-sync": "^1.1.0",
|
||||
"path-is-absolute": "^1.0.0",
|
||||
"private": "^0.1.6",
|
||||
"regenerator": "https://github.com/sebmck/regenerator/archive/block-hoist.tar.gz",
|
||||
"regenerator": "^0.8.20",
|
||||
"regexpu": "^1.1.2",
|
||||
"repeating": "^1.1.2",
|
||||
"shebang-regex": "^1.0.0",
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
{
|
||||
"name": "babel",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "5.1.0",
|
||||
"version": "5.1.2",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"repository": "babel/babel",
|
||||
"preferGlobal": true,
|
||||
"dependencies": {
|
||||
"babel-core": "^5.1.0",
|
||||
"babel-core": "^5.1.2",
|
||||
"chokidar": "^1.0.0",
|
||||
"commander": "^2.6.0",
|
||||
"fs-readdir-recursive": "^0.1.0",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "babel-runtime",
|
||||
"description": "babel selfContained runtime",
|
||||
"version": "5.1.0",
|
||||
"version": "5.1.2",
|
||||
"repository": "babel/babel",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"dependencies": {
|
||||
|
||||
@@ -77,7 +77,7 @@ writeFile("regenerator/runtime.js", selfContainify(readFile("regenerator-babel/r
|
||||
|
||||
var coreDefinitions = require("../lib/babel/transformation/transformers/other/runtime/definitions");
|
||||
|
||||
var paths = [];
|
||||
var paths = ["is-iterable", "get-iterator"];
|
||||
|
||||
each(coreDefinitions.builtins, function (path) {
|
||||
paths.push(path);
|
||||
|
||||
@@ -509,22 +509,24 @@ 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) {
|
||||
this.decorators.push(this.parseDecorator())
|
||||
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"
|
||||
this.takeDecorators(prop)
|
||||
node.properties.push(prop)
|
||||
continue
|
||||
}
|
||||
@@ -550,10 +552,9 @@ pp.parseObj = function(isPattern, refShorthandDefaultPos) {
|
||||
}
|
||||
this.parseObjPropValue(prop, start, isGenerator, isAsync, isPattern, refShorthandDefaultPos);
|
||||
this.checkPropClash(prop, propHash)
|
||||
this.takeDecorators(prop)
|
||||
node.properties.push(this.finishNode(prop, "Property"))
|
||||
}
|
||||
if (this.decorators.length) {
|
||||
if (decorators.length) {
|
||||
this.raise(this.start, "You have trailing decorators with no property");
|
||||
}
|
||||
return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
|
||||
|
||||
@@ -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())
|
||||
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")
|
||||
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
@@ -81,6 +81,7 @@
|
||||
"cosh": "math/cosh",
|
||||
"expm1": "math/expm1",
|
||||
"fround": "math/fround",
|
||||
"hypot": "math/hypot",
|
||||
"pot": "math/pot",
|
||||
"imul": "math/imul",
|
||||
"log10": "math/log10",
|
||||
@@ -110,6 +111,30 @@
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
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";
|
||||
@@ -8,53 +9,87 @@ var isSymbolIterator = t.buildMatchMemberExpression("Symbol.iterator");
|
||||
|
||||
const RUNTIME_MODULE_NAME = "babel-runtime";
|
||||
|
||||
var astVisitor = {
|
||||
enter(node, parent, scope, file) {
|
||||
var prop;
|
||||
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;
|
||||
|
||||
if (this.isMemberExpression() && this.isReferenced()) {
|
||||
// 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;
|
||||
prop = node.property;
|
||||
var prop = node.property;
|
||||
|
||||
if (!t.isReferenced(obj, node)) return;
|
||||
|
||||
if (node.computed) return;
|
||||
|
||||
if (!has(definitions.methods, obj.name)) return;
|
||||
if (!has(definitions.methods[obj.name], prop.name)) return;
|
||||
|
||||
var methods = definitions.methods[obj.name];
|
||||
if (!has(methods, prop.name)) return;
|
||||
|
||||
if (scope.getBindingIdentifier(obj.name)) return;
|
||||
|
||||
var modulePath = definitions.methods[obj.name][prop.name];
|
||||
var modulePath = methods[prop.name];
|
||||
return file.addImport(`${RUNTIME_MODULE_NAME}/core-js/${modulePath}`, `${obj.name}$${prop.name}`, true);
|
||||
} else if (this.isReferencedIdentifier() && !t.isMemberExpression(parent) && has(definitions.builtins, node.name) && !scope.getBindingIdentifier(node.name)) {
|
||||
// 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);
|
||||
} else if (this.isCallExpression()) {
|
||||
// arr[Symbol.iterator]() -> _core.$for.getIterator(arr)
|
||||
},
|
||||
|
||||
var callee = node.callee;
|
||||
if (node.arguments.length) return false;
|
||||
exit(node, parent, scope, file) {
|
||||
if (!this.isReferenced()) return;
|
||||
|
||||
if (!t.isMemberExpression(callee)) return false;
|
||||
if (!callee.computed) return false;
|
||||
var prop = node.property;
|
||||
var obj = node.object;
|
||||
|
||||
prop = callee.property;
|
||||
if (!isSymbolIterator(prop)) return false;
|
||||
if (!has(definitions.builtins, obj.name)) return;
|
||||
|
||||
return t.callExpression(file.addImport(`${RUNTIME_MODULE_NAME}/core-js/get-iterator`, "getIterator", true), [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 t.callExpression(file.addImport(`${RUNTIME_MODULE_NAME}/core-js/is-iterator`, "isIterable", true), [node.right]);
|
||||
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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -713,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();
|
||||
|
||||
@@ -722,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
|
||||
|
||||
@@ -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 }
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Promise.resolve;
|
||||
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
var _Promise = require("babel-runtime/core-js/promise")["default"];
|
||||
|
||||
_Promise.resolve;
|
||||
@@ -1,5 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
var _isIterable = require("babel-runtime/core-js/is-iterator")["default"];
|
||||
var _isIterable = require("babel-runtime/core-js/is-iterable")["default"];
|
||||
|
||||
_isIterable(Object(arr));
|
||||
|
||||
Reference in New Issue
Block a user