@@ -17,6 +17,7 @@ import (
17
17
"github.com/microsoft/typescript-go/internal/binder"
18
18
"github.com/microsoft/typescript-go/internal/collections"
19
19
"github.com/microsoft/typescript-go/internal/core"
20
+ "github.com/microsoft/typescript-go/internal/debug"
20
21
"github.com/microsoft/typescript-go/internal/diagnostics"
21
22
"github.com/microsoft/typescript-go/internal/evaluator"
22
23
"github.com/microsoft/typescript-go/internal/jsnum"
@@ -1542,7 +1543,7 @@ func (c *Checker) checkAndReportErrorForUsingTypeAsNamespace(errorLocation *ast.
1542
1543
if symbol != nil {
1543
1544
parent := errorLocation.Parent
1544
1545
if ast.IsQualifiedName(parent) {
1545
- // Debug.assert (parent.Left == errorLocation, "Should only be resolving left side of qualified name as a namespace")
1546
+ debug.Assert (parent.AsQualifiedName() .Left == errorLocation, "Should only be resolving left side of qualified name as a namespace")
1546
1547
propName := parent.AsQualifiedName().Right.Text()
1547
1548
propType := c.getPropertyOfType(c.getDeclaredTypeOfSymbol(symbol), propName)
1548
1549
if propType != nil {
@@ -1787,7 +1788,7 @@ func (c *Checker) onSuccessfullyResolvedSymbol(errorLocation *ast.Node, result *
1787
1788
}
1788
1789
1789
1790
func (c *Checker) checkResolvedBlockScopedVariable(result *ast.Symbol, errorLocation *ast.Node) {
1790
- // Debug.assert(!!( result.flags &ast.SymbolFlagsBlockScopedVariable || result.flags &ast.SymbolFlagsClass || result.flags &ast.SymbolFlagsEnum) )
1791
+ debug.Assert( result.Flags &ast.SymbolFlagsBlockScopedVariable != 0 || result.Flags &ast.SymbolFlagsClass != 0 || result.Flags &ast.SymbolFlagsEnum != 0 )
1791
1792
if result.Flags&(ast.SymbolFlagsFunction|ast.SymbolFlagsFunctionScopedVariable|ast.SymbolFlagsAssignment) != 0 && result.Flags&ast.SymbolFlagsClass != 0 {
1792
1793
// constructor functions aren't block scoped
1793
1794
return
@@ -1809,7 +1810,7 @@ func (c *Checker) checkResolvedBlockScopedVariable(result *ast.Symbol, errorLoca
1809
1810
} else if result.Flags&ast.SymbolFlagsRegularEnum != 0 {
1810
1811
diagnostic = c.error(errorLocation, diagnostics.Enum_0_used_before_its_declaration, declarationName)
1811
1812
} else {
1812
- // Debug.assert(!!( result.flags & ast.SymbolFlagsConstEnum) )
1813
+ debug.Assert( result.Flags& ast.SymbolFlagsConstEnum != 0 )
1813
1814
if c.compilerOptions.GetIsolatedModules() {
1814
1815
diagnostic = c.error(errorLocation, diagnostics.Enum_0_used_before_its_declaration, declarationName)
1815
1816
}
@@ -2045,7 +2046,7 @@ func (c *Checker) getTypeOnlyAliasDeclarationEx(symbol *ast.Symbol, include ast.
2045
2046
}
2046
2047
2047
2048
func (c *Checker) getImmediateAliasedSymbol(symbol *ast.Symbol) *ast.Symbol {
2048
- // Debug.assert(( symbol.flags& SymbolFlagsAlias) != 0, "Should only get Alias here.")
2049
+ debug.Assert( symbol.Flags&ast. SymbolFlagsAlias != 0, "Should only get Alias here.")
2049
2050
links := c.aliasSymbolLinks.Get(symbol)
2050
2051
if links.immediateTarget == nil {
2051
2052
node := c.getDeclarationOfAliasSymbol(symbol)
@@ -6439,7 +6440,7 @@ func (c *Checker) checkAliasSymbol(node *ast.Node) {
6439
6440
switch node.Kind {
6440
6441
case ast.KindImportClause, ast.KindImportSpecifier, ast.KindImportEqualsDeclaration:
6441
6442
if c.compilerOptions.VerbatimModuleSyntax.IsTrue() {
6442
- // Debug.assertIsDefined (node.Name, "An ImportClause with a symbol should have a name")
6443
+ debug.AssertIsDefined (node.Name() , "An ImportClause with a symbol should have a name")
6443
6444
var message *diagnostics.Message
6444
6445
switch {
6445
6446
case c.compilerOptions.VerbatimModuleSyntax.IsTrue() && ast.IsInternalModuleImportEqualsDeclaration(node):
@@ -6934,7 +6935,7 @@ func (c *Checker) checkUnusedRenamedBindingElements() {
6934
6935
for _, node := range c.renamedBindingElementsInTypes {
6935
6936
if c.symbolReferenceLinks.Get(c.getSymbolOfDeclaration(node)).referenceKinds == 0 {
6936
6937
wrappingDeclaration := ast.WalkUpBindingElementsAndPatterns(node)
6937
- // Debug.assert(isPartOfParameterDeclaration (wrappingDeclaration), "Only parameter declaration should be checked here")
6938
+ debug.Assert(ast.IsPartOfParameterDeclaration (wrappingDeclaration), "Only parameter declaration should be checked here")
6938
6939
diagnostic := NewDiagnosticForNode(node.Name(), diagnostics.X_0_is_an_unused_renaming_of_1_Did_you_intend_to_use_it_as_a_type_annotation, scanner.DeclarationNameToString(node.Name()), scanner.DeclarationNameToString(node.PropertyName()))
6939
6940
if wrappingDeclaration.Type() == nil {
6940
6941
// entire parameter does not have type annotation, suggest adding an annotation
@@ -7201,7 +7202,7 @@ func (c *Checker) checkConstEnumAccess(node *ast.Node, t *Type) {
7201
7202
// resolve to an import, because imports of ambient const enums get checked
7202
7203
// separately in `checkAliasSymbol`.
7203
7204
if c.compilerOptions.IsolatedModules.IsTrue() || c.compilerOptions.VerbatimModuleSyntax.IsTrue() && ok && c.resolveName(node, ast.GetFirstIdentifier(node).Text(), ast.SymbolFlagsAlias, nil, false, true) == nil {
7204
- // Debug.assert (t.symbol.Flags&ast.SymbolFlagsConstEnum != 0)
7205
+ debug.Assert (t.symbol.Flags&ast.SymbolFlagsConstEnum != 0)
7205
7206
constEnumDeclaration := t.symbol.ValueDeclaration
7206
7207
redirect := c.program.GetSourceAndProjectReference(ast.GetSourceFileOfNode(constEnumDeclaration).Path())
7207
7208
if constEnumDeclaration.Flags&ast.NodeFlagsAmbient != 0 && !ast.IsValidTypeOnlyAliasUseSite(node) && (redirect == nil || !redirect.Resolved.CompilerOptions().ShouldPreserveConstEnums()) {
@@ -8926,7 +8927,7 @@ func (c *Checker) checkTypeArguments(signature *Signature, typeArgumentNodes []*
8926
8927
typeArgumentTypes := c.fillMissingTypeArguments(core.Map(typeArgumentNodes, c.getTypeFromTypeNode), typeParameters, c.getMinTypeArgumentCount(typeParameters), isJavaScript)
8927
8928
var mapper *TypeMapper
8928
8929
for i := range typeArgumentNodes {
8929
- // Debug.assert (typeParameters[i] != nil, "Should not call checkTypeArguments with too many type arguments")
8930
+ debug.Assert (typeParameters[i] != nil, "Should not call checkTypeArguments with too many type arguments")
8930
8931
constraint := c.getConstraintOfTypeParameter(typeParameters[i])
8931
8932
if constraint != nil {
8932
8933
typeArgumentHeadMessage := core.OrElse(headMessage, diagnostics.Type_0_does_not_satisfy_the_constraint_1)
@@ -10299,8 +10300,8 @@ func (c *Checker) checkImportMetaProperty(node *ast.Node) *Type {
10299
10300
} else if c.moduleKind < core.ModuleKindES2020 && c.moduleKind != core.ModuleKindSystem {
10300
10301
c.error(node, diagnostics.The_import_meta_meta_property_is_only_allowed_when_the_module_option_is_es2020_es2022_esnext_system_node16_node18_or_nodenext)
10301
10302
}
10302
- // file := ast.GetSourceFileOfNode(node)
10303
- // Debug.assert (file.Flags&ast.NodeFlagsPossiblyContainsImportMeta != 0, "Containing file is missing import meta node flag.")
10303
+ file := ast.GetSourceFileOfNode(node)
10304
+ debug.Assert (file.Flags&ast.NodeFlagsPossiblyContainsImportMeta != 0, "Containing file is missing import meta node flag.")
10304
10305
if node.Name().Text() == "meta" {
10305
10306
return c.getGlobalImportMetaType()
10306
10307
}
@@ -12720,7 +12721,7 @@ func (c *Checker) checkObjectLiteral(node *ast.Node, checkMode CheckMode) *Type
12720
12721
// an ordinary function declaration(section 6.1) with no parameters.
12721
12722
// A set accessor declaration is processed in the same manner
12722
12723
// as an ordinary function declaration with a single parameter and a Void return type.
12723
- // Debug.assert (memberDecl.kind == KindGetAccessor || memberDecl.kind == KindSetAccessor)
12724
+ debug.Assert (memberDecl.Kind == ast. KindGetAccessor || memberDecl.Kind == ast. KindSetAccessor)
12724
12725
c.checkNodeDeferred(memberDecl)
12725
12726
}
12726
12727
if computedNameType != nil && computedNameType.flags&TypeFlagsStringOrNumberLiteralOrUnique == 0 {
@@ -13856,7 +13857,7 @@ func (c *Checker) getSymbolOfPartOfRightHandSideOfImportEquals(entityName *ast.N
13856
13857
}
13857
13858
// Case 2 in above example
13858
13859
// entityName.kind could be a QualifiedName or a Missing identifier
13859
- // Debug.assert (entityName.parent.kind == ast.KindImportEqualsDeclaration)
13860
+ debug.Assert (entityName.Parent.Kind == ast.KindImportEqualsDeclaration)
13860
13861
return c.resolveEntityName(entityName, ast.SymbolFlagsValue|ast.SymbolFlagsType|ast.SymbolFlagsNamespace, false /*ignoreErrors*/, dontResolveAlias, nil /*location*/)
13861
13862
}
13862
13863
@@ -14114,7 +14115,7 @@ func (c *Checker) combineValueAndTypeSymbols(valueSymbol *ast.Symbol, typeSymbol
14114
14115
return valueSymbol
14115
14116
}
14116
14117
result := c.newSymbol(valueSymbol.Flags|typeSymbol.Flags, valueSymbol.Name)
14117
- // Debug.assert( valueSymbol.declarations || typeSymbol.declarations )
14118
+ debug.Assert(len( valueSymbol.Declarations) > 0 || len( typeSymbol.Declarations) > 0 )
14118
14119
result.Declarations = slices.Compact(slices.Concat(valueSymbol.Declarations, typeSymbol.Declarations))
14119
14120
result.Parent = valueSymbol.Parent
14120
14121
if result.Parent == nil {
@@ -15271,7 +15272,7 @@ func (c *Checker) getResolvedMembersOrExportsOfSymbol(symbol *ast.Symbol, resolu
15271
15272
// @param lateSymbols The late-bound symbols of the parent.
15272
15273
// @param decl The member to bind.
15273
15274
func (c *Checker) lateBindMember(parent *ast.Symbol, earlySymbols ast.SymbolTable, lateSymbols ast.SymbolTable, decl *ast.Node) *ast.Symbol {
15274
- // Debug.assert (decl.Symbol, "The member is expected to have a symbol.")
15275
+ debug.AssertIsDefined (decl.Symbol() , "The member is expected to have a symbol.")
15275
15276
links := c.symbolNodeLinks.Get(decl)
15276
15277
if links.resolvedSymbol == nil {
15277
15278
// In the event we attempt to resolve the late-bound name of this member recursively,
@@ -15358,7 +15359,7 @@ func (c *Checker) lateBindIndexSignature(parent *ast.Symbol, earlySymbols ast.Sy
15358
15359
// late-bound members that `addDeclarationToSymbol` in binder.ts performs for early-bound
15359
15360
// members.
15360
15361
func (c *Checker) addDeclarationToLateBoundSymbol(symbol *ast.Symbol, member *ast.Node, symbolFlags ast.SymbolFlags) {
15361
- // Debug.assert(getCheckFlags( symbol) &ast.CheckFlagsLate != 0, "Expected a late-bound symbol.")
15362
+ debug.Assert( symbol.CheckFlags &ast.CheckFlagsLate != 0, "Expected a late-bound symbol.")
15362
15363
symbol.Flags |= symbolFlags
15363
15364
c.lateBoundLinks.Get(member.Symbol()).lateSymbol = symbol
15364
15365
if len(symbol.Declarations) == 0 || member.Symbol().Flags&ast.SymbolFlagsReplaceableByMethod == 0 {
@@ -15829,7 +15830,7 @@ func (c *Checker) getTypeOfVariableOrParameterOrPropertyWorker(symbol *ast.Symbo
15829
15830
members["exports"] = fileSymbol
15830
15831
return c.newAnonymousType(symbol, members, nil, nil, nil)
15831
15832
}
15832
- // Debug.assertIsDefined (symbol.valueDeclaration )
15833
+ debug.AssertIsDefined (symbol.ValueDeclaration )
15833
15834
declaration := symbol.ValueDeclaration
15834
15835
if ast.IsSourceFile(declaration) && ast.IsJsonSourceFile(declaration.AsSourceFile()) {
15835
15836
statements := declaration.AsSourceFile().Statements.Nodes
@@ -15960,7 +15961,7 @@ func (c *Checker) getTypeForVariableLikeDeclaration(declaration *ast.Node, inclu
15960
15961
thisParameter := c.getAccessorThisParameter(fn)
15961
15962
if thisParameter != nil && declaration == thisParameter {
15962
15963
// Use the type from the *getter*
15963
- // Debug.assert (thisParameter.Type_ == nil )
15964
+ debug.AssertNil (thisParameter.Type() )
15964
15965
return c.getTypeOfSymbol(getterSignature.thisParameter)
15965
15966
}
15966
15967
return c.getReturnTypeOfSignature(getterSignature)
@@ -17775,7 +17776,7 @@ func (c *Checker) addOptionalityEx(t *Type, isProperty bool, isOptional bool) *T
17775
17776
}
17776
17777
17777
17778
func (c *Checker) getOptionalType(t *Type, isProperty bool) *Type {
17778
- // Debug.assert (c.strictNullChecks)
17779
+ // debug.Assert (c.strictNullChecks) // TODO: fix bug in isRequiredInitializedParameter
17779
17780
missingOrUndefined := core.IfElse(isProperty, c.undefinedOrMissingType, c.undefinedType)
17780
17781
if t == missingOrUndefined || t.flags&TypeFlagsUnion != 0 && t.Types()[0] == missingOrUndefined {
17781
17782
return t
@@ -20271,7 +20272,7 @@ func (c *Checker) getUnionSignatures(signatureLists [][]*Signature) []*Signature
20271
20272
for _, signatures := range signatureLists {
20272
20273
if !core.Same(signatures, masterList) {
20273
20274
signature := signatures[0]
20274
- // Debug.assert (signature, "getUnionSignatures bails early on empty signature lists and should not have empty lists on second pass")
20275
+ debug.AssertIsDefined (signature, "getUnionSignatures bails early on empty signature lists and should not have empty lists on second pass")
20275
20276
if len(signature.typeParameters) != 0 && core.Some(results, func(s *Signature) bool {
20276
20277
return len(s.typeParameters) != 0 && !c.compareTypeParametersIdentical(signature.typeParameters, s.typeParameters)
20277
20278
}) {
@@ -22813,7 +22814,7 @@ func (c *Checker) getOuterTypeParametersOfClassOrInterface(symbol *ast.Symbol) [
22813
22814
return initializer != nil && ast.IsFunctionExpressionOrArrowFunction(initializer)
22814
22815
})
22815
22816
}
22816
- // Debug.assert(!! declaration, "Class was missing valueDeclaration -OR- non-class had no interface declarations")
22817
+ debug.AssertIsDefined( declaration, "Class was missing valueDeclaration -OR- non-class had no interface declarations")
22817
22818
return c.getOuterTypeParameters(declaration, false /*includeThisTypes*/)
22818
22819
}
22819
22820
@@ -23124,7 +23125,7 @@ func (c *Checker) evaluateEntity(expr *ast.Node, location *ast.Node) evaluator.R
23124
23125
name := expr.AsElementAccessExpression().ArgumentExpression.Text()
23125
23126
member := rootSymbol.Exports[name]
23126
23127
if member != nil {
23127
- // Debug.assert (ast.GetSourceFileOfNode(member.valueDeclaration ) == ast.GetSourceFileOfNode(rootSymbol.valueDeclaration ))
23128
+ debug.Assert (ast.GetSourceFileOfNode(member.ValueDeclaration ) == ast.GetSourceFileOfNode(rootSymbol.ValueDeclaration ))
23128
23129
if location != nil {
23129
23130
return c.evaluateEnumMember(expr, member, location)
23130
23131
}
@@ -27584,7 +27585,7 @@ func (c *Checker) getPromisedTypeOfPromiseEx(t *Type, errorNode *ast.Node, thisT
27584
27585
}
27585
27586
}
27586
27587
if len(candidates) == 0 {
27587
- // Debug.assertIsDefined (thisTypeForError)
27588
+ debug.AssertIsDefined (thisTypeForError)
27588
27589
if thisTypeForErrorOut != nil {
27589
27590
*thisTypeForErrorOut = thisTypeForError
27590
27591
}
@@ -28780,7 +28781,7 @@ func (c *Checker) getLegacyDecoratorCallSignature(decorator *ast.Node) *Signatur
28780
28781
break
28781
28782
}
28782
28783
index := slices.Index(node.Parent.Parameters(), node) - core.IfElse(ast.GetThisParameter(node.Parent) != nil, 1, 0)
28783
- // Debug.assert (index >= 0)
28784
+ debug.Assert (index >= 0)
28784
28785
// A parameter declaration decorator will have three arguments (see `ParameterDecorator` in
28785
28786
// core.d.ts).
28786
28787
var targetType *Type
0 commit comments