Do not put \n inside of empty object method bodies (#706)

Fixes #703
master
Christopher Chedeau 2017-02-15 17:52:54 -08:00 committed by James Long
parent 7046d978a4
commit d8c242891b
5 changed files with 23 additions and 1 deletions

View File

@ -542,7 +542,9 @@ function genericPrintNoParens(path, options, print) {
!n.comments &&
(parent.type === "ArrowFunctionExpression" ||
parent.type === "FunctionExpression" ||
parent.type === "FunctionDeclaration")
parent.type === "FunctionDeclaration" ||
parent.type === "ObjectMethod" ||
parent.type === "ClassMethod")
) {
return "{}";
}

View File

@ -41,6 +41,10 @@ class A { // comment
class A {
}
class A {
m() {}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class A {
// comment
@ -51,6 +55,10 @@ class A {
}
class A {}
class A {
m() {}
}
"
`;

View File

@ -7,3 +7,7 @@ class A { // comment
class A {
}
class A {
m() {}
}

View File

@ -9,6 +9,13 @@ a = () => ({}).x;
"
`;
exports[`test method.js 1`] = `
"a = { f() {} }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a = { f() {} };
"
`;
exports[`test range.js 1`] = `
"group(
concat([

1
tests/objects/method.js Normal file
View File

@ -0,0 +1 @@
a = { f() {} }