Repository: jlongster/prettier (js)

Issue:
Nothing but comment in object literal → invalid code
Input:

```js
const a = {
  // TODO
}
```

Output:

```js
const a = {
  // TODO};
```

... which is invalid.

Expected:

```js
const a = {
  // TODO
};
```

https://jlongster.github.io/prettier/#%7B%22content%22%3A%22const%20a%20%3D%20%7B%5Cn%20%20%2F%2F%20TODO%5Cn%7D%22%2C%22options%22%3A%7B%22printWidth%22%3A80%2C%22tabWidth%22%3A2%2C%22singleQuote%22%3Afalse%2C%22trailingComma%22%3Afalse%2C%22bracketSpacing%22%3Atrue%2C%22doc%22%3Afalse%7D%7D


Pull request description:
Fix syntax error in empty object with dangling comment
Fixes #524 

Patch:
diff --git a/src/printer.js b/src/printer.js
index 75472aab8..712f394e4 100644
--- a/src/printer.js
+++ b/src/printer.js
@@ -588,11 +588,14 @@ function genericPrintNoParens(path, options, print) {
       );
 
       if (props.length === 0) {
-        return concat([
-          "{",
-          comments.printDanglingComments(path, options),
-          "}"
-        ]);
+        return group(
+          concat([
+            "{",
+            comments.printDanglingComments(path, options),
+            softline,
+            "}"
+          ])
+        );
       } else {
         return group(
           concat([


Test patch:
diff --git a/tests/comments/__snapshots__/jsfmt.spec.js.snap b/tests/comments/__snapshots__/jsfmt.spec.js.snap
index 6888c6572..383a72251 100644
--- a/tests/comments/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/comments/__snapshots__/jsfmt.spec.js.snap
@@ -26,6 +26,9 @@ exports[`test blank.js 2`] = `
 
 exports[`test dangling.js 1`] = `
 "var x = {/* dangling */};
+var x = {
+  // dangling
+};
 var x = [/* dangling */];
 function x() {
   /* dangling */
@@ -33,6 +36,9 @@ function x() {
 declare class Foo extends Qux<string> {/* dangling */}
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 var x = {/* dangling */};
+var x = {
+  // dangling
+};
 var x = [/* dangling */];
 function x() {
   /* dangling */
@@ -43,6 +49,9 @@ declare class Foo extends Qux<string> {/* dangling */}
 
 exports[`test dangling.js 2`] = `
 "var x = {/* dangling */};
+var x = {
+  // dangling
+};
 var x = [/* dangling */];
 function x() {
   /* dangling */
@@ -50,6 +59,9 @@ function x() {
 declare class Foo extends Qux<string> {/* dangling */}
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 var x = {/* dangling */};
+var x = {
+  // dangling
+};
 var x = [/* dangling */];
 function x() {
   /* dangling */
diff --git a/tests/comments/dangling.js b/tests/comments/dangling.js
index 7049ef07f..22208dee5 100644
--- a/tests/comments/dangling.js
+++ b/tests/comments/dangling.js
@@ -1,4 +1,7 @@
 var x = {/* dangling */};
+var x = {
+  // dangling
+};
 var x = [/* dangling */];
 function x() {
   /* dangling */
diff --git a/tests/flow/this_type/lib/__snapshots__/jsfmt.spec.js.snap b/tests/flow/this_type/lib/__snapshots__/jsfmt.spec.js.snap
index 9ba16e9c0..8dc8bb152 100644
--- a/tests/flow/this_type/lib/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/this_type/lib/__snapshots__/jsfmt.spec.js.snap
@@ -35,7 +35,8 @@ declare module \"mini-immutable\" {
     set(key: K, value: V): this /* more precise than Map<K,V> (see below)*/
   }
   declare class OrderedMap<K, V> extends Map<K, V> {
-    /* inherits set method returning OrderedMap<K,V> instead of Map<K,V>*/}
+    /* inherits set method returning OrderedMap<K,V> instead of Map<K,V>*/
+  }
 }
 "
 `;
diff --git a/tests/flow/traits/__snapshots__/jsfmt.spec.js.snap b/tests/flow/traits/__snapshots__/jsfmt.spec.js.snap
index 409328331..8e66f054d 100644
--- a/tests/flow/traits/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/traits/__snapshots__/jsfmt.spec.js.snap
@@ -22,7 +22,8 @@ declare class Baz<T> {
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 declare class Foo extends Qux<string> {
   /* KeyedCollection <: Collection*/
-  /* ...KeyedIterable*/}
+  /* ...KeyedIterable*/
+}
 declare class Bar<T> extends Baz<T> {
   // KeyedIterable <: Iterable
   y: T