You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
panic: strings: negative Repeat count with --pretty; TS8010 span for an empty type annotation in JS ends before it starts #65078
tsc -p tsconfig.json --pretty true prints the TS8010 header and source line, then crashes while drawing the underline:
a.js:1:8 - error TS8010: Type annotations can only be used in TypeScript files.
1 var R: ;
panic: strings: negative Repeat count
goroutine 1 [running]:
strings.Repeat(...)
github.com/microsoft/TypeScript/tsc/internal/diagnosticwriter.writeCodeSnippet(..., 0x7, 0xffffffffffffffff, ...)
tsc/internal/diagnosticwriter/diagnosticwriter.go:343
github.com/microsoft/TypeScript/tsc/internal/diagnosticwriter.FormatDiagnosticWithColorAndContext(...)
tsc/internal/diagnosticwriter/diagnosticwriter.go:251
With --pretty false there is no crash, but TS8010 is at column 8:
a.js(1,8): error TS8010: Type annotations can only be used in TypeScript files.
a.js(1,8): error TS1110: Type expected.
🙂 Expected behavior
The same as TypeScript 6.0.3, which reports TS8010 at column 7 with an empty span and prints normally with --pretty:
a.js(1,7): error TS8010: Type annotations can only be used in TypeScript files.
a.js(1,8): error TS1110: Type expected.
Additional information about the issue
jsErrorAtRange (parser/parser.go:6745) builds the range as NewTextRange(scanner.SkipTrivia(p.sourceText, loc.Pos()), loc.End()). The type node here is missing (empty at index 6). Skipping the space moves the start to index 7, past the end, so the range has length −1. That gives the column-8 report, and writeCodeSnippet then calls strings.Repeat with a negative count. TypeScript 6.0.3 reports this through createDiagnosticForNode, whose getErrorSpanForNode doesn't skip trivia for missing nodes.
Activity