Repository navigation
fix: map parentheses and braces added by the printer to what they wrap - #214
Merged
Merged
Conversation
When the printer adds parentheses the AST does not have (a lower-precedence class base, await argument or decorator expression, or any maybe_wrap site, including authored parentheses that Acorn drops), the opening parenthesis had no location, so a diagnostic reported on the parenthesized span had nothing to map its start to. Map the synthesized parentheses to the wrapped node's start and end. Same for the braces added around a dangling-else consequent. Closes sveltejs#211 Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
Install the latest version of pnpm add https://pkg.svelte.dev/esrap/c/dc490e4bb4f93738fe96b83f65b38f7946f735b7Open 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: dc490e4 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 |
This was referenced Sep 24, 2026
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.
Closes #211.
When the printer adds parentheses the AST does not have, the
(and)were written without a location. That happens inmaybe_wrap(every precedence-driven wrap, which includes authored parentheses that Acorn drops withpreserveParensoff), around a lower-precedence class base, around anawaitargument, and around a decorator expression. TypeScript reports on the parenthesized span, so its range starts at the(, and that column resolved to whatever was mapped before it: forclass B extends function () {} {}the end ofB, for(a || b)()nothing at all.Change:
maybe_wrapsets the location to the wrapped node'sloc.startbefore writing(and to itsloc.endafter writing). The class-base,awaitand decorator sites now go throughmaybe_wrapinstead of their own copy of the wrap. The braces theifvisitor adds around a dangling-else consequent get the same treatment, mapped to the consequent's span.This stays within the rule from #198: the positions come from the wrapped node, nothing is estimated. Printed output is unchanged; twenty sample maps gain segments.
Tests: four cases in
sourcemap-keywords.test.jsassert that the synthesized(maps to the start of what it wraps: class heritage, a call on a dropped parenthesized expression, anawaitargument and a decorator expression.Not changed here: the class-base wrap is more conservative than the grammar requires (
extends function () {}andextends maybe!are valid without parentheses). That is an output change and can be its own PR if wanted.Validation:
pnpm test— 319 tests passedpnpm lint— passedpnpm check— the two pre-existing TS2580Buffererrors insrc/index.jsonmain, nothing newLike #212 and #213 this appends tests to
sourcemap-keywords.test.jsand regenerates sample maps, so whichever lands second needs a trivial rebase.🤖 Generated with Claude Code