From 5c9eba146f06b2e0531a901cb586c0a877edb3ea Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Tue, 7 Jan 2025 10:42:27 +0100 Subject: [PATCH] Update dev-dependencies --- Cargo.toml | 2 +- .../src/handle/list_item.rs | 3 +- src/construct/content.rs | 2 +- src/construct/document.rs | 65 +++++++++---------- src/mdast.rs | 2 +- src/parser.rs | 2 +- src/subtokenize.rs | 4 +- src/util/sanitize_uri.rs | 2 +- 8 files changed, 39 insertions(+), 43 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a5630d2f..23731b90 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ criterion = "0.5" env_logger = "0.11" pretty_assertions = { workspace = true } serde_json = { version = "1" } -swc_core = { version = "0.100", features = [ +swc_core = { version = "10", features = [ "common", "ecma_ast", "ecma_parser", diff --git a/mdast_util_to_markdown/src/handle/list_item.rs b/mdast_util_to_markdown/src/handle/list_item.rs index 67dafcdb..0f47b751 100644 --- a/mdast_util_to_markdown/src/handle/list_item.rs +++ b/mdast_util_to_markdown/src/handle/list_item.rs @@ -102,5 +102,6 @@ impl Handle for ListItem { } fn compute_size(a: usize) -> usize { - ((a + 4 - 1) / 4) * 4 + // `a.div_ceil(4)` is `((a + 4 - 1) / 4)` + a.div_ceil(4) * 4 } diff --git a/src/construct/content.rs b/src/construct/content.rs index 2c5d6e54..5ee03541 100644 --- a/src/construct/content.rs +++ b/src/construct/content.rs @@ -182,7 +182,7 @@ pub fn resolve(tokenizer: &mut Tokenizer) -> Result, message:: let result = subtokenize( &mut tokenizer.events, tokenizer.parse_state, - &Some(Content::Content), + Some(&Content::Content), )?; Ok(Some(result)) diff --git a/src/construct/document.rs b/src/construct/document.rs index c8e351a2..1859eef0 100644 --- a/src/construct/document.rs +++ b/src/construct/document.rs @@ -304,26 +304,24 @@ pub fn containers_after(tokenizer: &mut Tokenizer) -> State { != tokenizer.tokenize_state.document_container_stack.len(); child.define_skip(tokenizer.point.clone()); - match tokenizer.current { - // Note: EOL is part of data. - None => State::Retry(StateName::DocumentFlowEnd), - Some(_) => { - let current = tokenizer.events.len(); - let previous = tokenizer.tokenize_state.document_data_index; - if let Some(previous) = previous { - tokenizer.events[previous].link.as_mut().unwrap().next = Some(current); - } - tokenizer.tokenize_state.document_data_index = Some(current); - tokenizer.enter_link( - Name::Data, - Link { - previous, - next: None, - content: Content::Flow, - }, - ); - State::Retry(StateName::DocumentFlowInside) + if tokenizer.current.is_none() { + State::Retry(StateName::DocumentFlowEnd) + } else { + let current = tokenizer.events.len(); + let previous = tokenizer.tokenize_state.document_data_index; + if let Some(previous) = previous { + tokenizer.events[previous].link.as_mut().unwrap().next = Some(current); } + tokenizer.tokenize_state.document_data_index = Some(current); + tokenizer.enter_link( + Name::Data, + Link { + previous, + next: None, + content: Content::Flow, + }, + ); + State::Retry(StateName::DocumentFlowInside) } } @@ -450,23 +448,20 @@ pub fn flow_end(tokenizer: &mut Tokenizer) -> State { debug_assert!(result.is_ok(), "did not expect error when exiting"); } - match tokenizer.current { - None => { - tokenizer.tokenize_state.document_continued = 0; - if let Err(message) = exit_containers(tokenizer, &Phase::Eof) { - return State::Error(message); - } - resolve(tokenizer); - State::Ok - } - Some(_) => { - tokenizer.tokenize_state.document_continued = 0; - tokenizer.tokenize_state.document_lazy_accepting_before = - document_lazy_continuation_current; - // Containers would only be interrupting if we’ve continued. - tokenizer.interrupt = false; - State::Retry(StateName::DocumentContainerExistingBefore) + if tokenizer.current.is_none() { + tokenizer.tokenize_state.document_continued = 0; + if let Err(message) = exit_containers(tokenizer, &Phase::Eof) { + return State::Error(message); } + resolve(tokenizer); + State::Ok + } else { + tokenizer.tokenize_state.document_continued = 0; + tokenizer.tokenize_state.document_lazy_accepting_before = + document_lazy_continuation_current; + // Containers would only be interrupting if we’ve continued. + tokenizer.interrupt = false; + State::Retry(StateName::DocumentContainerExistingBefore) } } diff --git a/src/mdast.rs b/src/mdast.rs index 64f6bee9..341bb978 100644 --- a/src/mdast.rs +++ b/src/mdast.rs @@ -96,7 +96,7 @@ impl serde::ser::Serialize for AlignKind { struct AlignKindVisitor; #[cfg(feature = "serde")] -impl<'de> serde::de::Visitor<'de> for AlignKindVisitor { +impl serde::de::Visitor<'_> for AlignKindVisitor { type Value = AlignKind; fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { diff --git a/src/parser.rs b/src/parser.rs index 9bcfa0ac..67f8f1f7 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -74,6 +74,6 @@ pub fn parse<'a>( return Ok((events, parse_state)); } - result = subtokenize(&mut events, &parse_state, &None)?; + result = subtokenize(&mut events, &parse_state, None)?; } } diff --git a/src/subtokenize.rs b/src/subtokenize.rs index 467ca463..02f9afd4 100644 --- a/src/subtokenize.rs +++ b/src/subtokenize.rs @@ -78,7 +78,7 @@ pub fn link_to(events: &mut [Event], previous: usize, next: usize) { pub fn subtokenize( events: &mut Vec, parse_state: &ParseState, - filter: &Option, + filter: Option<&Content>, ) -> Result { let mut map = EditMap::new(); let mut index = 0; @@ -98,7 +98,7 @@ pub fn subtokenize( // No need to enter linked events again. if link.previous.is_none() - && (filter.is_none() || &link.content == filter.as_ref().unwrap()) + && (filter.is_none() || &link.content == *filter.as_ref().unwrap()) { // Index into `events` pointing to a chunk. let mut link_index = Some(index); diff --git a/src/util/sanitize_uri.rs b/src/util/sanitize_uri.rs index 392f7b18..924abc98 100644 --- a/src/util/sanitize_uri.rs +++ b/src/util/sanitize_uri.rs @@ -55,7 +55,7 @@ pub fn sanitize_with_protocols(value: &str, protocols: &[&str]) -> String { let value = sanitize(value); let end = value.find(|c| matches!(c, '?' | '#' | '/')); - let mut colon = value.find(|c| matches!(c, ':')); + let mut colon = value.find(':'); // If the first colon is after `?`, `#`, or `/`, it’s not a protocol. if let Some(end) = end {