Prevent panic and duplicate diagnostics for malformed tsconfig properties - #4762
Prevent panic and duplicate diagnostics for malformed tsconfig properties#4762jakebailey with Copilot wants to merge 3 commits into
Conversation
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
| func getErrorSpanForNode(sourceText string, node *ast.Node) core.TextRange { | ||
| pos := scanner.SkipTrivia(sourceText, node.Pos()) | ||
| return core.NewTextRange(pos, node.End()) | ||
| return core.NewTextRange(min(pos, node.End()), max(pos, node.End())) |
There was a problem hiding this comment.
@copilot This is evil, why would this ever be out of range?
There was a problem hiding this comment.
The node is a zero-width missing initializer; skipping its leading trivia moved the start past its end. Fixed in 8483220 by preserving missing-node spans, matching the shared/upstream error-span logic.
| errors = append(errors, err...) | ||
| for _, diagnostic := range err { | ||
| if !slices.ContainsFunc(sourceFile.Diagnostics(), func(parseDiagnostic *ast.Diagnostic) bool { | ||
| return parseDiagnostic.Code() == diagnostic.Code() && parseDiagnostic.Pos() == diagnostic.Pos() |
There was a problem hiding this comment.
@copilot Why are we doing this like this? Don't we already dedupe diags above this? This is quadratic
There was a problem hiding this comment.
Yes. Removed the local scan in 8483220 and rely on the existing final diagnostic sort/deduplication.
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Prevents malformed tsconfig.json properties from causing invalid diagnostic spans, duplicate diagnostics, and pretty-printing panics.
Changes:
- Preserve zero-width spans for missing JSON nodes.
- Add CLI regression coverage for
{"" }. - Baseline the expected TS1328 and TS1005 diagnostics.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
internal/parser/parser.go |
Avoids skipping trivia for missing nodes. |
internal/execute/tsctests/tsc_test.go |
Adds the malformed-config regression case. |
testdata/baselines/reference/tsc/commandLine/malformed-tsconfig-property-without-value.js |
Records non-panicking, deduplicated output. |
A malformed config property such as:
{"" }produced duplicate TS1328 diagnostics and an invalid source span that caused pretty diagnostic formatting to panic.
Changes
tsconfig.json:{"" }causes a panic, and more TS errors than v6 #4752