diff --git a/src/compiler/comments.ts b/src/compiler/comments.ts
index c50cacc2ccb..06285309f64 100644
--- a/src/compiler/comments.ts
+++ b/src/compiler/comments.ts
@@ -58,8 +58,10 @@ namespace ts {
}
const isEmittedNode = node.kind !== SyntaxKind.NotEmittedStatement;
- const skipLeadingComments = pos < 0 || (emitFlags & EmitFlags.NoLeadingComments) !== 0;
- const skipTrailingComments = end < 0 || (emitFlags & EmitFlags.NoTrailingComments) !== 0;
+ // We have to explicitly check that the node is JsxText because if the compilerOptions.jsx is "preserve" we will not do any transformation.
+ // It is expensive to walk entire tree just to set one kind of node to have no comments.
+ const skipLeadingComments = pos < 0 || (emitFlags & EmitFlags.NoLeadingComments) !== 0 || node.kind === SyntaxKind.JsxText;
+ const skipTrailingComments = end < 0 || (emitFlags & EmitFlags.NoTrailingComments) !== 0 || node.kind === SyntaxKind.JsxText;
// Emit leading comments if the position is not synthesized and the node
// has not opted out from emitting leading comments.
diff --git a/tests/baselines/reference/commentEmittingInPreserveJsx1.js b/tests/baselines/reference/commentEmittingInPreserveJsx1.js
new file mode 100644
index 00000000000..45e2148e007
--- /dev/null
+++ b/tests/baselines/reference/commentEmittingInPreserveJsx1.js
@@ -0,0 +1,57 @@
+//// [file.tsx]
+import React = require('react');
+
+
+ // Not Comment
+
;
+
+
+ // Not Comment
+ {
+ //Comment just Fine
+ }
+ // Another not Comment
+
;
+
+
+ // Not Comment
+ {
+ //Comment just Fine
+ "Hi"
+ }
+ // Another not Comment
+
;
+
+
+ /* Not Comment */
+ {
+ //Comment just Fine
+ "Hi"
+ }
+
;
+
+//// [file.jsx]
+"use strict";
+exports.__esModule = true;
+var React = require("react");
+
+ // Not Comment
+
;
+
+ // Not Comment
+
+ // Another not Comment
+
;
+
+ // Not Comment
+ {
+//Comment just Fine
+"Hi"}
+ // Another not Comment
+
;
+
+ /* Not Comment */
+ {
+//Comment just Fine
+"Hi"}
+
;
diff --git a/tests/baselines/reference/commentEmittingInPreserveJsx1.symbols b/tests/baselines/reference/commentEmittingInPreserveJsx1.symbols
new file mode 100644
index 00000000000..43d833e27b1
--- /dev/null
+++ b/tests/baselines/reference/commentEmittingInPreserveJsx1.symbols
@@ -0,0 +1,45 @@
+=== tests/cases/conformance/jsx/file.tsx ===
+import React = require('react');
+>React : Symbol(React, Decl(file.tsx, 0, 0))
+
+
+>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2399, 45))
+
+ // Not Comment
+
;
+>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2399, 45))
+
+
+>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2399, 45))
+
+ // Not Comment
+ {
+ //Comment just Fine
+ }
+ // Another not Comment
+
;
+>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2399, 45))
+
+
+>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2399, 45))
+
+ // Not Comment
+ {
+ //Comment just Fine
+ "Hi"
+ }
+ // Another not Comment
+
;
+>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2399, 45))
+
+
+>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2399, 45))
+
+ /* Not Comment */
+ {
+ //Comment just Fine
+ "Hi"
+ }
+
;
+>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2399, 45))
+
diff --git a/tests/baselines/reference/commentEmittingInPreserveJsx1.types b/tests/baselines/reference/commentEmittingInPreserveJsx1.types
new file mode 100644
index 00000000000..2e968033d4c
--- /dev/null
+++ b/tests/baselines/reference/commentEmittingInPreserveJsx1.types
@@ -0,0 +1,51 @@
+=== tests/cases/conformance/jsx/file.tsx ===
+import React = require('react');
+>React : typeof React
+
+
+>
// Not Comment
: JSX.Element
+>div : any
+
+ // Not Comment
+
;
+>div : any
+
+
+>
// Not Comment { //Comment just Fine } // Another not Comment
: JSX.Element
+>div : any
+
+ // Not Comment
+ {
+ //Comment just Fine
+ }
+ // Another not Comment
+
;
+>div : any
+
+
+>
// Not Comment { //Comment just Fine "Hi" } // Another not Comment
: JSX.Element
+>div : any
+
+ // Not Comment
+ {
+ //Comment just Fine
+ "Hi"
+>"Hi" : "Hi"
+ }
+ // Another not Comment
+
;
+>div : any
+
+
+>
/* Not Comment */ { //Comment just Fine "Hi" }
: JSX.Element
+>div : any
+
+ /* Not Comment */
+ {
+ //Comment just Fine
+ "Hi"
+>"Hi" : "Hi"
+ }
+
;
+>div : any
+
diff --git a/tests/cases/conformance/jsx/commentEmittingInPreserveJsx1.tsx b/tests/cases/conformance/jsx/commentEmittingInPreserveJsx1.tsx
new file mode 100644
index 00000000000..323cd029189
--- /dev/null
+++ b/tests/cases/conformance/jsx/commentEmittingInPreserveJsx1.tsx
@@ -0,0 +1,35 @@
+// @filename: file.tsx
+// @jsx: preserve
+// @noLib: true
+// @libFiles: react.d.ts,lib.d.ts
+
+import React = require('react');
+
+
+ // Not Comment
+
;
+
+
+ // Not Comment
+ {
+ //Comment just Fine
+ }
+ // Another not Comment
+
;
+
+
+ // Not Comment
+ {
+ //Comment just Fine
+ "Hi"
+ }
+ // Another not Comment
+
;
+
+
+ /* Not Comment */
+ {
+ //Comment just Fine
+ "Hi"
+ }
+
;
\ No newline at end of file