diff --git a/src/comments.js b/src/comments.js index 638821068..515ed12d3 100644 --- a/src/comments.js +++ b/src/comments.js @@ -369,6 +369,13 @@ function addCommentHelper(node, comment) { const comments = node.comments || (node.comments = []); comments.push(comment); comment.printed = false; + + // For some reason, TypeScript parses `// x` inside of JSXText as a comment + // We already "print" it via the raw text, we don't need to re-print it as a + // comment + if (node.type === "JSXText") { + comment.printed = true; + } } function addLeadingComment(node, comment) { diff --git a/tests/typescript_comments/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_comments/__snapshots__/jsfmt.spec.js.snap index 537599567..d4bfd9635 100644 --- a/tests/typescript_comments/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript_comments/__snapshots__/jsfmt.spec.js.snap @@ -21,6 +21,29 @@ abstract class AbstractRule { `; +exports[`jsx.ts 1`] = ` +var example1 =
+ https://test +
; + +var example2 =
+ /*test*/ +
; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +var example1 = ( +
+ https://test +
+); + +var example2 = ( +
+ /*test*/ +
+); + +`; + exports[`types.ts 1`] = ` (() => { // swallow error and fallback to using directory as path diff --git a/tests/typescript_comments/jsx.ts b/tests/typescript_comments/jsx.ts new file mode 100644 index 000000000..da5adae25 --- /dev/null +++ b/tests/typescript_comments/jsx.ts @@ -0,0 +1,7 @@ +var example1 =
+ https://test +
; + +var example2 =
+ /*test*/ +
;