Compare commits

..

15 Commits

Author SHA1 Message Date
Sebastian McKenzie
8f88afc037 v5.6.11 2015-06-26 02:39:04 +01:00
Sebastian McKenzie
6359675a4f make shadowed function findParent target finder more reliable 2015-06-26 02:38:14 +01:00
Sebastian McKenzie
a265c3f25c add missing semi 2015-06-26 02:25:46 +01:00
Sebastian McKenzie
29eb99ee93 rejigger shadowd function findParent logic 2015-06-26 02:24:42 +01:00
Sebastian McKenzie
0c5c1ff989 remove unused variable 2015-06-26 02:22:10 +01:00
Sebastian McKenzie
499951123a add 5.6.11 changelog 2015-06-26 02:21:34 +01:00
Sebastian McKenzie
c0fd4c1f9e merge es6.parameters.rest and es6.parameters.default transformers
This is necessary in order to retain correct function arity and to have
completely correct semantics. Sometimes features are tied together so much
that they would require so much desugaring to retain the correct semantics
that they'd be equivalent to... the normal transpiled output.
2015-06-26 02:20:16 +01:00
Sebastian McKenzie
579e6fecee upgrade internal dev babel dependency to 5.6.10 2015-06-26 02:05:43 +01:00
Sebastian McKenzie
bb3665a3b6 5.6.10 2015-06-26 01:12:50 +01:00
Sebastian McKenzie
e6de688234 v5.6.10 2015-06-26 01:11:32 +01:00
Sebastian McKenzie
4c233e88ff add use strict 2015-06-26 01:09:47 +01:00
Sebastian McKenzie
ae2ba0b5a3 add 5.6.10 changelog 2015-06-26 01:08:36 +01:00
Sebastian McKenzie
e34d950793 require babel-core at the top of the file 2015-06-26 01:07:54 +01:00
Sebastian McKenzie
e4083fbbd7 add support for trailing commas in arrow function parameter lists - fixes #1841 2015-06-26 00:37:33 +01:00
Sebastian McKenzie
59ed7977ef 5.6.9 2015-06-25 23:59:12 +01:00
48 changed files with 190 additions and 23 deletions

View File

@@ -13,6 +13,18 @@ _Note: Gaps between patch versions are faulty/broken releases._
See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
## 5.6.11
** **Internal**
* Merge `es6.parameters.rest` and `es6.parameters.default` transformers. See commit [c0fd4c1f9e0b18231f585c4fa793e4cb0e01aed1](https://github.com/babel/babel/commit/c0fd4c1f9e0b18231f585c4fa793e4cb0e01aed1) for more info.
## 5.6.10
* **Bug Fix**
* Fix faulty internal require check.
* **Polish**
* Add support for trailing commas in arrow function parameter lists.
## 5.6.8
* **Bug Fix**

View File

@@ -1,7 +1,7 @@
{
"name": "babel-core",
"description": "A compiler for writing next generation JavaScript",
"version": "5.6.9",
"version": "5.6.11",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",
"license": "MIT",
@@ -76,7 +76,7 @@
"trim-right": "^1.0.0"
},
"devDependencies": {
"babel": "5.6.7",
"babel": "5.6.10",
"browserify": "^9.0.8",
"chai": "^2.2.0",
"eslint": "^0.21.2",

View File

@@ -1,5 +1,7 @@
#!/usr/bin/env node
require("babel-core");
var moduleFormatters = require("babel-core/lib/babel/transformation/modules");
var pathExists = require("path-exists");
var commander = require("commander");

View File

@@ -1,14 +1,14 @@
{
"name": "babel",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "5.6.8",
"version": "5.6.10",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",
"license": "MIT",
"repository": "babel/babel",
"preferGlobal": true,
"dependencies": {
"babel-core": "^5.6.8",
"babel-core": "^5.6.10",
"chokidar": "^1.0.0",
"commander": "^2.6.0",
"convert-source-map": "^1.1.0",

View File

@@ -1,7 +1,7 @@
{
"name": "babel-runtime",
"description": "babel selfContained runtime",
"version": "5.6.8",
"version": "5.6.10",
"license": "MIT",
"repository": "babel/babel",
"author": "Sebastian McKenzie <sebmck@gmail.com>",

View File

@@ -432,9 +432,18 @@ pp.parseParenAndDistinguishExpression = function(start, isAsync, canBeArrow) {
}
let innerStart = this.markPosition(), exprList = [], first = true
let refShorthandDefaultPos = {start: 0}, spreadStart, innerParenStart
let refShorthandDefaultPos = {start: 0}, spreadStart, innerParenStart, optionalCommaStart
while (this.type !== tt.parenR) {
first ? first = false : this.expect(tt.comma)
if (first) {
first = false;
} else {
this.expect(tt.comma)
if (this.type === tt.parenR && this.options.features["es7.trailingFunctionCommas"]) {
optionalCommaStart = this.start
break
}
}
if (this.type === tt.ellipsis) {
let spreadNodeStart = this.markPosition()
spreadStart = this.start
@@ -462,6 +471,7 @@ pp.parseParenAndDistinguishExpression = function(start, isAsync, canBeArrow) {
this.unexpected(this.lastTokStart)
}
}
if (optionalCommaStart) this.unexpected(optionalCommaStart)
if (spreadStart) this.unexpected(spreadStart)
if (refShorthandDefaultPos.start) this.unexpected(refShorthandDefaultPos.start)

View File

@@ -8,5 +8,8 @@
"utility.inlineExpressions": "minification.constantFolding",
"utility.deadCodeElimination": "minification.deadCodeElimination",
"utility.removeConsoleCalls": "minification.removeConsole",
"utility.removeDebugger": "minification.removeDebugger"
"utility.removeDebugger": "minification.removeDebugger",
"es6.parameters.rest": "es6.parameters",
"es6.parameters.default": "es6.parameters"
}

View File

@@ -70,7 +70,15 @@ export var visitor = {
let pattern = node.params[i];
if (!t.isPattern(pattern)) continue;
var ref = node.params[i] = scope.generateUidIdentifier("ref");
var ref = scope.generateUidIdentifier("ref");
if (t.isAssignmentPattern(pattern)) {
var _pattern = pattern;
pattern = pattern.left;
_pattern.left = ref;
} else {
node.params[i] = ref;
}
t.inherits(ref, pattern);
var destructuring = new DestructuringTransformer({

View File

@@ -1,7 +1,7 @@
import callDelegate from "../../helpers/call-delegate";
import getFunctionArity from "../../helpers/get-function-arity";
import * as util from "../../../util";
import * as t from "../../../types";
import callDelegate from "../../../helpers/call-delegate";
import getFunctionArity from "../../../helpers/get-function-arity";
import * as util from "../../../../util";
import * as t from "../../../../types";
var hasDefaults = function (node) {
for (var i = 0; i < node.params.length; i++) {
@@ -38,7 +38,7 @@ export var visitor = {
//
var argsIdentifier = t.identifier("arguments");
argsIdentifier._shadowedFunctionLiteral = true;
argsIdentifier._shadowedFunctionLiteral = this;
// push a default parameter definition
function pushDefNode(left, right, i) {

View File

@@ -0,0 +1,10 @@
import * as visitors from "../../../../traversal/visitors";
import * as def from "./default";
import * as rest from "./rest";
export var metadata = {
group: "builtin-advanced"
};
export var visitor = visitors.merge([rest.visitor, def.visitor]);

View File

@@ -1,5 +1,5 @@
import * as util from "../../../util";
import * as t from "../../../types";
import * as util from "../../../../util";
import * as t from "../../../../types";
var memberExpressionOptimisationVisitor = {
Scope(node, parent, scope, state) {
@@ -84,7 +84,7 @@ export var visitor = {
var argsId = t.identifier("arguments");
// otherwise `arguments` will be remapped in arrow functions
argsId._shadowedFunctionLiteral = true;
argsId._shadowedFunctionLiteral = this;
// support patterns
if (t.isPattern(rest)) {

View File

@@ -43,6 +43,10 @@ function build(props, scope) {
return nodes;
}
export var metadata = {
group: "builtin-advanced"
};
export var visitor = {
ArrayExpression(node, parent, scope) {
var elements = node.elements;

View File

@@ -211,7 +211,7 @@ class TailCallTransformer {
var decl = t.variableDeclarator(this.argumentsId);
if (this.argumentsId) {
decl.init = t.identifier("arguments");
decl.init._shadowedFunctionLiteral = true;
decl.init._shadowedFunctionLiteral = this.path;
}
topVars.push(decl);
}

View File

@@ -46,9 +46,6 @@ export default {
"es6.regex.sticky": require("./es6/regex.sticky"),
"es6.regex.unicode": require("./es6/regex.unicode"),
"es6.constants": require("./es6/constants"),
"es6.parameters.rest": require("./es6/parameters.rest"),
"es6.spread": require("./es6/spread"),
"es6.parameters.default": require("./es6/parameters.default"),
"es7.exportExtensions": require("./es7/export-extensions"),
"spec.protoToAssign": require("babel-plugin-proto-to-assign"),
"es7.doExpressions": require("./es7/do-expressions"),
@@ -57,6 +54,8 @@ export default {
"spec.undefinedToVoid": require("babel-plugin-undefined-to-void"),
//- builtin-advanced
"es6.spread": require("./es6/spread"),
"es6.parameters": require("./es6/parameters"),
"es6.destructuring": require("./es6/destructuring"),
"es6.blockScoping": require("./es6/block-scoping"),
"es6.spec.blockScoping": require("./es6/spec.block-scoping"),

View File

@@ -8,7 +8,31 @@ function remap(path, key, create) {
// ensure that we're shadowed
if (!path.inShadow()) return;
var fnPath = path.findParent((path) => !path.is("shadow") && (path.isFunction() || path.isProgram()));
var shadowed = path.node._shadowedFunctionLiteral;
var currentFunction;
var fnPath = path.findParent(function (path) {
if (shadowed) {
// only match our shadowed function parent
if (path === shadowed) {
// found our target reference function
currentFunction = path;
return true;
} else {
return false;
}
} else if (path.isFunction() || path.isProgram()) {
// catch current function in case this is the shadowed one
if (!currentFunction) currentFunction = path;
return !path.is("shadow");
} else {
return false;
}
});
// no point in realiasing if we're in this function
if (fnPath === currentFunction) return;
var cached = fnPath.getData(key);
if (cached) return cached;
@@ -28,7 +52,7 @@ export var visitor = {
},
ReferencedIdentifier(node) {
if (node.name === "arguments" && !node._shadowedFunctionLiteral) {
if (node.name === "arguments") {
return remap(this, "arguments", () => t.identifier("arguments"));
}
}

View File

@@ -126,6 +126,8 @@ export function merge(visitors) {
var rootVisitor = {};
for (var visitor of (visitors: Array)) {
explode(visitor);
for (var type in visitor) {
var nodeVisitor = rootVisitor[type] = rootVisitor[type] || {};
mergePair(nodeVisitor, visitor[type]);

View File

@@ -3374,6 +3374,49 @@ test("class Foo { bar(a,) { } }", {
features: { "es7.trailingFunctionCommas": true }
});
test("(x, y, ) => 1;", {
start: 0,
body: [{
start: 0,
expression: {
start: 0,
id: null,
generator: false,
expression: true,
params: [
{
start: 1,
name: "x",
type: "Identifier",
end: 2
},
{
start: 4,
name: "y",
type: "Identifier",
end: 5
}
],
body: {
start: 12,
value: 1,
raw: "1",
type: "Literal",
end: 13
},
type: "ArrowFunctionExpression",
end: 13
},
type: "ExpressionStatement",
end: 14
}],
type: "Program",
end: 14
}, {
ecmaVersion: 7,
features: { "es7.trailingFunctionCommas": true }
});
testFail("log(,);", "Unexpected token (1:4)", {
ecmaVersion: 7,
features: { "es7.trailingFunctionCommas": true }
@@ -3383,3 +3426,8 @@ testFail("function log(,) { }", "Unexpected token (1:13)", {
ecmaVersion: 7,
features: { "es7.trailingFunctionCommas": true }
});
testFail("('foo',)", "Unexpected token (1:7)", {
ecmaVersion: 7,
features: { "es7.trailingFunctionCommas": true }
});

View File

@@ -0,0 +1,6 @@
function broken(x, ...foo) {
if (true) {
class Foo extends Bar { }
return hello(...foo)
}
}

View File

@@ -0,0 +1,35 @@
"use strict";
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
function broken(x) {
for (var _len = arguments.length, foo = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
foo[_key - 1] = arguments[_key];
}
if (true) {
var _ret = (function () {
var Foo = (function (_Bar) {
function Foo() {
_classCallCheck(this, Foo);
_get(Object.getPrototypeOf(Foo.prototype), "constructor", this).apply(this, arguments);
}
_inherits(Foo, _Bar);
return Foo;
})(Bar);
return {
v: hello.apply(undefined, foo)
};
})();
if (typeof _ret === "object") return _ret.v;
}
}

View File

@@ -0,0 +1,3 @@
"use strict";
(function (x, y) {});