Add the ability for SequenceExpression to break (#1749)

Fixes #1742
master
Christopher Chedeau 2017-05-26 12:29:00 -07:00 committed by GitHub
parent 5f73ba29ed
commit f9e324c4d0
4 changed files with 39 additions and 2 deletions

View File

@ -411,6 +411,7 @@ function genericPrintNoParens(path, options, print, args) {
(n.body.type === "ArrayExpression" ||
n.body.type === "ObjectExpression" ||
n.body.type === "BlockStatement" ||
n.body.type === "SequenceExpression" ||
isTemplateOnItsOwnLine(n.body, options.originalText) ||
n.body.type === "ArrowFunctionExpression")
) {
@ -1033,8 +1034,28 @@ function genericPrintNoParens(path, options, print, args) {
}
return concat(parts);
case "SequenceExpression":
return join(", ", path.map(print, "expressions"));
case "SequenceExpression": {
const parent = path.getParentNode();
const shouldInline =
parent.type === "ReturnStatement" ||
parent.type === "ForStatement" ||
parent.type === "ExpressionStatement";
if (shouldInline) {
return join(", ", path.map(print, "expressions"));
}
return group(
concat([
indent(
concat([
softline,
join(concat([",", line]), path.map(print, "expressions"))
])
),
softline
])
);
}
case "ThisExpression":
return "this";
case "Super":

View File

@ -0,0 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`break.js 1`] = `
const f = (argument1, argument2, argument3) =>
(doSomethingWithArgument(argument1), doSomethingWithArgument(argument2),argument1)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const f = (argument1, argument2, argument3) => (
doSomethingWithArgument(argument1),
doSomethingWithArgument(argument2),
argument1
);
`;

View File

@ -0,0 +1,2 @@
const f = (argument1, argument2, argument3) =>
(doSomethingWithArgument(argument1), doSomethingWithArgument(argument2),argument1)

View File

@ -0,0 +1 @@
run_spec(__dirname);