Skip to content

cjs: class method referencing a later module-level function loses the hoisted binding (ajv init: addNames is not defined) — blocks #6559 e2e #6585

Description

@proggeramlug

Found while landing #6559 (PR #6584): ajv@8 compiles natively (compilePackages) but ajv.compile() throws ReferenceError: addNames is not defined at library init — before any runtime-generated code runs.

Root shape: in ajv's dist/compile/codegen/index.js, class methods call the module-level function addNames that is declared later in the same CJS file. Node hoists the function declaration module-wide; perry's CJS compilation apparently binds the class-method reference before/without the hoisted binding, so the call site sees an undefined free variable.

Repro: run the #[ignore]d e2e in crates/perry/tests/issue_6559_real_libs_e2e.rs (PERRY_REQUIRE_NPM_E2E=1 … -- --ignored), or reduce to: a CJS module where a class method references a function declared after the class, instantiated + called from another module.

Blocks: #6559 real-library acceptance (ajv leg), kimi-code target #6565 (fastify stack inits ajv). The interpreter side is already proven against ajv's captured generated code (PR #6584 fixture suite), so this hoisting gap is the only thing between ajv and green.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed defect or regressionparityCompatibility gap with Node.js, ECMAScript, or the supported ecosystem

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions