@@ -299,7 +299,7 @@ namespace ts {
299
299
resolveName(name, location, meaning, excludeGlobals) {
300
300
return resolveName(location, escapeLeadingUnderscores(name), meaning, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false, excludeGlobals);
301
301
},
302
- getJsxNamespace: () => unescapeLeadingUnderscores(getJsxNamespace()),
302
+ getJsxNamespace: n => unescapeLeadingUnderscores(getJsxNamespace(n )),
303
303
getAccessibleSymbolChain,
304
304
getTypePredicateOfSignature,
305
305
resolveExternalModuleSymbol,
@@ -765,7 +765,23 @@ namespace ts {
765
765
}
766
766
}
767
767
768
- function getJsxNamespace(): __String {
768
+ function getJsxNamespace(location: Node | undefined): __String {
769
+ if (location) {
770
+ const file = getSourceFileOfNode(location);
771
+ if (file) {
772
+ if (file.localJsxNamespace) {
773
+ return file.localJsxNamespace;
774
+ }
775
+ const jsxPragma = file.pragmas.get("jsx");
776
+ if (jsxPragma) {
777
+ const chosenpragma = isArray(jsxPragma) ? jsxPragma[0] : jsxPragma;
778
+ file.localJsxFactory = parseIsolatedEntityName(chosenpragma.arguments.factory, languageVersion);
779
+ if (file.localJsxFactory) {
780
+ return file.localJsxNamespace = getFirstIdentifier(file.localJsxFactory).escapedText;
781
+ }
782
+ }
783
+ }
784
+ }
769
785
if (!_jsxNamespace) {
770
786
_jsxNamespace = "React" as __String;
771
787
if (compilerOptions.jsxFactory) {
@@ -15078,8 +15094,10 @@ namespace ts {
15078
15094
function checkJsxFragment(node: JsxFragment, checkMode: CheckMode): Type {
15079
15095
checkJsxOpeningLikeElementOrOpeningFragment(node.openingFragment, checkMode);
15080
15096
15081
- if (compilerOptions.jsx === JsxEmit.React && compilerOptions.jsxFactory) {
15082
- error(node, Diagnostics.JSX_fragment_is_not_supported_when_using_jsxFactory);
15097
+ if (compilerOptions.jsx === JsxEmit.React && (compilerOptions.jsxFactory || getSourceFileOfNode(node).pragmas.has("jsx"))) {
15098
+ error(node, compilerOptions.jsxFactory
15099
+ ? Diagnostics.JSX_fragment_is_not_supported_when_using_jsxFactory
15100
+ : Diagnostics.JSX_fragment_is_not_supported_when_using_an_inline_JSX_factory_pragma);
15083
15101
}
15084
15102
15085
15103
return getJsxGlobalElementType() || anyType;
@@ -15705,7 +15723,7 @@ namespace ts {
15705
15723
// The reactNamespace/jsxFactory's root symbol should be marked as 'used' so we don't incorrectly elide its import.
15706
15724
// And if there is no reactNamespace/jsxFactory's symbol in scope when targeting React emit, we should issue an error.
15707
15725
const reactRefErr = diagnostics && compilerOptions.jsx === JsxEmit.React ? Diagnostics.Cannot_find_name_0 : undefined;
15708
- const reactNamespace = getJsxNamespace();
15726
+ const reactNamespace = getJsxNamespace(node );
15709
15727
const reactLocation = isNodeOpeningLikeElement ? (<JsxOpeningLikeElement>node).tagName : node;
15710
15728
const reactSym = resolveName(reactLocation, reactNamespace, SymbolFlags.Value, reactRefErr, reactNamespace, /*isUse*/ true);
15711
15729
if (reactSym) {
@@ -25560,7 +25578,7 @@ namespace ts {
25560
25578
const symbol = node && getSymbolOfNode(node);
25561
25579
return !!(symbol && getCheckFlags(symbol) & CheckFlags.Late);
25562
25580
},
25563
- getJsxFactoryEntity: () => _jsxFactoryEntity
25581
+ getJsxFactoryEntity: location => location ? (getJsxNamespace(location), (getSourceFileOfNode(location).localJsxFactory || _jsxFactoryEntity)) : _jsxFactoryEntity
25564
25582
};
25565
25583
25566
25584
// defined here to avoid outer scope pollution
0 commit comments