Repository navigation
fix(core): map primitive type keywords so return-type diagnostics report (#210) - #217
Merged
Merged
Conversation
…ort (#210) `tsrx-tsc` exited 0 for `export class Model { value(): number {} }`, which TypeScript rejects with TS2355. TypeScript reports missing-return errors (TS2355, TS2366, TS2534, TS1064) on the return type, but the source-mapping walker in segments.js returned early for primitive type keywords without adding a mapping. Volar drops any diagnostic it cannot map back to the source. Map each primitive type keyword (`number`, `string`, `this`, and the rest) as a token, as identifiers are. esrap writes these keywords with their node's location. The walker also mapped a method's value as a `function` keyword when the file had no `function` or `async` keyword at all: an empty collected token list fell through to arithmetic meant for callers that collect no tokens, which mapped the 8 characters after the method's `(`. That stray span is how `value(): this {}` reported before. An empty list now means there is no keyword, and the arithmetic fallback checks the source text. Composite return types (`number[]`, `{ a: number }`, `keyof T`) still lose these diagnostics because esrap records no location at their boundaries. #216 tracks replacing the keyword tokens with a whole return type mapping once esrap ships sveltejs/esrap#198. Fixes #210 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Merged
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 #210
Problem
tsrx-tscexited 0 forexport class Model { value(): number {} }, whichtscrejects with TS2355. TypeScript reports missing-return errors on the return type: TS2355, TS2366 (no ending return), TS2534 (neverwith a reachable end), and TS1064 (async return type notPromise). The source-mapping walker insegments.jsreturned early for primitive type keywords without adding a mapping. Volar drops any diagnostic it cannot map back to the source.The problem was not limited to class methods.
function value(): number {}andfunction (): number {}were silent too, for every primitive keyword.A second bug hid part of this. When a file contains no
functionorasynckeyword at all, the lexer's collected keyword list is empty. The walker treated an empty list as "tokens not collected" and fell back to arithmetic that assumes a function starts withfunction. For a method value, which starts at(, that mapped the 8 characters(): numbas afunctionkeyword. That stray span is the[?,35)mapping the issue found. It also madevalue(): this {}report, but only in files with nofunctionkeyword.Fix
number,string,boolean,this,void,never, and the rest) as a token, as identifiers are. esrap writes these keywords with their node's location, so the lookup is exact.Verification
I compared
tsrx-tsc(Preact) withtscon the same code as.ts, over 24 cases. They cover primitive, union, generic, template-literal, and composite return types on class methods, functions, and function expressions, plus annotation and argument controls.tscorigin/mainThe issue's repro now reports
App.tsrx(1,31): error TS2355and exits 2, the same astsc.The 9 remaining cases are composite return types:
number[],[number],{ a: number },keyof Model,() => void,(string),Model["value"], andtypeof globalThis. esrap records no location at their boundaries, so tsrx has nothing to map them from. Onmain,keyof Modelandtypeof globalThisreported through the stray span, but only in files with nofunctionkeyword. Addexport function f() {}andmainmisses both. They now fail the same way as the other composite types.Tests
(. The file has nofunctionkeyword, so both bugs are exercised. Both assertions fail without the fix.tsrx-tscCLI test: TS2355 onvalue(): number {}at thenumbercolumn. Fails without the fix.pnpm test,pnpm typecheck,pnpm format:check, andpnpm changeset:checkpass. In one full run, the first spawn intsc.test.jshit the 5s timeout. That file passes on its own, as seen before in fix(core): map private names so their diagnostics report (#203) #207.Follow-up
#216 tracks replacing the keyword tokens with a verify-only mapping over the whole return type once tsrx is on an esrap release with sveltejs/esrap#198 (open). With #198 linked in and that mapping prototyped, all 24 cases match
tsc, with or without the keyword tokens. esrap main (with sveltejs/esrap#192 and #199) changes nothing here, and sveltejs/esrap#183 reaches 21/24 with the prototype. The code comment links to #216.🤖 Generated with Claude Code
Note
Medium Risk
Changes source-map/diagnostic anchoring in the core transform walker, which affects editor and CLI type-check reporting across all
.tsrxtargets; behavior is well-covered by new tests but touches a sensitive path.Overview
Fixes missing-return diagnostics (e.g. TS2355 on
value(): number {}) in.tsrxfiles by emitting Volar source mappings for primitive type keywords (number,string,void,this, etc.) instead of skipping them in the mapping walker.Also fixes false
functionkeyword mappings on class methods when the file has nofunction/asynctokens: an empty lexer keyword list is treated as “no keywords,” and the arithmetic fallback only maps when the source actually starts with the keyword at the computed offset.Adds shared mapping tests for all primitive return-type keywords (including the no-
function-in-file case) and atsrx-tscCLI test asserting TS2355 at thenumbercolumn. Composite return types (e.g.number[]) remain unmapped until esrap boundary locations land (#216).Reviewed by Cursor Bugbot for commit 4306581. Bugbot is set up for automated code reviews on this repo. Configure here.