Skip to content

Prevent panic and duplicate diagnostics for malformed tsconfig properties - #4762

Open
jakebailey with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-tsconfig-negative-repeat-count
Open

Prevent panic and duplicate diagnostics for malformed tsconfig properties#4762
jakebailey with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-tsconfig-negative-repeat-count

Conversation

Copilot AI commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

A malformed config property such as:

{"" }

produced duplicate TS1328 diagnostics and an invalid source span that caused pretty diagnostic formatting to panic.

Changes

  • Normalize recovered JSON node spans before creating diagnostics.
  • Suppress config-conversion diagnostics already reported by the JSON parser.
  • Add regression coverage confirming the output contains one TS1328 and one TS1005 diagnostic.

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix panic caused by tsconfig.json negative repeat count Prevent panic and duplicate diagnostics for malformed tsconfig properties Jul 27, 2026
Copilot AI requested a review from jakebailey July 27, 2026 16:43
Comment thread internal/parser/parser.go Outdated
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()))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot This is evil, why would this ever be out of range?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread internal/tsoptions/tsconfigparsing.go Outdated
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()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Why are we doing this like this? Don't we already dedupe diags above this? This is quadratic

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Copilot AI requested a review from jakebailey July 27, 2026 17:04
@jakebailey
jakebailey marked this pull request as ready for review July 27, 2026 17:05
Copilot AI review requested due to automatic review settings July 27, 2026 17:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tsconfig.json: {"" } causes a panic, and more TS errors than v6

3 participants