From d02a367e6422cbc476ecc024f9caac46855e16ee Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 24 Nov 2020 17:37:29 +0800 Subject: [PATCH] Remove `JSXText` spacial case in comment attaching (#9759) --- src/common/util.js | 8 --- .../comments/__snapshots__/jsfmt.spec.js.snap | 55 +++++++++++++++++++ .../comments/jsx-tag-comment-after-prop.js | 12 ++++ .../comments/like-a-comment-in-jsx-text.js | 6 ++ 4 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 tests/jsx/comments/jsx-tag-comment-after-prop.js create mode 100644 tests/jsx/comments/like-a-comment-in-jsx-text.js diff --git a/src/common/util.js b/src/common/util.js index 4b9f3e513..38a143e65 100644 --- a/src/common/util.js +++ b/src/common/util.js @@ -565,14 +565,6 @@ 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 - /* istanbul ignore next */ - if (node.type === "JSXText") { - comment.printed = true; - } } function addLeadingComment(node, comment) { diff --git a/tests/jsx/comments/__snapshots__/jsfmt.spec.js.snap b/tests/jsx/comments/__snapshots__/jsfmt.spec.js.snap index cd3f81c5d..a703688af 100644 --- a/tests/jsx/comments/__snapshots__/jsfmt.spec.js.snap +++ b/tests/jsx/comments/__snapshots__/jsfmt.spec.js.snap @@ -222,3 +222,58 @@ printWidth: 80 ================================================================================ `; + +exports[`jsx-tag-comment-after-prop.js - {"jsxBracketSameLine":true} format 1`] = ` +====================================options===================================== +jsxBracketSameLine: true +parsers: ["flow", "babel", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +// https://github.com/typescript-eslint/typescript-eslint/pull/703 + +const pure = () => { + return ( + + ); +} +=====================================output===================================== +// https://github.com/typescript-eslint/typescript-eslint/pull/703 + +const pure = () => { + return ( + + ); +}; + +================================================================================ +`; + +exports[`like-a-comment-in-jsx-text.js - {"jsxBracketSameLine":true} format 1`] = ` +====================================options===================================== +jsxBracketSameLine: true +parsers: ["flow", "babel", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== + + text + // comment + text + +=====================================output===================================== +text // comment text; + +================================================================================ +`; diff --git a/tests/jsx/comments/jsx-tag-comment-after-prop.js b/tests/jsx/comments/jsx-tag-comment-after-prop.js new file mode 100644 index 000000000..feb701527 --- /dev/null +++ b/tests/jsx/comments/jsx-tag-comment-after-prop.js @@ -0,0 +1,12 @@ +// https://github.com/typescript-eslint/typescript-eslint/pull/703 + +const pure = () => { + return ( + + ); +} \ No newline at end of file diff --git a/tests/jsx/comments/like-a-comment-in-jsx-text.js b/tests/jsx/comments/like-a-comment-in-jsx-text.js new file mode 100644 index 000000000..7aae724ab --- /dev/null +++ b/tests/jsx/comments/like-a-comment-in-jsx-text.js @@ -0,0 +1,6 @@ + + text + // comment + text + \ No newline at end of file