Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
90437d262b | ||
|
|
4aba7ec192 | ||
|
|
a924c9c218 | ||
|
|
a2ed0ea9c5 | ||
|
|
c5cd729c3d | ||
|
|
b065d43a6d | ||
|
|
281003c7bd | ||
|
|
6650336c64 | ||
|
|
f904734695 | ||
|
|
0528560d81 | ||
|
|
4362ba93de | ||
|
|
ca12e87370 | ||
|
|
ebaa735adc | ||
|
|
62e406a6fe | ||
|
|
0d45a8975c | ||
|
|
8f64fe2332 | ||
|
|
a8a7587c1f |
12
CHANGELOG.md
12
CHANGELOG.md
@@ -11,6 +11,18 @@
|
||||
|
||||
_Note: Gaps between patch versions are faulty/broken releases._
|
||||
|
||||
## 2.7.4
|
||||
|
||||
* **Polish**
|
||||
* Inherit assignments from their declaration in destructuring.
|
||||
* Properly align multi-declarator variable declarations.
|
||||
|
||||
## 2.7.3
|
||||
|
||||
* **Polish**
|
||||
* Indent and add newlines to `React.createElement` calls in `react` transformer.
|
||||
* Remove `Object.assign` calls and replace it with an `extends` helper.
|
||||
|
||||
## 2.7.1
|
||||
|
||||
* **New Feature**
|
||||
|
||||
@@ -35,7 +35,8 @@ File.helpers = [
|
||||
"async-to-generator",
|
||||
"interop-require-wildcard",
|
||||
"typeof",
|
||||
"exports-wildcard"
|
||||
"exports-wildcard",
|
||||
"extends"
|
||||
];
|
||||
|
||||
File.excludeHelpersFromRuntime = [
|
||||
|
||||
@@ -57,8 +57,28 @@ exports.ThisExpression = function () {
|
||||
|
||||
exports.CallExpression = function (node, print) {
|
||||
print(node.callee);
|
||||
|
||||
this.push("(");
|
||||
print.join(node.arguments, { separator: ", " });
|
||||
|
||||
var separator = ",";
|
||||
|
||||
if (node._prettyCall) {
|
||||
separator += "\n";
|
||||
this.newline();
|
||||
this.indent();
|
||||
} else {
|
||||
separator += " ";
|
||||
}
|
||||
|
||||
print.join(node.arguments, {
|
||||
separator: separator
|
||||
});
|
||||
|
||||
if (node._prettyCall) {
|
||||
this.newline();
|
||||
this.dedent();
|
||||
}
|
||||
|
||||
this.push(")");
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
var t = require("../../types");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.WithStatement = function (node, print) {
|
||||
this.keyword("with");
|
||||
@@ -157,7 +158,24 @@ exports.DebuggerStatement = function () {
|
||||
exports.VariableDeclaration = function (node, print, parent) {
|
||||
this.push(node.kind + " ");
|
||||
|
||||
print.join(node.declarations, { separator: ", " });
|
||||
var inits = 0;
|
||||
var noInits = 0;
|
||||
for (var i in node.declarations) {
|
||||
if (node.declarations[i].init) {
|
||||
inits++;
|
||||
} else {
|
||||
noInits++;
|
||||
}
|
||||
}
|
||||
|
||||
var sep = ",";
|
||||
if (inits > noInits) { // more inits than noinits
|
||||
sep += "\n" + util.repeat(node.kind.length + 1);
|
||||
} else {
|
||||
sep += " ";
|
||||
}
|
||||
|
||||
print.join(node.declarations, { separator: sep });
|
||||
|
||||
if (!t.isFor(parent)) {
|
||||
this.semicolon();
|
||||
|
||||
@@ -161,6 +161,9 @@ DefaultFormatter.prototype.getModuleName = function () {
|
||||
|
||||
moduleName += filenameRelative;
|
||||
|
||||
// normalise path separators
|
||||
moduleName = moduleName.replace(/\\/g, "/");
|
||||
|
||||
return moduleName;
|
||||
};
|
||||
|
||||
|
||||
@@ -83,10 +83,12 @@ CommonJSFormatter.prototype.exportDeclaration = function (node, nodes) {
|
||||
// this export isn't a function so we can't hoist it to the top so we need to set it
|
||||
// at the very end of the file with something like:
|
||||
//
|
||||
// module.exports = Object.assign(exports["default"], exports)
|
||||
// module.exports = _extends(exports["default"], exports)
|
||||
//
|
||||
|
||||
assign = util.template("common-export-default-assign", true);
|
||||
assign = util.template("common-export-default-assign", {
|
||||
EXTENDS_HELPER: this.file.addHelper("extends")
|
||||
}, true);
|
||||
assign._blockHoist = 0;
|
||||
|
||||
nodes.push(assign);
|
||||
|
||||
@@ -1 +1 @@
|
||||
module.exports = Object.assign(exports["default"], exports);
|
||||
module.exports = EXTENDS_HELPER(exports["default"], exports);
|
||||
|
||||
9
lib/6to5/transformation/templates/extends.js
Normal file
9
lib/6to5/transformation/templates/extends.js
Normal file
@@ -0,0 +1,9 @@
|
||||
(function (target) {
|
||||
for (var i = 1; i < arguments.length; i++) {
|
||||
var source = arguments[i];
|
||||
for (var key in source) {
|
||||
target[key] = source[key];
|
||||
}
|
||||
}
|
||||
return target;
|
||||
})
|
||||
@@ -300,10 +300,17 @@ exports.VariableDeclaration = function (node, parent, file, scope) {
|
||||
file: file,
|
||||
scope: scope
|
||||
};
|
||||
|
||||
if (t.isPattern(pattern) && patternId) {
|
||||
pushPattern(opts);
|
||||
|
||||
if (+i !== node.declarations.length - 1) {
|
||||
// we aren't the last declarator so let's just make the
|
||||
// last transformed node inherit from us
|
||||
t.inherits(nodes[nodes.length - 1], declar);
|
||||
}
|
||||
} else {
|
||||
nodes.push(buildVariableAssign(opts, declar.id, declar.init));
|
||||
nodes.push(t.inherits(buildVariableAssign(opts, declar.id, declar.init), declar));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ var t = require("../../types");
|
||||
|
||||
exports.experimental = true;
|
||||
|
||||
exports.ObjectExpression = function (node) {
|
||||
exports.ObjectExpression = function (node, parent, file) {
|
||||
var hasSpread = false;
|
||||
var i;
|
||||
var prop;
|
||||
@@ -42,5 +42,5 @@ exports.ObjectExpression = function (node) {
|
||||
args.unshift(t.objectExpression([]));
|
||||
}
|
||||
|
||||
return t.callExpression(t.memberExpression(t.identifier("Object"), t.identifier("assign")), args);
|
||||
return t.callExpression(file.addHelper("extends"), args);
|
||||
};
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
var OBJECT_ASSIGN_MEMBER = t.memberExpression(t.identifier("Object"), t.identifier("assign"));
|
||||
|
||||
var isProtoKey = function (node) {
|
||||
return t.isLiteral(t.toComputedKey(node, node.key), { value: "__proto__" });
|
||||
};
|
||||
@@ -43,7 +41,7 @@ exports.ExpressionStatement = function (node, parent, file) {
|
||||
}
|
||||
};
|
||||
|
||||
exports.ObjectExpression = function (node) {
|
||||
exports.ObjectExpression = function (node, parent, file) {
|
||||
var proto;
|
||||
|
||||
for (var i in node.properties) {
|
||||
@@ -58,6 +56,6 @@ exports.ObjectExpression = function (node) {
|
||||
if (proto) {
|
||||
var args = [t.objectExpression([]), proto];
|
||||
if (node.properties.length) args.push(node);
|
||||
return t.callExpression(OBJECT_ASSIGN_MEMBER, args);
|
||||
return t.callExpression(file.addHelper("extends"), args);
|
||||
}
|
||||
};
|
||||
|
||||
26
lib/6to5/transformation/transformers/react.js
vendored
26
lib/6to5/transformation/transformers/react.js
vendored
@@ -32,7 +32,7 @@ exports.XJSExpressionContainer = function (node) {
|
||||
exports.XJSAttribute = {
|
||||
exit: function (node) {
|
||||
var value = node.value || t.literal(true);
|
||||
return t.property("init", node.name, value);
|
||||
return t.inherits(t.property("init", node.name, value), node);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -107,26 +107,18 @@ exports.XJSOpeningElement = {
|
||||
if (tagName && isTag(tagName)) {
|
||||
return t.callExpression(
|
||||
t.memberExpression(
|
||||
t.memberExpression(
|
||||
t.identifier('React'),
|
||||
t.identifier('DOM'),
|
||||
false
|
||||
),
|
||||
t.memberExpression(t.identifier("React"), t.identifier("DOM")),
|
||||
tagExpr,
|
||||
t.isLiteral(tagExpr)
|
||||
),
|
||||
args
|
||||
);
|
||||
} else {
|
||||
return t.callExpression(
|
||||
tagExpr,
|
||||
args
|
||||
);
|
||||
}
|
||||
} else {
|
||||
tagExpr = t.memberExpression(t.identifier("React"), t.identifier("createElement"));
|
||||
return t.callExpression(tagExpr, args);
|
||||
}
|
||||
|
||||
return t.callExpression(tagExpr, args);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -148,16 +140,16 @@ exports.XJSElement = {
|
||||
var isLastLine = +i === lines.length - 1;
|
||||
|
||||
// replace rendered whitespace tabs with spaces
|
||||
var trimmedLine = line.replace(/\t/g, ' ');
|
||||
var trimmedLine = line.replace(/\t/g, " ");
|
||||
|
||||
// trim whitespace touching a newline
|
||||
if (!isFirstLine) {
|
||||
trimmedLine = trimmedLine.replace(/^[ ]+/, '');
|
||||
trimmedLine = trimmedLine.replace(/^[ ]+/, "");
|
||||
}
|
||||
|
||||
// trim whitespace touching an endline
|
||||
if (!isLastLine) {
|
||||
trimmedLine = trimmedLine.replace(/[ ]+$/, '');
|
||||
trimmedLine = trimmedLine.replace(/[ ]+$/, "");
|
||||
}
|
||||
|
||||
if (trimmedLine) {
|
||||
@@ -173,6 +165,10 @@ exports.XJSElement = {
|
||||
callExpr.arguments.push(child);
|
||||
}
|
||||
|
||||
if (callExpr.arguments.length >= 3) {
|
||||
callExpr._prettyCall = true;
|
||||
}
|
||||
|
||||
return t.inherits(callExpr, node);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "6to5",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "2.7.2",
|
||||
"version": "2.7.4",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://github.com/6to5/6to5",
|
||||
"repository": {
|
||||
|
||||
@@ -7,4 +7,5 @@ var test = {
|
||||
* Inside bracket init
|
||||
*/
|
||||
"b"]: "2"
|
||||
}, ok = 42;
|
||||
},
|
||||
ok = 42;
|
||||
|
||||
@@ -3,6 +3,7 @@ function test() {
|
||||
// Leading to VariableDeclarator
|
||||
// Leading to VariableDeclarator
|
||||
i = 20,
|
||||
|
||||
// Leading to VariableDeclarator
|
||||
// Leading to VariableDeclarator
|
||||
j = 20;
|
||||
|
||||
@@ -5,6 +5,7 @@ function test() {
|
||||
* Leading to VariableDeclarator
|
||||
*/
|
||||
i = 20,
|
||||
|
||||
/*
|
||||
* Leading to VariableDeclarator
|
||||
* Leading to VariableDeclarator
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
function* foo() {
|
||||
var a = yield wat(), b = 2;
|
||||
var a = yield wat(),
|
||||
b = 2;
|
||||
var c = yield a = b;
|
||||
yield a, yield b;
|
||||
yield a = b;
|
||||
|
||||
@@ -8,6 +8,9 @@ const foo = "foo";
|
||||
let foo, bar = "bar";
|
||||
var foo, bar = "bar";
|
||||
|
||||
let foo = "foo", bar = "bar";
|
||||
var foo = "foo", bar = "bar";
|
||||
const foo = "foo", bar = "bar";
|
||||
let foo = "foo",
|
||||
bar = "bar";
|
||||
var foo = "foo",
|
||||
bar = "bar";
|
||||
const foo = "foo",
|
||||
bar = "bar";
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
var { x, y } = coords, foo = "bar";
|
||||
var { x, y } = coords,
|
||||
foo = "bar";
|
||||
|
||||
@@ -1,6 +1,17 @@
|
||||
"use strict";
|
||||
|
||||
var _extends = function (target) {
|
||||
for (var i = 1; i < arguments.length; i++) {
|
||||
var source = arguments[i];
|
||||
for (var key in source) {
|
||||
target[key] = source[key];
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
};
|
||||
|
||||
exports.Cachier = Cachier;
|
||||
exports["default"] = new Cachier();
|
||||
function Cachier(databaseName) {}
|
||||
module.exports = Object.assign(exports["default"], exports);
|
||||
module.exports = _extends(exports["default"], exports);
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
var foo = 1;
|
||||
var foo = 1, bar = 2;
|
||||
var foo = 1,
|
||||
bar = 2;
|
||||
var foo2 = function () {};
|
||||
var foo3 = undefined;
|
||||
var foo4 = 2;
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
var A = new WeakMap();
|
||||
var B = new WeakMap(), C = new WeakMap();
|
||||
var B = new WeakMap(),
|
||||
C = new WeakMap();
|
||||
var D = (function () {
|
||||
var F = new WeakMap(), G = new WeakMap();
|
||||
var F = new WeakMap(),
|
||||
G = new WeakMap();
|
||||
var E = new WeakMap();
|
||||
var D = function D() {};
|
||||
|
||||
@@ -11,7 +13,8 @@ var D = (function () {
|
||||
})();
|
||||
|
||||
var H = (function () {
|
||||
var J = new WeakMap(), K = new WeakMap();
|
||||
var J = new WeakMap(),
|
||||
K = new WeakMap();
|
||||
var I = new WeakMap();
|
||||
var _class = function () {};
|
||||
|
||||
|
||||
@@ -1,3 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
z = Object.assign({ x: x }, y);
|
||||
var _extends = function (target) {
|
||||
for (var i = 1; i < arguments.length; i++) {
|
||||
var source = arguments[i];
|
||||
for (var key in source) {
|
||||
target[key] = source[key];
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
};
|
||||
|
||||
z = _extends({ x: x }, y);
|
||||
|
||||
@@ -1,3 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
Object.assign({ x: x }, y, { a: a }, b, { c: c });
|
||||
var _extends = function (target) {
|
||||
for (var i = 1; i < arguments.length; i++) {
|
||||
var source = arguments[i];
|
||||
for (var key in source) {
|
||||
target[key] = source[key];
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
};
|
||||
|
||||
_extends({ x: x }, y, { a: a }, b, { c: c });
|
||||
|
||||
@@ -1,3 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
var z = Object.assign({}, x);
|
||||
var _extends = function (target) {
|
||||
for (var i = 1; i < arguments.length; i++) {
|
||||
var source = arguments[i];
|
||||
for (var key in source) {
|
||||
target[key] = source[key];
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
};
|
||||
|
||||
var z = _extends({}, x);
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
var z = { ...x };
|
||||
@@ -1,9 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequire = function (obj) {
|
||||
return obj && (obj["default"] || obj);
|
||||
};
|
||||
|
||||
var _core = _interopRequire(require("core-js/library"));
|
||||
|
||||
var z = _core.Object.assign({}, x);
|
||||
@@ -1,10 +1,21 @@
|
||||
"use strict";
|
||||
|
||||
var foo = Object.assign({}, bar);
|
||||
var _extends = function (target) {
|
||||
for (var i = 1; i < arguments.length; i++) {
|
||||
var source = arguments[i];
|
||||
for (var key in source) {
|
||||
target[key] = source[key];
|
||||
}
|
||||
}
|
||||
|
||||
var foo = Object.assign({}, bar, {
|
||||
return target;
|
||||
};
|
||||
|
||||
var foo = _extends({}, bar);
|
||||
|
||||
var foo = _extends({}, bar, {
|
||||
bar: "foo" });
|
||||
|
||||
var foo = Object.assign({}, bar, {
|
||||
var foo = _extends({}, bar, {
|
||||
bar: "foo"
|
||||
});
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
React.createElement(Component, React.__spread({}, this.props, {
|
||||
sound: "moo"
|
||||
}));
|
||||
sound: "moo" }));
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
var x = Component({
|
||||
foo: "bar"
|
||||
}, Namespace.Component(null));
|
||||
var x = Component({ foo: "bar" }, Namespace.Component(null));
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
var x = React.DOM.div({
|
||||
foo: "bar"
|
||||
}, React.DOM["font-face"](null));
|
||||
var x = React.DOM.div({ foo: "bar" }, React.DOM["font-face"](null));
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
React.createElement(Component, {
|
||||
constructor: "foo"
|
||||
});
|
||||
React.createElement(Component, { constructor: "foo" });
|
||||
|
||||
@@ -1,7 +1,23 @@
|
||||
var x = React.createElement("div", null, React.createElement(Component, null));
|
||||
var x = React.createElement(
|
||||
"div",
|
||||
null,
|
||||
React.createElement(Component, null)
|
||||
);
|
||||
|
||||
var x = React.createElement("div", null, this.props.children);
|
||||
var x = React.createElement(
|
||||
"div",
|
||||
null,
|
||||
this.props.children
|
||||
);
|
||||
|
||||
var x = React.createElement(Composite, null, this.props.children);
|
||||
var x = React.createElement(
|
||||
Composite,
|
||||
null,
|
||||
this.props.children
|
||||
);
|
||||
|
||||
var x = React.createElement(Composite, null, React.createElement(Composite2, null));
|
||||
var x = React.createElement(
|
||||
Composite,
|
||||
null,
|
||||
React.createElement(Composite2, null)
|
||||
);
|
||||
|
||||
@@ -1 +1,5 @@
|
||||
var x = React.createElement("div", null, "text");
|
||||
var x = React.createElement(
|
||||
"div",
|
||||
null,
|
||||
"text"
|
||||
);
|
||||
|
||||
@@ -1 +1,5 @@
|
||||
React.createElement("hasOwnProperty", null, "testing");
|
||||
React.createElement(
|
||||
"hasOwnProperty",
|
||||
null,
|
||||
"testing"
|
||||
);
|
||||
|
||||
@@ -1 +1,17 @@
|
||||
var x = React.createElement("div", null, React.createElement("div", null, React.createElement("br", null)), React.createElement(Component, null, foo, React.createElement("br", null), bar), React.createElement("br", null));
|
||||
var x = React.createElement(
|
||||
"div",
|
||||
null,
|
||||
React.createElement(
|
||||
"div",
|
||||
null,
|
||||
React.createElement("br", null)
|
||||
),
|
||||
React.createElement(
|
||||
Component,
|
||||
null,
|
||||
foo,
|
||||
React.createElement("br", null),
|
||||
bar
|
||||
),
|
||||
React.createElement("br", null)
|
||||
);
|
||||
|
||||
@@ -2,5 +2,4 @@ var x = React.createElement("div", {
|
||||
attr1: "foo" + "bar",
|
||||
attr2: "foo" + "bar" + "baz" + "bug",
|
||||
attr3: "foo" + "bar" + "baz" + "bug",
|
||||
attr4: "baz"
|
||||
});
|
||||
attr4: "baz" });
|
||||
|
||||
@@ -1,4 +1 @@
|
||||
React.createElement(Component, React.__spread({}, x, {
|
||||
y: 2,
|
||||
z: true
|
||||
}));
|
||||
React.createElement(Component, React.__spread({}, x, { y: 2, z: true }));
|
||||
|
||||
@@ -1,4 +1 @@
|
||||
React.createElement(Component, React.__spread({
|
||||
y: 2,
|
||||
z: true
|
||||
}, x));
|
||||
React.createElement(Component, React.__spread({ y: 2, z: true }, x));
|
||||
|
||||
@@ -1,5 +1 @@
|
||||
React.createElement(Component, React.__spread({
|
||||
y: 2
|
||||
}, x, {
|
||||
z: true
|
||||
}));
|
||||
React.createElement(Component, React.__spread({ y: 2 }, x, { z: true }));
|
||||
|
||||
Reference in New Issue
Block a user