+
Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.

fix(rome_formatter): format range has incorrect source map #4149 #4241

Merged
merged 1 commit into from
Feb 27, 2023

Conversation

denbezrukov
Copy link
Contributor

@denbezrukov denbezrukov commented Feb 26, 2023

Summary

#4149
This PR tries to fix several issues when we format a node with a range.

  1. The transform function builds the source map by iterating over all tokens and pushing source text in the builder. This correctly builds up the source text for the sub-tree, but the offsets are incorrect if the root isn't at the start of the document.
  2. The transform function can detach a node if it updates a tree (splice_slots) while a traversing. We must return transformed a node back into the original tree to correct offset and sometimes a formatting result depends on a parent kind.

Test Plan

cargo test

Documentation

  • The PR requires documentation
  • I will create a new PR to update the documentation

@netlify
Copy link

netlify bot commented Feb 26, 2023

Deploy Preview for docs-rometools canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit e3b5c6a
🔍 Latest deploy log https://app.netlify.com/sites/docs-rometools/deploys/63fb77bf3731ca0007169e5d

@MichaReiser
Copy link
Contributor

Thanks for looking into fixing the source map issue!

@denbezrukov denbezrukov added this pull request to the merge queue Feb 27, 2023
Merged via the queue into rome:main with commit a8e6088 Feb 27, 2023
@denbezrukov denbezrukov deleted the fix/format_range branch February 27, 2023 12:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载