diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts
index 5d57e9d202..145478693a 100644
--- a/src/compiler/checker.ts
+++ b/src/compiler/checker.ts
@@ -8363,14 +8363,12 @@ namespace ts {
checkGrammarJsxElement(node);
checkJsxPreconditions(node);
- // If we're compiling under --jsx react, the symbol 'React' should
- // be marked as 'used' so we don't incorrectly elide its import. And if there
- // is no 'React' symbol in scope, we should issue an error.
- if (compilerOptions.jsx === JsxEmit.React) {
- const reactSym = resolveName(node.tagName, "React", SymbolFlags.Value, Diagnostics.Cannot_find_name_0, "React");
- if (reactSym) {
- getSymbolLinks(reactSym).referenced = true;
- }
+ // The symbol 'React' should be marked as 'used' so we don't incorrectly elide its import. And if there
+ // is no 'React' symbol in scope when targeting React emit, we should issue an error.
+ const reactRefErr = compilerOptions.jsx === JsxEmit.React ? Diagnostics.Cannot_find_name_0 : undefined;
+ const reactSym = resolveName(node.tagName, "React", SymbolFlags.Value, reactRefErr, "React");
+ if (reactSym) {
+ getSymbolLinks(reactSym).referenced = true;
}
const targetAttributesType = getJsxElementAttributesType(node);
diff --git a/tests/baselines/reference/tsxPreserveEmit1.js b/tests/baselines/reference/tsxPreserveEmit1.js
index 7ac6c18ebc..6d795c946c 100644
--- a/tests/baselines/reference/tsxPreserveEmit1.js
+++ b/tests/baselines/reference/tsxPreserveEmit1.js
@@ -34,7 +34,7 @@ module M {
//// [test.jsx]
-define(["require", "exports", 'react-router'], function (require, exports, ReactRouter) {
+define(["require", "exports", 'react', 'react-router'], function (require, exports, React, ReactRouter) {
"use strict";
var Route = ReactRouter.Route;
var routes1 = ;
diff --git a/tests/baselines/reference/tsxPreserveEmit2.js b/tests/baselines/reference/tsxPreserveEmit2.js
new file mode 100644
index 0000000000..6a87da7b28
--- /dev/null
+++ b/tests/baselines/reference/tsxPreserveEmit2.js
@@ -0,0 +1,10 @@
+//// [test.tsx]
+
+
+var Route: any;
+var routes1 = ;
+
+
+//// [test.jsx]
+var Route;
+var routes1 = ;
diff --git a/tests/baselines/reference/tsxPreserveEmit2.symbols b/tests/baselines/reference/tsxPreserveEmit2.symbols
new file mode 100644
index 0000000000..4013b2e35e
--- /dev/null
+++ b/tests/baselines/reference/tsxPreserveEmit2.symbols
@@ -0,0 +1,10 @@
+=== tests/cases/conformance/jsx/test.tsx ===
+
+
+var Route: any;
+>Route : Symbol(Route, Decl(test.tsx, 2, 3))
+
+var routes1 = ;
+>routes1 : Symbol(routes1, Decl(test.tsx, 3, 3))
+>Route : Symbol(Route, Decl(test.tsx, 2, 3))
+
diff --git a/tests/baselines/reference/tsxPreserveEmit2.types b/tests/baselines/reference/tsxPreserveEmit2.types
new file mode 100644
index 0000000000..c01f564ff5
--- /dev/null
+++ b/tests/baselines/reference/tsxPreserveEmit2.types
@@ -0,0 +1,11 @@
+=== tests/cases/conformance/jsx/test.tsx ===
+
+
+var Route: any;
+>Route : any
+
+var routes1 = ;
+>routes1 : any
+> : any
+>Route : any
+
diff --git a/tests/baselines/reference/tsxPreserveEmit3.js b/tests/baselines/reference/tsxPreserveEmit3.js
new file mode 100644
index 0000000000..500b7d26c9
--- /dev/null
+++ b/tests/baselines/reference/tsxPreserveEmit3.js
@@ -0,0 +1,24 @@
+//// [tests/cases/conformance/jsx/tsxPreserveEmit3.tsx] ////
+
+//// [file.tsx]
+
+declare module JSX {
+ interface Element { }
+ interface IntrinsicElements {
+ [s: string]: any;
+ }
+}
+
+//// [test.d.ts]
+export var React;
+
+//// [react-consumer.tsx]
+// This import should be elided
+import {React} from "./test";
+
+
+//// [file.jsx]
+//// [react-consumer.jsx]
+define(["require", "exports"], function (require, exports) {
+ "use strict";
+});
diff --git a/tests/baselines/reference/tsxPreserveEmit3.symbols b/tests/baselines/reference/tsxPreserveEmit3.symbols
new file mode 100644
index 0000000000..ab53424104
--- /dev/null
+++ b/tests/baselines/reference/tsxPreserveEmit3.symbols
@@ -0,0 +1,25 @@
+=== tests/cases/conformance/jsx/file.tsx ===
+
+declare module JSX {
+>JSX : Symbol(JSX, Decl(file.tsx, 0, 0))
+
+ interface Element { }
+>Element : Symbol(Element, Decl(file.tsx, 1, 20))
+
+ interface IntrinsicElements {
+>IntrinsicElements : Symbol(IntrinsicElements, Decl(file.tsx, 2, 22))
+
+ [s: string]: any;
+>s : Symbol(s, Decl(file.tsx, 4, 3))
+ }
+}
+
+=== tests/cases/conformance/jsx/test.d.ts ===
+export var React;
+>React : Symbol(React, Decl(test.d.ts, 0, 10))
+
+=== tests/cases/conformance/jsx/react-consumer.tsx ===
+// This import should be elided
+import {React} from "./test";
+>React : Symbol(React, Decl(react-consumer.tsx, 1, 8))
+
diff --git a/tests/baselines/reference/tsxPreserveEmit3.types b/tests/baselines/reference/tsxPreserveEmit3.types
new file mode 100644
index 0000000000..152f742a24
--- /dev/null
+++ b/tests/baselines/reference/tsxPreserveEmit3.types
@@ -0,0 +1,25 @@
+=== tests/cases/conformance/jsx/file.tsx ===
+
+declare module JSX {
+>JSX : any
+
+ interface Element { }
+>Element : Element
+
+ interface IntrinsicElements {
+>IntrinsicElements : IntrinsicElements
+
+ [s: string]: any;
+>s : string
+ }
+}
+
+=== tests/cases/conformance/jsx/test.d.ts ===
+export var React;
+>React : any
+
+=== tests/cases/conformance/jsx/react-consumer.tsx ===
+// This import should be elided
+import {React} from "./test";
+>React : any
+
diff --git a/tests/cases/conformance/jsx/tsxPreserveEmit2.tsx b/tests/cases/conformance/jsx/tsxPreserveEmit2.tsx
new file mode 100644
index 0000000000..978c96a201
--- /dev/null
+++ b/tests/cases/conformance/jsx/tsxPreserveEmit2.tsx
@@ -0,0 +1,8 @@
+//@module: amd
+//@jsx: preserve
+//@target: ES5
+
+//@Filename: test.tsx
+
+var Route: any;
+var routes1 = ;
diff --git a/tests/cases/conformance/jsx/tsxPreserveEmit3.tsx b/tests/cases/conformance/jsx/tsxPreserveEmit3.tsx
new file mode 100644
index 0000000000..d7565cacbe
--- /dev/null
+++ b/tests/cases/conformance/jsx/tsxPreserveEmit3.tsx
@@ -0,0 +1,17 @@
+//@jsx: preserve
+//@module: amd
+
+//@filename: file.tsx
+declare module JSX {
+ interface Element { }
+ interface IntrinsicElements {
+ [s: string]: any;
+ }
+}
+
+//@filename: test.d.ts
+export var React;
+
+//@filename: react-consumer.tsx
+// This import should be elided
+import {React} from "./test";