Repository navigation
fix(tsoptions): don't panic on empty files when AST node is missing - #65082
Open
Timur Vural (timurzvural) wants to merge 1 commit into
Open
Timur Vural (timurzvural) wants to merge 1 commit into
Timur Vural (timurzvural) wants to merge 1 commit into
Conversation
Use CreateDiagnosticForNodeInSourceFileOrCompilerDiagnostic for the empty "files" list diagnostic so malformed JSON that still recovers an empty files array falls back to a compiler diagnostic instead of dereferencing a nil property node. Fixes microsoft#65079
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The nil-node fallback still needs regression tests verifying that malformed JSON does not cause a panic, TS18002 is unlocated, and parse diagnostics are preserved, while valid empty-files input retains a located TS18002.
1 open issue
What changed in this PR
Fixes #65079 by preventing a compiler panic when malformed tsconfig.json input leaves an empty files array without a usable AST node.
Changes:
- Uses the existing diagnostic helper to fall back to an unlocated TS18002 when the node is missing, while preserving located diagnostics when available.
- Adds a comment explaining the parse-recovery case and alignment with Strada.
| File | Description |
|---|---|
tsc/internal/tsoptions/tsconfigparsing.go |
Uses a nil-safe diagnostic helper for empty files arrays. |
Review effort: Balanced
| // Prefer a node-anchored diagnostic when the "files" property is present in the AST; | ||
| // under parse recovery the raw value can still be an empty array while the property | ||
| // node is missing, so fall back to a compiler diagnostic (matches Strada). | ||
| errors = append(errors, CreateDiagnosticForNodeInSourceFileOrCompilerDiagnostic(sourceFile.SourceFile, nodeValue, diagnosticMessage, fileName)) |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #65079
Summary
When
tsconfig.jsonis malformed such that the recovered JSON value still has an empty"files"array but the AST no longer has a usable"files"property node (e.g.{"files":[]}]}), reporting TS18002 viaCreateDiagnosticForNodeInSourceFilenil-dereferences the missing node and panics.Use
CreateDiagnosticForNodeInSourceFileOrCompilerDiagnosticinstead, matching Strada: prefer a node-anchored diagnostic when the property exists, otherwise fall back to a compiler diagnostic.Test plan
{"files":[]}]}— no panic; emits unlocated TS18002 (+ parse errors); exit non-zero{"files":[]}— still emits located TS18002 at the empty arraytscfrom this branch and verified both cases locally