@@ -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) {
@@ -15082,8 +15098,10 @@ namespace ts {
15082
15098
function checkJsxFragment(node: JsxFragment, checkMode: CheckMode): Type {
15083
15099
checkJsxOpeningLikeElementOrOpeningFragment(node.openingFragment, checkMode);
15084
15100
15085
- if (compilerOptions.jsx === JsxEmit.React && compilerOptions.jsxFactory) {
15086
- error(node, Diagnostics.JSX_fragment_is_not_supported_when_using_jsxFactory);
15101
+ if (compilerOptions.jsx === JsxEmit.React && (compilerOptions.jsxFactory || getSourceFileOfNode(node).pragmas.has("jsx"))) {
15102
+ error(node, compilerOptions.jsxFactory
15103
+ ? Diagnostics.JSX_fragment_is_not_supported_when_using_jsxFactory
15104
+ : Diagnostics.JSX_fragment_is_not_supported_when_using_an_inline_JSX_factory_pragma);
15087
15105
}
15088
15106
15089
15107
return getJsxGlobalElementType() || anyType;
@@ -15709,7 +15727,7 @@ namespace ts {
15709
15727
// The reactNamespace/jsxFactory's root symbol should be marked as 'used' so we don't incorrectly elide its import.
15710
15728
// And if there is no reactNamespace/jsxFactory's symbol in scope when targeting React emit, we should issue an error.
15711
15729
const reactRefErr = diagnostics && compilerOptions.jsx === JsxEmit.React ? Diagnostics.Cannot_find_name_0 : undefined;
15712
- const reactNamespace = getJsxNamespace();
15730
+ const reactNamespace = getJsxNamespace(node );
15713
15731
const reactLocation = isNodeOpeningLikeElement ? (<JsxOpeningLikeElement>node).tagName : node;
15714
15732
const reactSym = resolveName(reactLocation, reactNamespace, SymbolFlags.Value, reactRefErr, reactNamespace, /*isUse*/ true);
15715
15733
if (reactSym) {
@@ -25556,7 +25574,7 @@ namespace ts {
25556
25574
return !!(symbol && getCheckFlags(symbol) & CheckFlags.Late);
25557
25575
},
25558
25576
writeLiteralConstValue,
25559
- getJsxFactoryEntity: () => _jsxFactoryEntity
25577
+ getJsxFactoryEntity: location => location ? (getJsxNamespace(location), (getSourceFileOfNode(location).localJsxFactory || _jsxFactoryEntity)) : _jsxFactoryEntity
25560
25578
};
25561
25579
25562
25580
// defined here to avoid outer scope pollution
0 commit comments