Don't add trailing commas in JSXAttribute for arrow functions (#3181)

master
Lucas Duailibe 2017-11-07 09:37:36 -02:00 committed by Lucas Azzola
parent ffd198beaa
commit 49b07c3983
3 changed files with 68 additions and 4 deletions

View File

@ -556,6 +556,9 @@ function genericPrintNoParens(path, options, print, args) {
(args && args.expandLastArg) ||
path.getParentNode().type === "JSXExpressionContainer";
const printTrailingComma =
args && args.expandLastArg && shouldPrintComma(options, "all");
// In order to avoid confusion between
// a => a ? a : a
// a <= a ? a : a
@ -580,10 +583,7 @@ function genericPrintNoParens(path, options, print, args) {
])
),
shouldAddSoftLine
? concat([
ifBreak(shouldPrintComma(options, "all") ? "," : ""),
softline
])
? concat([ifBreak(printTrailingComma ? "," : ""), softline])
: ""
])
)

View File

@ -210,6 +210,63 @@ a(
`;
exports[`jsx.js 1`] = `
<div
onClick={() =>
doSomething({
foo: bar
})
}
/>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<div
onClick={() =>
doSomething({
foo: bar
})
}
/>;
`;
exports[`jsx.js 2`] = `
<div
onClick={() =>
doSomething({
foo: bar
})
}
/>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<div
onClick={() =>
doSomething({
foo: bar,
})
}
/>;
`;
exports[`jsx.js 3`] = `
<div
onClick={() =>
doSomething({
foo: bar
})
}
/>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<div
onClick={() =>
doSomething({
foo: bar,
})
}
/>;
`;
exports[`object.js 1`] = `
const a = {
b: true,

View File

@ -0,0 +1,7 @@
<div
onClick={() =>
doSomething({
foo: bar
})
}
/>;