Skip to content

Commit aab4f07

Browse files
committed
Merge remote-tracking branch 'origin/main' into port/50372
2 parents 8031bd3 + 8cf32b4 commit aab4f07

File tree

65 files changed

+431
-1196
lines changed

Some content is hidden

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

65 files changed

+431
-1196
lines changed

internal/binder/binder.go

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,9 @@ func (b *Binder) declareSymbolAndAddToSymbolTable(node *ast.Node, symbolFlags as
443443
return b.declareClassMember(node, symbolFlags, symbolExcludes)
444444
case ast.KindEnumDeclaration:
445445
return b.declareSymbol(ast.GetExports(b.container.Symbol()), b.container.Symbol(), node, symbolFlags, symbolExcludes)
446-
case ast.KindTypeLiteral, ast.KindJSDocTypeLiteral, ast.KindObjectLiteralExpression, ast.KindInterfaceDeclaration, ast.KindJsxAttributes:
446+
case ast.KindTypeLiteral, ast.KindObjectLiteralExpression, ast.KindInterfaceDeclaration, ast.KindJsxAttributes:
447447
return b.declareSymbol(ast.GetMembers(b.container.Symbol()), b.container.Symbol(), node, symbolFlags, symbolExcludes)
448-
case ast.KindFunctionType, ast.KindConstructorType, ast.KindCallSignature, ast.KindConstructSignature, ast.KindJSDocSignature,
448+
case ast.KindFunctionType, ast.KindConstructorType, ast.KindCallSignature, ast.KindConstructSignature,
449449
ast.KindIndexSignature, ast.KindMethodDeclaration, ast.KindMethodSignature, ast.KindConstructor, ast.KindGetAccessor,
450450
ast.KindSetAccessor, ast.KindFunctionDeclaration, ast.KindFunctionExpression, ast.KindArrowFunction,
451451
ast.KindClassStaticBlockDeclaration, ast.KindTypeAliasDeclaration, ast.KindJSTypeAliasDeclaration, ast.KindMappedType:
@@ -672,10 +672,8 @@ func (b *Binder) bind(node *ast.Node) bool {
672672
case ast.KindSetAccessor:
673673
b.bindPropertyOrMethodOrAccessor(node, ast.SymbolFlagsSetAccessor, ast.SymbolFlagsSetAccessorExcludes)
674674
case ast.KindFunctionType, ast.KindConstructorType:
675-
// !!! KindJSDocSignature
676675
b.bindFunctionOrConstructorType(node)
677676
case ast.KindTypeLiteral, ast.KindMappedType:
678-
// !!! KindJSDocTypeLiteral
679677
b.bindAnonymousDeclaration(node, ast.SymbolFlagsTypeLiteral, ast.InternalSymbolNameType)
680678
case ast.KindObjectLiteralExpression:
681679
b.bindAnonymousDeclaration(node, ast.SymbolFlagsObjectLiteral, ast.InternalSymbolNameObject)
@@ -1121,10 +1119,6 @@ func (b *Binder) bindVariableDeclarationOrBindingElement(node *ast.Node) {
11211119
}
11221120

11231121
func (b *Binder) bindParameter(node *ast.Node) {
1124-
// !!!
1125-
// if node.kind == KindJSDocParameterTag && b.container.kind != KindJSDocSignature {
1126-
// return
1127-
// }
11281122
decl := node.AsParameterDeclaration()
11291123
if b.inStrictMode && node.Flags&ast.NodeFlagsAmbient == 0 {
11301124
// It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a
@@ -1190,17 +1184,6 @@ func (b *Binder) bindBlockScopedDeclaration(node *ast.Node, symbolFlags ast.Symb
11901184
}
11911185

11921186
func (b *Binder) bindTypeParameter(node *ast.Node) {
1193-
// !!!
1194-
// if isJSDocTemplateTag(node.parent) {
1195-
// var container *HasLocals = getEffectiveContainerForJSDocTemplateTag(node.parent)
1196-
// if container {
1197-
// Debug.assertNode(container, canHaveLocals)
1198-
// /* TODO(TS-TO-GO) QuestionQuestionEqualsToken BinaryExpression: container.locals ??= createSymbolTable() */ TODO
1199-
// b.declareSymbol(container.locals /*parent*/, nil, node, SymbolFlagsTypeParameter, SymbolFlagsTypeParameterExcludes)
1200-
// } else {
1201-
// b.declareSymbolAndAddToSymbolTable(node, SymbolFlagsTypeParameter, SymbolFlagsTypeParameterExcludes)
1202-
// }
1203-
// }
12041187
if node.Parent.Kind == ast.KindInferType {
12051188
container := b.getInferTypeContainer(node.Parent)
12061189
if container != nil {
@@ -1633,10 +1616,6 @@ func (b *Binder) bindChildren(node *ast.Node) {
16331616
b.bindCallExpressionFlow(node)
16341617
case ast.KindNonNullExpression:
16351618
b.bindNonNullExpressionFlow(node)
1636-
// case *JSDocTypedefTag, *JSDocCallbackTag, *JSDocEnumTag:
1637-
// b.bindJSDocTypeAlias(node)
1638-
// case *JSDocImportTag:
1639-
// b.bindJSDocImportTag(node)
16401619
case ast.KindSourceFile:
16411620
sourceFile := node.AsSourceFile()
16421621
b.bindEachStatementFunctionsFirst(sourceFile.Statements)
@@ -2565,7 +2544,7 @@ func SetValueDeclaration(symbol *ast.Symbol, node *ast.Node) {
25652544
func GetContainerFlags(node *ast.Node) ContainerFlags {
25662545
switch node.Kind {
25672546
case ast.KindClassExpression, ast.KindClassDeclaration, ast.KindEnumDeclaration, ast.KindObjectLiteralExpression, ast.KindTypeLiteral,
2568-
ast.KindJSDocTypeLiteral, ast.KindJsxAttributes:
2547+
ast.KindJsxAttributes:
25692548
return ContainerFlagsIsContainer
25702549
case ast.KindInterfaceDeclaration:
25712550
return ContainerFlagsIsContainer | ContainerFlagsIsInterface
@@ -2580,7 +2559,7 @@ func GetContainerFlags(node *ast.Node) ContainerFlags {
25802559
fallthrough
25812560
case ast.KindConstructor, ast.KindClassStaticBlockDeclaration:
25822561
return ContainerFlagsIsContainer | ContainerFlagsIsControlFlowContainer | ContainerFlagsHasLocals | ContainerFlagsIsFunctionLike | ContainerFlagsIsThisContainer
2583-
case ast.KindMethodSignature, ast.KindCallSignature, ast.KindJSDocSignature, ast.KindFunctionType, ast.KindConstructSignature, ast.KindConstructorType:
2562+
case ast.KindMethodSignature, ast.KindCallSignature, ast.KindFunctionType, ast.KindConstructSignature, ast.KindConstructorType:
25842563
return ContainerFlagsIsContainer | ContainerFlagsIsControlFlowContainer | ContainerFlagsHasLocals | ContainerFlagsIsFunctionLike
25852564
case ast.KindFunctionDeclaration:
25862565
return ContainerFlagsIsContainer | ContainerFlagsIsControlFlowContainer | ContainerFlagsHasLocals | ContainerFlagsIsFunctionLike | ContainerFlagsIsThisContainer
@@ -2617,9 +2596,6 @@ func isNarrowingExpression(expr *ast.Node) bool {
26172596
case ast.KindCallExpression:
26182597
return hasNarrowableArgument(expr)
26192598
case ast.KindParenthesizedExpression:
2620-
// if isJSDocTypeAssertion(expr) {
2621-
// return false
2622-
// }
26232599
return isNarrowingExpression(expr.AsParenthesizedExpression().Expression)
26242600
case ast.KindNonNullExpression:
26252601
return isNarrowingExpression(expr.AsNonNullExpression().Expression)

internal/checker/checker.go

Lines changed: 53 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10592,7 +10592,7 @@ func (c *Checker) checkIdentifier(node *ast.Node, checkMode CheckMode) *Type {
1059210592
return c.errorType
1059310593
}
1059410594
if symbol == c.argumentsSymbol {
10595-
if c.isInPropertyInitializerOrClassStaticBlock(node) {
10595+
if c.isInPropertyInitializerOrClassStaticBlock(node, true /*ignoreArrowFunctions*/) {
1059610596
c.error(node, diagnostics.X_arguments_cannot_be_referenced_in_property_initializers_or_class_static_initialization_blocks)
1059710597
return c.errorType
1059810598
}
@@ -11224,7 +11224,7 @@ func (c *Checker) checkPropertyNotUsedBeforeDeclaration(prop *ast.Symbol, node *
1122411224
}
1122511225
var diagnostic *ast.Diagnostic
1122611226
declarationName := right.Text()
11227-
if c.isInPropertyInitializerOrClassStaticBlock(node) &&
11227+
if c.isInPropertyInitializerOrClassStaticBlock(node, false /*ignoreArrowFunctions*/) &&
1122811228
!c.isOptionalPropertyDeclaration(valueDeclaration) &&
1122911229
!(ast.IsAccessExpression(node) && ast.IsAccessExpression(node.Expression())) &&
1123011230
!c.isBlockScopedNameDeclaredBeforeUse(valueDeclaration, right) &&
@@ -12415,17 +12415,32 @@ func (c *Checker) checkNullishCoalesceOperands(left *ast.Node, right *ast.Node)
1241512415
if ast.IsBinaryExpression(right) && ast.IsLogicalBinaryOperator(right.AsBinaryExpression().OperatorToken.Kind) {
1241612416
c.grammarErrorOnNode(right, diagnostics.X_0_and_1_operations_cannot_be_mixed_without_parentheses, scanner.TokenToString(right.AsBinaryExpression().OperatorToken.Kind), scanner.TokenToString(ast.KindQuestionQuestionToken))
1241712417
}
12418+
c.checkNullishCoalesceOperandLeft(left)
12419+
c.checkNullishCoalesceOperandRight(right)
12420+
}
12421+
12422+
func (c *Checker) checkNullishCoalesceOperandLeft(left *ast.Node) {
1241812423
leftTarget := ast.SkipOuterExpressions(left, ast.OEKAll)
1241912424
nullishSemantics := c.getSyntacticNullishnessSemantics(leftTarget)
1242012425
if nullishSemantics != PredicateSemanticsSometimes {
12421-
if left.Parent.Parent.Kind == ast.KindBinaryExpression {
12422-
c.error(leftTarget, diagnostics.This_binary_expression_is_never_nullish_Are_you_missing_parentheses)
12426+
if nullishSemantics == PredicateSemanticsAlways {
12427+
c.error(leftTarget, diagnostics.This_expression_is_always_nullish)
1242312428
} else {
12424-
if nullishSemantics == PredicateSemanticsAlways {
12425-
c.error(leftTarget, diagnostics.This_expression_is_always_nullish)
12426-
} else {
12427-
c.error(leftTarget, diagnostics.Right_operand_of_is_unreachable_because_the_left_operand_is_never_nullish)
12428-
}
12429+
c.error(leftTarget, diagnostics.Right_operand_of_is_unreachable_because_the_left_operand_is_never_nullish)
12430+
}
12431+
}
12432+
}
12433+
12434+
func (c *Checker) checkNullishCoalesceOperandRight(right *ast.Node) {
12435+
binaryExpression := right.Parent
12436+
if binaryExpression.Parent != nil && ast.IsBinaryExpression(binaryExpression.Parent) && binaryExpression.Parent.AsBinaryExpression().OperatorToken.Kind == ast.KindQuestionQuestionToken {
12437+
rightTarget := ast.SkipOuterExpressions(right, ast.OEKAll)
12438+
nullishSemantics := c.getSyntacticNullishnessSemantics(rightTarget)
12439+
switch nullishSemantics {
12440+
case PredicateSemanticsAlways:
12441+
c.error(rightTarget, diagnostics.This_expression_is_always_nullish)
12442+
case PredicateSemanticsNever:
12443+
c.error(rightTarget, diagnostics.This_expression_is_never_nullish)
1242912444
}
1243012445
}
1243112446
}
@@ -13145,25 +13160,19 @@ func (c *Checker) checkShorthandPropertyAssignment(node *ast.Node, inDestructuri
1314513160
return expressionType
1314613161
}
1314713162

13148-
func (c *Checker) isInPropertyInitializerOrClassStaticBlock(node *ast.Node) bool {
13163+
func (c *Checker) isInPropertyInitializerOrClassStaticBlock(node *ast.Node, ignoreArrowFunctions bool) bool {
1314913164
return ast.FindAncestorOrQuit(node, func(node *ast.Node) ast.FindAncestorResult {
1315013165
switch node.Kind {
13151-
case ast.KindPropertyDeclaration:
13166+
case ast.KindPropertyDeclaration, ast.KindClassStaticBlockDeclaration:
1315213167
return ast.FindAncestorTrue
13153-
case ast.KindPropertyAssignment, ast.KindMethodDeclaration, ast.KindGetAccessor, ast.KindSetAccessor, ast.KindSpreadAssignment,
13154-
ast.KindComputedPropertyName, ast.KindTemplateSpan, ast.KindJsxExpression, ast.KindJsxAttribute, ast.KindJsxAttributes,
13155-
ast.KindJsxSpreadAttribute, ast.KindJsxOpeningElement, ast.KindExpressionWithTypeArguments, ast.KindHeritageClause:
13156-
return ast.FindAncestorFalse
13157-
case ast.KindArrowFunction, ast.KindExpressionStatement:
13158-
if ast.IsBlock(node.Parent) && ast.IsClassStaticBlockDeclaration(node.Parent.Parent) {
13159-
return ast.FindAncestorTrue
13160-
}
13168+
case ast.KindTypeQuery, ast.KindJsxClosingElement:
1316113169
return ast.FindAncestorQuit
13170+
case ast.KindArrowFunction:
13171+
return core.IfElse(ignoreArrowFunctions, ast.FindAncestorFalse, ast.FindAncestorQuit)
13172+
case ast.KindBlock:
13173+
return core.IfElse(ast.IsFunctionLikeDeclaration(node.Parent) && node.Parent.Kind != ast.KindArrowFunction, ast.FindAncestorQuit, ast.FindAncestorFalse)
1316213174
default:
13163-
if ast.IsExpressionNode(node) {
13164-
return ast.FindAncestorFalse
13165-
}
13166-
return ast.FindAncestorQuit
13175+
return ast.FindAncestorFalse
1316713176
}
1316813177
}) != nil
1316913178
}
@@ -15409,9 +15418,7 @@ func (c *Checker) addDeclarationToLateBoundSymbol(symbol *ast.Symbol, member *as
1540915418
symbol.Declarations = append(symbol.Declarations, member)
1541015419
}
1541115420
if symbolFlags&ast.SymbolFlagsValue != 0 {
15412-
if symbol.ValueDeclaration == nil || symbol.ValueDeclaration.Kind != member.Kind {
15413-
symbol.ValueDeclaration = member
15414-
}
15421+
binder.SetValueDeclaration(symbol, member)
1541515422
}
1541615423
}
1541715424

@@ -15716,14 +15723,14 @@ func (c *Checker) getWriteTypeOfSymbolWithDeferredType(symbol *ast.Symbol) *Type
1571615723
// properties deriving from set accessors will either pre-compute or defer the union or
1571715724
// intersection of the writeTypes of their constituents.
1571815725
func (c *Checker) getWriteTypeOfSymbol(symbol *ast.Symbol) *Type {
15719-
if symbol.Flags&ast.SymbolFlagsProperty != 0 {
15720-
if symbol.CheckFlags&ast.CheckFlagsSyntheticProperty != 0 {
15721-
if symbol.CheckFlags&ast.CheckFlagsDeferredType != 0 {
15722-
return c.getWriteTypeOfSymbolWithDeferredType(symbol)
15723-
}
15724-
links := c.valueSymbolLinks.Get(symbol)
15725-
return core.OrElse(links.writeType, links.resolvedType)
15726+
if symbol.CheckFlags&ast.CheckFlagsSyntheticProperty != 0 {
15727+
if symbol.CheckFlags&ast.CheckFlagsDeferredType != 0 {
15728+
return c.getWriteTypeOfSymbolWithDeferredType(symbol)
1572615729
}
15730+
links := c.valueSymbolLinks.Get(symbol)
15731+
return core.OrElse(links.writeType, links.resolvedType)
15732+
}
15733+
if symbol.Flags&ast.SymbolFlagsProperty != 0 {
1572715734
return c.removeMissingType(c.getTypeOfSymbol(symbol), symbol.Flags&ast.SymbolFlagsOptional != 0)
1572815735
}
1572915736
if symbol.Flags&ast.SymbolFlagsAccessor != 0 {
@@ -20614,6 +20621,7 @@ func (c *Checker) getUnionOrIntersectionProperty(t *Type, name string, skipObjec
2061420621
}
2061520622

2061620623
func (c *Checker) createUnionOrIntersectionProperty(containingType *Type, name string, skipObjectFunctionPropertyAugment bool) *ast.Symbol {
20624+
propFlags := ast.SymbolFlagsNone
2061720625
var singleProp *ast.Symbol
2061820626
var propSet collections.OrderedSet[*ast.Symbol]
2061920627
var indexTypes []*Type
@@ -20643,6 +20651,7 @@ func (c *Checker) createUnionOrIntersectionProperty(containingType *Type, name s
2064320651
}
2064420652
if singleProp == nil {
2064520653
singleProp = prop
20654+
propFlags = core.OrElse(prop.Flags&ast.SymbolFlagsAccessor, ast.SymbolFlagsProperty)
2064620655
} else if prop != singleProp {
2064720656
isInstantiation := c.getTargetSymbol(prop) == c.getTargetSymbol(singleProp)
2064820657
// If the symbols are instances of one another with identical types - consider the symbols
@@ -20659,6 +20668,13 @@ func (c *Checker) createUnionOrIntersectionProperty(containingType *Type, name s
2065920668
}
2066020669
propSet.Add(prop)
2066120670
}
20671+
// classes created by mixins are represented as intersections
20672+
// and overriding a property in a derived class redefines it completely at runtime
20673+
// so a get accessor can't be merged with a set accessor in a base class,
20674+
// for that reason the accessor flags are only used when they are the same in all constituents
20675+
if propFlags&ast.SymbolFlagsAccessor != 0 && (prop.Flags&ast.SymbolFlagsAccessor != (propFlags & ast.SymbolFlagsAccessor)) {
20676+
propFlags = (propFlags &^ ast.SymbolFlagsAccessor) | ast.SymbolFlagsProperty
20677+
}
2066220678
}
2066320679
if isUnion && c.isReadonlySymbol(prop) {
2066420680
checkFlags |= ast.CheckFlagsReadonly
@@ -20686,6 +20702,7 @@ func (c *Checker) createUnionOrIntersectionProperty(containingType *Type, name s
2068620702
indexInfo = c.getApplicableIndexInfoForName(t, name)
2068720703
}
2068820704
if indexInfo != nil {
20705+
propFlags = propFlags&^ast.SymbolFlagsAccessor | ast.SymbolFlagsProperty
2068920706
checkFlags |= ast.CheckFlagsWritePartial | (core.IfElse(indexInfo.isReadonly, ast.CheckFlagsReadonly, 0))
2069020707
if isTupleType(t) {
2069120708
indexType := c.getRestTypeOfTupleType(t)
@@ -20778,7 +20795,7 @@ func (c *Checker) createUnionOrIntersectionProperty(containingType *Type, name s
2077820795
propTypes = append(propTypes, t)
2077920796
}
2078020797
propTypes = append(propTypes, indexTypes...)
20781-
result := c.newSymbolEx(ast.SymbolFlagsProperty|optionalFlag, name, checkFlags|syntheticFlag)
20798+
result := c.newSymbolEx(propFlags|optionalFlag, name, checkFlags|syntheticFlag)
2078220799
result.Declarations = declarations
2078320800
if !hasNonUniformValueDeclaration && firstValueDeclaration != nil {
2078420801
result.ValueDeclaration = firstValueDeclaration
@@ -23075,6 +23092,8 @@ func (c *Checker) computeEnumMemberValues(node *ast.Node) {
2307523092
func (c *Checker) computeEnumMemberValue(member *ast.Node, autoValue jsnum.Number, previous *ast.Node) evaluator.Result {
2307623093
if ast.IsComputedNonLiteralName(member.Name()) {
2307723094
c.error(member.Name(), diagnostics.Computed_property_names_are_not_allowed_in_enums)
23095+
} else if ast.IsBigIntLiteral(member.Name()) {
23096+
c.error(member.Name(), diagnostics.An_enum_member_cannot_have_a_numeric_name)
2307823097
} else {
2307923098
text := ast.GetTextOfPropertyName(member.Name())
2308023099
if isNumericLiteralName(text) && !isInfinityOrNaNString(text) {

internal/checker/emitresolver.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,14 @@ func (r *emitResolver) hasVisibleDeclarations(symbol *ast.Symbol, shouldComputeA
409409
continue
410410
}
411411
if symbol.Flags&ast.SymbolFlagsBlockScopedVariable != 0 {
412-
variableStatement := ast.FindAncestor(declaration, ast.IsVariableStatement)
412+
rootDeclaration := ast.WalkUpBindingElementsAndPatterns(declaration)
413+
if ast.IsParameter(rootDeclaration) {
414+
return nil
415+
}
416+
variableStatement := rootDeclaration.Parent.Parent
417+
if !ast.IsVariableStatement(variableStatement) {
418+
return nil
419+
}
413420
if ast.HasSyntacticModifier(variableStatement, ast.ModifierFlagsExport) {
414421
continue // no alias to add, already exported
415422
}

internal/checker/grammarchecks.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (c *Checker) grammarErrorAtPos(nodeForSourceFile *ast.Node, start int, leng
3737
func (c *Checker) grammarErrorOnNode(node *ast.Node, message *diagnostics.Message, args ...any) bool {
3838
sourceFile := ast.GetSourceFileOfNode(node)
3939
if !c.hasParseDiagnostics(sourceFile) {
40-
c.diagnostics.Add(NewDiagnosticForNode(node, message, args...))
40+
c.error(node, message, args...)
4141
return true
4242
}
4343
return false
@@ -1700,8 +1700,13 @@ func (c *Checker) checkGrammarVariableDeclarationList(declarationList *ast.Varia
17001700
}
17011701

17021702
blockScopeFlags := declarationList.Flags & ast.NodeFlagsBlockScoped
1703-
if (blockScopeFlags == ast.NodeFlagsUsing || blockScopeFlags == ast.NodeFlagsAwaitUsing) && ast.IsForInStatement(declarationList.Parent) {
1704-
return c.grammarErrorOnNode(declarationList.AsNode(), core.IfElse(blockScopeFlags == ast.NodeFlagsUsing, diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_using_declaration, diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_an_await_using_declaration))
1703+
if blockScopeFlags == ast.NodeFlagsUsing || blockScopeFlags == ast.NodeFlagsAwaitUsing {
1704+
if ast.IsForInStatement(declarationList.Parent) {
1705+
return c.grammarErrorOnNode(declarationList.AsNode(), core.IfElse(blockScopeFlags == ast.NodeFlagsUsing, diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_using_declaration, diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_an_await_using_declaration))
1706+
}
1707+
if declarationList.Flags&ast.NodeFlagsAmbient != 0 {
1708+
return c.grammarErrorOnNode(declarationList.AsNode(), core.IfElse(blockScopeFlags == ast.NodeFlagsUsing, diagnostics.X_using_declarations_are_not_allowed_in_ambient_contexts, diagnostics.X_await_using_declarations_are_not_allowed_in_ambient_contexts))
1709+
}
17051710
}
17061711

17071712
if blockScopeFlags == ast.NodeFlagsAwaitUsing {
@@ -1841,7 +1846,7 @@ func (c *Checker) checkGrammarForDisallowedBlockScopedVariableStatement(node *as
18411846
default:
18421847
panic("Unknown BlockScope flag")
18431848
}
1844-
return c.grammarErrorOnNode(node.AsNode(), diagnostics.X_0_declarations_can_only_be_declared_inside_a_block, keyword)
1849+
c.error(node.AsNode(), diagnostics.X_0_declarations_can_only_be_declared_inside_a_block, keyword)
18451850
}
18461851
}
18471852

@@ -2140,7 +2145,8 @@ func (c *Checker) checkGrammarNumericLiteral(node *ast.NumericLiteral) {
21402145
func (c *Checker) checkGrammarBigIntLiteral(node *ast.BigIntLiteral) bool {
21412146
literalType := ast.IsLiteralTypeNode(node.Parent) || ast.IsPrefixUnaryExpression(node.Parent) && ast.IsLiteralTypeNode(node.Parent.Parent)
21422147
if !literalType {
2143-
if c.languageVersion < core.ScriptTargetES2020 {
2148+
// Don't error on BigInt literals in ambient contexts
2149+
if node.Flags&ast.NodeFlagsAmbient == 0 && c.languageVersion < core.ScriptTargetES2020 {
21442150
if c.grammarErrorOnNode(node.AsNode(), diagnostics.BigInt_literals_are_not_available_when_targeting_lower_than_ES2020) {
21452151
return true
21462152
}

0 commit comments

Comments
 (0)