Repository navigation
feat: more granular sourcemaps - #198
Conversation
|
Install the latest version of pnpm add https://pkg.svelte.dev/esrap/c/a58cc621183aaf4899dcbe5508e416c6042a022dOpen in |
|
|
Actually, I misspoke — Some tests fail when I make that change; will take a closer look tomorrow. Worth noting that the second argument to |
|
Okay, the logic does need to live in |
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]>
* fix(core): map private names so their diagnostics report (#203) `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]> * docs(core): mark the private-name esrap workaround for removal (#208) 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]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
|
Seems like the tests are failing after merging |
…ort (#210) (#217) `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]>
teemingc
left a comment
There was a problem hiding this comment.
Was a little daunted to review this at first but most of the file changes are test fixtures and GPT helped explain the codebase a bit
Co-authored-by: Tee Ming <[email protected]>
This PR adds mappings around every visited node with a
locproperty, making sourcemaps more granular without us needing to docontext.location(...)at a bunch of different sites.Notably, this includes things like
PropertyandMethodDefinition, which means that opening[characters on computed property keys are correctly mapped. In the common case where the closing]immediately follows the key expression, this is sufficient for TypeScript diagnostics to match perfectly; in the uncommon case, it degrades to acceptable behaviour:To get this more correct behaviour,
boundaryTokens(from #148) must befalse. Candidly, we should delete this API, without regard for whether it's a breaking change. It was merged carelessly and without authority, and would not have passed a substantive review. Even aside from the buggy behaviour, it's not a desirable API.(It may still be necessary to merge some version of #183 to get return-type hints etc; that remains to be seen. It certainly makes it less urgent. Regardless,
boundaryTokenswould be unnecessary there too — the presence oftokenswould be sufficient as an API.)One design note: the logic exists in the
tsroot visitor, rather than oncontext.visit, because the latter doesn't know aboutloc. We could change that, and then any other visitors would inherit the same behaviour. For now I've left that as a future option.