Repository navigation
fix(core): map private names so their diagnostics report (#203) - #207
Merged
Merged
Conversation
`tsrx-tsc` exited 0 for `export class Model { #value: number = "bad"; }`
and for an uninitialized `#value: number`. TypeScript reports both errors
(TS2322, TS2564) on the private name, but the source-mapping walker in
segments.js returned early for PrivateIdentifier without adding a mapping.
Volar drops any diagnostic it cannot map back to the source.
Map each private name as the whole `#name`. esrap prints the `#` on its
own and anchors the node's source start on the name after it. The lookup
accepts that anchor or one on the `#`. The mapping covers field, method,
and accessor keys, `this.#name` reads, `#name in obj` checks, and the
extra source position a dynamic tag's closing `</{this.#Tag}>` records.
Fixes #203
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Point the name-anchor fallback at #208, which tracks replacing it with an ordinary token once esrap maps the `#` itself (sveltejs/esrap#198). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This branch was successfully 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 #203
Problem
tsrx-tscexited 0 forexport class Model { #value: number = "bad"; }, and for an uninitialized#value: numberunderstrict. TypeScript reports both errors (TS2322, TS2564) on the private name. The source-mapping walker insegments.jsreturned early forPrivateIdentifierwithout adding a mapping. Volar drops any diagnostic it cannot map back to the source, so both errors were lost.Fix
The walker now maps each private name as the whole
#name. esrap prints the#on its own, then writes the name with the node's location. The source#therefore resolves to the generated character after it. The lookup accepts that anchor or one on the#. Ripple's printer uses esrap's default here as well, so it gets the fix with a core bump.The mapping covers:
staticandaccessormembersthis.#nameandModel.#namereads#name in objchecks</{this.#Tag}>, which the walker previously dropped for private namesVerification
Ran a file with two private-field errors and two ordinary errors through each target's playground setup (preact shares the React one):
#value#missingtscon the same code as.tstsrx-tscbefore (React)tsrx-tscafter (React, Preact, Solid, Vue, Hono)The issue's exact repro now reports
App.tsrx(1,22): error TS2322and exits 2.Tests
#namein a class that uses private fields, methods, accessors, reads,in, and a dynamic tag maps to the same#namein the generated code. Without the fix, all 11 are unmapped.tsrx-tscCLI test: TS2322 and TS2564 on private fields at the right columns. Fails without the fix.pnpm test,pnpm typecheck,pnpm format:check, andpnpm changeset:checkpass. In one full run, the first spawn intsc.test.jsfailed and passed on rerun; that file passes on its own.Related
##208 tracks removing the name-anchor fallback once esrap maps the#itself. feat: more granular sourcemaps sveltejs/esrap#198 (open) does; esrap main and feat: locate internal delimiters exactly from parser tokens in boundaryTokens maps sveltejs/esrap#183 do not. The code comment links to it.!on class fields) is a separate Prettier fix.classkeyword source mapping assumes the class node starts atclass#193 (classkeyword mapping) is still waiting on the esrap upgrade and is not touched here.🤖 Generated with Claude Code
Note
Medium Risk
Changes core Volar source-mapping for private identifiers, which affects how all
.tsrxtype errors surface in the editor and CLI, but the change is localized with regression tests.Overview
Fixes missing TypeScript diagnostics on
#privateclass members in.tsrxfiles fortsrx-tscand the editor. The source-mapping walker used to skipPrivateIdentifiernodes, so Volar dropped errors (e.g. TS2322 on bad initializers, TS2564 on uninitialized fields) that TypeScript attaches to the full#namespan.The walker now emits verification mappings for each private name as
#name, includingextra_source_mappings(e.g. dynamic tag closings). A small esrap workaround steps the generated offset back one character when the#is printed without its own location.Coverage is exercised by a shared mapping test (fields, methods, accessors, reads,
in, dynamic tags) and atsrx-tscCLI test for TS2322/TS2564 columns.@tsrx/corepatch changeset added.Reviewed by Cursor Bugbot for commit 04135e1. Bugbot is set up for automated code reviews on this repo. Configure here.