) -> Option<&Node<'a>> {
id.map(|id| &self[id])
}
pub(crate) fn parent_of(&self, id: Id) -> Option<&Node<'a>> {
self.node_at(self.parent(id))
}
pub(crate) fn prev_of(&self, id: Id) -> Option<&Node<'a>> {
self.node_at(self.prev(id))
}
pub(crate) fn next_of(&self, id: Id) -> Option<&Node<'a>> {
self.node_at(self.next(id))
}
/// `hasPrettierIgnore`
pub(crate) fn has_prettier_ignore(&self, id: Id, ignore: &[u8]) -> bool {
self.prev_of(id).is_some_and(|prev| is_prettier_ignore(prev, ignore))
}
/// `isVueSfcBlock`
pub(crate) fn is_vue_sfc_block(&self, id: Id, options: &Options<'_>) -> bool {
options.parser == Parser::Vue
&& self[id].kind == Kind::Element
&& self.parent_of(id).is_some_and(|parent| parent.kind == Kind::Root)
&& !(self[id].namespace.is_empty() && self[id].name.eq_ignore_ascii_case(b"html"))
}
/// `isVueCustomBlock`
pub(crate) fn is_vue_custom_block(&self, id: Id, options: &Options<'_>) -> bool {
self.is_vue_sfc_block(id, options)
&& !(self[id].namespace.is_empty()
&& matches!(&self[id].name[..], b"template" | b"style" | b"script"))
}
/// `isVueNonHtmlBlock`
pub(crate) fn is_vue_non_html_block(&self, id: Id, options: &Options<'_>) -> bool {
self.is_vue_sfc_block(id, options)
&& (self.is_vue_custom_block(id, options)
|| self.attribute_value(id, b"lang").is_some_and(|lang| lang != b"html"))
}
/// `isVueScriptTag`
pub(crate) fn is_vue_script_tag(&self, id: Id, options: &Options<'_>) -> bool {
self.is_vue_sfc_block(id, options) && &self[id].name[..] == b"script"
}
/// `shouldPreserveContent`. Call it once nothing in `id` changes anymore. It looks at all children.
pub(crate) fn should_preserve_content(&self, id: Id, options: &Options<'_>) -> bool {
let node = &self[id];
if node.kind == Kind::IeConditionalComment {
// An element that isn't closed inside the comment, or contents that couldn't be parsed.
if self
.node_at(self.last_child(id))
.is_some_and(|last| !last.has(Flags::IS_SELF_CLOSING) && !last.has(Flags::HAS_END_SPAN))
{
return true;
}
if !node.has(Flags::IS_COMPLETE) {
return true;
}
}
if is_pre_like(node) && self.children(id).any(|child| !is_text_or_interpolation(&self[child])) {
return true;
}
// Whitespace-only content of a `` is rendered, and in a `