Repository navigation
Fix crash locating a content mapper option diagnostic inherited through extends - #65652
Ben Snyder (benpsnyder) wants to merge 4 commits into
Conversation
…gh extends GetContentMapperOptionDiagnosticLocation looked for the contentMappers syntax only in the project's own tsconfig.json. When the entry was inherited through "extends", no syntax was found, the node stayed nil, and walking a non-empty option path dereferenced it. Look in the config file that declared the setting, which the parser already tracks for its own content mapper diagnostics, so the diagnostic points at the option in the base config. Return no location instead of walking a nil node when no syntax exists at all. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s and overrides Cover an entry inherited through two levels of "extends" and from an earlier entry of an "extends" list, both of which panicked before the fix, and an entry the child config overrides, whose diagnostic must stay in the child's tsconfig.json. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the change to locate content mapper diagnostics in the configuration that declared them.
No open issues 🎉
What changed in this PR
Fixes #65651 by making the compiler locate content mapper option diagnostics in the config that declared contentMappers, including when inherited through extends, rather than crashing.
Changes:
- Preserve the declaring config file when creating or copying parsed configurations.
- Use that file for diagnostic locations and return no location safely when syntax is missing.
- Add regression tests for inheritance, child overrides, nested options, and command-line diagnostic output.
| File | Description |
|---|---|
tsc/testdata/baselines/reference/tsc/contentMapperOptionDiagnostics/mapper-option-diagnostic-from-extended-config-in-another-directory.js |
Records the expected diagnostic location in the base config. |
tsc/internal/tsoptions/tsconfigparsing.go |
Retains the declaring file and guards diagnostic lookup against missing syntax. |
tsc/internal/tsoptions/tsconfigparsing_test.go |
Tests inherited locations, overrides, option paths, and missing syntax. |
tsc/internal/tsoptions/parsedcommandline.go |
Stores and preserves the declaring file across file-name updates. |
tsc/internal/execute/tsctests/tsc_test.go |
Adds an end-to-end regression test using a base config in another directory. |
Review effort: Balanced
|
@microsoft-github-policy-service agree |
Andrew Branch (andrewbranch)
left a comment
There was a problem hiding this comment.
Alternative considered: dropping the location for an inherited entry, reporting the diagnostic with no file. That also removes the crash, but it discards the location the mapper asked for when the base config's syntax is already available.
I know it's not ideal, but I think we want to go with this approach for now. This is how every other program-time config error is reported when the offending location comes from an extended config. The current approach clashes with how project diagnostics are published in the LSP (they always go to project's own tsconfig.json). If we're going to improve on this, we should do it across the board for program diagnostics on extended configs.
A contentMappers entry inherited through extends has no syntax in the project's own tsconfig.json, so its option diagnostic now has no file, as other program-time config errors from an extended config do. The nil check moves above the option path walk, which crashed on the missing node. This drops the declaring config file the PR had stored on ParsedCommandLine. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Changed in 91d7614: an option diagnostic for a |
Fixes #65651
Analysis
GetContentMapperOptionDiagnosticLocationlooks for thecontentMapperssyntax only in the project's own config file. When the entry is inherited throughextends, that file has nocontentMappersproperty:so
getContentMapperSyntaxreturns nil for both the mapper and itsoptions. When the mapper answersopenProjectwith an option diagnostic whose path is not empty (here["a"]), the walk over the path callsast.IsObjectLiteralExpression(nil)(orast.IsArrayLiteralExpression(nil)for an index segment) andtsc --runExternalCodepanics. With an empty path nothing is dereferenced, and the diagnostic already had no location.Fix
The existing
node == nilcheck now runs before the path walk. An option diagnostic for an entry inherited throughextendsis reported without a location (error fake1: Option 'a' must be a string.for the example above), the waycreateCompilerOptionsDiagnosticinprogram.goreports other program-time config errors whose syntax is in an extended config. AcontentMappersentry the project's owntsconfig.jsondeclares still gets its location there. Better locations for diagnostics from extended configs are left for a change that covers all program diagnostics.Tests:
TestContentMapperOptionDiagnosticLocationInheritedFromExtendedConfig: a base config in another directory, with a nested option, an array element, an empty path, and a mapper not in the config. Each expects no file and an undefined range.TestContentMapperOptionDiagnosticLocationWithExtends: an entry inherited through two levels ofextendsand one from an earlier entry of anextendslist, both with no location, and an entry the child overrides, whose diagnostic stays in the child'stsconfig.json.TestContentMapperOptionDiagnosticLocationWithoutContentMappersSyntax: property and index segments when no config hascontentMapperssyntax.TestTscContentMapperOptionDiagnosticsFromExtendedConfig, with a new baseline: the fulltscrun, which reportserror mapper123: Option 'name' requires a string.With the check moved back below the loop, every case with a non-empty path panics; the empty path and the child override pass. The
tsctest panics inGetContentMapperOptionDiagnosticLocation, as in the issue.Not changed: the mapper's position is still found with
slices.Index(config.ContentMappers(), mapper), which is not its position in thecontentMappersarray when an earlier entry was dropped. With[{ "package": "missing-mapper", "extensions": [".other"] }, { "package": "fake-mapper", "extensions": [".fake"], "options": { "a": 1 } }]intsconfig.json, the diagnostic forais reported at the first entry, before and after this change. That is a wrong location, not a crash, and is left for a separate change.Copilot Checklist
I successfully ran the applicable command at the end of my session, and it completed without error: