Skip to content

CommonJS model: loops, switch, short-circuit and try writes are modelled as straight-line #30

Open

Description

@inth3shadows

Found in the PR #29 round-14 review. The CommonJS value model walks top-level code as straight-line, so a write that may never run replaces the real export, and the file stays modelled with a wrong answer. Only if and logical assignment fork the graph.

Repro: m.js function run(){} exports.run = run; for (const k of []) exports.run = 42; with c.js const {run} = require('./m'); const lib = require('./m'); function go(){ run(); lib.run(); }.

  • Pre-PR: go → m.js:run (x2).
  • PR29: no edge, because run is modelled as data 42.

Same with switch arms, cond && (exports.run = 1), ?: and try bodies written after the real write.

Fix direction: fork the graph for these constructs, or treat an exports write inside them as an unmodelled use (Rule 1), which makes the file resolve as pre-PR.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions