Repository: jlongster/prettier (js)

Issue:
Missing parenthesis around object dereference inside of arrow
```js
a = () => ({}).x
```

outputs

```js
a = () => {}.x;
```

which is invalid

https://jlongster.github.io/prettier/#%7B%22content%22%3A%22a%20%3D%20()%20%3D%3E%20(%7B%7D).x%22%2C%22options%22%3A%7B%22printWidth%22%3A80%2C%22tabWidth%22%3A2%2C%22singleQuote%22%3Afalse%2C%22trailingComma%22%3Afalse%2C%22bracketSpacing%22%3Afalse%2C%22doc%22%3Afalse%7D%7D

Pull request description:
Fix missing parens around object in MemberExpression
Fixes #415

Patch:
diff --git a/src/fast-path.js b/src/fast-path.js
index 44800b3c4..36e0cc1db 100644
--- a/src/fast-path.js
+++ b/src/fast-path.js
@@ -463,6 +463,9 @@ FPp.needsParens = function(assumeExpressionContext) {
       if (parent.type === "TaggedTemplateExpression") {
         return true;
       }
+      if (parent.type === "MemberExpression") {
+        return name === "object" && parent.object === node;
+      }
 
     default:
       if (


Test patch:
diff --git a/tests/objects/__snapshots__/jsfmt.spec.js.snap b/tests/objects/__snapshots__/jsfmt.spec.js.snap
index c3fa28ebb..2b8644ba8 100644
--- a/tests/objects/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/objects/__snapshots__/jsfmt.spec.js.snap
@@ -46,9 +46,11 @@ var z = Object(123);
 exports[`test expression.js 1`] = `
 "() => ({}\`\`);
 ({})\`\`;
+a = () => ({}).x;
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 (() => ({})\`\`);
 ({})\`\`;
+a = () => ({}).x;
 "
 `;
 
diff --git a/tests/objects/expression.js b/tests/objects/expression.js
index fd92a69bf..861275eb0 100644
--- a/tests/objects/expression.js
+++ b/tests/objects/expression.js
@@ -1,2 +1,3 @@
 () => ({}``);
 ({})``;
+a = () => ({}).x;
diff --git a/tests/refinements/__snapshots__/jsfmt.spec.js.snap b/tests/refinements/__snapshots__/jsfmt.spec.js.snap
index 249a95d4d..47713d4d6 100644
--- a/tests/refinements/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/refinements/__snapshots__/jsfmt.spec.js.snap
@@ -2565,7 +2565,7 @@ let tests = [
     if (x.kind === null.toString()) {
     }
     // error, method on null
-    if ({ kind: 1 }.kind === null.toString()) {
+    if (({ kind: 1 }).kind === null.toString()) {
     } // error, method on null
   },
   // non-objects on LHS