Skip to content

Commit 52c9f0a

Browse files
committed
Merge branch 'master' into declaration-emit-refactor
2 parents 9e34a3f + 32c63a2 commit 52c9f0a

File tree

52 files changed

+1205
-370
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1205
-370
lines changed

src/compiler/checker.ts

+24-6
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ namespace ts {
299299
resolveName(name, location, meaning, excludeGlobals) {
300300
return resolveName(location, escapeLeadingUnderscores(name), meaning, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false, excludeGlobals);
301301
},
302-
getJsxNamespace: () => unescapeLeadingUnderscores(getJsxNamespace()),
302+
getJsxNamespace: n => unescapeLeadingUnderscores(getJsxNamespace(n)),
303303
getAccessibleSymbolChain,
304304
getTypePredicateOfSignature,
305305
resolveExternalModuleSymbol,
@@ -765,7 +765,23 @@ namespace ts {
765765
}
766766
}
767767

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+
}
769785
if (!_jsxNamespace) {
770786
_jsxNamespace = "React" as __String;
771787
if (compilerOptions.jsxFactory) {
@@ -15078,8 +15094,10 @@ namespace ts {
1507815094
function checkJsxFragment(node: JsxFragment, checkMode: CheckMode): Type {
1507915095
checkJsxOpeningLikeElementOrOpeningFragment(node.openingFragment, checkMode);
1508015096

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);
1508315101
}
1508415102

1508515103
return getJsxGlobalElementType() || anyType;
@@ -15705,7 +15723,7 @@ namespace ts {
1570515723
// The reactNamespace/jsxFactory's root symbol should be marked as 'used' so we don't incorrectly elide its import.
1570615724
// And if there is no reactNamespace/jsxFactory's symbol in scope when targeting React emit, we should issue an error.
1570715725
const reactRefErr = diagnostics && compilerOptions.jsx === JsxEmit.React ? Diagnostics.Cannot_find_name_0 : undefined;
15708-
const reactNamespace = getJsxNamespace();
15726+
const reactNamespace = getJsxNamespace(node);
1570915727
const reactLocation = isNodeOpeningLikeElement ? (<JsxOpeningLikeElement>node).tagName : node;
1571015728
const reactSym = resolveName(reactLocation, reactNamespace, SymbolFlags.Value, reactRefErr, reactNamespace, /*isUse*/ true);
1571115729
if (reactSym) {
@@ -25560,7 +25578,7 @@ namespace ts {
2556025578
const symbol = node && getSymbolOfNode(node);
2556125579
return !!(symbol && getCheckFlags(symbol) & CheckFlags.Late);
2556225580
},
25563-
getJsxFactoryEntity: () => _jsxFactoryEntity
25581+
getJsxFactoryEntity: location => location ? (getJsxNamespace(location), (getSourceFileOfNode(location).localJsxFactory || _jsxFactoryEntity)) : _jsxFactoryEntity
2556425582
};
2556525583

2556625584
// defined here to avoid outer scope pollution

src/compiler/diagnosticMessages.json

+4
Original file line numberDiff line numberDiff line change
@@ -3788,6 +3788,10 @@
37883788
"category": "Error",
37893789
"code": 17016
37903790
},
3791+
"JSX fragment is not supported when using an inline JSX factory pragma": {
3792+
"category": "Error",
3793+
"code": 17017
3794+
},
37913795

37923796
"Circularity detected while resolving configuration: {0}": {
37933797
"category": "Error",

src/compiler/factory.ts

+3
Original file line numberDiff line numberDiff line change
@@ -2451,6 +2451,9 @@ namespace ts {
24512451
if (node.resolvedTypeReferenceDirectiveNames !== undefined) updated.resolvedTypeReferenceDirectiveNames = node.resolvedTypeReferenceDirectiveNames;
24522452
if (node.imports !== undefined) updated.imports = node.imports;
24532453
if (node.moduleAugmentations !== undefined) updated.moduleAugmentations = node.moduleAugmentations;
2454+
if (node.pragmas !== undefined) updated.pragmas = node.pragmas;
2455+
if (node.localJsxFactory !== undefined) updated.localJsxFactory = node.localJsxFactory;
2456+
if (node.localJsxNamespace !== undefined) updated.localJsxNamespace = node.localJsxNamespace;
24542457
return updateNode(updated, node);
24552458
}
24562459

0 commit comments

Comments
 (0)