Compare commits

...

12 Commits

Author SHA1 Message Date
Sebastian McKenzie
5f931525bc v5.3.1 2015-05-13 03:20:33 +01:00
Sebastian McKenzie
b86545a320 update 5.3.1 changelog 2015-05-13 03:19:39 +01:00
Sebastian McKenzie
06e75c42bf update module call remap tests 2015-05-13 03:18:55 +01:00
Sebastian McKenzie
05dd65244d add 5.3.1 changelog 2015-05-13 03:16:43 +01:00
Sebastian McKenzie
c4ebfeb0fa fix explosion of modules and colliding identifiers 2015-05-13 03:16:03 +01:00
Sebastian McKenzie
1aa0bbfac9 add TraversalPath#equals 2015-05-13 03:13:27 +01:00
Sebastian McKenzie
58f1e6cbc6 remove incorrect es6.tailCall visitor comment 2015-05-13 03:13:20 +01:00
Sebastian McKenzie
83e0be3038 make import calls sequence expressions - fixes #1514 2015-05-13 03:13:10 +01:00
Sebastian McKenzie
5fc242e4ec upgrade bable dev dependency to 5.3.0 2015-05-13 03:12:32 +01:00
Sebastian McKenzie
dc101adad3 more es6.tailCall transformer cleanup 2015-05-13 01:13:08 +01:00
Sebastian McKenzie
faade72787 optimise and clean up es6.tailCall transformer 2015-05-13 01:11:26 +01:00
Sebastian McKenzie
2a78ae9889 5.3.0 2015-05-13 01:07:11 +01:00
17 changed files with 121 additions and 93 deletions

View File

@@ -13,6 +13,13 @@ _Note: Gaps between patch versions are faulty/broken releases._
See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
## 5.3.1
* **Bug Fix**
* Fix unique export specifiers not being cloned when exploding class and function exports,
* **Polish**
* Turn import remaps to sequence expressions to remove their context and improve performance.
## 5.3.0
**Speeeeeeed**

View File

@@ -1,7 +1,7 @@
{
"name": "babel-core",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "5.3.0",
"version": "5.3.1",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",
"license": "MIT",
@@ -64,7 +64,7 @@
"user-home": "^1.1.1"
},
"devDependencies": {
"babel": "5.1.13",
"babel": "5.3.0",
"browserify": "^9.0.8",
"chai": "^2.2.0",
"eslint": "^0.18.0",

View File

@@ -1,13 +1,13 @@
{
"name": "babel",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "5.2.17",
"version": "5.3.0",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",
"repository": "babel/babel",
"preferGlobal": true,
"dependencies": {
"babel-core": "^5.2.17",
"babel-core": "^5.3.0",
"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.2.17",
"version": "5.3.0",
"repository": "babel/babel",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"dependencies": {

View File

@@ -17,7 +17,11 @@ var remapVisitor = {
if (remap && node !== remap) {
if (!scope.hasBinding(node.name) || scope.bindingIdentifierEquals(node.name, formatter.localImports[node.name])) {
return remap;
if (this.key === "callee" && this.parentPath.isCallExpression()) {
return t.sequenceExpression([t.literal(0), remap]);
} else {
return remap;
}
}
}
},

View File

@@ -20,8 +20,7 @@ function returnBlock(expr) {
return t.blockStatement([t.returnStatement(expr)]);
}
// looks for and replaces tail recursion calls
var firstPass = {
var visitor = {
enter(node, parent, scope, state) {
if (t.isTryStatement(parent)) {
if (node === parent.block) {
@@ -33,7 +32,6 @@ var firstPass = {
},
ReturnStatement(node, parent, scope, state) {
this.skip();
return state.subTransform(node.argument);
},
@@ -42,46 +40,18 @@ var firstPass = {
},
VariableDeclaration(node, parent, scope, state) {
this.skip();
state.vars.push(node);
}
};
},
// hoists up function declarations, replaces `this` and `arguments` and marks
// them as needed
var secondPass = {
ThisExpression(node, parent, scope, state) {
state.needsThis = true;
return state.getThisId();
state.thisPaths.push(this);
},
ReferencedIdentifier(node, parent, scope, state) {
if (node.name !== "arguments") return;
state.needsArguments = true;
return state.getArgumentsId();
},
Function(node, parent, scope, state) {
this.skip();
if (this.isFunctionDeclaration()) {
node = t.variableDeclaration("var", [
t.variableDeclarator(node.id, t.toExpression(node))
]);
node._blockHoist = 2;
return node;
}
}
};
// optimizes recursion by removing `this` and `arguments` if they aren't used
var thirdPass = {
AssignmentExpression(node, parent, scope, state) {
if (!state.needsThis && node.left === state.getThisId()) {
this.remove();
} else if (!state.needsArguments && node.left === state.getArgumentsId() && t.isArrayExpression(node.right)) {
return map(node.right.elements, function (elem) {
return t.expressionStatement(elem);
});
if (node.name === "arguments") {
state.needsArguments = true;
state.argumentsPaths.push(this);
}
}
};
@@ -89,11 +59,16 @@ var thirdPass = {
class TailCallTransformer {
constructor(path, scope, file) {
this.hasTailRecursion = false;
this.needsArguments = false;
this.setsArguments = false;
this.needsThis = false;
this.ownerId = path.node.id;
this.vars = [];
this.needsArguments = false;
this.argumentsPaths = [];
this.setsArguments = false;
this.needsThis = false;
this.thisPaths = [];
this.ownerId = path.node.id;
this.vars = [];
this.scope = scope;
this.path = path;
@@ -159,10 +134,12 @@ class TailCallTransformer {
if (!ownerId) return;
// traverse the function and look for tail recursion
this.path.traverse(firstPass, this);
this.path.traverse(visitor, this);
// has no tail call recursion
if (!this.hasTailRecursion) return;
// the function binding isn't constant so we can't be sure that it's the same function :(
if (this.hasDeopt()) {
this.file.log.deopt(node, messages.get("tailCallReassignmentDeopt"));
return;
@@ -170,14 +147,18 @@ class TailCallTransformer {
//
this.path.traverse(secondPass, this);
if (!this.needsThis || !this.needsArguments) {
this.path.traverse(thirdPass, this);
}
var body = t.ensureBlock(node).body;
for (var i = 0; i < body.length; i++) {
var bodyNode = body[i];
if (!t.isFunctionDeclaration(bodyNode)) continue;
bodyNode = body[i] = t.variableDeclaration("var", [
t.variableDeclarator(bodyNode.id, t.toExpression(bodyNode))
]);
bodyNode._blockHoist = 2;
}
if (this.vars.length > 0) {
var declarations = flatten(map(this.vars, function (decl) {
return decl.declarations;
@@ -204,22 +185,28 @@ class TailCallTransformer {
);
node.body = util.template("tail-call-body", {
AGAIN_ID: this.getAgainId(),
THIS_ID: this.thisId,
ARGUMENTS_ID: this.argumentsId,
FUNCTION_ID: this.getFunctionId(),
BLOCK: node.body
FUNCTION_ID: this.getFunctionId(),
AGAIN_ID: this.getAgainId(),
BLOCK: node.body
});
var topVars = [];
if (this.needsThis) {
for (var path of (this.thisPaths: Array)) {
path.replaceWith(this.getThisId());
}
topVars.push(t.variableDeclarator(this.getThisId(), t.thisExpression()));
}
if (this.needsArguments || this.setsArguments) {
var decl = t.variableDeclarator(this.getArgumentsId());
if (this.needsArguments) {
for (var path of (this.argumentsPaths: Array)) {
path.replaceWith(this.argumentsId);
}
var decl = t.variableDeclarator(this.argumentsId);
if (this.argumentsId) {
decl.init = t.identifier("arguments");
}
topVars.push(decl);
@@ -332,7 +319,7 @@ class TailCallTransformer {
var body = [];
if (!t.isThisExpression(thisBinding)) {
if (this.needsThis && !t.isThisExpression(thisBinding)) {
body.push(t.expressionStatement(t.assignmentExpression(
"=",
this.getThisId(),
@@ -345,29 +332,35 @@ class TailCallTransformer {
}
var argumentsId = this.getArgumentsId();
var params = this.getParams();
var params = this.getParams();
body.push(t.expressionStatement(t.assignmentExpression(
"=",
argumentsId,
args
)));
var i, param;
if (this.needsArguments) {
body.push(t.expressionStatement(t.assignmentExpression(
"=",
argumentsId,
args
)));
}
if (t.isArrayExpression(args)) {
var elems = args.elements;
for (i = 0; i < elems.length && i < params.length; i++) {
param = params[i];
for (let i = 0; i < elems.length && i < params.length; i++) {
let param = params[i];
var elem = elems[i] || (elems[i] = t.identifier("undefined"));
if (!param._isDefaultPlaceholder) {
elems[i] = t.assignmentExpression("=", param, elem);
}
}
if (!this.needsArguments) {
for (var elem of (elems: Array)) {
body.push(t.expressionStatement(elem));
}
}
} else {
this.setsArguments = true;
for (i = 0; i < params.length; i++) {
param = params[i];
for (let i = 0; i < params.length; i++) {
let param = params[i];
if (!param._isDefaultPlaceholder) {
body.push(t.expressionStatement(t.assignmentExpression(
"=",
@@ -381,6 +374,7 @@ class TailCallTransformer {
body.push(t.expressionStatement(
t.assignmentExpression("=", this.getAgainId(), t.literal(true))
));
body.push(t.continueStatement(this.getFunctionId()));
return body;

View File

@@ -13,6 +13,18 @@ function buildClone(bindingKey, refKey) {
};
}
function buildListClone(listKey, bindingKey, refKey) {
var clone = buildClone(bindingKey, refKey);
return function (node) {
if (!node[listKey]) return;
for (var subNode of (node[listKey]: Array)) {
clone(subNode);
}
};
}
export var Property = buildClone("value", "key");
export var ExportSpecifier = buildClone("local", "exported");
export var ImportSpecifier = buildClone("local", "imported");
export var ExportDeclaration = buildListClone("specifiers", "local", "exported");
export var ImportDeclaration = buildListClone("specifiers", "local", "imported");

View File

@@ -49,6 +49,10 @@ export function ExportDefaultDeclaration(node, parent, scope) {
}
}
function buildExportSpecifier(id) {
return t.exportSpecifier(clone(id), clone(id));
}
export function ExportNamedDeclaration(node, parent, scope) {
ImportDeclaration.apply(this, arguments);
@@ -61,12 +65,12 @@ export function ExportNamedDeclaration(node, parent, scope) {
if (t.isClassDeclaration(declar)) {
// export class Foo {}
node.specifiers = [t.exportSpecifier(declar.id, declar.id)];
node.specifiers = [buildExportSpecifier(declar.id)];
node.declaration = null;
return [getDeclar(), node];
} else if (t.isFunctionDeclaration(declar)) {
// export function Foo() {}
node.specifiers = [t.exportSpecifier(declar.id, declar.id)];
node.specifiers = [buildExportSpecifier(declar.id)];
node.declaration = null;
node._blockHoist = 2;
return [getDeclar(), node];
@@ -75,8 +79,7 @@ export function ExportNamedDeclaration(node, parent, scope) {
var specifiers = [];
var bindings = this.get("declaration").getBindingIdentifiers();
for (var key in bindings) {
var id = bindings[key];
specifiers.push(t.exportSpecifier(clone(id), clone(id)));
specifiers.push(buildExportSpecifier(bindings[key]));
}
return [declar, t.exportNamedDeclaration(null, specifiers)];
}

View File

@@ -922,6 +922,14 @@ export default class TraversalPath {
return !this.has(key);
}
/**
* Description
*/
equals(key, value): boolean {
return this.node[key] === value;
}
/**
* Description
*/

View File

@@ -7,7 +7,7 @@ define(["exports", "./evens"], function (exports, _evens) {
exports.nextOdd = nextOdd;
function nextOdd(n) {
return _evens.isEven(n) ? n + 1 : n + 2;
return (0, _evens.isEven)(n) ? n + 1 : n + 2;
}
var isOdd = (function (isEven) {

View File

@@ -8,7 +8,7 @@ exports.nextOdd = nextOdd;
var _evens = require("./evens");
function nextOdd(n) {
return _evens.isEven(n) ? n + 1 : n + 2;
return (0, _evens.isEven)(n) ? n + 1 : n + 2;
}
var isOdd = (function (isEven) {
@@ -16,4 +16,4 @@ var isOdd = (function (isEven) {
return !isEven(n);
};
})(_evens.isEven);
exports.isOdd = isOdd;
exports.isOdd = isOdd;

View File

@@ -19,7 +19,7 @@
exports.nextOdd = nextOdd;
function nextOdd(n) {
return _evens.isEven(n) ? n + 1 : n + 2;
return (0, _evens.isEven)(n) ? n + 1 : n + 2;
}
var isOdd = (function (isEven) {
@@ -28,4 +28,4 @@
};
})(_evens.isEven);
exports.isOdd = isOdd;
});
});

View File

@@ -14,7 +14,7 @@ var Foo = (function () {
}
var _Foo = Foo;
Foo = _foo2["default"](Foo) || Foo;
Foo = (0, _foo2["default"])(Foo) || Foo;
return Foo;
})();

View File

@@ -1,7 +1,7 @@
define(["exports", "foo", "babel-runtime/helpers/interop-require"], function (exports, _foo, _babelRuntimeHelpersInteropRequire) {
"use strict";
var _foo2 = _babelRuntimeHelpersInteropRequire["default"](_foo);
var _foo2 = (0, _babelRuntimeHelpersInteropRequire["default"])(_foo);
_foo2;
});

View File

@@ -13,5 +13,5 @@
})(this, function (exports, _foo, _babelRuntimeHelpersInteropRequire) {
"use strict";
var _foo2 = _babelRuntimeHelpersInteropRequire["default"](_foo);
});
var _foo2 = (0, _babelRuntimeHelpersInteropRequire["default"])(_foo);
});

View File

@@ -20,11 +20,11 @@ var Container = (function () {
return;
}
return _lodashArrayLast2["default"](this.tokens.get(key));
return (0, _lodashArrayLast2["default"])(this.tokens.get(key));
}
}]);
return Container;
})();
exports["default"] = Container;
module.exports = exports["default"];
module.exports = exports["default"];

View File

@@ -19,11 +19,11 @@ var Login = (function (_React$Component) {
babelHelpers.createClass(Login, [{
key: "getForm",
value: function getForm() {
return _store.getForm().toJS();
return (0, _store.getForm)().toJS();
}
}]);
return Login;
})(React.Component);
exports["default"] = Login;
module.exports = exports["default"];
module.exports = exports["default"];