diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3ef2c6ada2a..7a85a2f08b2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7299,6 +7299,16 @@ 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) { + let reactSym = resolveName(node.tagName, 'React', SymbolFlags.Value, Diagnostics.Cannot_find_name_0, 'React'); + if (reactSym) { + getSymbolLinks(reactSym).referenced = true; + } + } + let targetAttributesType = getJsxElementAttributesType(node); if (getNodeLinks(node).jsxFlags & JsxFlags.ClassElement) { diff --git a/tests/baselines/reference/tsxElementResolution19.js b/tests/baselines/reference/tsxElementResolution19.js index ebcb66e536f..72612e8ce54 100644 --- a/tests/baselines/reference/tsxElementResolution19.js +++ b/tests/baselines/reference/tsxElementResolution19.js @@ -31,6 +31,6 @@ define(["require", "exports"], function (require, exports) { exports.MyClass = MyClass; }); //// [file2.js] -define(["require", "exports", './file1'], function (require, exports, file1_1) { +define(["require", "exports", 'react', './file1'], function (require, exports, React, file1_1) { React.createElement(file1_1.MyClass, null); });