Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mod(es/base): Move comments following the order of insertion in fixer #7097

Merged
merged 1 commit into from Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/swc_ecma_transforms_base/Cargo.toml
Expand Up @@ -19,6 +19,7 @@ concurrent-renamer = ["rayon"]
[dependencies]
better_scoped_tls = { version = "0.1.0", path = "../better_scoped_tls" }
bitflags = "1"
indexmap = "1.6.1"
once_cell = "1.10.0"
phf = { version = "0.10", features = ["macros"] }
rayon = { version = "1", optional = true }
Expand Down
11 changes: 7 additions & 4 deletions crates/swc_ecma_transforms_base/src/fixer.rs
@@ -1,4 +1,7 @@
use rustc_hash::FxHashMap;
use std::{hash::BuildHasherDefault, ops::RangeFull};

use indexmap::IndexMap;
use rustc_hash::FxHasher;
use swc_atoms::js_word;
use swc_common::{comments::Comments, util::take::Take, Span, Spanned};
use swc_ecma_ast::*;
Expand Down Expand Up @@ -37,7 +40,7 @@ struct Fixer<'a> {
///
/// Key is span of inner expression, and value is span of the paren
/// expression.
span_map: FxHashMap<Span, Span>,
span_map: IndexMap<Span, Span, BuildHasherDefault<FxHasher>>,

in_for_stmt_head: bool,

Expand Down Expand Up @@ -613,7 +616,7 @@ impl VisitMut for Fixer<'_> {

n.visit_mut_children_with(self);
if let Some(c) = self.comments {
for (to, from) in self.span_map.drain() {
for (to, from) in self.span_map.drain(RangeFull).rev() {
c.move_leading(from.lo, to.lo);
c.move_trailing(from.hi, to.hi);
}
Expand Down Expand Up @@ -673,7 +676,7 @@ impl VisitMut for Fixer<'_> {

n.visit_mut_children_with(self);
if let Some(c) = self.comments {
for (to, from) in self.span_map.drain() {
for (to, from) in self.span_map.drain(RangeFull).rev() {
c.move_leading(from.lo, to.lo);
c.move_trailing(from.hi, to.hi);
}
Expand Down