Fix various print inefficiencies/bugs
This commit is contained in:
parent
fd998cb9af
commit
ed5a057e4e
@ -107,7 +107,12 @@ function buildLabelStatement(prefix, key = "label") {
|
||||
|
||||
let label = node[key];
|
||||
if (label) {
|
||||
this.push(" ");
|
||||
if (!(this.format.minified && (t.isUnaryExpression(label, { prefix: true }) ||
|
||||
t.isUpdateExpression(label, { prefix: true })))) {
|
||||
this.push(" ");
|
||||
|
||||
}
|
||||
|
||||
let terminatorState = this.startTerminatorless();
|
||||
this.print(label, node);
|
||||
this.endTerminatorless(terminatorState);
|
||||
@ -153,7 +158,8 @@ export function CatchClause(node: Object) {
|
||||
this.keyword("catch");
|
||||
this.push("(");
|
||||
this.print(node.param, node);
|
||||
this.push(") ");
|
||||
this.push(")");
|
||||
this.space();
|
||||
this.print(node.body, node);
|
||||
}
|
||||
|
||||
|
||||
@ -123,6 +123,22 @@ export function SequenceExpression(node: Object, parent: Object): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (t.isSwitchStatement(parent) && parent.discriminant === node) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (t.isWhileStatement(parent) && parent.test === node) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (t.isIfStatement(parent) && parent.test === node) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (t.isForInStatement(parent) && parent.right === node) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Otherwise err on the side of overparenthesization, adding
|
||||
// explicit exceptions above if this proves overzealous.
|
||||
return true;
|
||||
|
||||
7
packages/babel-generator/test/fixtures/minified/labeled-statement/actual.js
vendored
Normal file
7
packages/babel-generator/test/fixtures/minified/labeled-statement/actual.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
function x() {
|
||||
return -1;
|
||||
return --i;
|
||||
return !2;
|
||||
}
|
||||
|
||||
throw -1;
|
||||
1
packages/babel-generator/test/fixtures/minified/labeled-statement/expected.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/minified/labeled-statement/expected.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
function x(){return-1;return--i;return!2}throw-1;
|
||||
13
packages/babel-generator/test/fixtures/parentheses/sequence-expressions/actual.js
vendored
Normal file
13
packages/babel-generator/test/fixtures/parentheses/sequence-expressions/actual.js
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
function foo() {
|
||||
return a, b;
|
||||
}
|
||||
|
||||
if (a, b, c) d();
|
||||
|
||||
throw a, b, c;
|
||||
|
||||
switch (a, b, c) {}
|
||||
|
||||
for (a in b, c);
|
||||
|
||||
while (a, b, c);
|
||||
13
packages/babel-generator/test/fixtures/parentheses/sequence-expressions/expected.js
vendored
Normal file
13
packages/babel-generator/test/fixtures/parentheses/sequence-expressions/expected.js
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
function foo() {
|
||||
return a, b;
|
||||
}
|
||||
|
||||
if (a, b, c) d();
|
||||
|
||||
throw a, b, c;
|
||||
|
||||
switch (a, b, c) {}
|
||||
|
||||
for (a in b, c);
|
||||
|
||||
while (a, b, c);
|
||||
Loading…
x
Reference in New Issue
Block a user