Repository: jlongster/prettier (js)

Issue:
Don't remove semicolon from exports
#### expected behavior:

```js
export default MyComponent;
```

#### current behavior:

```js
export default MyComponent
```

Pull request description:
Add semicolons to `export` declarations.
Closes #22.

Patch:
diff --git a/src/printer.js b/src/printer.js
index 0bba17879..8364ca070 100644
--- a/src/printer.js
+++ b/src/printer.js
@@ -443,7 +443,7 @@ function genericPrintNoParens(path, options, print) {
       parts.push(" as ", path.call(print, "exported"));
     }
 
-    parts.push(" from ", path.call(print, "source"));
+    parts.push(" from ", path.call(print, "source"), ";");
 
     return concat(parts);
   case "ExportNamespaceSpecifier":
@@ -1819,6 +1819,10 @@ function printExportDeclaration(path, options, print) {
 
   if (decl.declaration) {
     parts.push(path.call(print, "declaration"));
+
+    if (decl.type === "ExportDefaultDeclaration" && decl.declaration.type == "Identifier") {
+      parts.push(";");
+    }
   } else if (decl.specifiers && decl.specifiers.length > 0) {
     if (
       decl.specifiers.length === 1 &&
@@ -1837,6 +1841,8 @@ function printExportDeclaration(path, options, print) {
     if (decl.source) {
       parts.push(" from ", path.call(print, "source"));
     }
+
+    parts.push(';');
   }
 
   return concat(parts);


Test patch:
diff --git a/tests/declare_export/__snapshots__/jsfmt.spec.js.snap b/tests/declare_export/__snapshots__/jsfmt.spec.js.snap
index 7bbda5680..a171c31c9 100644
--- a/tests/declare_export/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/declare_export/__snapshots__/jsfmt.spec.js.snap
@@ -178,7 +178,7 @@ declare export default class FooImpl { givesANum(): number }
 // Regression test for https://github.com/facebook/flow/issues/511
 //
 // Default-exported class should also be available in local scope
-declare export { FooImpl as Foo }
+declare export { FooImpl as Foo };
 declare export function getAFoo(): FooImpl;"
 `;
 
@@ -335,7 +335,7 @@ 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\";"
 `;
 
 exports[`test ES6_ExportFrom_Intermediary2.js 1`] = `
@@ -354,7 +354,7 @@ 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\";"
 `;
 
 exports[`test ES6_ExportFrom_Source1.js 1`] = `
@@ -427,10 +427,10 @@ var specifierNumber3 = 3;
 var groupedSpecifierNumber1 = 1;
 var groupedSpecifierNumber2 = 2;
 
-declare export { specifierNumber1 }
-declare export { specifierNumber2 as specifierNumber2Renamed }
-declare export { specifierNumber3 }
-declare export { groupedSpecifierNumber1, groupedSpecifierNumber2 }
+declare export { specifierNumber1 };
+declare export { specifierNumber2 as specifierNumber2Renamed };
+declare export { specifierNumber3 };
+declare export { groupedSpecifierNumber1, groupedSpecifierNumber2 };
 
 declare export function givesANumber(): number;
 declare export class NumberGenerator { givesANumber(): number }
@@ -470,9 +470,9 @@ var specifierNumber5 = 2;
 var groupedSpecifierNumber3 = 1;
 var groupedSpecifierNumber4 = 2;
 
-declare export { specifierNumber4 }
-declare export { specifierNumber5 as specifierNumber5Renamed }
-declare export { groupedSpecifierNumber3, groupedSpecifierNumber4 }
+declare export { specifierNumber4 };
+declare export { specifierNumber5 as specifierNumber5Renamed };
+declare export { groupedSpecifierNumber3, groupedSpecifierNumber4 };
 
 declare export function givesANumber2(): number;
 declare export class NumberGenerator2 { givesANumber(): number }
diff --git a/tests/es6modules/__snapshots__/jsfmt.spec.js.snap b/tests/es6modules/__snapshots__/jsfmt.spec.js.snap
index 79d8a93e4..115957e4d 100644
--- a/tests/es6modules/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/es6modules/__snapshots__/jsfmt.spec.js.snap
@@ -330,7 +330,7 @@ export * from \"ES6_ExportAllFrom_Source1\";
  * @flow
  */
 
-export * from \"ES6_ExportAllFrom_Source1\""
+export * from \"ES6_ExportAllFrom_Source1\";"
 `;
 
 exports[`test ES6_ExportAllFrom_Intermediary2.js 1`] = `
@@ -346,7 +346,7 @@ export * from \"ES6_ExportAllFrom_Source2\";
  * @flow
  */
 
-export * from \"ES6_ExportAllFrom_Source2\""
+export * from \"ES6_ExportAllFrom_Source2\";"
 `;
 
 exports[`test ES6_ExportAllFrom_Source1.js 1`] = `
@@ -389,8 +389,8 @@ export * from \"./ES6_ExportAllFrom_Source2\";
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 // @flow
 
-export * from \"./ES6_ExportAllFrom_Source1\"
-export * from \"./ES6_ExportAllFrom_Source2\""
+export * from \"./ES6_ExportAllFrom_Source1\";
+export * from \"./ES6_ExportAllFrom_Source2\";"
 `;
 
 exports[`test ES6_ExportFrom_Intermediary1.js 1`] = `
@@ -409,7 +409,7 @@ export {
  * @flow
  */
 
-export { numberValue1, numberValue2 as numberValue2_renamed } from \"ES6_ExportFrom_Source1\""
+export { numberValue1, numberValue2 as numberValue2_renamed } from \"ES6_ExportFrom_Source1\";"
 `;
 
 exports[`test ES6_ExportFrom_Intermediary2.js 1`] = `
@@ -428,7 +428,7 @@ export {
  * @flow
  */
 
-export { numberValue1, numberValue2 as numberValue2_renamed2 } from \"ES6_ExportFrom_Source2\""
+export { numberValue1, numberValue2 as numberValue2_renamed2 } from \"ES6_ExportFrom_Source2\";"
 `;
 
 exports[`test ES6_ExportFrom_Source1.js 1`] = `
@@ -498,10 +498,10 @@ var specifierNumber3 = 3;
 var groupedSpecifierNumber1 = 1;
 var groupedSpecifierNumber2 = 2;
 
-export { specifierNumber1 }
-export { specifierNumber2 as specifierNumber2Renamed }
-export { specifierNumber3 }
-export { groupedSpecifierNumber1, groupedSpecifierNumber2 }
+export { specifierNumber1 };
+export { specifierNumber2 as specifierNumber2Renamed };
+export { specifierNumber3 };
+export { groupedSpecifierNumber1, groupedSpecifierNumber2 };
 
 export function givesANumber(): number {
   return 42;
@@ -550,9 +550,9 @@ var specifierNumber5 = 2;
 var groupedSpecifierNumber3 = 1;
 var groupedSpecifierNumber4 = 2;
 
-export { specifierNumber4 }
-export { specifierNumber5 as specifierNumber5Renamed }
-export { groupedSpecifierNumber3, groupedSpecifierNumber4 }
+export { specifierNumber4 };
+export { specifierNumber5 as specifierNumber5Renamed };
+export { groupedSpecifierNumber3, groupedSpecifierNumber4 };
 
 export function givesANumber2(): number {
   return 42;
diff --git a/tests/es_declare_module/flow-typed/__snapshots__/jsfmt.spec.js.snap b/tests/es_declare_module/flow-typed/__snapshots__/jsfmt.spec.js.snap
index f2a1a5e09..05eac8134 100644
--- a/tests/es_declare_module/flow-typed/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/es_declare_module/flow-typed/__snapshots__/jsfmt.spec.js.snap
@@ -32,7 +32,7 @@ declare module \"CJS_Clobbered\" {
 }
 declare module \"ES\" {
   declare var strHidden: string;
-  declare export { strHidden as str3 }
+  declare export { strHidden as str3 };
   declare export var num3: number;
   declare export class C {}
   declare export type T = number;
diff --git a/tests/export_type/__snapshots__/jsfmt.spec.js.snap b/tests/export_type/__snapshots__/jsfmt.spec.js.snap
index ade4a4862..7e5f567e5 100644
--- a/tests/export_type/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/export_type/__snapshots__/jsfmt.spec.js.snap
@@ -101,12 +101,12 @@ var a: inlinedType1 = 42;
 var b: inlinedType1 = \"asdf\";
 // Error: string ~> number
 type standaloneType1 = number;
-export type { standaloneType1 }
+export type { standaloneType1 };
 
 type standaloneType2 = number;
-export { standaloneType2 }
+export { standaloneType2 };
 // Error: Missing \`type\` keyword
-export type { talias1, talias2 as talias3, IFoo2 } from \"./types_only2\"
+export type { talias1, talias2 as talias3, IFoo2 } from \"./types_only2\";
 
 export interface IFoo  { prop: number }
 "
diff --git a/tests/get-def/helpers/__snapshots__/jsfmt.spec.js.snap b/tests/get-def/helpers/__snapshots__/jsfmt.spec.js.snap
index c36593833..dce969033 100644
--- a/tests/get-def/helpers/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/get-def/helpers/__snapshots__/jsfmt.spec.js.snap
@@ -9,7 +9,7 @@ export default x;
 
 const x = \"foo\";
 
-export default x"
+export default x;"
 `;
 
 exports[`test exports_named.js 1`] = `
diff --git a/tests/import_type/__snapshots__/jsfmt.spec.js.snap b/tests/import_type/__snapshots__/jsfmt.spec.js.snap
index 60f02d0f2..24a3d9a39 100644
--- a/tests/import_type/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/import_type/__snapshots__/jsfmt.spec.js.snap
@@ -100,7 +100,7 @@ class ClassFoo1 {
   }
 }
 
-export default ClassFoo1
+export default ClassFoo1;
 export var foo1Inst = new ClassFoo1();"
 `;
 
@@ -155,7 +155,7 @@ class ClassFoo2 {
   }
 }
 
-export { ClassFoo2 }
+export { ClassFoo2 };
 export var foo2Inst = new ClassFoo2();"
 `;
 
@@ -345,5 +345,5 @@ export default ClassFoo6;
 
 class ClassFoo6 {}
 
-export default ClassFoo6"
+export default ClassFoo6;"
 `;
diff --git a/tests/import_typeof/__snapshots__/jsfmt.spec.js.snap b/tests/import_typeof/__snapshots__/jsfmt.spec.js.snap
index d99bdc4f9..82506cf8e 100644
--- a/tests/import_typeof/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/import_typeof/__snapshots__/jsfmt.spec.js.snap
@@ -87,7 +87,7 @@ class ClassFoo1 {
   }
 }
 
-export default ClassFoo1"
+export default ClassFoo1;"
 `;
 
 exports[`test ExportDefault_Number.js 1`] = `
@@ -150,7 +150,7 @@ class ClassFoo2 {
   }
 }
 
-export { ClassFoo2 }"
+export { ClassFoo2 };"
 `;
 
 exports[`test ExportNamed_Multi.js 1`] = `
diff --git a/tests/method_properties/__snapshots__/jsfmt.spec.js.snap b/tests/method_properties/__snapshots__/jsfmt.spec.js.snap
index 3fa3a4564..1dcdd7733 100644
--- a/tests/method_properties/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/method_properties/__snapshots__/jsfmt.spec.js.snap
@@ -11,7 +11,7 @@ export {Foo};
 
 declare class Foo { bar?: () => string }
 
-export { Foo }"
+export { Foo };"
 `;
 
 exports[`test test.js 1`] = `