Compare commits

...

10 Commits

Author SHA1 Message Date
Sebastian McKenzie
5b961ea3e7 v1.11.14 2014-11-11 15:35:18 +11:00
Sebastian McKenzie
35b28cf722 more reliable jsx literal whitespace 2014-11-11 15:34:29 +11:00
Sebastian McKenzie
c5bfbf37f0 add 1.11.14 changelog 2014-11-11 15:27:23 +11:00
Sebastian McKenzie
cfee68aa67 jsx: replace all newlines and excess whitespace with spaces - fixes #142 2014-11-11 15:26:25 +11:00
Sebastian McKenzie
7d0dae129c nicer let-scoping switch 2014-11-11 15:25:37 +11:00
Sebastian McKenzie
f9d14fa2ed add runtime, property-literals and shebang tests 2014-11-11 15:25:27 +11:00
Sebastian McKenzie
11d55e661e rename let-scoping tests to traceur-let-scoping and add additional let-scoping tests 2014-11-11 15:25:13 +11:00
Sebastian McKenzie
0544e98fb1 add switch case generated node whitespace 2014-11-11 15:24:40 +11:00
Sebastian McKenzie
59d918ea67 remove unused isArray traverse.hasType 2014-11-11 15:23:52 +11:00
Sebastian McKenzie
b4232699d2 add newline after shebang 2014-11-11 15:23:31 +11:00
67 changed files with 206 additions and 39 deletions

View File

@@ -1,3 +1,8 @@
# 1.11.14
* Avoid using a switch for let-scoping continue and break statements and use an if statement instead.
* Remove excess whitespace and newlines from JSX literals.
# 1.11.13
* Update regenerator-6to5

View File

@@ -146,7 +146,7 @@ File.prototype.generate = function () {
if (this.shebang) {
// add back shebang
result.code = this.shebang + result.code;
result.code = this.shebang + "\n" + result.code;
}
if (opts.sourceMap === "inline") {

View File

@@ -80,6 +80,10 @@ Node.prototype.needsWhitespace = function (type) {
if (t.isProperty(node) && parent.properties[0] === node) {
return 1;
}
if (t.isSwitchCase(node) && parent.cases[0] === node) {
return 1;
}
}
if (type === "after") {

View File

@@ -80,7 +80,19 @@ exports.XJSElement = {
var callExpr = node.openingElement;
var children = node.children;
_.each(children, function (child) {
_.each(children, function (child, i) {
var val = child.value;
if (t.isLiteral(child) && _.isString(val)) {
val = val.replace(/\n(\s+)/g, " ");
i = +i;
if (i === 0) val = val.trimLeft();
if (i === children.length - 1) val = val.trimRight();
if (!val) return;
child.value = val;
}
callExpr.arguments.push(child);
});

View File

@@ -133,7 +133,7 @@ var checkFor = function (forParent, block) {
} else if (t.isReturnStatement(node)) {
has.hasReturn = true;
replace = t.returnStatement(t.objectExpression([
t.property("init", t.identifier("v"), node.argument)
t.property("init", t.identifier("v"), node.argument || t.identifier("undefined"))
]));
}
@@ -286,16 +286,13 @@ var run = function (forParent, block, parent, file, scope) {
var retCheck;
var cases = [];
if (has.hasReturn) {
// typeof ret === "object"
retCheck = util.template("let-scoping-return", {
RETURN: ret,
});
// there's no `break` or `continue` so we can just push in the `if`
if (!has.hasBreak && !has.hasContinue) {
body.push(retCheck);
}
}
if (has.hasBreak || has.hasContinue) {
@@ -303,8 +300,6 @@ var run = function (forParent, block, parent, file, scope) {
// need to be able to access it
var label = forParent.label = forParent.label || t.identifier(file.generateUid("loop", scope));
var cases = [];
if (has.hasBreak) {
cases.push(t.switchCase(t.literal("break"), [t.breakStatement(label)]));
}
@@ -317,7 +312,17 @@ var run = function (forParent, block, parent, file, scope) {
cases.push(t.switchCase(null, [retCheck]));
}
body.push(t.switchStatement(ret, cases));
if (cases.length === 1) {
var single = cases[0];
body.push(t.ifStatement(
t.binaryExpression("===", ret, single.test),
single.consequent[0]
));
} else {
body.push(t.switchStatement(ret, cases));
}
} else {
if (has.hasReturn) body.push(retCheck);
}
} else {
body.push(t.expressionStatement(call));

View File

@@ -40,8 +40,6 @@ function traverse(parent, callbacks, opts) {
// type is blacklisted
if (_.contains(blacklistTypes, node.type)) return;
var result;
// replace node
var maybeReplace = function (result) {
if (result === false) return;
@@ -54,12 +52,11 @@ function traverse(parent, callbacks, opts) {
// enter
if (callbacks.enter) {
result = callbacks.enter(node, parent, opts2.scope);
var result = callbacks.enter(node, parent, opts2.scope);
maybeReplace(result);
// stop iteration
if (result === false) return;
maybeReplace(result);
}
// traverse node
@@ -114,25 +111,18 @@ traverse.hasType = function (tree, type, blacklistTypes) {
var has = false;
if (_.isArray(tree)) {
// array of nodes, find the first
return tree.some(function (node) {
return traverse.hasType(node, type, blacklistTypes);
});
} else {
// the node we're searching in is blacklisted
if (_.contains(blacklistTypes, tree.type)) return false;
// the node we're searching in is blacklisted
if (_.contains(blacklistTypes, tree.type)) return false;
// the type we're looking for is the same as the passed node
if (tree.type === type) return true;
// the type we're looking for is the same as the passed node
if (tree.type === type) return true;
traverse(tree, function (node) {
if (node.type === type) {
has = true;
return false;
}
}, { blacklist: blacklistTypes });
}
traverse(tree, function (node) {
if (node.type === type) {
has = true;
return false;
}
}, { blacklist: blacklistTypes });
return has;
};

View File

@@ -1,7 +1,7 @@
{
"name": "6to5",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "1.11.13",
"version": "1.11.14",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://github.com/6to5/6to5",
"repository": {

View File

@@ -3,5 +3,5 @@
X({
"data-prop": x ? Y({
prop: 2
}) : Z(null, "\n")
}) : Z(null)
});

View File

@@ -1,9 +1,9 @@
"use strict";
(X(null, " "));
(X(null));
(X(null, "\n"));
(X(null));
(X(null, "\n string\n"));
(X(null, "string"));
(X(null, "\n string\n string\n "));
(X(null, "string string"));

View File

@@ -0,0 +1,10 @@
for (let i in nums) {
fns.push(function () { return i; });
if (i === 1) {
continue;
} else if (i === 2) {
break;
} else if (i === 3) {
return i;
}
}

View File

@@ -0,0 +1,24 @@
"use strict";
_loop: for (var i in nums) {
var _ret = (function (i) {
fns.push(function () {
return i;
});
if (i === 1) {
return "continue";
} else if (i === 2) {
return "break";
} else if (i === 3) {
return {
v: i
};
}
})(i);
switch (_ret) {
case "break": break _loop;
case "continue": continue _loop;
default: if (typeof _ret === "object") return _ret.v;
}
}

View File

@@ -0,0 +1,4 @@
for (let i in nums) {
fns.push(function () { return i; });
break;
}

View File

@@ -0,0 +1,12 @@
"use strict";
_loop: for (var i in nums) {
var _ret = (function (i) {
fns.push(function () {
return i;
});
return "break";
})(i);
if (_ret === "break") break _loop;
}

View File

@@ -0,0 +1,4 @@
for (let i in nums) {
fns.push(function () { return i; });
continue;
}

View File

@@ -0,0 +1,12 @@
"use strict";
_loop: for (var i in nums) {
var _ret = (function (i) {
fns.push(function () {
return i;
});
return "continue";
})(i);
if (_ret === "continue") continue _loop;
}

View File

@@ -0,0 +1,4 @@
for (let i in nums) {
fns.push(function () { return i; });
return;
}

View File

@@ -0,0 +1,14 @@
"use strict";
for (var i in nums) {
var _ret = (function (i) {
fns.push(function () {
return i;
});
return {
v: undefined
};
})(i);
if (typeof _ret === "object") return _ret.v;
}

View File

@@ -0,0 +1,4 @@
for (let i in nums) {
fns.push(function () { return i; });
return i;
}

View File

@@ -0,0 +1,14 @@
"use strict";
for (var i in nums) {
var _ret = (function (i) {
fns.push(function () {
return i;
});
return {
v: i
};
})(i);
if (typeof _ret === "object") return _ret.v;
}

View File

@@ -0,0 +1,3 @@
function test() {
let foo = "bar";
}

View File

@@ -0,0 +1,5 @@
"use strict";
function test() {
var foo = "bar";
}

View File

@@ -0,0 +1 @@
let test = "foo";

View File

@@ -0,0 +1,3 @@
"use strict";
var test = "foo";

View File

@@ -0,0 +1,3 @@
function foo(...test) {
}

View File

@@ -0,0 +1,5 @@
"use strict";
function foo() {
var test = customNamespace.slice.call(arguments);
}

View File

@@ -0,0 +1,3 @@
{
"runtime": "customNamespace"
}

View File

@@ -0,0 +1,3 @@
var obj = {
"foobar": "lol"
};

View File

@@ -0,0 +1,5 @@
"use strict";
var obj = {
foobar: "lol"
};

View File

@@ -0,0 +1,3 @@
function foo(...test) {
}

View File

@@ -0,0 +1,5 @@
"use strict";
function foo() {
var test = to5Runtime.slice.call(arguments);
}

View File

@@ -0,0 +1,3 @@
{
"runtime": true
}

View File

@@ -0,0 +1,3 @@
#!/usr/bin/env node
foobar();

View File

@@ -0,0 +1,4 @@
#!/usr/bin/env node
"use strict";
foobar();