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
3 changes: 1 addition & 2 deletions Herebyfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ const { values: rawOptions } = parseArgs({
debug: { type: "boolean" },
dirty: { type: "boolean" },
release: { type: "boolean" },
assert: { type: "boolean" },

setPrerelease: { type: "string" },
forRelease: { type: "boolean" },
Expand Down Expand Up @@ -210,7 +209,7 @@ function buildTsgo(opts) {
opts ||= {};
const out = opts.out ?? "./built/local/";
const env = { ...goBuildEnv, ...opts.env };
return $({ cancelSignal: opts.abortSignal, env })`go build ${goBuildFlags} ${opts.extraFlags ?? []} ${options.debug || options.assert ? goBuildTags("noembed") : goBuildTags("noembed", "noassert")} -o ${out} ./cmd/tsgo`;
return $({ cancelSignal: opts.abortSignal, env })`go build ${goBuildFlags} ${opts.extraFlags ?? []} ${goBuildTags("noembed")} -o ${out} ./cmd/tsgo`;
}

export const tsgoBuild = task({
Expand Down
14 changes: 7 additions & 7 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6589,7 +6589,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.Assert(node.Name() != nil, "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 @@ -15493,7 +15493,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.AssertIsDefined(decl.Symbol(), "The member is expected to have a symbol.")
debug.Assert(decl.Symbol() != nil, "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 @@ -16064,7 +16064,7 @@ func (c *Checker) getTypeOfVariableOrParameterOrPropertyWorker(symbol *ast.Symbo
members["exports"] = fileSymbol
return c.newAnonymousType(symbol, members, nil, nil, nil)
}
debug.AssertIsDefined(symbol.ValueDeclaration)
debug.Assert(symbol.ValueDeclaration != nil)
declaration := symbol.ValueDeclaration
if ast.IsSourceFile(declaration) && ast.IsJsonSourceFile(declaration.AsSourceFile()) {
statements := declaration.Statements()
Expand Down Expand Up @@ -16197,7 +16197,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.AssertNil(thisParameter.Type())
debug.Assert(thisParameter.Type() == nil)
return c.getTypeOfSymbol(getterSignature.thisParameter)
}
return c.getReturnTypeOfSignature(getterSignature)
Expand Down Expand Up @@ -20593,7 +20593,7 @@ func (c *Checker) getUnionSignatures(signatureLists [][]*Signature) []*Signature
for _, signatures := range signatureLists {
if !core.Same(signatures, masterList) {
signature := signatures[0]
debug.AssertIsDefined(signature, "getUnionSignatures bails early on empty signature lists and should not have empty lists on second pass")
debug.Assert(signature != nil, "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 @@ -23113,7 +23113,7 @@ func (c *Checker) getOuterTypeParametersOfClassOrInterface(symbol *ast.Symbol) [
return initializer != nil && ast.IsFunctionExpressionOrArrowFunction(initializer)
})
}
debug.AssertIsDefined(declaration, "Class was missing valueDeclaration -OR- non-class had no interface declarations")
debug.Assert(declaration != nil, "Class was missing valueDeclaration -OR- non-class had no interface declarations")
return c.getOuterTypeParameters(declaration, false /*includeThisTypes*/)
}

Expand Down Expand Up @@ -27997,7 +27997,7 @@ func (c *Checker) getPromisedTypeOfPromiseEx(t *Type, errorNode *ast.Node, thisT
}
}
if len(candidates) == 0 {
debug.AssertIsDefined(thisTypeForError)
debug.Assert(thisTypeForError != nil)
if thisTypeForErrorOut != nil {
*thisTypeForErrorOut = thisTypeForError
}
Expand Down
2 changes: 1 addition & 1 deletion internal/checker/jsx.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ func (c *Checker) createJsxAttributesTypeFromAttributesProperty(openingLikeEleme
}
if contextualType != nil && checkMode&CheckModeInferential != 0 && checkMode&CheckModeSkipContextSensitive == 0 && c.isContextSensitive(attributeDecl) {
inferenceContext := c.getInferenceContext(attributes)
debug.AssertIsDefined(inferenceContext)
debug.Assert(inferenceContext != nil)
// In CheckMode.Inferential we should always have an inference context
inferenceNode := attributeDecl.Initializer().Expression()
c.addIntraExpressionInferenceSite(inferenceContext, inferenceNode, exprType)
Expand Down
2 changes: 1 addition & 1 deletion internal/checker/nodebuilderimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ func (b *NodeBuilderImpl) lookupSymbolChainWorker(symbol *ast.Symbol, meaning as
if !isTypeParameter && (b.ctx.enclosingDeclaration != nil || b.ctx.flags&nodebuilder.FlagsUseFullyQualifiedType != 0) && (b.ctx.internalFlags&nodebuilder.InternalFlagsDoNotIncludeSymbolChain == 0) {
res := b.getSymbolChain(symbol, meaning /*endOfChain*/, true, yieldModuleSymbol)
chain = res
debug.CheckDefined(chain)
debug.Assert(chain != nil)
debug.Assert(len(chain) > 0)
} else {
chain = append(chain, symbol)
Expand Down
4 changes: 2 additions & 2 deletions internal/checker/nodebuilderscopes.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (b *NodeBuilderImpl) enterNewScope(declaration *ast.Node, expandedParams []
// traverse all ancestors.
pushFakeScope := func(kind string, addAll func(addSymbol func(name string, symbol *ast.Symbol))) func() {
// We only ever need to look two declarations upward.
debug.AssertIsDefined(b.ctx.enclosingDeclaration)
debug.Assert(b.ctx.enclosingDeclaration != nil)
var existingFakeScope *ast.Node
if b.links.Has(b.ctx.enclosingDeclaration) {
links := b.links.Get(b.ctx.enclosingDeclaration)
Expand All @@ -118,7 +118,7 @@ func (b *NodeBuilderImpl) enterNewScope(declaration *ast.Node, expandedParams []
}
}
}
debug.AssertOptionalNode(existingFakeScope, ast.IsBlock)
debug.Assert(existingFakeScope == nil || ast.IsBlock(existingFakeScope))

var locals ast.SymbolTable
if existingFakeScope != nil {
Expand Down
198 changes: 0 additions & 198 deletions internal/debug/assert.go

This file was deleted.

28 changes: 23 additions & 5 deletions internal/debug/shared.go → internal/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func FailBadSyntaxKind(node interface{ KindString() string }, message ...any) {
} else {
msg = fmt.Sprint(message...)
}
Fail(fmt.Sprintf("%s\r\nNode %s was unexpected.", msg, node.KindString()))
Fail(fmt.Sprintf("%s\nNode %s was unexpected.", msg, node.KindString()))
}

func AssertNever(member any, message ...any) {
Expand All @@ -32,12 +32,30 @@ func AssertNever(member any, message ...any) {
msg = fmt.Sprint(message...)
}
var detail string
if member, ok := member.(interface{ KindString() string }); ok {
detail = member.KindString()
} else if member, ok := member.(fmt.Stringer); ok {
detail = member.String()
if m, ok := member.(interface{ KindString() string }); ok {
detail = m.KindString()
} else if m, ok := member.(fmt.Stringer); ok {
detail = m.String()
} else {
detail = fmt.Sprintf("%v", member)
}
Fail(fmt.Sprintf("%s %s", msg, detail))
}

func Assert(value bool, message ...any) {
if value {
return
}
assertSlow(message...)
}

func assertSlow(message ...any) {
// See https://dave.cheney.net/2020/05/02/mid-stack-inlining-in-go
var msg string
if len(message) > 0 {
msg = "False expression: " + fmt.Sprint(message...)
} else {
msg = "False expression."
}
Fail(msg)
}
Loading
Loading