diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js index ad4f1c65..f8813aee 100644 --- a/src/language-js/printer-estree.js +++ b/src/language-js/printer-estree.js @@ -1845,7 +1845,12 @@ function printPathNoParens(path, options, print, args) { // Don't break self-closing elements with no attributes and no comments if (n.selfClosing && !n.attributes.length && !nameHasComments) { - return concat(["<", path.call(print, "name"), " />"]); + return concat([ + "<", + path.call(print, "name"), + path.call(print, "typeParameters"), + " />" + ]); } // don't break up opening elements with a single long text attribute @@ -1871,6 +1876,7 @@ function printPathNoParens(path, options, print, args) { concat([ "<", path.call(print, "name"), + path.call(print, "typeParameters"), " ", concat(path.map(print, "attributes")), n.selfClosing ? " />" : ">" @@ -1909,6 +1915,7 @@ function printPathNoParens(path, options, print, args) { concat([ "<", path.call(print, "name"), + path.call(print, "typeParameters"), concat([ indent( concat( diff --git a/tests/typescript_tsx/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_tsx/__snapshots__/jsfmt.spec.js.snap index a4f5062a..c3ce20fd 100644 --- a/tests/typescript_tsx/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript_tsx/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,20 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`generic-component.tsx 1`] = ` +const c1 = data={12} /> + +const c2 = /> + +const c3 = attr="value" /> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const c1 = data={12} />; + +const c2 = />; + +const c3 = attr="value" />; + +`; + exports[`keyword.tsx 1`] = ` ; diff --git a/tests/typescript_tsx/generic-component.tsx b/tests/typescript_tsx/generic-component.tsx new file mode 100644 index 00000000..015199f3 --- /dev/null +++ b/tests/typescript_tsx/generic-component.tsx @@ -0,0 +1,5 @@ +const c1 = data={12} /> + +const c2 = /> + +const c3 = attr="value" />