Skip to content

Commit

Permalink
Add EndTag.removed property to consolidate impl_mutations_end_tag
Browse files Browse the repository at this point in the history
  • Loading branch information
taina0407 authored and kornelski committed Mar 7, 2025
1 parent 38ad28c commit e95998e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 42 deletions.
2 changes: 1 addition & 1 deletion js-api/src/end_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use lol_html::html_content::EndTag as NativeEndTag;
pub struct EndTag(NativeRefWrap<NativeEndTag<'static>>);

impl_from_native!(NativeEndTag => EndTag);
impl_mutations_end_tag!(EndTag);
impl_mutations!(EndTag);

#[wasm_bindgen]
impl EndTag {
Expand Down
41 changes: 0 additions & 41 deletions js-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,47 +155,6 @@ macro_rules! impl_mutations {
};
}

macro_rules! impl_mutations_end_tag {
($Ty:ident) => {
#[wasm_bindgen]
impl $Ty {
pub fn before(
&mut self,
content: &str,
content_type: Option<ContentTypeOptions>,
) -> Result<(), JsValue> {
self.0
.get_mut()
.map(|o| o.before(content, content_type.into_native()))
}

pub fn after(
&mut self,
content: &str,
content_type: Option<ContentTypeOptions>,
) -> Result<(), JsValue> {
self.0
.get_mut()
.map(|o| o.after(content, content_type.into_native()))
}

pub fn replace(
&mut self,
content: &str,
content_type: Option<ContentTypeOptions>,
) -> Result<(), JsValue> {
self.0
.get_mut()
.map(|o| o.replace(content, content_type.into_native()))
}

pub fn remove(&mut self) -> Result<(), JsValue> {
self.0.get_mut().map(|o| o.remove())
}
}
};
}

macro_rules! impl_from_native {
($Ty:ty => $JsTy:path) => {
impl $JsTy {
Expand Down
7 changes: 7 additions & 0 deletions src/rewritable_units/tokens/end_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ impl<'i> EndTag<'i> {
self.mutations.mutate().remove();
}

/// Returns `true` if the end tag has been replaced or removed.
#[inline]
#[must_use]
pub fn removed(&self) -> bool {
self.mutations.removed()
}

#[inline]
fn serialize_self(&self, output_handler: &mut dyn FnMut(&[u8])) -> Result<(), RewritingError> {
if let Some(raw) = &self.raw {
Expand Down

0 comments on commit e95998e

Please sign in to comment.