Repository navigation
Fix crash locating a content mapper option diagnostic inherited through extends - #1
Closed
benpsnyder wants to merge 2 commits into
Closed
benpsnyder wants to merge 2 commits into
benpsnyder wants to merge 2 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>
Owner
Author
|
Replaced by microsoft#65652. |
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.
No upstream issue: a search of microsoft/TypeScript and microsoft/typescript-go found no report of this crash, and none has been filed. This PR is on the fork only.
Analysis
tsc --runExternalCodepanics with a nil pointer dereference when a content mapper answersopenProjectwith an option diagnostic and the project'scontentMappersentry is inherited throughextends:Minimal reproduction (found on
typescript@7.1.0-beta, reproduced onmainat 88071f4 with a locally builttsc):The mapper answers
openProjectwithoptionDiagnostics: [{ path: ["a"], messageText: "bad option a", code: 9002 }]. Runningtsc --noEmit --runExternalCodeinapppanics. With the same entry written inapp/tsconfig.jsonitself, the diagnostic is reported attsconfig.json(2,94); with no option diagnostic, the project checks clean.Root cause:
GetContentMapperOptionDiagnosticLocationlooks for thecontentMapperssyntax only inconfig.ConfigFile.SourceFile, the project's own file. For an inherited entry that file has nocontentMappersproperty, sogetContentMapperSyntaxreturns nil for both the mapper and itsoptions, and the loop over a non-empty option path callsast.IsObjectLiteralExpression(nil)(orast.IsArrayLiteralExpression(nil)for an index segment). The parser already records which config file declared the setting (parsedConfig.contentMapperSourceFile) and uses it for every content mapper diagnostic it reports itself, but that file was not kept on theParsedCommandLine, so this later lookup could not use it.Inputs that reach the nil, all with a non-empty path:
extends(the reported case);config.ContentMappers()(slices.Indexreturns -1) when the entry is inherited. With the entry in the project's own file, -1 resolves to thecontentMappersarray and did not crash;ParsedCommandLinewhose config file has nocontentMapperssyntax at all but has mappers set.With an empty path the nil was not dereferenced, but the diagnostic for an inherited entry lost its location.
Fix
Keep the config file that declared
contentMapperson theParsedCommandLine(set where it is built, copied byWithFileNamesandReloadFileNamesOfParsedCommandLine) and look up the option there, falling back to the project's own file. An option diagnostic for an inherited entry now points at the option in the base config, as the parser's own content mapper diagnostics already do (../base/tsconfig.base.json(2,94): error fake9002: bad option a). The existing nil check now runs before the path walk, so a config with nocontentMapperssyntax gets a diagnostic without a location instead of a panic. The diagnostic is still always reported.Alternative considered: attributing the diagnostic to the child's
extendsproperty. It is less precise, and pointing into the base config matches how the other content mapper diagnostics already treat inherited entries.Not changed: the mapper's position is still found with
slices.Index(config.ContentMappers(), mapper), which can differ from its position in thecontentMappersarray when an earlier entry was dropped (for example a failed package resolution). That gives a wrong location, not a crash, and is left for a separate change.Tests:
TestContentMapperOptionDiagnosticLocationInheritedFromExtendedConfig(tsc/internal/tsoptions): base config in another directory; nested option, array element, empty path, and a mapper not in the config. Three panic onmainand the empty-path case fails with a nil file.TestContentMapperOptionDiagnosticLocationWithoutContentMappersSyntax: property and index segments with nocontentMapperssyntax. Both panic onmain.TestTscContentMapperOptionDiagnosticsFromExtendedConfig(tsc/internal/execute/tsctests), new baselinetsc/contentMapperOptionDiagnostics/mapper-option-diagnostic-from-extended-config-in-another-directory.js: the fulltscrun with the test mapper. It panics onmainwith the reported stack, and with the fix reports../base/tsconfig.base.json(6,48): error mapper123: Option 'name' requires a string.Copilot Checklist
I successfully ran the applicable command at the end of my session, and it completed without error:
Not checked, because
npx hereby validate --alldid not complete without error on this machine (macOS 27.2, Go 1.27.4, Node 26.7.0). It reportedtest:tsc,test:tools,test:codegenandlintas failed. Each failure also occurs on unmodifiedmainat 88071f4 or comes from the host's toolchain:test:tsc: 23 failures out of 173,495 tests, all incmd/tscTestCommandLineTermination,internal/fswatchandinternal/lsp/lspwatcher. Each of these also fails onmain. Run alone,TestCommandLineTermination(watch-mode processes that time out waiting to terminate) failed in 3 of 4 runs onmainand 4 of 4 on this branch, andfswatchandlspwatcherfailed onmaintoo.test:tools:tools/cmd/machotooldoes not link, because the Command Line Tools linker rejects the SDK'sarm64e.x1stubs. It fails the same way onmain.test:codegen:tools/scripts/gen/cache.test.mtsexpects/private/var/...and gets/var/.... It fails the same way onmain.lint: building golangci-lint fails at the same cgo link step.CGO_ENABLED=0 npx hereby lintpasses with 0 issues in both modules.What passed:
npx hereby check:format,npx hereby tidywith no diff,CGO_ENABLED=0 npx hereby lint, the API tests included invalidate --all, andgo testforinternal/tsoptions/...,internal/compiler/...,internal/execute/...,internal/contentmapper/...andinternal/project/.... I also rebuilttscwithnpx hereby buildand reran the reproduction above.An AI coding agent (Claude) wrote this change at the owner's request.