Permalink
Browse files

Fix: add parens for yield statement (fixes #10432) (#10468)

  • Loading branch information...
g-plane authored and platinumazure committed Jun 15, 2018
1 parent d477c5e commit 05343fdd1be4bc444209c45ec0341110444dbc83
Showing with 13 additions and 1 deletion.
  1. +1 −1 lib/rules/no-unneeded-ternary.js
  2. +12 −0 tests/lib/rules/no-unneeded-ternary.js
@@ -140,7 +140,7 @@ module.exports = {
fix: fixer => {
let nodeAlternate = astUtils.getParenthesisedText(sourceCode, node.alternate);
if (node.alternate.type === "ConditionalExpression") {
if (node.alternate.type === "ConditionalExpression" || node.alternate.type === "YieldExpression") {
const isAlternateParenthesised = astUtils.isParenthesised(sourceCode, node.alternate);
nodeAlternate = isAlternateParenthesised ? nodeAlternate : `(${nodeAlternate})`;
@@ -197,6 +197,18 @@ ruleTester.run("no-unneeded-ternary", rule, {
column: 7
}]
},
{
code: "function* fn() { foo ? foo : yield bar }",
output: "function* fn() { foo || (yield bar) }",
options: [{ defaultAssignment: false }],
parserOptions: { ecmaVersion: 6 },
errors: [{
message: "Unnecessary use of conditional expression for default assignment.",
type: "ConditionalExpression",
line: 1,
column: 24
}]
},
{
code: "var a = foo ? foo : 'No';",
output: "var a = foo || 'No';",

0 comments on commit 05343fd

Please sign in to comment.