mirror of
https://github.com/swc-project/swc.git
synced 2024-11-28 02:29:04 +03:00
Add borrow_all()
to SingleThreadedComments
(#1262)
Co-authored-by: 강동윤 <kdy1997.dev@gmail.com>
This commit is contained in:
parent
718f47803b
commit
01b6a0a90f
@ -6,7 +6,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_common"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.10.6"
|
||||
version = "0.10.7"
|
||||
|
||||
[features]
|
||||
concurrent = ["parking_lot"]
|
||||
|
@ -3,7 +3,11 @@ use crate::{
|
||||
syntax_pos::{BytePos, Span},
|
||||
};
|
||||
use fxhash::FxHashMap;
|
||||
use std::{cell::RefCell, rc::Rc, sync::Arc};
|
||||
use std::{
|
||||
cell::{Ref, RefCell},
|
||||
rc::Rc,
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
/// Stores comment.
|
||||
///
|
||||
@ -107,7 +111,8 @@ where
|
||||
delegate!();
|
||||
}
|
||||
|
||||
pub type SingleThreadedCommentsMap = Rc<RefCell<FxHashMap<BytePos, Vec<Comment>>>>;
|
||||
pub type SingleThreadedCommentsMapInner = FxHashMap<BytePos, Vec<Comment>>;
|
||||
pub type SingleThreadedCommentsMap = Rc<RefCell<SingleThreadedCommentsMapInner>>;
|
||||
|
||||
/// Single-threaded storage for comments.
|
||||
#[derive(Debug, Clone, Default)]
|
||||
@ -184,6 +189,16 @@ impl SingleThreadedComments {
|
||||
(self.leading, self.trailing)
|
||||
}
|
||||
|
||||
/// Borrows all the comments as (leading, trailing).
|
||||
pub fn borrow_all<'a>(
|
||||
&'a self,
|
||||
) -> (
|
||||
Ref<'a, SingleThreadedCommentsMapInner>,
|
||||
Ref<'a, SingleThreadedCommentsMapInner>,
|
||||
) {
|
||||
(self.leading.borrow(), self.trailing.borrow())
|
||||
}
|
||||
|
||||
pub fn with_leading<F, Ret>(&self, pos: BytePos, op: F) -> Ret
|
||||
where
|
||||
F: FnOnce(&[Comment]) -> Ret,
|
||||
@ -206,6 +221,7 @@ impl SingleThreadedComments {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Comment {
|
||||
pub kind: CommentKind,
|
||||
|
Loading…
Reference in New Issue
Block a user