Skip to content

Commit

Permalink
fix(javascript): correctly handle comments in empty arrow function ex…
Browse files Browse the repository at this point in the history
…pressions (#6087)
  • Loading branch information
evilebottnawi committed Apr 30, 2019
1 parent c085aeb commit 157b020
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.unreleased.md
Expand Up @@ -60,3 +60,23 @@ Examples:
test(/** @type {!Array} */ (arrOrString).length);
test(/** @type {!Array} */ (arrOrString).length + 1);
```

- JavaScript: respect parenthesis around optional chaining before await ([#6087] by [@evilebottnawi])

<!-- prettier-ignore -->
```js
// Input
async function myFunction() {
var x = (await foo.bar.blah)?.hi;
}

// Output (Prettier stable)
async function myFunction() {
var x = await foo.bar.blah?.hi;
}

// Output (Prettier master)
async function myFunction() {
var x = (await foo.bar.blah)?.hi;
}
```
1 change: 1 addition & 0 deletions src/language-js/needs-parens.js
Expand Up @@ -455,6 +455,7 @@ function needsParens(path, options) {
case "TSAsExpression":
case "TSNonNullExpression":
case "BindExpression":
case "OptionalMemberExpression":
return true;

case "MemberExpression":
Expand Down
8 changes: 8 additions & 0 deletions tests/optional_chaining/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -33,6 +33,10 @@ a?.b[3].c?.(x).d.e?.f[3].g?.(y).h;
(list || list2)?.length;
(list || list2)?.[(list || list2)];
async function HelloWorld() {
var x = (await foo.bar.blah)?.hi;
}
=====================================output=====================================
var street = user.address?.street;
var fooValue = myForm.querySelector("input[name=foo]")?.value;
Expand Down Expand Up @@ -61,5 +65,9 @@ a?.b?.c.d?.e;
(list || list2)?.length;
(list || list2)?.[list || list2];
async function HelloWorld() {
var x = (await foo.bar.blah)?.hi;
}
================================================================================
`;
4 changes: 4 additions & 0 deletions tests/optional_chaining/chaining.js
Expand Up @@ -24,3 +24,7 @@ a?.b[3].c?.(x).d.e?.f[3].g?.(y).h;

(list || list2)?.length;
(list || list2)?.[(list || list2)];

async function HelloWorld() {
var x = (await foo.bar.blah)?.hi;
}

0 comments on commit 157b020

Please sign in to comment.