fix(javascript): correctly handle comments in empty arrow function expressions (#6087)

master
Evilebot Tnawi 2019-04-30 14:25:20 +03:00 committed by GitHub
parent c085aeb152
commit 157b020de6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 0 deletions

View File

@ -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;
}
```

View File

@ -455,6 +455,7 @@ function needsParens(path, options) {
case "TSAsExpression":
case "TSNonNullExpression":
case "BindExpression":
case "OptionalMemberExpression":
return true;
case "MemberExpression":

View File

@ -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;
@ -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;
}
================================================================================
`;

View File

@ -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;
}