Skip to content

fix(core): map private names so their diagnostics report (#203) - #207

Merged
leonidaz merged 2 commits into
mainfrom
fix/private-identifier-mapping-203
Sep 23, 2026
Merged

leonidaz merged 2 commits into
mainfrom
fix/private-identifier-mapping-203

Conversation

@leonidaz

@leonidaz leonidaz commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #203

Problem

tsrx-tsc exited 0 for export class Model { #value: number = "bad"; }, and for an uninitialized #value: number under strict. TypeScript reports both errors (TS2322, TS2564) on the private name. 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, 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:

  • field, method, and getter/setter keys, including static and accessor members
  • this.#name and Model.#name reads
  • #name in obj checks
  • the extra source position recorded for a dynamic tag's closing </{this.#Tag}>, which the walker previously dropped for private names

Verification

Ran a file with two private-field errors and two ordinary errors through each target's playground setup (preact shares the React one):

TS2322 #value TS2564 #missing exit
tsc on the same code as .ts ✓ ✓ 2
tsrx-tsc before (React) missing missing 2 (ordinary errors only)
tsrx-tsc after (React, Preact, Solid, Vue, Hono) ✓ ✓ 2

The issue's exact repro now reports App.tsrx(1,22): error TS2322 and exits 2.

Tests

  • Shared source-mapping test, run for every target: every #name in a class that uses private fields, methods, accessors, reads, in, and a dynamic tag maps to the same #name in the generated code. Without the fix, all 11 are unmapped.
  • tsrx-tsc CLI test: TS2322 and TS2564 on private fields at the right columns. Fails without the fix.
  • pnpm test, pnpm typecheck, pnpm format:check, and pnpm changeset:check pass. In one full run, the first spawn in tsc.test.js failed and passed on rerun; that file passes on its own.

Related

🤖 Generated with Claude Code


Note

Medium Risk
Changes core Volar source-mapping for private identifiers, which affects how all .tsrx type errors surface in the editor and CLI, but the change is localized with regression tests.

Overview
Fixes missing TypeScript diagnostics on #private class members in .tsrx files for tsrx-tsc and the editor. The source-mapping walker used to skip PrivateIdentifier nodes, so Volar dropped errors (e.g. TS2322 on bad initializers, TS2564 on uninitialized fields) that TypeScript attaches to the full #name span.

The walker now emits verification mappings for each private name as #name, including extra_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 a tsrx-tsc CLI test for TS2322/TS2564 columns. @tsrx/core patch changeset added.

Reviewed by Cursor Bugbot for commit 04135e1. Bugbot is set up for automated code reviews on this repo. Configure here.

`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]>
@vercel

vercel Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
tsrx-website Ready Ready Preview Sep 23, 2026 10:30pm UTC
tsrx-website-mcp Ready Ready Preview Sep 23, 2026 10:30pm UTC

Request Review

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

2 active deployments
Preview – tsrx-website — 04135e15 Deployed Sep 23, 2026 by vercel[bot]
Preview – tsrx-website-mcp — 04135e15 Deployed Sep 23, 2026 by vercel[bot]
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.

[Bug]: tsrx-tsc silently accepts incompatible and uninitialized #private fields

1 participant