Compare commits

...

5 Commits

Author SHA1 Message Date
Sebastian McKenzie
e549c37ca1 v2.4.1 2015-01-02 03:00:33 +11:00
Sebastian McKenzie
02512da38d fix generation tests with parenthesized expressions and trailing comments 2015-01-02 02:59:53 +11:00
Sebastian McKenzie
abe9c4fd30 add 2.4.1 changelog 2015-01-02 02:57:16 +11:00
Sebastian McKenzie
af21c52cc6 set generator on correct node #252 2015-01-02 02:55:55 +11:00
Sebastian McKenzie
706626f79a better whitespace handling of parenthesized comments due to trailing comments 2015-01-02 02:55:40 +11:00
7 changed files with 22 additions and 13 deletions

View File

@@ -2,6 +2,11 @@
Gaps between patch versions are faulty/broken releases.
## 2.4.1
* Better whitespace handling of parenthesized expressions due to trailing comments.
* Fix `yield` inside of comprehensions.
## 2.4.0
* Use a closure always for classes with a super.

View File

@@ -148,10 +148,11 @@ CodeGenerator.prototype.print = function (node, parent, opts) {
};
if (this[node.type]) {
// only compute if this node needs parens if our parent has been changed
// since acorn would've wrapped us in a ParanthesizedExpression
var needsParens = n.needsParens(node, parent);
var needsCommentParens = t.isExpression(node) && node.leadingComments && node.leadingComments.length;
var needsParens = needsCommentParens || n.needsParens(node, parent);
if (needsParens) this.push("(");
if (needsCommentParens) this.indent();
this.printLeadingComments(node, parent);
@@ -162,6 +163,10 @@ CodeGenerator.prototype.print = function (node, parent, opts) {
this[node.type](node, this.buildPrint(node), parent);
if (needsCommentParens) {
this.newline();
this.dedent();
}
if (needsParens) this.push(")");
this.map.mark(node, "end");

View File

@@ -60,10 +60,6 @@ Node.prototype.needsParens = function () {
if (!parent) return false;
if (t.isExpression(node) && node.leadingComments && node.leadingComments.length) {
return true;
}
if (t.isNewExpression(parent) && parent.callee === node) {
return t.isCallExpression(node) || _.some(node, function (val) {
return t.isCallExpression(val);

View File

@@ -16,7 +16,7 @@ var build = function (node, file) {
var body = block.body;
if (traverse.hasType(node, "YieldExpression", t.FUNCTION_TYPES)) {
container.generator = true;
container.callee.generator = true;
container = t.yieldExpression(container, true);
}

View File

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

View File

@@ -6,5 +6,6 @@ var test = {
[( /*
* Inside bracket init
*/
"b")]: "2"
"b"
)]: "2"
}, ok = 42;

View File

@@ -7,7 +7,8 @@ var test = {
[( /*
* Inside bracket init
*/
"b")]: "2",
"b"
)]: "2",
["c"
/*
@@ -18,8 +19,9 @@ var test = {
["d"]: "4",
[(
// Inside bracket, line comment
"e")]: "5",
// Inside bracket, line comment
"e"
)]: "5",
["f"
// After bracket, line comment