Skip to content

Commit 1568bfd

Browse files
committed
Mark 'React' symbol as used and error if it doesn't exist
1 parent 1a8200f commit 1568bfd

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/compiler/checker.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7299,6 +7299,16 @@ namespace ts {
72997299
checkGrammarJsxElement(node);
73007300
checkJsxPreconditions(node);
73017301

7302+
// If we're compiling under --jsx react, the symbol 'React' should
7303+
// be marked as 'used' so we don't incorrectly elide its import. And if there
7304+
// is no 'React' symbol in scope, we should issue an error.
7305+
if(compilerOptions.jsx === JsxEmit.React) {
7306+
let reactSym = resolveName(node.tagName, 'React', SymbolFlags.Value, Diagnostics.Cannot_find_name_0, 'React');
7307+
if (reactSym) {
7308+
getSymbolLinks(reactSym).referenced = true;
7309+
}
7310+
}
7311+
73027312
let targetAttributesType = getJsxElementAttributesType(node);
73037313

73047314
if (getNodeLinks(node).jsxFlags & JsxFlags.ClassElement) {

tests/baselines/reference/tsxElementResolution19.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ define(["require", "exports"], function (require, exports) {
3131
exports.MyClass = MyClass;
3232
});
3333
//// [file2.js]
34-
define(["require", "exports", './file1'], function (require, exports, file1_1) {
34+
define(["require", "exports", 'react', './file1'], function (require, exports, React, file1_1) {
3535
React.createElement(file1_1.MyClass, null);
3636
});

0 commit comments

Comments
 (0)