Skip to main content

Module inventory

Module inventory 

Source
Expand description

Function inventory walker for fallow coverage upload-inventory.

Emits one InventoryEntry per function (declaration, expression, arrow, method) whose name matches what oxc-coverage-instrument produces at instrument time. This is the static side of the three-state production coverage story: uploaded inventory minus runtime-seen functions equals untracked.

§Naming contract

The cloud stores function identity as (filePath, functionName, lineNumber). This walker is responsible for the functionName and lineNumber parts of that contract. Anonymous functions are named (anonymous_N) where N is a file-scoped monotonic counter that starts at 0 and increments in pre-order AST traversal each time a function is entered without a resolvable explicit name. Name resolution precedence:

  1. Parent-provided pending_name: from a MethodDefinition / VariableDeclarator binding, OR from the callee of the call / new expression a function is passed to as an argument (arr.map(cb) -> “map”, foo(cb) -> “foo”, new Promise(cb) -> “Promise”). The callee case matches oxc-coverage-instrument’s opt-in name_callback_arguments (which the Fallow runtime beacon enables), so a callback’s static name lines up with its runtime-instrumented name instead of both sides drifting to different anonymous placeholders.
  2. The function’s own id (named function foo() {}, named function expression const x = function named() {}).
  3. (anonymous_N) with the current counter value; counter then increments. Only genuinely unnamed functions reach this: an immediately-invoked function expression, an arrow returned from another function, or a computed non-string-key call.

Counter scope is per-file. Reference implementation: oxc-coverage-instrument/src/transform.rs (resolve_function_name + callback_argument_name).

Structs§

InventoryComplexity
Per-function static complexity collected alongside the inventory walk.
InventoryEntry
A single static-inventory entry for one function.

Functions§

walk_source
Parse source at path and return every function as an InventoryEntry.
walk_source_with_complexity
Parse source at path once and return every function as an InventoryEntry together with a source_hash -> InventoryComplexity map.