Compare commits

..

26 Commits

Author SHA1 Message Date
Sebastian McKenzie
90437d262b v2.7.4 2015-01-08 01:02:39 +11:00
Sebastian McKenzie
4aba7ec192 fix generation tests and add variable kind length 2015-01-08 01:00:32 +11:00
Sebastian McKenzie
a924c9c218 fix up declarations being split up and use a new algorithm to determine whether or not we should align them 2015-01-08 00:54:01 +11:00
Sebastian McKenzie
a2ed0ea9c5 only align variable declarations if at least one declarator has an init 2015-01-08 00:44:53 +11:00
Sebastian McKenzie
c5cd729c3d add 2.7.4 changelog 2015-01-08 00:40:43 +11:00
Sebastian McKenzie
b065d43a6d add custom level to buffer getIndent 2015-01-08 00:37:46 +11:00
Sebastian McKenzie
281003c7bd properly align multi declarator var declarations - fixes #413 2015-01-08 00:37:32 +11:00
Sebastian McKenzie
6650336c64 inherit assign from declaration in destructuring - fixes #413 2015-01-08 00:37:07 +11:00
Sebastian McKenzie
f904734695 rename prettyPrint to the more descriptive prettyCall 2015-01-08 00:36:40 +11:00
Sebastian McKenzie
0528560d81 v2.7.3 2015-01-07 22:55:09 +11:00
Sebastian McKenzie
4362ba93de fix verison number in changelog 2015-01-07 22:53:02 +11:00
Sebastian McKenzie
ca12e87370 remove unused variables 2015-01-07 22:50:24 +11:00
Sebastian McKenzie
ebaa735adc add 2.7.2 changelog 2015-01-07 22:49:21 +11:00
Sebastian McKenzie
62e406a6fe fix better jsx output 2015-01-07 22:47:37 +11:00
Sebastian McKenzie
0d45a8975c normalise module name paths 2015-01-07 22:43:05 +11:00
Sebastian McKenzie
8f64fe2332 add extends helper instead of using Object.assign 2015-01-07 22:42:26 +11:00
Sebastian McKenzie
a8a7587c1f better jsx output #369 2015-01-07 22:42:03 +11:00
Sebastian McKenzie
7736fa11f2 v2.7.2 2015-01-07 18:38:00 +11:00
Sebastian McKenzie
d203924541 disable module import reassignment tests 2015-01-07 18:35:36 +11:00
Sebastian McKenzie
cd23e500a1 add back specNoForInOfAssignment transformer 2015-01-07 18:30:48 +11:00
Sebastian McKenzie
bf24a0d6b5 temporarily disable module collission detections 2015-01-07 18:30:33 +11:00
Sebastian McKenzie
279d1affea v2.7.1 2015-01-07 14:15:16 +11:00
Sebastian McKenzie
2a1e012240 upgrade core-js 2015-01-07 14:12:21 +11:00
Sebastian McKenzie
a307a961a6 add istanbul to travis test 2015-01-07 14:10:47 +11:00
Sebastian McKenzie
fe5b1dc542 add reactCompat default to file opts 2015-01-07 14:10:37 +11:00
Sebastian McKenzie
f057347ae9 add version to browser and node build 2015-01-07 14:10:27 +11:00
68 changed files with 279 additions and 98 deletions

View File

@@ -11,12 +11,31 @@
_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**
* 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

View File

@@ -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:

View File

@@ -1,5 +1,7 @@
var transform = module.exports = require("./transformation/transform");
transform.version = require("../../package").version;
transform.transform = transform;
transform.run = function (code, opts) {

View File

@@ -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,

View File

@@ -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(")");
};

View File

@@ -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();

View File

@@ -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");

View File

@@ -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;
};

View File

@@ -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);

View File

@@ -1 +1 @@
module.exports = Object.assign(exports["default"], exports);
module.exports = EXTENDS_HELPER(exports["default"], exports);

View 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;
})

View File

@@ -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"),

View File

@@ -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));
}
}

View File

@@ -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);
};

View File

@@ -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);
}
};

View File

@@ -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._prettyCall = true;
}
return t.inherits(callExpr, node);
}
};

View File

@@ -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");
}
};

View File

@@ -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) {

View File

@@ -1,7 +1,7 @@
{
"name": "6to5",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "2.7.0",
"version": "2.7.4",
"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",

View File

@@ -7,4 +7,5 @@ var test = {
* Inside bracket init
*/
"b"]: "2"
}, ok = 42;
},
ok = 42;

View File

@@ -3,6 +3,7 @@ function test() {
// Leading to VariableDeclarator
// Leading to VariableDeclarator
i = 20,
// Leading to VariableDeclarator
// Leading to VariableDeclarator
j = 20;

View File

@@ -5,6 +5,7 @@ function test() {
* Leading to VariableDeclarator
*/
i = 20,
/*
* Leading to VariableDeclarator
* Leading to VariableDeclarator

View File

@@ -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;

View File

@@ -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";

View File

@@ -1 +1,2 @@
var { x, y } = coords, foo = "bar";
var { x, y } = coords,
foo = "bar";

View File

@@ -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);

View File

@@ -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;

View File

@@ -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 () {};

View File

@@ -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);

View File

@@ -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 });

View File

@@ -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);

View File

@@ -1 +0,0 @@
var z = { ...x };

View File

@@ -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);

View File

@@ -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"
});

View File

@@ -1,3 +1,2 @@
React.createElement(Component, React.__spread({}, this.props, {
sound: "moo"
}));
sound: "moo" }));

View File

@@ -1,3 +1 @@
var x = Component({
foo: "bar"
}, Namespace.Component(null));
var x = Component({ foo: "bar" }, Namespace.Component(null));

View File

@@ -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));

View File

@@ -1,3 +1 @@
React.createElement(Component, {
constructor: "foo"
});
React.createElement(Component, { constructor: "foo" });

View File

@@ -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)
);

View File

@@ -1 +1,5 @@
var x = React.createElement("div", null, "text");
var x = React.createElement(
"div",
null,
"text"
);

View File

@@ -1 +1,5 @@
React.createElement("hasOwnProperty", null, "testing");
React.createElement(
"hasOwnProperty",
null,
"testing"
);

View File

@@ -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)
);

View File

@@ -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" });

View File

@@ -1,4 +1 @@
React.createElement(Component, React.__spread({}, x, {
y: 2,
z: true
}));
React.createElement(Component, React.__spread({}, x, { y: 2, z: true }));

View File

@@ -1,4 +1 @@
React.createElement(Component, React.__spread({
y: 2,
z: true
}, x));
React.createElement(Component, React.__spread({ y: 2, z: true }, x));

View File

@@ -1,5 +1 @@
React.createElement(Component, React.__spread({
y: 2
}, x, {
z: true
}));
React.createElement(Component, React.__spread({ y: 2 }, x, { z: true }));

View File

@@ -0,0 +1,3 @@
for (var i = 0 in obj) {
}

View File

@@ -0,0 +1,3 @@
{
"throws": "No assignments allowed in for-in/of head"
}

View File

@@ -0,0 +1,3 @@
for (var i = 0 of obj) {
}

View File

@@ -0,0 +1,3 @@
{
"throws": "No assignments allowed in for-in/of head"
}