refactor(es/parser): Cleanup codes for the comment buffer (#2410)

This commit is contained in:
David Sherret 2021-10-11 23:08:06 -04:00 committed by GitHub
parent 4411d1d3a5
commit d114e7d364
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 18 deletions

10
Cargo.lock generated
View File

@ -2363,9 +2363,7 @@ dependencies = [
[[package]]
name = "swc_atoms"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "837a3ef86c2817228e733b6f173c821fd76f9eb21a0bc9001a826be48b00b4e7"
version = "0.2.8"
dependencies = [
"string_cache",
"string_cache_codegen",
@ -2374,6 +2372,8 @@ dependencies = [
[[package]]
name = "swc_atoms"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a20e0ff436c9967b5cbafbc0872f384fef5be6f9913ce92fb5f017427e95c7e"
dependencies = [
"string_cache",
"string_cache_codegen",
@ -2706,7 +2706,7 @@ dependencies = [
[[package]]
name = "swc_ecma_parser"
version = "0.73.10"
version = "0.73.11"
dependencies = [
"either",
"enum_kind",
@ -3114,7 +3114,7 @@ dependencies = [
"libloading",
"serde",
"serde_json",
"swc_atoms 0.2.7",
"swc_atoms 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"swc_common",
"swc_ecma_ast",
"swc_ecma_codegen",

View File

@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs", "examples/**/*.rs"]
license = "Apache-2.0/MIT"
name = "swc_ecma_parser"
repository = "https://github.com/swc-project/swc.git"
version = "0.73.10"
version = "0.73.11"
[package.metadata.docs.rs]
all-features = true

View File

@ -58,13 +58,9 @@ impl<T: Clone> OneDirectionalList<T> {
Self { last_node: None }
}
pub fn len(&self) -> usize {
self.last_node.as_ref().map(|i| i.length).unwrap_or(0)
}
pub fn take_all(&mut self) -> Rev<IntoIter<T>> {
// these are stored in reverse, so we need to reverse them back
let mut items = Vec::with_capacity(self.len());
let mut items = Vec::new();
let mut current_node = self.last_node.take();
while let Some(node) = current_node {
let mut node = match Rc::try_unwrap(node) {
@ -79,12 +75,7 @@ impl<T: Clone> OneDirectionalList<T> {
pub fn push(&mut self, item: T) {
let previous = self.last_node.take();
let length = previous.as_ref().map(|p| p.length + 1).unwrap_or(1);
let new_item = OneDirectionalListNode {
item,
previous,
length,
};
let new_item = OneDirectionalListNode { item, previous };
self.last_node = Some(Rc::new(new_item));
}
}
@ -93,5 +84,4 @@ impl<T: Clone> OneDirectionalList<T> {
struct OneDirectionalListNode<T: Clone> {
item: T,
previous: Option<Rc<OneDirectionalListNode<T>>>,
length: usize,
}