Skip to content

Commit

Permalink
mod(es/base): Move comments following the order of insertion in fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
Austaras committed Mar 20, 2023
1 parent 85c51a8 commit 112ecfb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
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

0 comments on commit 112ecfb

Please sign in to comment.