File tree Expand file tree Collapse file tree 5 files changed +192
-2
lines changed Expand file tree Collapse file tree 5 files changed +192
-2
lines changed Original file line number Diff line number Diff line change @@ -58,8 +58,10 @@ namespace ts {
58
58
}
59
59
60
60
const isEmittedNode = node . kind !== SyntaxKind . NotEmittedStatement ;
61
- const skipLeadingComments = pos < 0 || ( emitFlags & EmitFlags . NoLeadingComments ) !== 0 ;
62
- const skipTrailingComments = end < 0 || ( emitFlags & EmitFlags . NoTrailingComments ) !== 0 ;
61
+ // We have to explicitly check that the node is JsxText because if the compilerOptions.jsx is "preserve" we will not do any transformation.
62
+ // It is expensive to walk entire tree just to set one kind of node to have no comments.
63
+ const skipLeadingComments = pos < 0 || ( emitFlags & EmitFlags . NoLeadingComments ) !== 0 || node . kind === SyntaxKind . JsxText ;
64
+ const skipTrailingComments = end < 0 || ( emitFlags & EmitFlags . NoTrailingComments ) !== 0 || node . kind === SyntaxKind . JsxText ;
63
65
64
66
// Emit leading comments if the position is not synthesized and the node
65
67
// has not opted out from emitting leading comments.
Original file line number Diff line number Diff line change
1
+ //// [file.tsx]
2
+ import React = require ( 'react' ) ;
3
+
4
+ < div >
5
+ // Not Comment
6
+ </ div > ;
7
+
8
+ < div >
9
+ // Not Comment
10
+ {
11
+ //Comment just Fine
12
+ }
13
+ // Another not Comment
14
+ </ div > ;
15
+
16
+ < div >
17
+ // Not Comment
18
+ {
19
+ //Comment just Fine
20
+ "Hi"
21
+ }
22
+ // Another not Comment
23
+ </ div > ;
24
+
25
+ < div >
26
+ /* Not Comment */
27
+ {
28
+ //Comment just Fine
29
+ "Hi"
30
+ }
31
+ </ div > ;
32
+
33
+ //// [file.jsx]
34
+ "use strict" ;
35
+ exports . __esModule = true ;
36
+ var React = require ( "react" ) ;
37
+ < div >
38
+ // Not Comment
39
+ </ div > ;
40
+ < div >
41
+ // Not Comment
42
+
43
+ // Another not Comment
44
+ </ div > ;
45
+ < div >
46
+ // Not Comment
47
+ {
48
+ //Comment just Fine
49
+ "Hi" }
50
+ // Another not Comment
51
+ </ div > ;
52
+ < div >
53
+ /* Not Comment */
54
+ {
55
+ //Comment just Fine
56
+ "Hi" }
57
+ </ div > ;
Original file line number Diff line number Diff line change
1
+ === tests/cases/conformance/jsx/file.tsx ===
2
+ import React = require('react');
3
+ >React : Symbol(React, Decl(file.tsx, 0, 0))
4
+
5
+ <div>
6
+ >div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2399, 45))
7
+
8
+ // Not Comment
9
+ </div>;
10
+ >div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2399, 45))
11
+
12
+ <div>
13
+ >div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2399, 45))
14
+
15
+ // Not Comment
16
+ {
17
+ //Comment just Fine
18
+ }
19
+ // Another not Comment
20
+ </div>;
21
+ >div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2399, 45))
22
+
23
+ <div>
24
+ >div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2399, 45))
25
+
26
+ // Not Comment
27
+ {
28
+ //Comment just Fine
29
+ "Hi"
30
+ }
31
+ // Another not Comment
32
+ </div>;
33
+ >div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2399, 45))
34
+
35
+ <div>
36
+ >div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2399, 45))
37
+
38
+ /* Not Comment */
39
+ {
40
+ //Comment just Fine
41
+ "Hi"
42
+ }
43
+ </div>;
44
+ >div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2399, 45))
45
+
Original file line number Diff line number Diff line change
1
+ === tests/cases/conformance/jsx/file.tsx ===
2
+ import React = require('react');
3
+ >React : typeof React
4
+
5
+ <div>
6
+ ><div> // Not Comment</div> : JSX.Element
7
+ >div : any
8
+
9
+ // Not Comment
10
+ </div>;
11
+ >div : any
12
+
13
+ <div>
14
+ ><div> // Not Comment { //Comment just Fine } // Another not Comment</div> : JSX.Element
15
+ >div : any
16
+
17
+ // Not Comment
18
+ {
19
+ //Comment just Fine
20
+ }
21
+ // Another not Comment
22
+ </div>;
23
+ >div : any
24
+
25
+ <div>
26
+ ><div> // Not Comment { //Comment just Fine "Hi" } // Another not Comment</div> : JSX.Element
27
+ >div : any
28
+
29
+ // Not Comment
30
+ {
31
+ //Comment just Fine
32
+ "Hi"
33
+ >"Hi" : "Hi"
34
+ }
35
+ // Another not Comment
36
+ </div>;
37
+ >div : any
38
+
39
+ <div>
40
+ ><div> /* Not Comment */ { //Comment just Fine "Hi" }</div> : JSX.Element
41
+ >div : any
42
+
43
+ /* Not Comment */
44
+ {
45
+ //Comment just Fine
46
+ "Hi"
47
+ >"Hi" : "Hi"
48
+ }
49
+ </div>;
50
+ >div : any
51
+
Original file line number Diff line number Diff line change
1
+ // @filename : file.tsx
2
+ // @jsx : preserve
3
+ // @noLib : true
4
+ // @libFiles : react.d.ts,lib.d.ts
5
+
6
+ import React = require( 'react' ) ;
7
+
8
+ < div >
9
+ // Not Comment
10
+ </ div > ;
11
+
12
+ < div >
13
+ // Not Comment
14
+ {
15
+ //Comment just Fine
16
+ }
17
+ // Another not Comment
18
+ </ div > ;
19
+
20
+ < div >
21
+ // Not Comment
22
+ {
23
+ //Comment just Fine
24
+ "Hi"
25
+ }
26
+ // Another not Comment
27
+ </ div > ;
28
+
29
+ < div >
30
+ /* Not Comment */
31
+ {
32
+ //Comment just Fine
33
+ "Hi"
34
+ }
35
+ </ div > ;
You can’t perform that action at this time.
0 commit comments