@@ -335,6 +335,9 @@ namespace ts {
335335 });
336336
337337 let jsxElementType: Type;
338+ let _jsxNamespace: string;
339+ let _jsxFactoryEntity: EntityName;
340+
338341 /** Things we lazy load from the JSX namespace */
339342 const jsxTypes = createMap<Type>();
340343 const JsxNames = {
@@ -372,6 +375,22 @@ namespace ts {
372375
373376 return checker;
374377
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+
375394 function getEmitResolver(sourceFile: SourceFile, cancellationToken: CancellationToken) {
376395 // Ensure we have all the type information in place for this file so that all the
377396 // emitter questions of this resolver will return the right information.
@@ -11468,10 +11487,10 @@ namespace ts {
1146811487 function checkJsxOpeningLikeElement(node: JsxOpeningLikeElement) {
1146911488 checkGrammarJsxElement(node);
1147011489 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.
1147311492 const reactRefErr = compilerOptions.jsx === JsxEmit.React ? Diagnostics.Cannot_find_name_0 : undefined;
11474- const reactNamespace = compilerOptions.reactNamespace ? compilerOptions.reactNamespace : "React" ;
11493+ const reactNamespace = getJsxNamespace() ;
1147511494 const reactSym = resolveName(node.tagName, reactNamespace, SymbolFlags.Value, reactRefErr, reactNamespace);
1147611495 if (reactSym) {
1147711496 // Mark local symbol as referenced here because it might not have been marked
@@ -19738,7 +19757,8 @@ namespace ts {
1973819757 getTypeReferenceDirectivesForEntityName,
1973919758 getTypeReferenceDirectivesForSymbol,
1974019759 isLiteralConstDeclaration,
19741- writeLiteralConstValue
19760+ writeLiteralConstValue,
19761+ getJsxFactoryEntity: () => _jsxFactoryEntity
1974219762 };
1974319763
1974419764 // defined here to avoid outer scope pollution
0 commit comments