From 79e8d099bbbebfa4d804484eeeeea9c074ede870 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Sun, 21 Jul 2019 10:18:05 +0800 Subject: [PATCH] Fix: add parens for sequence expr in arrow-body-style (fixes #11917) (#11918) --- lib/rules/arrow-body-style.js | 4 ++-- tests/lib/rules/arrow-body-style.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/rules/arrow-body-style.js b/lib/rules/arrow-body-style.js index 6d84c7adfb1..8d3b400037a 100644 --- a/lib/rules/arrow-body-style.js +++ b/lib/rules/arrow-body-style.js @@ -175,10 +175,10 @@ module.exports = { } /* - * If the first token of the reutrn value is `{`, + * If the first token of the reutrn value is `{` or the return value is a sequence expression, * enclose the return value by parentheses to avoid syntax error. */ - if (astUtils.isOpeningBraceToken(firstValueToken)) { + if (astUtils.isOpeningBraceToken(firstValueToken) || blockBody[0].argument.type === "SequenceExpression") { fixes.push( fixer.insertTextBefore(firstValueToken, "("), fixer.insertTextAfter(lastValueToken, ")") diff --git a/tests/lib/rules/arrow-body-style.js b/tests/lib/rules/arrow-body-style.js index 2c4fa953acc..4e755c2cab6 100644 --- a/tests/lib/rules/arrow-body-style.js +++ b/tests/lib/rules/arrow-body-style.js @@ -162,6 +162,18 @@ ruleTester.run("arrow-body-style", rule, { } ] }, + { + code: "var foo = () => { return a, b }", + output: "var foo = () => (a, b)", + errors: [ + { + line: 1, + column: 17, + type: "ArrowFunctionExpression", + messageId: "unexpectedSingleBlock" + } + ] + }, { code: "var foo = () => { return };", output: null, // not fixed