Repository: jlongster/prettier (js)

Issue:
Semi-colons stripped from multi-line default exports
I am running prettier against master for all the great jsx fixes. I'm still seeing it strip semi-colons from some default exports.

My original code:

```jsx
export default ({ children }) => (
  <Provider store={store} key="provider">
    <IntlProvider locale="en">
      {children}
    </IntlProvider>
  </Provider>
);
```

Prettier-formatted code:

```jsx
export default ({ children }) => (
  <Provider store={store} key="provider">
    <IntlProvider locale="en">
      {children}
    </IntlProvider>
  </Provider>
)
```

I know there have been other issues around semi-colons in default exports but it seems this is an edge case that hasn't been fixed yet.

Pull request:
Handle additional export default parens cases
Fixes #292

Patch:
diff --git a/src/printer.js b/src/printer.js
index fbd6c54d4..52f9ed72b 100644
--- a/src/printer.js
+++ b/src/printer.js
@@ -1830,6 +1830,12 @@ function printReturnType(path, print) {
   return concat(parts);
 }
 
+function typeIsFunction(type) {
+  return type === "FunctionExpression" ||
+    type === "ArrowFunctionExpression" ||
+    type === "NewExpression";
+}
+
 function printExportDeclaration(path, options, print) {
   var decl = path.getValue();
   var parts = [ "export " ];
@@ -1847,7 +1853,8 @@ function printExportDeclaration(path, options, print) {
     if (
       decl.type === "ExportDefaultDeclaration" &&
         (decl.declaration.type == "Identifier" ||
-          decl.declaration.type === "CallExpression")
+          decl.declaration.type === "CallExpression" ||
+          typeIsFunction(decl.declaration.type))
     ) {
       parts.push(";");
     }
@@ -1986,9 +1993,7 @@ function printMemberChain(node, options, print) {
   function argIsFunction(call) {
     if (call.arguments.length > 0) {
       const type = call.arguments[(0)].type;
-      return type === "FunctionExpression" ||
-        type === "ArrowFunctionExpression" ||
-        type === "NewExpression";
+      return typeIsFunction(type);
     }
     return false;
   }


Test patch:
diff --git a/tests/es6modules/__snapshots__/jsfmt.spec.js.snap b/tests/es6modules/__snapshots__/jsfmt.spec.js.snap
index df441d6b2..efd59b9c1 100644
--- a/tests/es6modules/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/es6modules/__snapshots__/jsfmt.spec.js.snap
@@ -1347,10 +1347,33 @@ import {
 "
 `;
 
+exports[`test export_default_arrow_expression.js 1`] = `
+"export default () => {};
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+export default () => {
+};
+"
+`;
+
 exports[`test export_default_call_expression.js 1`] = `
-"export default connect(mapStateToProps)(MyComponent);
+"export default foo()
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+export default foo();
+"
+`;
+
+exports[`test export_default_function_expression.js 1`] = `
+"export default (function() {});
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+export default function() {
+};
+"
+`;
+
+exports[`test export_default_new_expression.js 1`] = `
+"export default new Foo();
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-export default connect(mapStateToProps)(MyComponent);
+export default new Foo();
 "
 `;
 
diff --git a/tests/es6modules/export_default_arrow_expression.js b/tests/es6modules/export_default_arrow_expression.js
new file mode 100644
index 000000000..2d1ec2382
--- /dev/null
+++ b/tests/es6modules/export_default_arrow_expression.js
@@ -0,0 +1,1 @@
+export default () => {};
diff --git a/tests/es6modules/export_default_call_expression.js b/tests/es6modules/export_default_call_expression.js
index c3fae600c..4b9b7b3d8 100644
--- a/tests/es6modules/export_default_call_expression.js
+++ b/tests/es6modules/export_default_call_expression.js
@@ -1,1 +1,1 @@
-export default connect(mapStateToProps)(MyComponent);
+export default foo()
diff --git a/tests/es6modules/export_default_function_expression.js b/tests/es6modules/export_default_function_expression.js
new file mode 100644
index 000000000..01e4503a7
--- /dev/null
+++ b/tests/es6modules/export_default_function_expression.js
@@ -0,0 +1,1 @@
+export default (function() {});
diff --git a/tests/es6modules/export_default_new_expression.js b/tests/es6modules/export_default_new_expression.js
new file mode 100644
index 000000000..92c970c73
--- /dev/null
+++ b/tests/es6modules/export_default_new_expression.js
@@ -0,0 +1,1 @@
+export default new Foo();