Skip to content

Commit 89d6c67

Browse files
Add test case to reproduce JSX comment duplication issue
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
1 parent 127e310 commit 89d6c67

9 files changed

Lines changed: 106 additions & 4 deletions

src/compiler/emitter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4785,10 +4785,10 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
47854785
}
47864786
}
47874787

4788-
// Emit this child.
4789-
if (shouldEmitInterveningComments) {
4790-
const commentRange = getCommentRange(child);
4791-
emitTrailingCommentsOfPosition(commentRange.pos);
4788+
// Emit this child.
4789+
if (shouldEmitInterveningComments) {
4790+
const commentRange = getCommentRange(child);
4791+
emitTrailingCommentsOfPosition(commentRange.pos);
47924792
}
47934793
else {
47944794
shouldEmitInterveningComments = mayEmitInterveningComments;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//// [tests/cases/compiler/jsxCommentDuplication.tsx] ////
2+
3+
//// [jsxCommentDuplication.tsx]
4+
// Simple test case to reproduce JSX comment duplication
5+
const x = 42;
6+
const jsx = <div>/*pre*/{x}/*post*/</div>;
7+
8+
//// [jsxCommentDuplication.jsx]
9+
// Simple test case to reproduce JSX comment duplication
10+
var x = 42;
11+
var jsx = <div> /*pre*//*pre*/{x} /*post*//*post*/</div>;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//// [tests/cases/compiler/jsxCommentDuplication.tsx] ////
2+
3+
=== jsxCommentDuplication.tsx ===
4+
// Simple test case to reproduce JSX comment duplication
5+
const x = 42;
6+
>x : Symbol(x, Decl(jsxCommentDuplication.tsx, 1, 5))
7+
8+
const jsx = <div>/*pre*/{x}/*post*/</div>;
9+
>jsx : Symbol(jsx, Decl(jsxCommentDuplication.tsx, 2, 5))
10+
>x : Symbol(x, Decl(jsxCommentDuplication.tsx, 1, 5))
11+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//// [tests/cases/compiler/jsxCommentDuplication.tsx] ////
2+
3+
=== jsxCommentDuplication.tsx ===
4+
// Simple test case to reproduce JSX comment duplication
5+
const x = 42;
6+
>x : 42
7+
> : ^^
8+
>42 : 42
9+
> : ^^
10+
11+
const jsx = <div>/*pre*/{x}/*post*/</div>;
12+
>jsx : error
13+
><div>/*pre*/{x}/*post*/</div> : error
14+
>div : any
15+
> : ^^^
16+
>x : 42
17+
> : ^^
18+
>div : any
19+
> : ^^^
20+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
jsxCommentDuplication.tsx(3,13): error TS2875: This JSX tag requires the module path 'react/jsx-runtime' to exist, but none could be found. Make sure you have types for the appropriate package installed.
2+
3+
4+
==== jsxCommentDuplication.tsx (1 errors) ====
5+
// Simple test case to reproduce JSX comment duplication
6+
const x = 42;
7+
const jsx = <div>/*pre*/{x}/*post*/</div>;
8+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9+
!!! error TS2875: This JSX tag requires the module path 'react/jsx-runtime' to exist, but none could be found. Make sure you have types for the appropriate package installed.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//// [tests/cases/compiler/jsxCommentDuplication.tsx] ////
2+
3+
//// [jsxCommentDuplication.tsx]
4+
// Simple test case to reproduce JSX comment duplication
5+
const x = 42;
6+
const jsx = <div>/*pre*/{x}/*post*/</div>;
7+
8+
//// [jsxCommentDuplication.js]
9+
"use strict";
10+
Object.defineProperty(exports, "__esModule", { value: true });
11+
var jsx_runtime_1 = require("react/jsx-runtime");
12+
// Simple test case to reproduce JSX comment duplication
13+
var x = 42;
14+
var jsx = (0, jsx_runtime_1.jsxs)("div", { children: ["/*pre*/", x, "/*post*/"] });
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//// [tests/cases/compiler/jsxCommentDuplication.tsx] ////
2+
3+
=== jsxCommentDuplication.tsx ===
4+
// Simple test case to reproduce JSX comment duplication
5+
const x = 42;
6+
>x : Symbol(x, Decl(jsxCommentDuplication.tsx, 1, 5))
7+
8+
const jsx = <div>/*pre*/{x}/*post*/</div>;
9+
>jsx : Symbol(jsx, Decl(jsxCommentDuplication.tsx, 2, 5))
10+
>x : Symbol(x, Decl(jsxCommentDuplication.tsx, 1, 5))
11+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//// [tests/cases/compiler/jsxCommentDuplication.tsx] ////
2+
3+
=== jsxCommentDuplication.tsx ===
4+
// Simple test case to reproduce JSX comment duplication
5+
const x = 42;
6+
>x : 42
7+
> : ^^
8+
>42 : 42
9+
> : ^^
10+
11+
const jsx = <div>/*pre*/{x}/*post*/</div>;
12+
>jsx : any
13+
> : ^^^
14+
><div>/*pre*/{x}/*post*/</div> : any
15+
> : ^^^
16+
>div : any
17+
> : ^^^
18+
>x : 42
19+
> : ^^
20+
>div : any
21+
> : ^^^
22+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// @jsx: preserve,react-jsx
2+
// Simple test case to reproduce JSX comment duplication
3+
const x = 42;
4+
const jsx = <div>/*pre*/{x}/*post*/</div>;

0 commit comments

Comments
 (0)