Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a185f91433 | ||
|
|
d053622802 | ||
|
|
74d6b61973 | ||
|
|
97784c8cca | ||
|
|
812d93553a | ||
|
|
d251b4cb56 | ||
|
|
caf38e1962 | ||
|
|
4ccbee4639 | ||
|
|
84196a3a07 | ||
|
|
29361c055a | ||
|
|
4277265591 | ||
|
|
812a2b315d | ||
|
|
0a1724fc3f | ||
|
|
bcc9e016b1 | ||
|
|
4ea0175ca7 | ||
|
|
799445c745 | ||
|
|
481ea12999 | ||
|
|
de6b608dda | ||
|
|
606f813822 | ||
|
|
e06c8cd106 | ||
|
|
9e3c67a8a2 | ||
|
|
91362f80b1 | ||
|
|
cde988f99f | ||
|
|
9ec0854659 |
14
CHANGELOG.md
14
CHANGELOG.md
@@ -11,6 +11,17 @@
|
||||
|
||||
_Note: Gaps between patch versions are faulty/broken releases._
|
||||
|
||||
## 3.5.2
|
||||
|
||||
* Disable `es6.tailCall` temporairly after reports of it breaking.
|
||||
|
||||
## 3.5.1
|
||||
|
||||
* **Polish**
|
||||
* Allow tail calls to work across files without the runtime.
|
||||
* **Internal**
|
||||
* Upgrade `acorn-6to5`.
|
||||
|
||||
## 3.5.0
|
||||
|
||||
* **Bug Fix**
|
||||
@@ -18,6 +29,9 @@ _Note: Gaps between patch versions are faulty/broken releases._
|
||||
* **Polish**
|
||||
* Make default parameter IIFE invocation smarter.
|
||||
* Make `__esModule` flag non-enumerable. Thanks [@daliwali](https://github.com/daliwali)!
|
||||
* **Internal**
|
||||
* More performance improvements.
|
||||
* Parsing is now ~30% faster thanks to [marijnh/acorn@7264bc0178e7e6af7cfe02e9e0c6b26ee0e6007f](https://github.com/marijnh/acorn/commit/7264bc0178e7e6af7cfe02e9e0c6b26ee0e6007f).
|
||||
* **New Feature**
|
||||
* Optional `es6.blockScopingTDZ` is now completely functional and handles all edgecases.
|
||||
* `super` in object literals.
|
||||
|
||||
@@ -36,15 +36,18 @@ exports.property = function (node, file, scope) {
|
||||
|
||||
scope.traverse(node, visitor, state);
|
||||
|
||||
var method = node.value;
|
||||
|
||||
if (state.selfReference) {
|
||||
// todo: support generators
|
||||
node.value = util.template("property-method-assignment-wrapper", {
|
||||
FUNCTION: node.value,
|
||||
var templateName = "property-method-assignment-wrapper";
|
||||
if (method.generator) templateName += "-generator";
|
||||
node.value = util.template(templateName, {
|
||||
FUNCTION: method,
|
||||
FUNCTION_ID: key,
|
||||
FUNCTION_KEY: scope.generateUidIdentifier(id),
|
||||
WRAPPER_KEY: scope.generateUidIdentifier(id + "Wrapper")
|
||||
});
|
||||
} else {
|
||||
node.value.id = key;
|
||||
method.id = key;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
(function (FUNCTION_KEY) {
|
||||
var WRAPPER_KEY = function* FUNCTION_ID() {
|
||||
return yield* FUNCTION_KEY.apply(this, arguments);
|
||||
};
|
||||
|
||||
WRAPPER_KEY.toString = function () {
|
||||
return FUNCTION_KEY.toString();
|
||||
};
|
||||
|
||||
return WRAPPER_KEY;
|
||||
})(FUNCTION)
|
||||
@@ -4,21 +4,16 @@
|
||||
if (desc === undefined) {
|
||||
var parent = Object.getPrototypeOf(object);
|
||||
|
||||
if (parent === null) {
|
||||
return;
|
||||
} else {
|
||||
if (parent !== null) {
|
||||
return set(parent, property, value, receiver);
|
||||
}
|
||||
} else if ("value" in desc && desc.writable) {
|
||||
desc.value = value;
|
||||
return;
|
||||
return desc.value = value;
|
||||
} else {
|
||||
var setter = desc.set;
|
||||
|
||||
if (setter === undefined) {
|
||||
return;
|
||||
if (setter !== undefined) {
|
||||
return setter.call(receiver, value);
|
||||
}
|
||||
|
||||
return setter.call(receiver, value);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
Tail.prototype._isTailDescriptor = true;
|
||||
|
||||
var isRunning = false;
|
||||
|
||||
return function (func, args, context) {
|
||||
@@ -13,7 +15,7 @@
|
||||
isRunning = true;
|
||||
do {
|
||||
result = result.func.apply(result.context, result.args);
|
||||
} while (result instanceof Tail);
|
||||
} while (result instanceof Tail || (result && result._isTailDescriptor));
|
||||
isRunning = false;
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -112,6 +112,12 @@ Destructuring.prototype.pushObjectPattern = function (pattern, parentId) {
|
||||
));
|
||||
}
|
||||
|
||||
if (pattern.properties.length > 1 && t.isMemberExpression(parentId)) {
|
||||
var temp = this.scope.generateUidBasedOnNode(parentId, this.file);
|
||||
this.nodes.push(this.buildVariableDeclaration(temp, parentId));
|
||||
parentId = temp;
|
||||
}
|
||||
|
||||
for (var i = 0; i < pattern.properties.length; i++) {
|
||||
var prop = pattern.properties[i];
|
||||
if (t.isSpreadProperty(prop)) {
|
||||
|
||||
@@ -27,7 +27,8 @@ exports.ForOfStatement = function (node, parent, scope, file) {
|
||||
|
||||
// push the rest of the original loop body onto our new body
|
||||
block.body = block.body.concat(node.body.body);
|
||||
block._declarations = node.body._declarations;
|
||||
|
||||
t.inherits(loop, node);
|
||||
|
||||
// todo: find out why this is necessary? #538
|
||||
loop._scopeInfo = node._scopeInfo;
|
||||
|
||||
@@ -1,62 +1,29 @@
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
var t = require("../../../types");
|
||||
|
||||
function returnBlock(expr) {
|
||||
return t.blockStatement([t.returnStatement(expr)]);
|
||||
}
|
||||
|
||||
function transformExpression(node, scope, state) {
|
||||
if (!node) return;
|
||||
|
||||
return (function subTransform(node) {
|
||||
switch (node.type) {
|
||||
case "ConditionalExpression":
|
||||
var callConsequent = subTransform(node.consequent);
|
||||
var callAlternate = subTransform(node.alternate);
|
||||
if (!callConsequent && !callAlternate) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if ternary operator had tail recursion in value, convert to optimized if-statement
|
||||
node.type = "IfStatement";
|
||||
node.consequent = callConsequent ? t.toBlock(callConsequent) : returnBlock(node.consequent);
|
||||
if (callAlternate) {
|
||||
node.alternate = t.isIfStatement(callAlternate) ? callAlternate : t.toBlock(callAlternate);
|
||||
} else {
|
||||
node.alternate = returnBlock(node.alternate);
|
||||
}
|
||||
return [node];
|
||||
// any value of ternary operator can be final one
|
||||
subTransform(node.consequent);
|
||||
subTransform(node.alternate);
|
||||
break;
|
||||
|
||||
case "LogicalExpression":
|
||||
// only call in right-value of can be optimized
|
||||
var callRight = subTransform(node.right);
|
||||
if (!callRight) {
|
||||
return;
|
||||
}
|
||||
|
||||
var test = state.wrapSideEffect(node.left);
|
||||
if (node.operator === "&&") {
|
||||
test.expr = t.unaryExpression("!", test.expr);
|
||||
}
|
||||
return [t.ifStatement(test.expr, returnBlock(test.ref))].concat(callRight);
|
||||
// only right expression can be final and so optimized
|
||||
subTransform(node.right);
|
||||
break;
|
||||
|
||||
case "SequenceExpression":
|
||||
// only last element of sequence can be optimized
|
||||
var seq = node.expressions;
|
||||
|
||||
// only last element can be optimized
|
||||
var lastCall = subTransform(seq[seq.length - 1]);
|
||||
if (!lastCall) {
|
||||
return;
|
||||
}
|
||||
|
||||
// remove converted expression from sequence
|
||||
// and convert to regular expression if needed
|
||||
if (--seq.length === 1) {
|
||||
node = seq[0];
|
||||
}
|
||||
|
||||
return [t.expressionStatement(node)].concat(lastCall);
|
||||
subTransform(seq[seq.length - 1]);
|
||||
break;
|
||||
|
||||
case "CallExpression":
|
||||
var callee = node.callee, thisBinding;
|
||||
@@ -77,10 +44,9 @@ function transformExpression(node, scope, state) {
|
||||
args.push(thisBinding);
|
||||
}
|
||||
|
||||
return [t.returnStatement(t.callExpression(
|
||||
state.getHelperRef(),
|
||||
args
|
||||
))];
|
||||
node.callee = state.getHelperRef();
|
||||
node.arguments = args;
|
||||
break;
|
||||
}
|
||||
})(node);
|
||||
}
|
||||
@@ -92,19 +58,17 @@ var functionChildrenVisitor = {
|
||||
this.skip();
|
||||
// transform return argument into statement if
|
||||
// it contains tail recursion
|
||||
return transformExpression(node.argument, scope, state);
|
||||
transformExpression(node.argument, scope, state);
|
||||
} else if (t.isFunction(node)) {
|
||||
return this.skip();
|
||||
// inner function's bodies are irrelevant
|
||||
this.skip();
|
||||
} else if (t.isTryStatement(parent)) {
|
||||
if (node === parent.block) {
|
||||
return this.skip();
|
||||
} else if (node === parent.finalizer) {
|
||||
return;
|
||||
} else {
|
||||
if (parent.finalizer) {
|
||||
this.skip();
|
||||
}
|
||||
return;
|
||||
// `try`-blocks can't be optimized
|
||||
this.skip();
|
||||
} else if (parent.finalizer && node !== parent.finalizer) {
|
||||
// `catch` clause followed by `finally` can't be optimized
|
||||
this.skip();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -151,3 +115,4 @@ exports.FunctionExpression = function (node, parent, scope, file) {
|
||||
]));
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
||||
@@ -92,5 +92,7 @@ module.exports = {
|
||||
"minification.removeDebugger": require("./minification/remove-debugger"),
|
||||
"minification.removeConsoleCalls": require("./minification/remove-console-calls"),
|
||||
"minification.deadCodeElimination": require("./minification/dead-code-elimination"),
|
||||
"minification.renameLocalVariables": require("./minification/rename-local-variables")
|
||||
"minification.renameLocalVariables": require("./minification/rename-local-variables"),
|
||||
|
||||
_cleanUp: require("./internal/cleanup")
|
||||
};
|
||||
|
||||
5
lib/6to5/transformation/transformers/internal/cleanup.js
Normal file
5
lib/6to5/transformation/transformers/internal/cleanup.js
Normal file
@@ -0,0 +1,5 @@
|
||||
exports.SequenceExpression = function (node) {
|
||||
if (node.expressions.length === 1) {
|
||||
return node.expressions[0];
|
||||
}
|
||||
};
|
||||
@@ -690,10 +690,12 @@ t.inheritsComments = function (child, parent) {
|
||||
*/
|
||||
|
||||
t.inherits = function (child, parent) {
|
||||
child.range = parent.range;
|
||||
child.start = parent.start;
|
||||
child.loc = parent.loc;
|
||||
child.end = parent.end;
|
||||
child._declarations = parent._declarations;
|
||||
child._scopeInfo = parent._scopeInfo;
|
||||
child.range = parent.range;
|
||||
child.start = parent.start;
|
||||
child.loc = parent.loc;
|
||||
child.end = parent.end;
|
||||
t.inheritsComments(child, parent);
|
||||
return child;
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "6to5",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "3.5.0",
|
||||
"version": "3.5.2",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://6to5.org/",
|
||||
"repository": "6to5/6to5",
|
||||
@@ -33,7 +33,7 @@
|
||||
"test": "make test"
|
||||
},
|
||||
"dependencies": {
|
||||
"acorn-6to5": "0.11.1-27",
|
||||
"acorn-6to5": "0.11.1-28",
|
||||
"ast-types": "~0.6.1",
|
||||
"chalk": "^0.5.1",
|
||||
"chokidar": "0.12.6",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "6to5-runtime",
|
||||
"description": "6to5 selfContained runtime",
|
||||
"version": "3.4.1",
|
||||
"version": "3.5.1",
|
||||
"repository": "6to5/6to5",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>"
|
||||
}
|
||||
@@ -37,6 +37,8 @@ chai.assert.throw = function (fn, msg) {
|
||||
msg = "Generator is already running";
|
||||
} else if (msg === "Sent value to newborn generator") {
|
||||
msg = /^attempt to send (.*?) to newborn generator$/;
|
||||
} else if (msg === "super prototype must be an Object or null") {
|
||||
msg = "Object prototype may only be an Object or null";
|
||||
}
|
||||
|
||||
return chai.assert._throw(fn, msg);
|
||||
|
||||
9
test/fixtures/transformation/.es6-tail-call/call-apply/expected.js
vendored
Normal file
9
test/fixtures/transformation/.es6-tail-call/call-apply/expected.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
(function f(n) {
|
||||
if (n <= 0) {
|
||||
console.log(this, arguments);
|
||||
return "foo";
|
||||
}
|
||||
return Math.random() > 0.5 ? to5Runtime.tailCall(f.call, [this, n - 1], f) : to5Runtime.tailCall(f.apply, [this, [n - 1]], f);
|
||||
})(1000000) === "foo";
|
||||
7
test/fixtures/transformation/.es6-tail-call/cross-function/actual.js
vendored
Normal file
7
test/fixtures/transformation/.es6-tail-call/cross-function/actual.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
function f(n) {
|
||||
return n <= 0 ? "foo" : g(n - 1);
|
||||
}
|
||||
|
||||
function g(n) {
|
||||
return n <= 0 ? "goo" : f(n - 1);
|
||||
}
|
||||
9
test/fixtures/transformation/.es6-tail-call/cross-function/expected.js
vendored
Normal file
9
test/fixtures/transformation/.es6-tail-call/cross-function/expected.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
function f(n) {
|
||||
return n <= 0 ? "foo" : to5Runtime.tailCall(g, [n - 1]);
|
||||
}
|
||||
|
||||
function g(n) {
|
||||
return n <= 0 ? "goo" : to5Runtime.tailCall(f, [n - 1]);
|
||||
}
|
||||
5
test/fixtures/transformation/.es6-tail-call/expressions/expected.js
vendored
Normal file
5
test/fixtures/transformation/.es6-tail-call/expressions/expected.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
(function f(n) {
|
||||
return n <= 0 ? "foo" : (doSmth(), getTrueValue() && (getFalseValue() || to5Runtime.tailCall(f, [n - 1])));
|
||||
})(1000000, true) === "foo";
|
||||
@@ -1,5 +1,5 @@
|
||||
function f() {
|
||||
return getObj().method();
|
||||
return getObj().method();
|
||||
}
|
||||
|
||||
function g() {
|
||||
@@ -6,9 +6,5 @@ function f() {
|
||||
}
|
||||
|
||||
function g() {
|
||||
var _temp;
|
||||
if (_temp = getFalseValue()) {
|
||||
return _temp;
|
||||
}
|
||||
return to5Runtime.tailCall(getValue);
|
||||
return getFalseValue() || to5Runtime.tailCall(getValue);
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
var x1 = rect.topLeft.x;
|
||||
var y1 = rect.topLeft.y;
|
||||
var x2 = rect.bottomRight.x;
|
||||
var y2 = rect.bottomRight.y;
|
||||
var _rect$topLeft = rect.topLeft;
|
||||
var x1 = _rect$topLeft.x;
|
||||
var y1 = _rect$topLeft.y;
|
||||
var _rect$bottomRight = rect.bottomRight;
|
||||
var x2 = _rect$bottomRight.x;
|
||||
var y2 = _rect$bottomRight.y;
|
||||
@@ -3,10 +3,12 @@
|
||||
var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } };
|
||||
|
||||
function somethingAdvanced(_ref) {
|
||||
var x1 = _ref.topLeft.x;
|
||||
var y1 = _ref.topLeft.y;
|
||||
var x2 = _ref.bottomRight.x;
|
||||
var y2 = _ref.bottomRight.y;
|
||||
var _ref$topLeft = _ref.topLeft;
|
||||
var x1 = _ref$topLeft.x;
|
||||
var y1 = _ref$topLeft.y;
|
||||
var _ref$bottomRight = _ref.bottomRight;
|
||||
var x2 = _ref$bottomRight.x;
|
||||
var y2 = _ref$bottomRight.y;
|
||||
}
|
||||
|
||||
function unpackObject(_ref) {
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
(function f(n) {
|
||||
if (n <= 0) {
|
||||
console.log(this, arguments);
|
||||
return "foo";
|
||||
}
|
||||
if (Math.random() > 0.5) {
|
||||
return to5Runtime.tailCall(f.call, [this, n - 1], f);
|
||||
} else {
|
||||
return to5Runtime.tailCall(f.apply, [this, [n - 1]], f);
|
||||
}
|
||||
})(1000000) === "foo";
|
||||
@@ -1,7 +0,0 @@
|
||||
function f(n) {
|
||||
return n <= 0 ? "foo" : g(n - 1);
|
||||
}
|
||||
|
||||
function g(n) {
|
||||
return n <= 0 ? "goo" : f(n - 1);
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
function f(n) {
|
||||
if (n <= 0) {
|
||||
return "foo";
|
||||
} else {
|
||||
return to5Runtime.tailCall(g, [n - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
function g(n) {
|
||||
if (n <= 0) {
|
||||
return "goo";
|
||||
} else {
|
||||
return to5Runtime.tailCall(f, [n - 1]);
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
(function f(n) {
|
||||
var _temp;
|
||||
if (n <= 0) {
|
||||
return "foo";
|
||||
} else {
|
||||
doSmth();
|
||||
|
||||
if (!(_temp = getTrueValue())) {
|
||||
return _temp;
|
||||
}
|
||||
if (_temp = getFalseValue()) {
|
||||
return _temp;
|
||||
}
|
||||
return to5Runtime.tailCall(f, [n - 1]);
|
||||
}
|
||||
})(1000000, true) === "foo";
|
||||
@@ -1,5 +1,3 @@
|
||||
if (!process.env.ALL_6TO5_TESTS) return;
|
||||
|
||||
require("./_helper").assertVendor("traceur");
|
||||
|
||||
var fs = require("fs");
|
||||
@@ -10,8 +8,8 @@ require("./_transformation-helper")({
|
||||
loc: __dirname + "/../vendor/traceur/test/feature",
|
||||
|
||||
ignoreSuites: [
|
||||
// weird environmental issue make these hard to test
|
||||
"Modules",
|
||||
"Classes",
|
||||
|
||||
// these are the responsibility of regenerator
|
||||
"AsyncFunctions",
|
||||
@@ -36,6 +34,16 @@ require("./_transformation-helper")({
|
||||
],
|
||||
|
||||
ignoreTasks: [
|
||||
// TODO: #426
|
||||
"Classes/SuperUnary",
|
||||
"Classes/SuperPostfix",
|
||||
|
||||
// TODO: investigate
|
||||
"Classes/SuperSet",
|
||||
"Classes/PrototypeDescriptor",
|
||||
"Classes/ExtendStrange",
|
||||
"Classes/ClassNameBinding",
|
||||
|
||||
// these are the responsibility of core-js
|
||||
"Symbol/GetOwnPropertySymbols",
|
||||
"Spread/Type",
|
||||
@@ -59,7 +67,7 @@ require("./_transformation-helper")({
|
||||
// they have no names
|
||||
"PropertyMethodAssignment/PropertyMethodAssignment",
|
||||
|
||||
// 6to5 assumes that all code transformed is a module
|
||||
// 6to5 assumes that all code transformed is a module so this isn't necessary
|
||||
"Strict",
|
||||
"Syntax/UseStrictEscapeSequence",
|
||||
"Syntax/UseStrictLineContinuation",
|
||||
|
||||
Reference in New Issue
Block a user