Fix minified labeledStatement printing

Unary expressions with alphabetic operators like 'void' were being
squished next to the statement.
This commit is contained in:
Amjad Masad 2016-01-12 17:28:46 -08:00
parent b7aa49d9f5
commit 0d9459dbb6
3 changed files with 7 additions and 3 deletions

View File

@ -1,6 +1,8 @@
import repeating from "repeating";
import * as t from "babel-types";
const NON_ALPHABETIC_UNARY_OPERATORS = t.UPDATE_OPERATORS.concat(t.NUMBER_UNARY_OPERATORS).concat(['!']);
export function WithStatement(node: Object) {
this.keyword("with");
this.push("(");
@ -107,8 +109,9 @@ function buildLabelStatement(prefix, key = "label") {
let label = node[key];
if (label) {
if (!(this.format.minified && (t.isUnaryExpression(label, { prefix: true }) ||
t.isUpdateExpression(label, { prefix: true })))) {
if (!(this.format.minified && ((t.isUnaryExpression(label, { prefix: true }) ||
t.isUpdateExpression(label, { prefix: true })) &&
NON_ALPHABETIC_UNARY_OPERATORS.indexOf(label.operator) > -1))) {
this.push(" ");
}

View File

@ -2,6 +2,7 @@ function x() {
return -1;
return --i;
return !2;
return void 0;
}
throw -1;

View File

@ -1 +1 @@
function x(){return-1;return--i;return!2}throw-1;
function x(){return-1;return--i;return!2;return void 0}throw-1;