#![allow(clippy::wildcard_imports, clippy::enum_glob_use)]
use super::*;
impl Getter for MozjsCode {
fn get_space_kind(node: &Node) -> SpaceKind {
use Mozjs::*;
match node.kind_id().into() {
FunctionExpression
| MethodDefinition
| GeneratorFunction
| FunctionDeclaration
| GeneratorFunctionDeclaration
| ArrowFunction
| ClassStaticBlock => SpaceKind::Function,
Class | ClassDeclaration => SpaceKind::Class,
Program => SpaceKind::Unit,
_ => SpaceKind::Unknown,
}
}
fn get_func_space_name<'a, 'tree>(
node: &Node<'tree>,
code: &'a [u8],
ancestors: Ancestors<'tree, '_>,
) -> Option<&'a str> {
if node.kind_id() == Mozjs::ClassStaticBlock as u16 {
return Some("<static-init>");
}
if let Some(name) = node.child_by_field_name("name") {
return node_text(code, &name);
}
let bound_name = ancestors.parent(node).and_then(|parent| {
let field = match parent.kind_id().into() {
Mozjs::Pair => "key",
Mozjs::VariableDeclarator => "name",
_ => return None,
};
parent.child_by_field_name(field)
});
bound_name.map_or(Some("<anonymous>"), |name| node_text(code, &name))
}
impl_js_family_get_op_type!(
Mozjs,
op_extras: [OptionalChain],
operand_extras: [Identifier2, String2],
);
get_operator!(Mozjs);
}