Repository: jlongster/prettier
Pull request #156 (2017-01-12 19:55:20)

Break long `exports` into multiple lines.
This supercedes https://github.com/jlongster/prettier/pull/104 so that I can go ahead and get it in.


Patch:
diff --git a/src/printer.js b/src/printer.js
index 3e3389087..5fd4d66f8 100644
--- a/src/printer.js
+++ b/src/printer.js
@@ -1866,9 +1866,19 @@ function printExportDeclaration(path, options, print) {
     } else {
       parts.push(
         decl.exportKind === "type" ? "type " : "",
-        shouldPrintSpaces ? "{ " : "{",
-        join(", ", path.map(print, "specifiers")),
-        shouldPrintSpaces ? " }" : "}"
+        group(concat([
+          "{",
+          indent(
+            options.tabWidth,
+            concat([
+              options.bracketSpacing ? line : softline,
+              join(concat([",", options.bracketSpacing ? line : softline]),
+                   path.map(print, "specifiers"))
+            ])
+          ),
+          options.bracketSpacing ? line : softline,
+          "}"
+        ]))
       );
     }
 


Test patch:
diff --git a/tests/declare_export/__snapshots__/jsfmt.spec.js.snap b/tests/declare_export/__snapshots__/jsfmt.spec.js.snap
index aa2d614d4..d9a5c75e7 100644
--- a/tests/declare_export/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/declare_export/__snapshots__/jsfmt.spec.js.snap
@@ -352,7 +352,10 @@ declare export {
  * @flow
  */
 
-declare export { numberValue1, numberValue2 as numberValue2_renamed } from \"ES6_ExportFrom_Source1\";
+declare export {
+  numberValue1,
+  numberValue2 as numberValue2_renamed
+} from \"ES6_ExportFrom_Source1\";
 "
 `;
 
@@ -372,7 +375,10 @@ declare export {
  * @flow
  */
 
-declare export { numberValue1, numberValue2 as numberValue2_renamed2 } from \"ES6_ExportFrom_Source2\";
+declare export {
+  numberValue1,
+  numberValue2 as numberValue2_renamed2
+} from \"ES6_ExportFrom_Source2\";
 "
 `;
 
diff --git a/tests/es6modules/__snapshots__/jsfmt.spec.js.snap b/tests/es6modules/__snapshots__/jsfmt.spec.js.snap
index 2bc7d5b35..f5c5abbef 100644
--- a/tests/es6modules/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/es6modules/__snapshots__/jsfmt.spec.js.snap
@@ -429,7 +429,10 @@ export {
  * @flow
  */
 
-export { numberValue1, numberValue2 as numberValue2_renamed } from \"ES6_ExportFrom_Source1\";
+export {
+  numberValue1,
+  numberValue2 as numberValue2_renamed
+} from \"ES6_ExportFrom_Source1\";
 "
 `;
 
@@ -449,7 +452,10 @@ export {
  * @flow
  */
 
-export { numberValue1, numberValue2 as numberValue2_renamed2 } from \"ES6_ExportFrom_Source2\";
+export {
+  numberValue1,
+  numberValue2 as numberValue2_renamed2
+} from \"ES6_ExportFrom_Source2\";
 "
 `;
 
diff --git a/tests/prettier/__snapshots__/jsfmt.spec.js.snap b/tests/prettier/__snapshots__/jsfmt.spec.js.snap
index 8fb274d19..287f35f05 100644
--- a/tests/prettier/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/prettier/__snapshots__/jsfmt.spec.js.snap
@@ -13,6 +13,19 @@ function fn() {
 "
 `;
 
+exports[`test exports.js 1`] = `
+"export { value1, value2 as value2_renamed, value3, value4 as value4_renamed, value5 } from \"exports\";
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+export {
+  value1,
+  value2 as value2_renamed,
+  value3,
+  value4 as value4_renamed,
+  value5
+} from \"exports\";
+"
+`;
+
 exports[`test optional-type-name.js 1`] = `
 "type Foo = (any) => string
 
diff --git a/tests/prettier/exports.js b/tests/prettier/exports.js
new file mode 100644
index 000000000..e3699c9fc
--- /dev/null
+++ b/tests/prettier/exports.js
@@ -0,0 +1,1 @@
+export { value1, value2 as value2_renamed, value3, value4 as value4_renamed, value5 } from "exports";