Do not throw for unprinted comments inside of JSX (#2036)

Fixes #1990
master
Christopher Chedeau 2017-06-07 12:57:03 -07:00 committed by GitHub
parent ccda4c7115
commit 09f147decd
3 changed files with 37 additions and 0 deletions

View File

@ -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) {

View File

@ -21,6 +21,29 @@ abstract class AbstractRule {
`;
exports[`jsx.ts 1`] = `
var example1 = <div>
https://test
</div>;
var example2 = <div>
/*test*/
</div>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var example1 = (
<div>
https://test
</div>
);
var example2 = (
<div>
/*test*/
</div>
);
`;
exports[`types.ts 1`] = `
(() => {
// swallow error and fallback to using directory as path

View File

@ -0,0 +1,7 @@
var example1 = <div>
https://test
</div>;
var example2 = <div>
/*test*/
</div>;