diff --git a/changelog_unreleased/javascript/pr-9011.md b/changelog_unreleased/javascript/pr-9011.md new file mode 100644 index 000000000..e24709f5e --- /dev/null +++ b/changelog_unreleased/javascript/pr-9011.md @@ -0,0 +1,21 @@ +#### Add parens when yielding jsx ([#9011](https://github.com/prettier/prettier/pull/9011) by [@fisker](https://github.com/fisker)) + +In `v2.0.0` we [removed the parens when yielding jsx](https://prettier.io/blog/2020/03/21/2.0.0.html#remove-unnecessary-parens-when-yielding-jsx-7367httpsgithubcomprettierprettierpull7367-by-cola119httpsgithubcomcola119), this works for most parsers, but ESLint throws when parsing it, [related issue](https://github.com/acornjs/acorn-jsx/issues/82). + + +```js +// Input +function* f() { + yield
generator
+} + +// Prettier stable +function* f() { + yield
generator
+} + +// Prettier master +function* f() { + yield (
generator
); +} +``` diff --git a/src/language-js/needs-parens.js b/src/language-js/needs-parens.js index 8df5d92e6..771a64655 100644 --- a/src/language-js/needs-parens.js +++ b/src/language-js/needs-parens.js @@ -730,8 +730,7 @@ function needsParens(path, options) { parent.type !== "ReturnStatement" && parent.type !== "ThrowStatement" && parent.type !== "TypeCastExpression" && - parent.type !== "VariableDeclarator" && - parent.type !== "YieldExpression") + parent.type !== "VariableDeclarator") ); case "TypeAnnotation": return ( diff --git a/tests/js/yield/__snapshots__/jsfmt.spec.js.snap b/tests/js/yield/__snapshots__/jsfmt.spec.js.snap index 6c703566b..9e8052439 100644 --- a/tests/js/yield/__snapshots__/jsfmt.spec.js.snap +++ b/tests/js/yield/__snapshots__/jsfmt.spec.js.snap @@ -87,8 +87,8 @@ function* f() { =====================================output===================================== function* f() { - yield
generator
; - yield
generator
; + yield (
generator
); + yield (
generator
); yield (

generator