Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0528560d81 | ||
|
|
4362ba93de | ||
|
|
ca12e87370 | ||
|
|
ebaa735adc | ||
|
|
62e406a6fe | ||
|
|
0d45a8975c | ||
|
|
8f64fe2332 | ||
|
|
a8a7587c1f | ||
|
|
7736fa11f2 | ||
|
|
d203924541 | ||
|
|
cd23e500a1 | ||
|
|
bf24a0d6b5 | ||
|
|
279d1affea | ||
|
|
2a1e012240 | ||
|
|
a307a961a6 | ||
|
|
fe5b1dc542 | ||
|
|
f057347ae9 |
15
CHANGELOG.md
15
CHANGELOG.md
@@ -11,12 +11,25 @@
|
||||
|
||||
_Note: Gaps between patch versions are faulty/broken releases._
|
||||
|
||||
## 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**
|
||||
* Expose `version` on browser and node API.
|
||||
* **Internal**
|
||||
* Upgrade `core-js` to 0.4.1
|
||||
|
||||
## 2.7.0
|
||||
|
||||
* **Spec Compliancy**
|
||||
* Disallow reassignments of imports.
|
||||
* **New Feature**
|
||||
* `reactCompat` to enable pre-v0.12 react components.
|
||||
* `reactCompat` option to enable pre-v0.12 react components.
|
||||
|
||||
## 2.6.3
|
||||
|
||||
|
||||
2
Makefile
2
Makefile
@@ -53,7 +53,7 @@ test-cov:
|
||||
node $(ISTANBUL_CMD) $(MOCHA_CMD) --
|
||||
|
||||
test-travis: bootstrap
|
||||
$(MOCHA_CMD)
|
||||
node $(ISTANBUL_CMD) $(MOCHA_CMD) --
|
||||
if test -n "$$CODECLIMATE_REPO_TOKEN"; then codeclimate < coverage/lcov.info; fi
|
||||
|
||||
test-browser:
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
var transform = module.exports = require("./transformation/transform");
|
||||
|
||||
transform.version = require("../../package").version;
|
||||
|
||||
transform.transform = transform;
|
||||
|
||||
transform.run = function (code, opts) {
|
||||
|
||||
@@ -35,7 +35,8 @@ File.helpers = [
|
||||
"async-to-generator",
|
||||
"interop-require-wildcard",
|
||||
"typeof",
|
||||
"exports-wildcard"
|
||||
"exports-wildcard",
|
||||
"extends"
|
||||
];
|
||||
|
||||
File.excludeHelpersFromRuntime = [
|
||||
@@ -48,6 +49,7 @@ File.normaliseOptions = function (opts) {
|
||||
|
||||
_.defaults(opts, {
|
||||
experimental: false,
|
||||
reactCompat: false,
|
||||
playground: false,
|
||||
whitespace: true,
|
||||
moduleIds: opts.amdModuleIds || false,
|
||||
|
||||
@@ -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._prettyPrint) {
|
||||
separator += "\n";
|
||||
this.newline();
|
||||
this.indent();
|
||||
} else {
|
||||
separator += " ";
|
||||
}
|
||||
|
||||
print.join(node.arguments, {
|
||||
separator: separator
|
||||
});
|
||||
|
||||
if (node._prettyPrint) {
|
||||
this.newline();
|
||||
this.dedent();
|
||||
}
|
||||
|
||||
this.push(")");
|
||||
};
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ var util = require("./util");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
|
||||
exports.version = require("../../package").version;
|
||||
|
||||
exports.types = require("./types");
|
||||
|
||||
exports.runtime = require("./runtime-generator");
|
||||
|
||||
@@ -13,7 +13,7 @@ function DefaultFormatter(file) {
|
||||
|
||||
this.remapAssignments();
|
||||
|
||||
this.checkCollisions();
|
||||
//this.checkCollisions();
|
||||
}
|
||||
|
||||
DefaultFormatter.prototype.getLocalExports = function () {
|
||||
@@ -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;
|
||||
})
|
||||
@@ -39,6 +39,8 @@ transform.moduleFormatters = {
|
||||
};
|
||||
|
||||
_.each({
|
||||
specNoForInOfAssignment: require("./transformers/spec-no-for-in-of-assignment"),
|
||||
|
||||
// playground
|
||||
methodBinding: require("./transformers/playground-method-binding"),
|
||||
memoizationOperator: require("./transformers/playground-memoization-operator"),
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
28
lib/6to5/transformation/transformers/react.js
vendored
28
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);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -42,7 +42,7 @@ var isTag = function(tagName) {
|
||||
|
||||
exports.XJSOpeningElement = {
|
||||
exit: function (node, parent, file) {
|
||||
var reactCompat = file.opts && file.opts.reactCompat;
|
||||
var reactCompat = file.opts.reactCompat;
|
||||
var tagExpr = node.name;
|
||||
var args = [];
|
||||
|
||||
@@ -107,25 +107,17 @@ 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"));
|
||||
}
|
||||
|
||||
tagExpr = t.memberExpression(t.identifier("React"), t.identifier("createElement"));
|
||||
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._prettyPrint = true;
|
||||
}
|
||||
|
||||
return t.inherits(callExpr, node);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
var t = require("../../types");
|
||||
|
||||
exports.ForInStatement =
|
||||
exports.ForOfStatement = function (node, parent, file) {
|
||||
var left = node.left;
|
||||
if (t.isVariableDeclaration(left)) {
|
||||
var declar = left.declarations[0];
|
||||
if (declar.init) throw file.errorWithNode(declar, "No assignments allowed in for-in/of head");
|
||||
}
|
||||
};
|
||||
@@ -146,10 +146,10 @@ exports.template = function (name, nodes, keepExpression) {
|
||||
var node = template.body[0];
|
||||
|
||||
if (!keepExpression && t.isExpressionStatement(node)) {
|
||||
node = node.expression;
|
||||
return node.expression;
|
||||
} else {
|
||||
return node;
|
||||
}
|
||||
|
||||
return node;
|
||||
};
|
||||
|
||||
exports.codeFrame = function (lines, lineNumber, colNumber) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "6to5",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "2.7.0",
|
||||
"version": "2.7.3",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://github.com/6to5/6to5",
|
||||
"repository": {
|
||||
@@ -43,7 +43,7 @@
|
||||
"ast-types": "~0.6.1",
|
||||
"chokidar": "0.11.1",
|
||||
"commander": "2.5.0",
|
||||
"core-js": "^0.4.0",
|
||||
"core-js": "^0.4.1",
|
||||
"estraverse": "1.8.0",
|
||||
"esutils": "1.1.6",
|
||||
"esvalid": "^1.1.0",
|
||||
|
||||
@@ -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,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 }));
|
||||
|
||||
3
test/fixtures/transformation/spec/for-in-assignment/actual.js
vendored
Normal file
3
test/fixtures/transformation/spec/for-in-assignment/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
for (var i = 0 in obj) {
|
||||
|
||||
}
|
||||
3
test/fixtures/transformation/spec/for-in-assignment/options.json
vendored
Normal file
3
test/fixtures/transformation/spec/for-in-assignment/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "No assignments allowed in for-in/of head"
|
||||
}
|
||||
3
test/fixtures/transformation/spec/for-of-assignment/actual.js
vendored
Normal file
3
test/fixtures/transformation/spec/for-of-assignment/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
for (var i = 0 of obj) {
|
||||
|
||||
}
|
||||
3
test/fixtures/transformation/spec/for-of-assignment/options.json
vendored
Normal file
3
test/fixtures/transformation/spec/for-of-assignment/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "No assignments allowed in for-in/of head"
|
||||
}
|
||||
Reference in New Issue
Block a user