@@ -335,6 +335,9 @@ namespace ts {
335
335
});
336
336
337
337
let jsxElementType: Type;
338
+ let _jsxNamespace: string;
339
+ let _jsxFactoryEntity: EntityName;
340
+
338
341
/** Things we lazy load from the JSX namespace */
339
342
const jsxTypes = createMap<Type>();
340
343
const JsxNames = {
@@ -372,6 +375,22 @@ namespace ts {
372
375
373
376
return checker;
374
377
378
+ function getJsxNamespace(): string {
379
+ if (_jsxNamespace === undefined) {
380
+ _jsxNamespace = "React";
381
+ if (compilerOptions.jsxFactory) {
382
+ _jsxFactoryEntity = parseIsolatedEntityName(compilerOptions.jsxFactory, languageVersion);
383
+ if (_jsxFactoryEntity) {
384
+ _jsxNamespace = getFirstIdentifier(_jsxFactoryEntity).text;
385
+ }
386
+ }
387
+ else if (compilerOptions.reactNamespace) {
388
+ _jsxNamespace = compilerOptions.reactNamespace;
389
+ }
390
+ }
391
+ return _jsxNamespace;
392
+ }
393
+
375
394
function getEmitResolver(sourceFile: SourceFile, cancellationToken: CancellationToken) {
376
395
// Ensure we have all the type information in place for this file so that all the
377
396
// emitter questions of this resolver will return the right information.
@@ -11468,10 +11487,10 @@ namespace ts {
11468
11487
function checkJsxOpeningLikeElement(node: JsxOpeningLikeElement) {
11469
11488
checkGrammarJsxElement(node);
11470
11489
checkJsxPreconditions(node);
11471
- // The reactNamespace symbol should be marked as 'used' so we don't incorrectly elide its import. And if there
11472
- // is no reactNamespace symbol in scope when targeting React emit, we should issue an error.
11490
+ // The reactNamespace/jsxFactory's root symbol should be marked as 'used' so we don't incorrectly elide its import.
11491
+ // And if there is no reactNamespace/jsxFactory's symbol in scope when targeting React emit, we should issue an error.
11473
11492
const reactRefErr = compilerOptions.jsx === JsxEmit.React ? Diagnostics.Cannot_find_name_0 : undefined;
11474
- const reactNamespace = compilerOptions.reactNamespace ? compilerOptions.reactNamespace : "React" ;
11493
+ const reactNamespace = getJsxNamespace() ;
11475
11494
const reactSym = resolveName(node.tagName, reactNamespace, SymbolFlags.Value, reactRefErr, reactNamespace);
11476
11495
if (reactSym) {
11477
11496
// Mark local symbol as referenced here because it might not have been marked
@@ -19738,7 +19757,8 @@ namespace ts {
19738
19757
getTypeReferenceDirectivesForEntityName,
19739
19758
getTypeReferenceDirectivesForSymbol,
19740
19759
isLiteralConstDeclaration,
19741
- writeLiteralConstValue
19760
+ writeLiteralConstValue,
19761
+ getJsxFactoryEntity: () => _jsxFactoryEntity
19742
19762
};
19743
19763
19744
19764
// defined here to avoid outer scope pollution
0 commit comments