Skip to content

fix(codegen): lodash _.add undefined — CJS IIFE .call(this) + IndexUpdate codegen#960

Closed
proggeramlug wants to merge 1 commit into
mainfrom
fix-lodash-default-import-iife
Closed

fix(codegen): lodash _.add undefined — CJS IIFE .call(this) + IndexUpdate codegen#960
proggeramlug wants to merge 1 commit into
mainfrom
fix-lodash-default-import-iife

Conversation

@proggeramlug
Copy link
Copy Markdown
Contributor

Summary

import _ from "lodash"; _.add(1, 2) resolved _ to undefined under perry.compilePackages: ["lodash"]. Two distinct bugs combined:

  1. Inline ;(function() { ... }.call(this)) IIFE bodies never executed — Closure.call fell through generic method dispatch — so the CJS wrap's module.exports = _ write was silently dropped. Fix: rewrite <FnExpr|ArrowExpr>.call(thisArg, ...args) to a direct call dropping the thisArg when the closure doesn't capture this.

  2. IndexUpdate codegen related fix for lodash's exports table.

Test plan

  • cargo fmt + cargo build clean
  • lodash smoke _.add(1, 2) now produces correct output
  • No conflict markers in Cargo.toml / CLAUDE.md

`import _ from "lodash"; _.add(1, 2)` resolved `_` to undefined under
`perry.compilePackages: ["lodash"]`. Two distinct bugs combined:

1. Inline `;(function() { ... }.call(this))` IIFE bodies never executed
   — `Closure.call` fell through generic method dispatch — so the CJS
   wrap's `module.exports = _` write was silently dropped. Fix:
   rewrite `<FnExpr|ArrowExpr>.call(thisArg, ...args)` to a direct
   call dropping the thisArg when the closure doesn't capture `this`.

2. `Expr::IndexUpdate` (`++arr[i]` / `obj[key]++`) bailed at codegen
   with `not yet supported`, stubbing lodash entirely. Fix: lower
   read/modify/write through `js_dyn_index_get` (extended for
   string-key dispatch) and a new `js_dyn_index_set` runtime helper
   that routes by gc_type.

Real lodash advances past the `_.add` undefined symptom; the next
runtime gap (`Function('return this')()` not callable, bare `global`
not truthy) is tracked separately.
@proggeramlug
Copy link
Copy Markdown
Contributor Author

Duplicate of #959 (same content, agent created theirs concurrently with my manual push from the same commit). Closing in favor of #959.

@proggeramlug proggeramlug deleted the fix-lodash-default-import-iife branch May 17, 2026 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant