@@ -701,6 +701,7 @@ type Checker struct {
701
701
permissiveMapper *TypeMapper
702
702
emptyObjectType *Type
703
703
emptyJsxObjectType *Type
704
+ emptyFreshJsxObjectType *Type
704
705
emptyTypeLiteralType *Type
705
706
unknownEmptyObjectType *Type
706
707
unknownUnionType *Type
@@ -967,6 +968,7 @@ func NewChecker(program Program) *Checker {
967
968
c.permissiveMapper = newFunctionTypeMapper(c.permissiveMapperWorker)
968
969
c.emptyObjectType = c.newAnonymousType(nil /*symbol*/, nil, nil, nil, nil)
969
970
c.emptyJsxObjectType = c.newAnonymousType(nil /*symbol*/, nil, nil, nil, nil)
971
+ c.emptyFreshJsxObjectType = c.newAnonymousType(nil /*symbol*/, nil, nil, nil, nil)
970
972
c.emptyTypeLiteralType = c.newAnonymousType(c.newSymbol(ast.SymbolFlagsTypeLiteral, ast.InternalSymbolNameType), nil, nil, nil, nil)
971
973
c.unknownEmptyObjectType = c.newAnonymousType(nil /*symbol*/, nil, nil, nil, nil)
972
974
c.unknownUnionType = c.createUnknownUnionType()
@@ -8057,7 +8059,7 @@ func (c *Checker) resolveSignature(node *ast.Node, candidatesOutArray *[]*Signat
8057
8059
return c.resolveTaggedTemplateExpression(node, candidatesOutArray, checkMode)
8058
8060
case ast.KindDecorator:
8059
8061
return c.resolveDecorator(node, candidatesOutArray, checkMode)
8060
- case ast.KindJsxOpeningElement, ast.KindJsxSelfClosingElement:
8062
+ case ast.KindJsxOpeningFragment, ast. KindJsxOpeningElement, ast.KindJsxSelfClosingElement:
8061
8063
return c.resolveJsxOpeningLikeElement(node, candidatesOutArray, checkMode)
8062
8064
case ast.KindBinaryExpression:
8063
8065
return c.resolveInstanceofExpression(node, candidatesOutArray, checkMode)
@@ -8435,7 +8437,7 @@ func (c *Checker) resolveCall(node *ast.Node, signatures []*Signature, candidate
8435
8437
reportErrors := !c.isInferencePartiallyBlocked && candidatesOutArray == nil
8436
8438
var s CallState
8437
8439
s.node = node
8438
- if !isDecorator && !isInstanceof && !isSuperCall(node) {
8440
+ if !isDecorator && !isInstanceof && !isSuperCall(node) && !ast.IsJsxOpeningFragment(node) {
8439
8441
s.typeArguments = node.TypeArguments()
8440
8442
// We already perform checking on the type arguments on the class declaration itself.
8441
8443
if isTaggedTemplate || isJsxOpeningOrSelfClosingElement || node.Expression().Kind != ast.KindSuperKeyword {
@@ -8529,7 +8531,7 @@ func (c *Checker) resolveCall(node *ast.Node, signatures []*Signature, candidate
8529
8531
if headMessage == nil && isInstanceof {
8530
8532
headMessage = diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_assignable_to_the_first_argument_of_the_right_hand_side_s_Symbol_hasInstance_method
8531
8533
}
8532
- c.reportCallResolutionErrors(&s, signatures, headMessage)
8534
+ c.reportCallResolutionErrors(node, &s, signatures, headMessage)
8533
8535
}
8534
8536
return result
8535
8537
}
@@ -8711,6 +8713,9 @@ func (c *Checker) getImplementationSignature(signature *Signature) *Signature {
8711
8713
}
8712
8714
8713
8715
func (c *Checker) hasCorrectArity(node *ast.Node, args []*ast.Node, signature *Signature, signatureHelpTrailingComma bool) bool {
8716
+ if ast.IsJsxOpeningFragment(node) {
8717
+ return true
8718
+ }
8714
8719
var argCount int
8715
8720
callIsIncomplete := false
8716
8721
// In incomplete call we want to be lenient when we have too few arguments
@@ -8856,8 +8861,8 @@ func (c *Checker) checkTypeArguments(signature *Signature, typeArgumentNodes []*
8856
8861
}
8857
8862
8858
8863
func (c *Checker) isSignatureApplicable(node *ast.Node, args []*ast.Node, signature *Signature, relation *Relation, checkMode CheckMode, reportErrors bool, inferenceContext *InferenceContext, diagnosticOutput *[]*ast.Diagnostic) bool {
8859
- if ast.IsJsxOpeningLikeElement (node) {
8860
- return c.checkApplicableSignatureForJsxOpeningLikeElement (node, signature, relation, checkMode, reportErrors, diagnosticOutput)
8864
+ if ast.IsJsxCallLike (node) {
8865
+ return c.checkApplicableSignatureForJsxCallLikeElement (node, signature, relation, checkMode, reportErrors, diagnosticOutput)
8861
8866
}
8862
8867
thisType := c.getThisTypeOfSignature(signature)
8863
8868
if thisType != nil && thisType != c.voidType && !(ast.IsNewExpression(node) || ast.IsCallExpression(node) && isSuperProperty(node.Expression())) {
@@ -9251,7 +9256,7 @@ func (c *Checker) tryGetRestTypeOfSignature(signature *Signature) *Type {
9251
9256
return c.getIndexTypeOfType(restType, c.numberType)
9252
9257
}
9253
9258
9254
- func (c *Checker) reportCallResolutionErrors(s *CallState, signatures []*Signature, headMessage *diagnostics.Message) {
9259
+ func (c *Checker) reportCallResolutionErrors(node *ast.Node, s *CallState, signatures []*Signature, headMessage *diagnostics.Message) {
9255
9260
switch {
9256
9261
case len(s.candidatesForArgumentError) != 0:
9257
9262
last := s.candidatesForArgumentError[len(s.candidatesForArgumentError)-1]
@@ -9275,7 +9280,7 @@ func (c *Checker) reportCallResolutionErrors(s *CallState, signatures []*Signatu
9275
9280
c.diagnostics.Add(c.getArgumentArityError(s.node, []*Signature{s.candidateForArgumentArityError}, s.args, headMessage))
9276
9281
case s.candidateForTypeArgumentError != nil:
9277
9282
c.checkTypeArguments(s.candidateForTypeArgumentError, s.node.TypeArguments(), true /*reportErrors*/, headMessage)
9278
- default :
9283
+ case !ast.IsJsxOpeningFragment(node) :
9279
9284
signaturesWithCorrectTypeArgumentArity := core.Filter(signatures, func(sig *Signature) bool {
9280
9285
return c.hasCorrectTypeArgumentArity(sig, s.typeArguments)
9281
9286
})
@@ -26940,10 +26945,15 @@ func (c *Checker) markJsxAliasReferenced(node *ast.Node /*JsxOpeningLikeElement
26940
26945
if ast.IsJsxOpeningLikeElement(node) {
26941
26946
jsxFactoryLocation = node.TagName()
26942
26947
}
26943
- // allow null as jsxFragmentFactory
26948
+ shouldFactoryRefErr := c.compilerOptions.Jsx != core.JsxEmitPreserve && c.compilerOptions.Jsx != core.JsxEmitReactNative
26949
+ // #38720/60122, allow null as jsxFragmentFactory
26944
26950
var jsxFactorySym *ast.Symbol
26945
26951
if !(ast.IsJsxOpeningFragment(node) && jsxFactoryNamespace == "null") {
26946
- jsxFactorySym = c.resolveName(jsxFactoryLocation, jsxFactoryNamespace, ast.SymbolFlagsValue, jsxFactoryRefErr, true /*isUse*/, false /*excludeGlobals*/)
26952
+ flags := ast.SymbolFlagsValue
26953
+ if !shouldFactoryRefErr {
26954
+ flags &= ^ast.SymbolFlagsEnum
26955
+ }
26956
+ jsxFactorySym = c.resolveName(jsxFactoryLocation, jsxFactoryNamespace, flags, jsxFactoryRefErr, true /*isUse*/, false /*excludeGlobals*/)
26947
26957
}
26948
26958
if jsxFactorySym != nil {
26949
26959
// Mark local symbol as referenced here because it might not have been marked
@@ -26954,12 +26964,16 @@ func (c *Checker) markJsxAliasReferenced(node *ast.Node /*JsxOpeningLikeElement
26954
26964
c.markAliasSymbolAsReferenced(jsxFactorySym)
26955
26965
}
26956
26966
}
26957
- // For JsxFragment, mark jsx pragma as referenced via resolveName
26967
+ // if JsxFragment, additionally mark jsx pragma as referenced, since `getJsxNamespace` above would have resolved to only the fragment factory if they are distinct
26958
26968
if ast.IsJsxOpeningFragment(node) {
26959
26969
file := ast.GetSourceFileOfNode(node)
26960
26970
localJsxNamespace := c.getLocalJsxNamespace(file)
26961
26971
if localJsxNamespace != "" {
26962
- c.resolveName(jsxFactoryLocation, localJsxNamespace, ast.SymbolFlagsValue, jsxFactoryRefErr, true /*isUse*/, false /*excludeGlobals*/)
26972
+ flags := ast.SymbolFlagsValue
26973
+ if !shouldFactoryRefErr {
26974
+ flags &= ^ast.SymbolFlagsEnum
26975
+ }
26976
+ c.resolveName(jsxFactoryLocation, localJsxNamespace, flags, jsxFactoryRefErr, true /*isUse*/, false /*excludeGlobals*/)
26963
26977
}
26964
26978
}
26965
26979
}
@@ -28218,6 +28232,9 @@ func (c *Checker) getContextualImportAttributeType(node *ast.Node) *Type {
28218
28232
// Returns the effective arguments for an expression that works like a function invocation.
28219
28233
func (c *Checker) getEffectiveCallArguments(node *ast.Node) []*ast.Node {
28220
28234
switch {
28235
+ case ast.IsJsxOpeningFragment(node):
28236
+ // This attributes Type does not include a children property yet, the same way a fragment created with <React.Fragment> does not at this stage
28237
+ return []*ast.Node{c.createSyntheticExpression(node, c.emptyFreshJsxObjectType, false, nil)}
28221
28238
case ast.IsTaggedTemplateExpression(node):
28222
28239
template := node.AsTaggedTemplateExpression().Template
28223
28240
firstArg := c.createSyntheticExpression(template, c.getGlobalTemplateStringsArrayType(), false, nil)
0 commit comments