Repository navigation
fix: map the end of a typed identifier to the end of its name - #215
Merged
Merged
Conversation
For a typed, optional or definite binding both Acorn and typescript-estree give the Identifier a range that runs to the end of its annotation, so the segment at the end of the name pointed past the annotation. Derive the name's end from its length instead. Untyped identifiers keep the node's own location, so names written with unicode escapes are unaffected. Closes sveltejs#205 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Install the latest version of pnpm add https://pkg.svelte.dev/esrap/c/8043982405b71a3ad6a28205b79ca55af9f72907Open 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: 8043982 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 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 #205.
For a typed, optional or definite binding, both Acorn and typescript-estree give the
Identifiera range that runs to the end of its annotation (id: string,id?: string,x!: number). TheIdentifiervisitor writes the name with the node's location, so the segment at the end of the name pointed past the annotation: infunction f(id: string) {}the generated:mapped to the). A consumer building the name's range from its start and end segments gotid: stringinstead ofid.Change: when the identifier has a type annotation, is optional or is definite, the name is written with an end derived from its length. Untyped identifiers keep the node's own location, so a name written with unicode escapes is unaffected; a typed name written with escapes would be short by the escape length, which I have not seen in practice.
The root visitor's end mapping after the annotation is untouched, so the position after
stringstill maps to the end of the whole declaration. Printed output is unchanged; 36 sample maps change one segment each.Tests: five cases in
sourcemap-keywords.test.jsassert that the segment at the end of the name maps to the end of the name and not one column past it, for typed, optional and definite bindings, and that an untyped name is unchanged.Validation:
pnpm test— 320 tests passedpnpm lint— passedpnpm check— the two pre-existing TS2580Buffererrors insrc/index.jsonmain, nothing newLike #212, #213 and #214 this appends tests to
sourcemap-keywords.test.jsand regenerates sample maps, so whichever lands later needs a trivial rebase.🤖 Generated with Claude Code