Skip to main content

elixir_is_inside_quote_block

Function elixir_is_inside_quote_block 

Source
pub fn elixir_is_inside_quote_block<'a>(
    node: &Node<'a>,
    code: &[u8],
    ancestors: Ancestors<'a, '_>,
) -> bool
Expand description

Returns true when node is lexically nested inside the do_block of a quote do … end Call (Elixir’s metaprogramming template). A def / defp / defmacro / defmacrop inside quote does not define a method of any enclosing module — the syntax tree is a code template emitted later, when the surrounding macro is invoked. Treating those quoted Calls as methods inflates Wmc and disagrees with Npm’s direct-children classification (#310).

Walks the ancestor chain looking for a quote Call ancestor. Stops at the first match (true) or at the root (false). Each step is a single child_by_field_name("target") + identifier byte compare, so the cost is O(steps) when ancestors is known — with Ancestors::unknown each step additionally pays Node::parent’s O(depth) (#1084).