Skip to content

fix(wasm): include CJS require bindings in importedNames for resolveReceiverEdge #1689

Description

@carlos-alm

Problem

The build-parity.test.ts sample-project (JS) fixture fails because native emits a receiver edge main → Calculator that WASM does not.

Root cause: For a CJS require pattern like const { Calculator } = require('./utils'):

  • Native extractor adds the CJS require to symbols.imports (with cjs_require = Some(true)), so buildImportedNamesForNative includes Calculator in imported_names. In emit_receiver_edge, is_local_definition = false → global fallback → finds the class in utils.js → emits receiver edge. ✓ Correct.

  • WASM extractor puts CJS requires into symbols.cjsRequireBindings (NOT symbols.imports). buildImportedNamesMap only iterates symbols.imports, so Calculator is not in importedNames. In resolveReceiverEdge, isLocalDefinition = true (same-file function node exists) → restricted to same-file receiver-kind candidates (empty) → no receiver edge. ✗ Incorrect.

Fix

buildImportedNamesMap (used by WASM path in buildFileCallEdges) should also process symbols.cjsRequireBindings to include CJS-required names. This matches what buildImportArtifactNames does on the PR #1688 branch.

Alternatively, wire buildImportArtifactNames into buildFileCallEdges as the 1683 branch does.

Context

  • Native receiver-edge test receiver_edge_imported_function_node_falls_through_to_global_class documents the expected behavior.
  • This divergence was hidden because the TS build was broken (wrong arg count to resolveReceiverEdge) and the dist was stale.
  • Related: PR fix(wasm): preserve dyn=1 when deduplicating edges with same source/target/kind/conf #1688 (parity-1683) introduces buildImportArtifactNames which fixes this for the resolveReceiverEdge call in buildFileCallEdges.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions