diff --git a/src/printer.js b/src/printer.js index f7b0632115fa..a0a53d9ca964 100644 --- a/src/printer.js +++ b/src/printer.js @@ -1716,7 +1716,28 @@ function genericPrintNoParens(path, options, print, args) { case "TSQualifiedName": return join(".", [path.call(print, "left"), path.call(print, "right")]); case "JSXSpreadAttribute": - return concat(["{...", path.call(print, "argument"), "}"]); + case "JSXSpreadChild": { + return concat([ + "{", + path.call(p => { + const printed = concat(["...", print(p)]); + const n = p.getValue(); + if (!n.comments || !n.comments.length) { + return printed; + } + return concat([ + indent( + concat([ + softline, + comments.printComments(p, () => printed, options) + ]) + ), + softline + ]); + }, n.type === "JSXSpreadAttribute" ? "argument" : "expression"), + "}" + ]); + } case "JSXExpressionContainer": { const parent = path.getParentNode(0); @@ -4973,7 +4994,9 @@ function printAstToDoc(ast, options, addAlignmentSize) { if ( ((node && node.type === "JSXElement") || (parent && - (parent.type === "UnionTypeAnnotation" || + (parent.type === "JSXSpreadAttribute" || + parent.type === "JSXSpreadChild" || + parent.type === "UnionTypeAnnotation" || parent.type === "TSUnionType" || ((parent.type === "ClassDeclaration" || parent.type === "ClassExpression") && diff --git a/tests/jsx_spread/__snapshots__/jsfmt.spec.js.snap b/tests/jsx_spread/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..289ec48d48d6 --- /dev/null +++ b/tests/jsx_spread/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,117 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`attribute.js 1`] = ` +
; + +
; + +
; + +
; + +
; + +
; + +
; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +
; + +
; + +
; + +
; + +
; + +
; + +
; + +`; + +exports[`child.js 1`] = ` +
{...a}
; + +
{...a /* comment */}
; + +
{/* comment */...a}
; + +
{...a //comment +}
; + +
{...a + //comment +}
; + +
{ + //comment + ...a +}
; + +
{//comment + ...a // comment +}
; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +
{...a}
; + +
{...a /* comment */}
; + +
{/* comment */ ...a}
; + +
+ { + ...a //comment + } +
; + +
+ { + ...a + //comment + } +
; + +
+ { + //comment + ...a + } +
; + +
+ { + //comment + ...a // comment + } +
; + +`; diff --git a/tests/jsx_spread/attribute.js b/tests/jsx_spread/attribute.js new file mode 100644 index 000000000000..6c76903a01ad --- /dev/null +++ b/tests/jsx_spread/attribute.js @@ -0,0 +1,21 @@ +
; + +
; + +
; + +
; + +
; + +
; + +
; diff --git a/tests/jsx_spread/child.js b/tests/jsx_spread/child.js new file mode 100644 index 000000000000..c8798b1e0d2a --- /dev/null +++ b/tests/jsx_spread/child.js @@ -0,0 +1,21 @@ +
{...a}
; + +
{...a /* comment */}
; + +
{/* comment */...a}
; + +
{...a //comment +}
; + +
{...a + //comment +}
; + +
{ + //comment + ...a +}
; + +
{//comment + ...a // comment +}
; diff --git a/tests/jsx_spread/jsfmt.spec.js b/tests/jsx_spread/jsfmt.spec.js new file mode 100644 index 000000000000..f974ed6c7f92 --- /dev/null +++ b/tests/jsx_spread/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, { parser: "babylon" });