Make terminator paren comment check more strict (#5651)

This commit is contained in:
Brian Ng
2017-09-15 13:06:24 -05:00
committed by Logan Smyth
parent bf93be47c2
commit 7f390b0282
6 changed files with 21 additions and 5 deletions

View File

@@ -199,7 +199,7 @@ export function AssignmentExpression(node: Object): boolean {
}
}
// Walk up the print stack to deterimine if our node can come first
// Walk up the print stack to determine if our node can come first
// in statement.
function isFirstInStatement(
printStack: Array<Object>,

View File

@@ -246,8 +246,10 @@ export default class Printer {
if (i === str.length) return;
const cha = str[i];
if (cha === "\n" || cha === "/") {
// we're going to break this terminator expression so we need to add a parentheses
const chaPost = str[i + 1];
// Check for newline or comment
if (cha === "\n" || (cha === "/" && (chaPost === "/" || chaPost === "*"))) {
this.token("(");
this.indent();
parenPushNewlineState.printed = true;

View File

@@ -9,3 +9,7 @@ function bar() {
function foo() {
return 1, "foo";
}
() => { return /a/; }
function foo() { return /a/; }

View File

@@ -8,4 +8,12 @@ function bar() {
function foo() {
return 1, "foo";
}
}
() => {
return /a/;
};
function foo() {
return /a/;
}

View File

@@ -1,3 +1,4 @@
throw err;
throw Error("foobar");
throw new Error("foobar");
throw /a/;

View File

@@ -1,3 +1,4 @@
throw err;
throw Error("foobar");
throw new Error("foobar");
throw new Error("foobar");
throw /a/;