@@ -939,6 +939,7 @@ namespace ts {
939
939
if (jsxPragma) {
940
940
const chosenpragma = isArray(jsxPragma) ? jsxPragma[0] : jsxPragma;
941
941
file.localJsxFactory = parseIsolatedEntityName(chosenpragma.arguments.factory, languageVersion);
942
+ visitNode(file.localJsxFactory, markAsSynthetic);
942
943
if (file.localJsxFactory) {
943
944
return file.localJsxNamespace = getFirstIdentifier(file.localJsxFactory).escapedText;
944
945
}
@@ -949,6 +950,7 @@ namespace ts {
949
950
_jsxNamespace = "React" as __String;
950
951
if (compilerOptions.jsxFactory) {
951
952
_jsxFactoryEntity = parseIsolatedEntityName(compilerOptions.jsxFactory, languageVersion);
953
+ visitNode(_jsxFactoryEntity, markAsSynthetic);
952
954
if (_jsxFactoryEntity) {
953
955
_jsxNamespace = getFirstIdentifier(_jsxFactoryEntity).escapedText;
954
956
}
@@ -957,7 +959,16 @@ namespace ts {
957
959
_jsxNamespace = escapeLeadingUnderscores(compilerOptions.reactNamespace);
958
960
}
959
961
}
962
+ if (!_jsxFactoryEntity) {
963
+ _jsxFactoryEntity = createQualifiedName(createIdentifier(unescapeLeadingUnderscores(_jsxNamespace)), "createElement");
964
+ }
960
965
return _jsxNamespace;
966
+
967
+ function markAsSynthetic(node: Node): VisitResult<Node> {
968
+ node.pos = -1;
969
+ node.end = -1;
970
+ return visitEachChild(node, markAsSynthetic, nullTransformationContext);
971
+ }
961
972
}
962
973
963
974
function getEmitResolver(sourceFile: SourceFile, cancellationToken: CancellationToken) {
@@ -2801,8 +2812,8 @@ namespace ts {
2801
2812
const namespaceMeaning = SymbolFlags.Namespace | (isInJSFile(name) ? meaning & SymbolFlags.Value : 0);
2802
2813
let symbol: Symbol | undefined;
2803
2814
if (name.kind === SyntaxKind.Identifier) {
2804
- const message = meaning === namespaceMeaning ? Diagnostics.Cannot_find_namespace_0 : getCannotFindNameDiagnosticForName(getFirstIdentifier(name));
2805
- const symbolFromJSPrototype = isInJSFile(name) ? resolveEntityNameFromAssignmentDeclaration(name, meaning) : undefined;
2815
+ const message = meaning === namespaceMeaning || nodeIsSynthesized(name) ? Diagnostics.Cannot_find_namespace_0 : getCannotFindNameDiagnosticForName(getFirstIdentifier(name));
2816
+ const symbolFromJSPrototype = isInJSFile(name) && !nodeIsSynthesized(name) ? resolveEntityNameFromAssignmentDeclaration(name, meaning) : undefined;
2806
2817
symbol = resolveName(location || name, name.escapedText, meaning, ignoreErrors || symbolFromJSPrototype ? undefined : message, name, /*isUse*/ true);
2807
2818
if (!symbol) {
2808
2819
return symbolFromJSPrototype;
@@ -2845,7 +2856,7 @@ namespace ts {
2845
2856
throw Debug.assertNever(name, "Unknown entity name kind.");
2846
2857
}
2847
2858
Debug.assert((getCheckFlags(symbol) & CheckFlags.Instantiated) === 0, "Should never get an instantiated symbol here.");
2848
- if (isEntityName(name) && (symbol.flags & SymbolFlags.Alias || name.parent.kind === SyntaxKind.ExportAssignment)) {
2859
+ if (!nodeIsSynthesized(name) && isEntityName(name) && (symbol.flags & SymbolFlags.Alias || name.parent.kind === SyntaxKind.ExportAssignment)) {
2849
2860
markSymbolOfAliasDeclarationIfTypeOnly(getAliasDeclarationFromName(name), symbol, /*finalTarget*/ undefined, /*overwriteEmpty*/ true);
2850
2861
}
2851
2862
return (symbol.flags & meaning) || dontResolveAlias ? symbol : resolveAlias(symbol);
@@ -24298,7 +24309,7 @@ namespace ts {
24298
24309
// can be specified by users through attributes property.
24299
24310
const paramType = getEffectiveFirstArgumentForJsxSignature(signature, node);
24300
24311
const attributesType = checkExpressionWithContextualType(node.attributes, paramType, /*inferenceContext*/ undefined, checkMode);
24301
- return checkTypeRelatedToAndOptionallyElaborate(
24312
+ return checkTagNameDoesNotExpectTooManyArguments() && checkTypeRelatedToAndOptionallyElaborate(
24302
24313
attributesType,
24303
24314
paramType,
24304
24315
relation,
@@ -24307,6 +24318,80 @@ namespace ts {
24307
24318
/*headMessage*/ undefined,
24308
24319
containingMessageChain,
24309
24320
errorOutputContainer);
24321
+
24322
+ function checkTagNameDoesNotExpectTooManyArguments(): boolean {
24323
+ const tagType = isJsxOpeningElement(node) || isJsxSelfClosingElement(node) && !isJsxIntrinsicIdentifier(node.tagName) ? checkExpression(node.tagName) : undefined;
24324
+ if (!tagType) {
24325
+ return true;
24326
+ }
24327
+ const tagCallSignatures = getSignaturesOfType(tagType, SignatureKind.Call);
24328
+ if (!length(tagCallSignatures)) {
24329
+ return true;
24330
+ }
24331
+ const factory = getJsxFactoryEntity(node);
24332
+ if (!factory) {
24333
+ return true;
24334
+ }
24335
+ const factorySymbol = resolveEntityName(factory, SymbolFlags.Value, /*ignoreErrors*/ true, /*dontResolveAlias*/ false, node);
24336
+ if (!factorySymbol) {
24337
+ return true;
24338
+ }
24339
+
24340
+ const factoryType = getTypeOfSymbol(factorySymbol);
24341
+ const callSignatures = getSignaturesOfType(factoryType, SignatureKind.Call);
24342
+ if (!length(callSignatures)) {
24343
+ return true;
24344
+ }
24345
+
24346
+ let hasFirstParamSignatures = false;
24347
+ let maxParamCount = 0;
24348
+ // Check that _some_ first parameter expects a FC-like thing, and that some overload of the SFC expects an acceptable number of arguments
24349
+ for (const sig of callSignatures) {
24350
+ const firstparam = getTypeAtPosition(sig, 0);
24351
+ const signaturesOfParam = getSignaturesOfType(firstparam, SignatureKind.Call);
24352
+ if (!length(signaturesOfParam)) continue;
24353
+ for (const paramSig of signaturesOfParam) {
24354
+ hasFirstParamSignatures = true;
24355
+ if (hasEffectiveRestParameter(paramSig)) {
24356
+ return true; // some signature has a rest param, so function components can have an arbitrary number of arguments
24357
+ }
24358
+ const paramCount = getParameterCount(paramSig);
24359
+ if (paramCount > maxParamCount) {
24360
+ maxParamCount = paramCount;
24361
+ }
24362
+ }
24363
+ }
24364
+ if (!hasFirstParamSignatures) {
24365
+ // Not a single signature had a first parameter which expected a signature - for back compat, and
24366
+ // to guard against generic factories which won't have signatures directly, do not error
24367
+ return true;
24368
+ }
24369
+ let absoluteMinArgCount = Infinity;
24370
+ for (const tagSig of tagCallSignatures) {
24371
+ const tagRequiredArgCount = getMinArgumentCount(tagSig);
24372
+ if (tagRequiredArgCount < absoluteMinArgCount) {
24373
+ absoluteMinArgCount = tagRequiredArgCount;
24374
+ }
24375
+ }
24376
+ if (absoluteMinArgCount <= maxParamCount) {
24377
+ return true; // some signature accepts the number of arguments the function component provides
24378
+ }
24379
+
24380
+ if (reportErrors) {
24381
+ const diag = createDiagnosticForNode(node.tagName, Diagnostics.Tag_0_expects_at_least_1_arguments_but_the_JSX_factory_2_provides_at_most_3, entityNameToString(node.tagName), absoluteMinArgCount, entityNameToString(factory), maxParamCount);
24382
+ const tagNameDeclaration = getSymbolAtLocation(node.tagName)?.valueDeclaration;
24383
+ if (tagNameDeclaration) {
24384
+ addRelatedInfo(diag, createDiagnosticForNode(tagNameDeclaration, Diagnostics._0_is_declared_here, entityNameToString(node.tagName)));
24385
+ }
24386
+ if (errorOutputContainer && errorOutputContainer.skipLogging) {
24387
+ (errorOutputContainer.errors || (errorOutputContainer.errors = [])).push(diag);
24388
+ }
24389
+ if (!errorOutputContainer.skipLogging) {
24390
+ diagnostics.add(diag);
24391
+ }
24392
+ }
24393
+ return false;
24394
+ }
24310
24395
}
24311
24396
24312
24397
function getSignatureApplicabilityError(
@@ -35175,6 +35260,10 @@ namespace ts {
35175
35260
return literalTypeToNode(<FreshableType>type, node, tracker);
35176
35261
}
35177
35262
35263
+ function getJsxFactoryEntity(location: Node) {
35264
+ return location ? (getJsxNamespace(location), (getSourceFileOfNode(location).localJsxFactory || _jsxFactoryEntity)) : _jsxFactoryEntity;
35265
+ }
35266
+
35178
35267
function createResolver(): EmitResolver {
35179
35268
// this variable and functions that use it are deliberately moved here from the outer scope
35180
35269
// to avoid scope pollution
@@ -35246,7 +35335,7 @@ namespace ts {
35246
35335
const symbol = node && getSymbolOfNode(node);
35247
35336
return !!(symbol && getCheckFlags(symbol) & CheckFlags.Late);
35248
35337
},
35249
- getJsxFactoryEntity: location => location ? (getJsxNamespace(location), (getSourceFileOfNode(location).localJsxFactory || _jsxFactoryEntity)) : _jsxFactoryEntity ,
35338
+ getJsxFactoryEntity,
35250
35339
getAllAccessorDeclarations(accessor: AccessorDeclaration): AllAccessorDeclarations {
35251
35340
accessor = getParseTreeNode(accessor, isGetOrSetAccessorDeclaration)!; // TODO: GH#18217
35252
35341
const otherKind = accessor.kind === SyntaxKind.SetAccessor ? SyntaxKind.GetAccessor : SyntaxKind.SetAccessor;
0 commit comments