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

This commit is contained in:
Evilebot Tnawi authored and Lucas Duailibe committed 2019-05-15 12:46:12 -03:00
1 parent 2cebeecb4f
commit 7a76e5d08e
4 files changed
+37 -3

No files matched your search

+15
View File
@@ -95,6 +95,20 @@ console.log(
);
```
### JavaScript: Correctly handle comments in empty arrow function expressions ([#6086] by [@evilebottnawi])
<!-- prettier-ignore -->
```js
// Input
const fn = (/*event, data*/) => doSomething(anything);
// Output (Prettier stable)
const fn = () => /*event, data*/ doSomething(anything);
// Output (Prettier master)
const fn = (/*event, data*/) => doSomething(anything);
```
### TypeScript: Keep trailing comma in tsx type parameters ([#6115] by [@sosukesuzuki])
Previously, a trailing comma after single type parameter in arrow function was cleaned up. The formatted result is valid as ts, but is invalid as tsx. Prettier master fixes this issue.
@@ -203,6 +217,7 @@ This changes the method of finding the required count of backticks from using 2
````
[#5979]: https://github.com/prettier/prettier/pull/5979
[#6086]: https://github.com/prettier/prettier/pull/6086
[#6088]: https://github.com/prettier/prettier/pull/6088
[#6115]: https://github.com/prettier/prettier/pull/6115
[#6106]: https://github.com/prettier/prettier/pull/6106
+1 -3
View File
@@ -558,9 +558,7 @@ function handleCommentInEmptyParens(text, enclosingNode, comment, options) {
enclosingNode &&
(((enclosingNode.type === "FunctionDeclaration" ||
enclosingNode.type === "FunctionExpression" ||
(enclosingNode.type === "ArrowFunctionExpression" &&
(enclosingNode.body.type !== "CallExpression" ||
enclosingNode.body.arguments.length === 0)) ||
enclosingNode.type === "ArrowFunctionExpression" ||
enclosingNode.type === "ClassMethod" ||
enclosingNode.type === "ObjectMethod") &&
enclosingNode.params.length === 0) ||
@@ -1,5 +1,23 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`arrow.js 1`] = `
====================================options=====================================
parsers: ["flow", "babel"]
printWidth: 80
| printWidth
=====================================input======================================
const fn = (/*event, data*/) => doSomething();
const fn2 = (/*event, data*/) => doSomething(anything);
=====================================output=====================================
const fn = (/*event, data*/) => doSomething();
const fn2 = (/*event, data*/) => doSomething(anything);
================================================================================
`;
exports[`assignment-pattern.js 1`] = `
====================================options=====================================
parsers: ["flow", "babel"]
+3
View File
@@ -0,0 +1,3 @@
const fn = (/*event, data*/) => doSomething();
const fn2 = (/*event, data*/) => doSomething(anything);