Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Herebyfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export const lib = task({
function buildTsgo(opts) {
opts ||= {};
const out = opts.out ?? "./built/local/";
return $({ cancelSignal: opts.abortSignal, env: opts.env })`go build ${goBuildFlags} ${opts.extraFlags ?? []} ${goBuildTags("noembed")} -o ${out} ./cmd/tsgo`;
return $({ cancelSignal: opts.abortSignal, env: opts.env })`go build ${goBuildFlags} ${opts.extraFlags ?? []} ${options.debug ? goBuildTags("noembed") : goBuildTags("noembed", "release")} -o ${out} ./cmd/tsgo`;
}

export const tsgoBuild = task({
Expand Down
2 changes: 2 additions & 0 deletions internal/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ func (n *Node) LiteralLikeData() *LiteralLikeBase { return n.data.Litera
func (n *Node) TemplateLiteralLikeData() *TemplateLiteralLikeBase {
return n.data.TemplateLiteralLikeData()
}
func (n *Node) KindString() string { return n.Kind.String() }
func (n *Node) KindValue() int16 { return int16(n.Kind) }

type mutableNode Node

Expand Down
3 changes: 2 additions & 1 deletion internal/ast/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"sync/atomic"

"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/debug"
"github.com/microsoft/typescript-go/internal/tspath"
)

Expand Down Expand Up @@ -3154,7 +3155,7 @@ func IsTemplateLiteralToken(node *Node) bool {
}

func GetExternalModuleImportEqualsDeclarationExpression(node *Node) *Node {
// Debug.assert(isExternalModuleImportEqualsDeclaration(node))
debug.Assert(IsExternalModuleImportEqualsDeclaration(node))
return node.AsImportEqualsDeclaration().ModuleReference.AsExternalModuleReference().Expression
}

Expand Down
3 changes: 2 additions & 1 deletion internal/binder/binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/microsoft/typescript-go/internal/ast"
"github.com/microsoft/typescript-go/internal/collections"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/debug"
"github.com/microsoft/typescript-go/internal/diagnostics"
"github.com/microsoft/typescript-go/internal/scanner"
"github.com/microsoft/typescript-go/internal/tspath"
Expand Down Expand Up @@ -149,7 +150,7 @@ func (b *Binder) declareSymbol(symbolTable ast.SymbolTable, parent *ast.Symbol,
}

func (b *Binder) declareSymbolEx(symbolTable ast.SymbolTable, parent *ast.Symbol, node *ast.Node, includes ast.SymbolFlags, excludes ast.SymbolFlags, isReplaceableByMethod bool, isComputedName bool) *ast.Symbol {
// Debug.assert(isComputedName || !ast.HasDynamicName(node))
debug.Assert(isComputedName || !ast.HasDynamicName(node))
isDefaultExport := ast.HasSyntacticModifier(node, ast.ModifierFlagsDefault) || ast.IsExportSpecifier(node) && ast.ModuleExportNameIsDefault(node.AsExportSpecifier().Name())
// The exported symbol for an export default function/class node is always named "default"
var name string
Expand Down
47 changes: 24 additions & 23 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/microsoft/typescript-go/internal/binder"
"github.com/microsoft/typescript-go/internal/collections"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/debug"
"github.com/microsoft/typescript-go/internal/diagnostics"
"github.com/microsoft/typescript-go/internal/evaluator"
"github.com/microsoft/typescript-go/internal/jsnum"
Expand Down Expand Up @@ -1542,7 +1543,7 @@ func (c *Checker) checkAndReportErrorForUsingTypeAsNamespace(errorLocation *ast.
if symbol != nil {
parent := errorLocation.Parent
if ast.IsQualifiedName(parent) {
// Debug.assert(parent.Left == errorLocation, "Should only be resolving left side of qualified name as a namespace")
debug.Assert(parent.AsQualifiedName().Left == errorLocation, "Should only be resolving left side of qualified name as a namespace")
propName := parent.AsQualifiedName().Right.Text()
propType := c.getPropertyOfType(c.getDeclaredTypeOfSymbol(symbol), propName)
if propType != nil {
Expand Down Expand Up @@ -1787,7 +1788,7 @@ func (c *Checker) onSuccessfullyResolvedSymbol(errorLocation *ast.Node, result *
}

func (c *Checker) checkResolvedBlockScopedVariable(result *ast.Symbol, errorLocation *ast.Node) {
// Debug.assert(!!(result.flags&ast.SymbolFlagsBlockScopedVariable || result.flags&ast.SymbolFlagsClass || result.flags&ast.SymbolFlagsEnum))
debug.Assert(result.Flags&ast.SymbolFlagsBlockScopedVariable != 0 || result.Flags&ast.SymbolFlagsClass != 0 || result.Flags&ast.SymbolFlagsEnum != 0)
if result.Flags&(ast.SymbolFlagsFunction|ast.SymbolFlagsFunctionScopedVariable|ast.SymbolFlagsAssignment) != 0 && result.Flags&ast.SymbolFlagsClass != 0 {
// constructor functions aren't block scoped
return
Expand All @@ -1809,7 +1810,7 @@ func (c *Checker) checkResolvedBlockScopedVariable(result *ast.Symbol, errorLoca
} else if result.Flags&ast.SymbolFlagsRegularEnum != 0 {
diagnostic = c.error(errorLocation, diagnostics.Enum_0_used_before_its_declaration, declarationName)
} else {
// Debug.assert(!!(result.flags & ast.SymbolFlagsConstEnum))
debug.Assert(result.Flags&ast.SymbolFlagsConstEnum != 0)
if c.compilerOptions.GetIsolatedModules() {
diagnostic = c.error(errorLocation, diagnostics.Enum_0_used_before_its_declaration, declarationName)
}
Expand Down Expand Up @@ -2045,7 +2046,7 @@ func (c *Checker) getTypeOnlyAliasDeclarationEx(symbol *ast.Symbol, include ast.
}

func (c *Checker) getImmediateAliasedSymbol(symbol *ast.Symbol) *ast.Symbol {
// Debug.assert((symbol.flags&SymbolFlagsAlias) != 0, "Should only get Alias here.")
debug.Assert(symbol.Flags&ast.SymbolFlagsAlias != 0, "Should only get Alias here.")
links := c.aliasSymbolLinks.Get(symbol)
if links.immediateTarget == nil {
node := c.getDeclarationOfAliasSymbol(symbol)
Expand Down Expand Up @@ -6439,7 +6440,7 @@ func (c *Checker) checkAliasSymbol(node *ast.Node) {
switch node.Kind {
case ast.KindImportClause, ast.KindImportSpecifier, ast.KindImportEqualsDeclaration:
if c.compilerOptions.VerbatimModuleSyntax.IsTrue() {
// Debug.assertIsDefined(node.Name, "An ImportClause with a symbol should have a name")
debug.AssertIsDefined(node.Name(), "An ImportClause with a symbol should have a name")
var message *diagnostics.Message
switch {
case c.compilerOptions.VerbatimModuleSyntax.IsTrue() && ast.IsInternalModuleImportEqualsDeclaration(node):
Expand Down Expand Up @@ -6934,7 +6935,7 @@ func (c *Checker) checkUnusedRenamedBindingElements() {
for _, node := range c.renamedBindingElementsInTypes {
if c.symbolReferenceLinks.Get(c.getSymbolOfDeclaration(node)).referenceKinds == 0 {
wrappingDeclaration := ast.WalkUpBindingElementsAndPatterns(node)
// Debug.assert(isPartOfParameterDeclaration(wrappingDeclaration), "Only parameter declaration should be checked here")
debug.Assert(ast.IsPartOfParameterDeclaration(wrappingDeclaration), "Only parameter declaration should be checked here")
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()))
if wrappingDeclaration.Type() == nil {
// entire parameter does not have type annotation, suggest adding an annotation
Expand Down Expand Up @@ -7201,7 +7202,7 @@ func (c *Checker) checkConstEnumAccess(node *ast.Node, t *Type) {
// resolve to an import, because imports of ambient const enums get checked
// separately in `checkAliasSymbol`.
if c.compilerOptions.IsolatedModules.IsTrue() || c.compilerOptions.VerbatimModuleSyntax.IsTrue() && ok && c.resolveName(node, ast.GetFirstIdentifier(node).Text(), ast.SymbolFlagsAlias, nil, false, true) == nil {
// Debug.assert(t.symbol.Flags&ast.SymbolFlagsConstEnum != 0)
debug.Assert(t.symbol.Flags&ast.SymbolFlagsConstEnum != 0)
constEnumDeclaration := t.symbol.ValueDeclaration
redirect := c.program.GetSourceAndProjectReference(ast.GetSourceFileOfNode(constEnumDeclaration).Path())
if constEnumDeclaration.Flags&ast.NodeFlagsAmbient != 0 && !ast.IsValidTypeOnlyAliasUseSite(node) && (redirect == nil || !redirect.Resolved.CompilerOptions().ShouldPreserveConstEnums()) {
Expand Down Expand Up @@ -8926,7 +8927,7 @@ func (c *Checker) checkTypeArguments(signature *Signature, typeArgumentNodes []*
typeArgumentTypes := c.fillMissingTypeArguments(core.Map(typeArgumentNodes, c.getTypeFromTypeNode), typeParameters, c.getMinTypeArgumentCount(typeParameters), isJavaScript)
var mapper *TypeMapper
for i := range typeArgumentNodes {
// Debug.assert(typeParameters[i] != nil, "Should not call checkTypeArguments with too many type arguments")
debug.Assert(typeParameters[i] != nil, "Should not call checkTypeArguments with too many type arguments")
constraint := c.getConstraintOfTypeParameter(typeParameters[i])
if constraint != nil {
typeArgumentHeadMessage := core.OrElse(headMessage, diagnostics.Type_0_does_not_satisfy_the_constraint_1)
Expand Down Expand Up @@ -10299,8 +10300,8 @@ func (c *Checker) checkImportMetaProperty(node *ast.Node) *Type {
} else if c.moduleKind < core.ModuleKindES2020 && c.moduleKind != core.ModuleKindSystem {
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)
}
// file := ast.GetSourceFileOfNode(node)
// Debug.assert(file.Flags&ast.NodeFlagsPossiblyContainsImportMeta != 0, "Containing file is missing import meta node flag.")
file := ast.GetSourceFileOfNode(node)
debug.Assert(file.Flags&ast.NodeFlagsPossiblyContainsImportMeta != 0, "Containing file is missing import meta node flag.")
if node.Name().Text() == "meta" {
return c.getGlobalImportMetaType()
}
Expand Down Expand Up @@ -12720,7 +12721,7 @@ func (c *Checker) checkObjectLiteral(node *ast.Node, checkMode CheckMode) *Type
// an ordinary function declaration(section 6.1) with no parameters.
// A set accessor declaration is processed in the same manner
// as an ordinary function declaration with a single parameter and a Void return type.
// Debug.assert(memberDecl.kind == KindGetAccessor || memberDecl.kind == KindSetAccessor)
debug.Assert(memberDecl.Kind == ast.KindGetAccessor || memberDecl.Kind == ast.KindSetAccessor)
c.checkNodeDeferred(memberDecl)
}
if computedNameType != nil && computedNameType.flags&TypeFlagsStringOrNumberLiteralOrUnique == 0 {
Expand Down Expand Up @@ -13856,7 +13857,7 @@ func (c *Checker) getSymbolOfPartOfRightHandSideOfImportEquals(entityName *ast.N
}
// Case 2 in above example
// entityName.kind could be a QualifiedName or a Missing identifier
// Debug.assert(entityName.parent.kind == ast.KindImportEqualsDeclaration)
debug.Assert(entityName.Parent.Kind == ast.KindImportEqualsDeclaration)
return c.resolveEntityName(entityName, ast.SymbolFlagsValue|ast.SymbolFlagsType|ast.SymbolFlagsNamespace, false /*ignoreErrors*/, dontResolveAlias, nil /*location*/)
}

Expand Down Expand Up @@ -14114,7 +14115,7 @@ func (c *Checker) combineValueAndTypeSymbols(valueSymbol *ast.Symbol, typeSymbol
return valueSymbol
}
result := c.newSymbol(valueSymbol.Flags|typeSymbol.Flags, valueSymbol.Name)
// Debug.assert(valueSymbol.declarations || typeSymbol.declarations)
debug.Assert(len(valueSymbol.Declarations) > 0 || len(typeSymbol.Declarations) > 0)
result.Declarations = slices.Compact(slices.Concat(valueSymbol.Declarations, typeSymbol.Declarations))
result.Parent = valueSymbol.Parent
if result.Parent == nil {
Expand Down Expand Up @@ -15269,7 +15270,7 @@ func (c *Checker) getResolvedMembersOrExportsOfSymbol(symbol *ast.Symbol, resolu
// @param lateSymbols The late-bound symbols of the parent.
// @param decl The member to bind.
func (c *Checker) lateBindMember(parent *ast.Symbol, earlySymbols ast.SymbolTable, lateSymbols ast.SymbolTable, decl *ast.Node) *ast.Symbol {
// Debug.assert(decl.Symbol, "The member is expected to have a symbol.")
debug.AssertIsDefined(decl.Symbol(), "The member is expected to have a symbol.")
links := c.symbolNodeLinks.Get(decl)
if links.resolvedSymbol == nil {
// In the event we attempt to resolve the late-bound name of this member recursively,
Expand Down Expand Up @@ -15356,7 +15357,7 @@ func (c *Checker) lateBindIndexSignature(parent *ast.Symbol, earlySymbols ast.Sy
// late-bound members that `addDeclarationToSymbol` in binder.ts performs for early-bound
// members.
func (c *Checker) addDeclarationToLateBoundSymbol(symbol *ast.Symbol, member *ast.Node, symbolFlags ast.SymbolFlags) {
// Debug.assert(getCheckFlags(symbol)&ast.CheckFlagsLate != 0, "Expected a late-bound symbol.")
debug.Assert(symbol.CheckFlags&ast.CheckFlagsLate != 0, "Expected a late-bound symbol.")
symbol.Flags |= symbolFlags
c.lateBoundLinks.Get(member.Symbol()).lateSymbol = symbol
if len(symbol.Declarations) == 0 || member.Symbol().Flags&ast.SymbolFlagsReplaceableByMethod == 0 {
Expand Down Expand Up @@ -15827,7 +15828,7 @@ func (c *Checker) getTypeOfVariableOrParameterOrPropertyWorker(symbol *ast.Symbo
members["exports"] = fileSymbol
return c.newAnonymousType(symbol, members, nil, nil, nil)
}
// Debug.assertIsDefined(symbol.valueDeclaration)
debug.AssertIsDefined(symbol.ValueDeclaration)
declaration := symbol.ValueDeclaration
if ast.IsSourceFile(declaration) && ast.IsJsonSourceFile(declaration.AsSourceFile()) {
statements := declaration.AsSourceFile().Statements.Nodes
Expand Down Expand Up @@ -15958,7 +15959,7 @@ func (c *Checker) getTypeForVariableLikeDeclaration(declaration *ast.Node, inclu
thisParameter := c.getAccessorThisParameter(fn)
if thisParameter != nil && declaration == thisParameter {
// Use the type from the *getter*
// Debug.assert(thisParameter.Type_ == nil)
debug.AssertNil(thisParameter.Type())
return c.getTypeOfSymbol(getterSignature.thisParameter)
}
return c.getReturnTypeOfSignature(getterSignature)
Expand Down Expand Up @@ -17773,7 +17774,7 @@ func (c *Checker) addOptionalityEx(t *Type, isProperty bool, isOptional bool) *T
}

func (c *Checker) getOptionalType(t *Type, isProperty bool) *Type {
// Debug.assert(c.strictNullChecks)
// debug.Assert(c.strictNullChecks) // TODO: fix bug in isRequiredInitializedParameter
missingOrUndefined := core.IfElse(isProperty, c.undefinedOrMissingType, c.undefinedType)
if t == missingOrUndefined || t.flags&TypeFlagsUnion != 0 && t.Types()[0] == missingOrUndefined {
return t
Expand Down Expand Up @@ -20269,7 +20270,7 @@ func (c *Checker) getUnionSignatures(signatureLists [][]*Signature) []*Signature
for _, signatures := range signatureLists {
if !core.Same(signatures, masterList) {
signature := signatures[0]
// Debug.assert(signature, "getUnionSignatures bails early on empty signature lists and should not have empty lists on second pass")
debug.AssertIsDefined(signature, "getUnionSignatures bails early on empty signature lists and should not have empty lists on second pass")
if len(signature.typeParameters) != 0 && core.Some(results, func(s *Signature) bool {
return len(s.typeParameters) != 0 && !c.compareTypeParametersIdentical(signature.typeParameters, s.typeParameters)
}) {
Expand Down Expand Up @@ -22811,7 +22812,7 @@ func (c *Checker) getOuterTypeParametersOfClassOrInterface(symbol *ast.Symbol) [
return initializer != nil && ast.IsFunctionExpressionOrArrowFunction(initializer)
})
}
// Debug.assert(!!declaration, "Class was missing valueDeclaration -OR- non-class had no interface declarations")
debug.AssertIsDefined(declaration, "Class was missing valueDeclaration -OR- non-class had no interface declarations")
return c.getOuterTypeParameters(declaration, false /*includeThisTypes*/)
}

Expand Down Expand Up @@ -23122,7 +23123,7 @@ func (c *Checker) evaluateEntity(expr *ast.Node, location *ast.Node) evaluator.R
name := expr.AsElementAccessExpression().ArgumentExpression.Text()
member := rootSymbol.Exports[name]
if member != nil {
// Debug.assert(ast.GetSourceFileOfNode(member.valueDeclaration) == ast.GetSourceFileOfNode(rootSymbol.valueDeclaration))
debug.Assert(ast.GetSourceFileOfNode(member.ValueDeclaration) == ast.GetSourceFileOfNode(rootSymbol.ValueDeclaration))
if location != nil {
return c.evaluateEnumMember(expr, member, location)
}
Expand Down Expand Up @@ -27582,7 +27583,7 @@ func (c *Checker) getPromisedTypeOfPromiseEx(t *Type, errorNode *ast.Node, thisT
}
}
if len(candidates) == 0 {
// Debug.assertIsDefined(thisTypeForError)
debug.AssertIsDefined(thisTypeForError)
if thisTypeForErrorOut != nil {
*thisTypeForErrorOut = thisTypeForError
}
Expand Down Expand Up @@ -28778,7 +28779,7 @@ func (c *Checker) getLegacyDecoratorCallSignature(decorator *ast.Node) *Signatur
break
}
index := slices.Index(node.Parent.Parameters(), node) - core.IfElse(ast.GetThisParameter(node.Parent) != nil, 1, 0)
// Debug.assert(index >= 0)
debug.Assert(index >= 0)
// A parameter declaration decorator will have three arguments (see `ParameterDecorator` in
// core.d.ts).
var targetType *Type
Expand Down
3 changes: 2 additions & 1 deletion internal/checker/emitresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/microsoft/typescript-go/internal/ast"
"github.com/microsoft/typescript-go/internal/binder"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/debug"
"github.com/microsoft/typescript-go/internal/evaluator"
"github.com/microsoft/typescript-go/internal/jsnum"
"github.com/microsoft/typescript-go/internal/nodebuilder"
Expand Down Expand Up @@ -574,7 +575,7 @@ func (r *emitResolver) isOptionalParameter(node *ast.Node) bool {
if node.Initializer() != nil {
signature := r.checker.getSignatureFromDeclaration(node.Parent)
parameterIndex := core.FindIndex(node.Parent.Parameters(), func(p *ast.ParameterDeclarationNode) bool { return p == node })
// Debug.assert(parameterIndex >= 0); // !!!
debug.Assert(parameterIndex >= 0)
// Only consider syntactic or instantiated parameters as optional, not `void` parameters as this function is used
// in grammar checks and checking for `void` too early results in parameter types widening too early
// and causes some noImplicitAny errors to be lost.
Expand Down
5 changes: 3 additions & 2 deletions internal/checker/grammarchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/microsoft/typescript-go/internal/binder"
"github.com/microsoft/typescript-go/internal/collections"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/debug"
"github.com/microsoft/typescript-go/internal/diagnostics"
"github.com/microsoft/typescript-go/internal/jsnum"
"github.com/microsoft/typescript-go/internal/scanner"
Expand Down Expand Up @@ -1264,7 +1265,7 @@ func (c *Checker) checkGrammarForInOrForOfStatement(forInOrOfStatement *ast.ForI
diagnostic := createDiagnosticForNode(forInOrOfStatement.AwaitModifier, diagnostics.X_for_await_loops_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules)
containingFunc := getContainingFunction(forInOrOfStatement.AsNode())
if containingFunc != nil && containingFunc.Kind != ast.KindConstructor {
// Debug.assert((getFunctionFlags(containingFunc)&FunctionFlagsAsync) == 0, "Enclosing function should never be an async function.")
debug.Assert((getFunctionFlags(containingFunc)&FunctionFlagsAsync) == 0, "Enclosing function should never be an async function.")
if hasAsyncModifier(containingFunc) {
panic("Enclosing function should never be an async function.")
}
Expand Down Expand Up @@ -2100,7 +2101,7 @@ func (c *Checker) checkGrammarStatementInAmbientContext(node *ast.Node) bool {
} else {
// We must be parented by a statement. If so, there's no need
// to report the error as our parent will have already done it.
// Debug.assert(isStatement(node.parent));
// debug.Assert(ast.IsStatement(node.Parent)) // !!! commented out in strada - fails if uncommented
}
}
return false
Expand Down
Loading
Loading