Compare commits

...

30 Commits

Author SHA1 Message Date
Sebastian McKenzie
85fb4304b0 v5.1.8 2015-04-13 15:45:46 -07:00
Sebastian McKenzie
c2da77d7ec only make parenthesized object patterns illegal - fixes #1254, ref jshint/jshint#2269 2015-04-13 15:44:54 -07:00
Sebastian McKenzie
c54c3d3c15 5.1.7 2015-04-13 15:44:02 -07:00
Sebastian McKenzie
2a7c954155 v5.1.7 2015-04-13 14:59:56 -07:00
Sebastian McKenzie
3fb7f7c7cc add 5.1.6-5.1.7 changelog 2015-04-13 14:56:33 -07:00
Sebastian McKenzie
c4b2818336 remove useless kind on import declarations 2015-04-13 14:55:46 -07:00
Sebastian McKenzie
061561bfd8 add proper ecmaVersion and sourceType to parse api 2015-04-13 14:55:37 -07:00
Sebastian McKenzie
d4944d606b 5.1.6 2015-04-13 14:29:21 -07:00
Sebastian McKenzie
736b689c3b v5.1.6 2015-04-13 14:27:09 -07:00
Sebastian McKenzie
e12b377014 don't fall back to runtime catch all on locally declared variables 2015-04-13 14:26:06 -07:00
Sebastian McKenzie
5fd5b815ab fix whitespace in resolveRc 2015-04-13 14:25:47 -07:00
Sebastian McKenzie
92db8312f6 add parse api 2015-04-13 14:25:37 -07:00
Sebastian McKenzie
e080fe547d 5.1.5 2015-04-13 11:59:47 -07:00
Sebastian McKenzie
b967ecf063 v5.1.5 2015-04-13 11:58:58 -07:00
Sebastian McKenzie
365b7285d2 bump core-js version 2015-04-13 11:58:09 -07:00
Sebastian McKenzie
a40d532b0e 5.1.4 2015-04-13 09:38:21 -07:00
Sebastian McKenzie
0487bf911d v5.1.4 2015-04-13 09:36:21 -07:00
Sebastian McKenzie
57c72d1cd0 fix syntax error in runtime definitions 2015-04-13 09:35:35 -07:00
Sebastian McKenzie
335bdffec2 add missing Reflect methods to runtime transformer #1248 2015-04-13 09:34:45 -07:00
Sebastian McKenzie
e1d76a1dfe 5.1.3 2015-04-13 09:25:37 -07:00
Sebastian McKenzie
a4845323a2 v5.1.3 2015-04-13 09:24:00 -07:00
Sebastian McKenzie
792951b489 add 5.1.3 changelog 2015-04-13 09:23:12 -07:00
Sebastian McKenzie
5adda836af don't do TCO on generators and async functions - fixes #1251 2015-04-13 09:21:59 -07:00
Sebastian McKenzie
4c2c3098c3 Merge branch 'master' of github.com:babel/babel 2015-04-13 09:20:36 -07:00
Sebastian McKenzie
087c714098 simplify runtime transformer traversal and add a catch-all - fixes #1248 2015-04-13 09:20:28 -07:00
Sebastian McKenzie
5a33e4fe05 Merge pull request #1245 from deepsweet/travis-cache
let Travis cache node_modules
2015-04-13 08:29:59 -07:00
Sebastian McKenzie
5f8667eaa7 make parsing of decorators stateless - fixes shuhei/babel-angular2-app#4 2015-04-13 08:26:51 -07:00
Sebastian McKenzie
31b4468514 switch to vanilla regenerator - closes #1247, closes #1123 2015-04-13 08:08:00 -07:00
Kir Belevich
2be9678bbe let Travis cache node_modules 2015-04-13 17:54:50 +07:00
Sebastian McKenzie
b5210877cf 5.1.2 2015-04-13 00:54:00 -07:00
16 changed files with 363 additions and 56 deletions

View File

@@ -1,5 +1,8 @@
sudo: false
language: node_js
cache:
directories:
- node_modules
node_js:
- "0.12"
- "iojs"

View File

@@ -13,6 +13,40 @@ _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.8
* **Bug Fix**
* Only make parenthesized object pattern LHS illegal.
## 5.1.7
* **Internal**
* Add `parse` node API.
## 5.1.6
* **Bug Fix**
* Fix `runtime` built-in catchall not properly checking for local variables.
## 5.1.5
* **Internal**
* Bump `core-js` version.
## 5.1.4
* **Polish**
* Add missing `Reflect` methods to runtime transformer.
## 5.1.3
* **Internal**
* Switch entirely to vanilla regenerator.
* Clean up and make the parsing of decorators stateless.
* **Bug Fix**
* Don't do TCO on generators and async functions.
* Add missing `core-js` runtime definitions.
## 5.1.2
* **Bug Fix**

View File

@@ -1,7 +1,7 @@
{
"name": "babel-core",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "5.1.2",
"version": "5.1.8",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",
"repository": "babel/babel",
@@ -30,7 +30,7 @@
"ast-types": "~0.7.0",
"chalk": "^1.0.0",
"convert-source-map": "^1.0.0",
"core-js": "^0.8.1",
"core-js": "^0.8.3",
"debug": "^2.1.1",
"detect-indent": "^3.0.0",
"estraverse": "^3.0.0",
@@ -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",

View File

@@ -1,13 +1,13 @@
{
"name": "babel",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "5.1.1",
"version": "5.1.7",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",
"repository": "babel/babel",
"preferGlobal": true,
"dependencies": {
"babel-core": "^5.1.1",
"babel-core": "^5.1.7",
"chokidar": "^1.0.0",
"commander": "^2.6.0",
"fs-readdir-recursive": "^0.1.0",

View File

@@ -1,7 +1,7 @@
{
"name": "babel-runtime",
"description": "babel selfContained runtime",
"version": "5.1.1",
"version": "5.1.7",
"repository": "babel/babel",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"dependencies": {

View File

@@ -103,12 +103,8 @@ pp.parseMaybeAssign = function(noIn, refShorthandDefaultPos, afterLeftParse) {
node.left = this.type === tt.eq ? this.toAssignable(left) : left
refShorthandDefaultPos.start = 0 // reset because shorthand default was used correctly
this.checkLVal(left)
if (left.parenthesizedExpression) {
if (left.type === "ObjectPattern") {
this.raise(left.start, "You're trying to assign to a parenthesized expression, instead of `({ foo }) = {}` use `({ foo } = {})`");
} else {
this.raise(left.start, "Parenthesized left hand expressions are illegal");
}
if (left.parenthesizedExpression && left.type === "ObjectPattern") {
this.raise(left.start, "You're trying to assign to a parenthesized expression, instead of `({ foo }) = {}` use `({ foo } = {})`");
}
this.next()
node.right = this.parseMaybeAssign(noIn)
@@ -509,22 +505,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 +548,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")

View File

@@ -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")
@@ -687,7 +691,6 @@ pp.parseImport = function(node) {
if (this.type === tt.string) {
node.specifiers = empty
node.source = this.parseExprAtom()
node.kind = ""
} else {
node.specifiers = []
this.parseImportSpecifiers(node)

View File

@@ -4,12 +4,11 @@ import * as acorn from "../../acorn";
import * as util from "../util";
import fs from "fs";
export { util, acorn };
export { util, acorn, transform };
export { canCompile } from "../util";
export { default as options } from "../transformation/file/options";
export { default as Transformer } from "../transformation/transformer";
export { default as transform } from "../transformation";
export { default as traverse } from "../traversal";
export { default as buildExternalHelpers } from "../tools/build-external-helpers";
export { version } from "../../../package";
@@ -54,3 +53,19 @@ export function transformFileSync(filename: string, opts?: Object = {}) {
opts.filename = filename;
return transform(fs.readFileSync(filename), opts);
}
export function parse(code, opts = {}) {
opts.sourceType = "module";
opts.ecmaVersion = Infinity;
opts.plugins = {
flow: true,
jsx: true
};
opts.features = {};
for (var key in transform.transformers) {
opts.features[key] = true;
}
return acorn.parse(code, opts);
}

View File

@@ -44,11 +44,10 @@ export default function (loc, opts = {}) {
find(up, rel);
}
}
if (opts.breakConfig !== true) {
find(loc, rel);
}
return opts;
};

View File

@@ -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();
};

View File

@@ -41,6 +41,7 @@
"unshift": "array/unshift",
"values": "array/values"
},
"Object": {
"assign": "object/assign",
"classof": "object/classof",
@@ -65,13 +66,16 @@
"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",
@@ -81,6 +85,7 @@
"cosh": "math/cosh",
"expm1": "math/expm1",
"fround": "math/fround",
"hypot": "math/hypot",
"pot": "math/pot",
"imul": "math/imul",
"log10": "math/log10",
@@ -91,11 +96,13 @@
"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",
@@ -110,6 +117,49 @@
"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"
}
}
}

View File

@@ -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,88 @@ 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;
if (scope.getBindingIdentifier(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-iterable`, "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

View File

@@ -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) {

View File

@@ -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 }

View File

@@ -0,0 +1 @@
Promise.resolve;

View File

@@ -0,0 +1,5 @@
"use strict";
var _Promise = require("babel-runtime/core-js/promise")["default"];
_Promise.resolve;