mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 22:22:34 +03:00
refactor(es/fixer): Move comments with the insertion order (#7097)
This commit is contained in:
parent
85c51a81e7
commit
f250f243cb
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -3844,6 +3844,7 @@ dependencies = [
|
|||||||
"better_scoped_tls",
|
"better_scoped_tls",
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"criterion",
|
"criterion",
|
||||||
|
"indexmap",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"phf",
|
"phf",
|
||||||
"rayon",
|
"rayon",
|
||||||
|
@ -19,6 +19,7 @@ concurrent-renamer = ["rayon"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
better_scoped_tls = { version = "0.1.0", path = "../better_scoped_tls" }
|
better_scoped_tls = { version = "0.1.0", path = "../better_scoped_tls" }
|
||||||
bitflags = "1"
|
bitflags = "1"
|
||||||
|
indexmap = "1.6.1"
|
||||||
once_cell = "1.10.0"
|
once_cell = "1.10.0"
|
||||||
phf = { version = "0.10", features = ["macros"] }
|
phf = { version = "0.10", features = ["macros"] }
|
||||||
rayon = { version = "1", optional = true }
|
rayon = { version = "1", optional = true }
|
||||||
|
@ -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_atoms::js_word;
|
||||||
use swc_common::{comments::Comments, util::take::Take, Span, Spanned};
|
use swc_common::{comments::Comments, util::take::Take, Span, Spanned};
|
||||||
use swc_ecma_ast::*;
|
use swc_ecma_ast::*;
|
||||||
@ -37,7 +40,7 @@ struct Fixer<'a> {
|
|||||||
///
|
///
|
||||||
/// Key is span of inner expression, and value is span of the paren
|
/// Key is span of inner expression, and value is span of the paren
|
||||||
/// expression.
|
/// expression.
|
||||||
span_map: FxHashMap<Span, Span>,
|
span_map: IndexMap<Span, Span, BuildHasherDefault<FxHasher>>,
|
||||||
|
|
||||||
in_for_stmt_head: bool,
|
in_for_stmt_head: bool,
|
||||||
|
|
||||||
@ -613,7 +616,7 @@ impl VisitMut for Fixer<'_> {
|
|||||||
|
|
||||||
n.visit_mut_children_with(self);
|
n.visit_mut_children_with(self);
|
||||||
if let Some(c) = self.comments {
|
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_leading(from.lo, to.lo);
|
||||||
c.move_trailing(from.hi, to.hi);
|
c.move_trailing(from.hi, to.hi);
|
||||||
}
|
}
|
||||||
@ -673,7 +676,7 @@ impl VisitMut for Fixer<'_> {
|
|||||||
|
|
||||||
n.visit_mut_children_with(self);
|
n.visit_mut_children_with(self);
|
||||||
if let Some(c) = self.comments {
|
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_leading(from.lo, to.lo);
|
||||||
c.move_trailing(from.hi, to.hi);
|
c.move_trailing(from.hi, to.hi);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user