Skip to content

Updatess to tsc tests #1589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Aug 15, 2025
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 cmd/tsgo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ func runMain() int {
return runAPI(args[1:])
}
}
result := execute.CommandLine(newSystem(), args, false)
result := execute.CommandLine(newSystem(), args, nil)
return int(result.Status)
}
5 changes: 0 additions & 5 deletions cmd/tsgo/sys.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ func (s *osSys) Writer() io.Writer {
return s.writer
}

func (s *osSys) EndWrite() {
// do nothing, this is needed in the interface for testing
// todo: revisit if improving tsc/build/watch unittest baselines
}

func (s *osSys) WriteOutputIsTTY() bool {
return term.IsTerminal(int(os.Stdout.Fd()))
}
Expand Down
55 changes: 29 additions & 26 deletions internal/diagnosticwriter/diagnosticwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,38 +44,41 @@ func FormatDiagnosticsWithColorAndContext(output io.Writer, diags []*ast.Diagnos
if i > 0 {
fmt.Fprint(output, formatOpts.NewLine)
}
FormatDiagnosticWithColorAndContext(output, diagnostic, formatOpts)
}
}

if diagnostic.File() != nil {
file := diagnostic.File()
pos := diagnostic.Loc().Pos()
WriteLocation(output, file, pos, formatOpts, writeWithStyleAndReset)
fmt.Fprint(output, " - ")
}
func FormatDiagnosticWithColorAndContext(output io.Writer, diagnostic *ast.Diagnostic, formatOpts *FormattingOptions) {
if diagnostic.File() != nil {
file := diagnostic.File()
pos := diagnostic.Loc().Pos()
WriteLocation(output, file, pos, formatOpts, writeWithStyleAndReset)
fmt.Fprint(output, " - ")
}

writeWithStyleAndReset(output, diagnostic.Category().Name(), getCategoryFormat(diagnostic.Category()))
fmt.Fprintf(output, "%s TS%d: %s", foregroundColorEscapeGrey, diagnostic.Code(), resetEscapeSequence)
WriteFlattenedDiagnosticMessage(output, diagnostic, formatOpts.NewLine)
writeWithStyleAndReset(output, diagnostic.Category().Name(), getCategoryFormat(diagnostic.Category()))
fmt.Fprintf(output, "%s TS%d: %s", foregroundColorEscapeGrey, diagnostic.Code(), resetEscapeSequence)
WriteFlattenedDiagnosticMessage(output, diagnostic, formatOpts.NewLine)

if diagnostic.File() != nil && diagnostic.Code() != diagnostics.File_appears_to_be_binary.Code() {
fmt.Fprint(output, formatOpts.NewLine)
writeCodeSnippet(output, diagnostic.File(), diagnostic.Pos(), diagnostic.Len(), getCategoryFormat(diagnostic.Category()), "", formatOpts)
fmt.Fprint(output, formatOpts.NewLine)
}
if diagnostic.File() != nil && diagnostic.Code() != diagnostics.File_appears_to_be_binary.Code() {
fmt.Fprint(output, formatOpts.NewLine)
writeCodeSnippet(output, diagnostic.File(), diagnostic.Pos(), diagnostic.Len(), getCategoryFormat(diagnostic.Category()), "", formatOpts)
fmt.Fprint(output, formatOpts.NewLine)
}

if (diagnostic.RelatedInformation() != nil) && (len(diagnostic.RelatedInformation()) > 0) {
for _, relatedInformation := range diagnostic.RelatedInformation() {
file := relatedInformation.File()
if file != nil {
fmt.Fprint(output, formatOpts.NewLine)
fmt.Fprint(output, " ")
pos := relatedInformation.Pos()
WriteLocation(output, file, pos, formatOpts, writeWithStyleAndReset)
fmt.Fprint(output, " - ")
WriteFlattenedDiagnosticMessage(output, relatedInformation, formatOpts.NewLine)
writeCodeSnippet(output, file, pos, relatedInformation.Len(), foregroundColorEscapeCyan, " ", formatOpts)
}
if (diagnostic.RelatedInformation() != nil) && (len(diagnostic.RelatedInformation()) > 0) {
for _, relatedInformation := range diagnostic.RelatedInformation() {
file := relatedInformation.File()
if file != nil {
fmt.Fprint(output, formatOpts.NewLine)
fmt.Fprint(output, " ")
pos := relatedInformation.Pos()
WriteLocation(output, file, pos, formatOpts, writeWithStyleAndReset)
fmt.Fprint(output, " - ")
WriteFlattenedDiagnosticMessage(output, relatedInformation, formatOpts.NewLine)
writeCodeSnippet(output, file, pos, relatedInformation.Len(), foregroundColorEscapeCyan, " ", formatOpts)
}
fmt.Fprint(output, formatOpts.NewLine)
}
}
}
Expand Down
24 changes: 11 additions & 13 deletions internal/execute/outputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,18 @@ func getFormatOptsOfSys(sys System) *diagnosticwriter.FormattingOptions {

type diagnosticReporter = func(*ast.Diagnostic)

func quietDiagnosticReporter(diagnostic *ast.Diagnostic) {}
func createDiagnosticReporter(sys System, options *core.CompilerOptions) diagnosticReporter {
if options.Quiet.IsTrue() {
return func(diagnostic *ast.Diagnostic) {}
return quietDiagnosticReporter
}

formatOpts := getFormatOptsOfSys(sys)
if !shouldBePretty(sys, options) {
return func(diagnostic *ast.Diagnostic) {
diagnosticwriter.WriteFormatDiagnostic(sys.Writer(), diagnostic, formatOpts)
sys.EndWrite()
}
}
writeDiagnostic := core.IfElse(shouldBePretty(sys, options), diagnosticwriter.FormatDiagnosticWithColorAndContext, diagnosticwriter.WriteFormatDiagnostic)

return func(diagnostic *ast.Diagnostic) {
diagnosticwriter.FormatDiagnosticsWithColorAndContext(sys.Writer(), []*ast.Diagnostic{diagnostic}, formatOpts)
sys.EndWrite()
writeDiagnostic(sys.Writer(), diagnostic, formatOpts)
fmt.Fprint(sys.Writer(), formatOpts.NewLine)
}
}

Expand Down Expand Up @@ -132,15 +129,18 @@ func createReportErrorSummary(sys System, options *core.CompilerOptions) func(di
formatOpts := getFormatOptsOfSys(sys)
return func(diagnostics []*ast.Diagnostic) {
diagnosticwriter.WriteErrorSummaryText(sys.Writer(), diagnostics, formatOpts)
sys.EndWrite()
}
}
return func(diagnostics []*ast.Diagnostic) {}
}

func reportStatistics(sys System, program *compiler.Program, result compileAndEmitResult, memStats *runtime.MemStats) {
func reportStatistics(sys System, program *compiler.Program, result compileAndEmitResult, memStats *runtime.MemStats, testing CommandLineTesting) {
var stats table

if testing != nil {
testing.OnStatisticsStart()
defer testing.OnStatisticsEnd()
}
stats.add("Files", len(program.SourceFiles()))
stats.add("Lines", program.LineCount())
stats.add("Identifiers", program.IdentifierCount())
Expand Down Expand Up @@ -175,7 +175,6 @@ func reportStatistics(sys System, program *compiler.Program, result compileAndEm

func printVersion(sys System) {
fmt.Fprintln(sys.Writer(), diagnostics.Version_0.Format(core.Version()))
sys.EndWrite()
}

func printHelp(sys System, commandLine *tsoptions.ParsedCommandLine) {
Expand Down Expand Up @@ -268,7 +267,6 @@ func printEasyHelp(sys System, simpleOptions []*tsoptions.CommandLineOption) {
for _, chunk := range output {
fmt.Fprint(sys.Writer(), chunk)
}
sys.EndWrite()
}

func generateSectionOptionsOutput(
Expand Down
1 change: 0 additions & 1 deletion internal/execute/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

type System interface {
Writer() io.Writer
EndWrite() // needed for testing
FS() vfs.FS
DefaultLibraryPath() string
GetCurrentDirectory() string
Expand Down
Loading
Loading