Repository navigation
feat: optional boundaryTokens source-map anchors for structural tokens - #148
Merged
Merged
Conversation
Structural tokens — array/object brackets and braces, preserved parentheses, unary operators, and the closing tokens of calls and computed member access — are written without location markers. Since source-map consumers attribute every generated character to the nearest PRECEDING segment, these characters (and any whitespace after them) are attributed to the previous token's source position, and a node whose source span begins or ends on one of them has no resolvable boundary position at all. Tools that map node-boundary positions back to source (e.g. Volar-style virtual-file tooling translating diagnostics) must then fail or degrade. Add a `boundaryTokens` language option that anchors each such token with a one-character location at the node boundary it represents. Printed output is byte-identical; maps gain segments (measured ~13% mappings growth on a dense file), which is why the option is OFF by default — existing consumers are completely unaffected.
|
Install the latest version of pnpm add https://pkg.svelte.dev/esrap/c/6a4aa4eec33c064f134d35051587ac558bdbef76Open in Note This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed. |
🦋 Changeset detectedLatest commit: 6a4aa4e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
trueadm
approved these changes
Jul 18, 2026
trueadm
left a comment
There was a problem hiding this comment.
Looks like a good quality of life win.
This was referenced Sep 2, 2026
Closed
leonidaz
added a commit
to leonidaz/esrap
that referenced
this pull request
Sep 2, 2026
…ryTokens maps The AST records where a computed key's expression is, not where its brackets are. `boundaryTokens` (sveltejs#148) anchored those brackets by assuming they touch the key, which is wrong whenever whitespace, newlines or comments sit between bracket and key. Add a `tokens` option: the parser's token stream (Acorn `onToken`, Babel `tokens`, ESLint-style `ast.tokens`). With it, every delimiter internal to a node — computed-key brackets, the parentheses of calls, functions, signatures and control-flow statements, the braces of import/export lists, enums, static blocks and template interpolations — is anchored to its real source position via a bounded nearest-token search. Without it those delimiters are left unmapped rather than guessed. Node-boundary anchors are unchanged and output stays byte-identical. The token index sorts on demand: acorn-typescript re-emits tokens when it backtracks, so its stream is not monotone and a plain binary search would silently miss brackets. The anchoring lives in `boundary-tokens.js`, memoised per options object and shared with `tsx`; `write_params`, `write_keyword_paren` and `write_parenthesized` replace the per-visitor copies of the same open/close pattern.
leonidaz
added a commit
to leonidaz/esrap
that referenced
this pull request
Sep 2, 2026
…ryTokens maps The AST records where a computed key's expression is, not where its brackets are. `boundaryTokens` (sveltejs#148) anchored those brackets by assuming they touch the key, which is wrong whenever whitespace, newlines or comments sit between bracket and key. Add a `tokens` option: the parser's token stream (Acorn `onToken`, Babel `tokens`, ESLint-style `ast.tokens`). With it, every delimiter internal to a node — computed-key brackets, the parentheses of calls, functions, signatures and control-flow statements, the braces of import/export lists, enums, static blocks and template interpolations — is anchored to its real source position via a bounded nearest-token search. Without it those delimiters are left unmapped rather than guessed. Node-boundary anchors are unchanged and output stays byte-identical. The token index sorts on demand: acorn-typescript re-emits tokens when it backtracks, so its stream is not monotone and a plain binary search would silently miss brackets. The anchoring lives in `boundary-tokens.js`, memoised per options object and shared with `tsx`; `write_params`, `write_keyword_paren` and `write_parenthesized` replace the per-visitor copies of the same open/close pattern.
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.
Structural tokens — array/object brackets and braces, preserved parentheses, unary operators, and the closing tokens of calls and computed member access are written without location markers. Since source-map consumers attribute every generated character to the nearest PRECEDING segment, these characters (and any whitespace after them) are attributed to the previous token's source position, and a node whose source span begins or ends on one of them has no resolvable boundary position at all. Tools that map node-boundary positions back to source (e.g. Volar-style virtual-file tooling translating diagnostics) must then fail or degrade.
Add a
boundaryTokenslanguage option that anchors each such token with a one-character location at the node boundary it represents. Printed output is byte-identical; maps gain segments (measured ~13% mappings growth on a dense file), which is why the option is OFF by default - existing consumers are completely unaffected.