macro_rules! impl_js_family_doc_binding {
($lang:ident, $hidden:expr, $standalone:path, $target:path, $after_code:expr) => {
const DOC_BINDING: Option<$crate::lang_helpers::DocBinding> =
Some($crate::lang_helpers::DocBinding {
skips: |node, _| node.kind_id() == $lang::Decorator,
forward: |comment, code, ancestors| {
$crate::lang_helpers::doc_comment::outside_function_bodies::<Self>(
comment, code, ancestors,
) && !$standalone($crate::lang_helpers::doc_comment::node_bytes(comment, code))
},
..$crate::lang_helpers::DocBinding::new($crate::lang_helpers::KeptDocs::Leading {
hidden: $hidden,
joins: $crate::lang_helpers::doc_comment::never_joins,
after_code: $after_code,
})
});
fn is_doc_target<'a>(node: &Node<'a>, code: &[u8], ancestors: Ancestors<'a, '_>) -> bool {
$target(node, code, ancestors)
}
fn holds_doc_comment_in_body<'a>(
ancestor: &Node<'a>,
code: &[u8],
ancestors: Ancestors<'a, '_>,
below: &Node<'a>,
) -> bool {
if !Self::is_func_with_code(ancestor, code, ancestors)
&& !Self::is_closure(ancestor, ancestors)
{
return false;
}
if ancestor.kind_id() == $lang::ArrowFunction {
return below.end_byte() == ancestor.end_byte()
&& below.start_byte() != ancestor.start_byte()
&& !Self::is_comment(below);
}
below.kind_id() == $lang::StatementBlock
}
};
}
macro_rules! tsdoc_target {
($lang:ident, $roles:ident) => {
fn tsdoc_target<'a>(node: &Node<'a>, code: &[u8], ancestors: Ancestors<'a, '_>) -> bool {
if ancestors.parent(node).is_some_and(|parent| {
matches!(
parent.kind_id().into(),
$lang::ExportStatement | $lang::AmbientDeclaration
)
}) {
return false;
}
$crate::roles::$roles::doc_target::owns(node, code, ancestors)
}
};
}