You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(codegen): const-fold literal new Function bodies to native functions #1679
Part of #1677. Blocked by #1678 — do not start until it is merged to main and parity-green.
Problem
When a new Function body is a compile-time constant string, an AOT compiler should turn it into a real native function instead of refusing it. This is true ahead-of-time eval and it builds the string → HIR plumbing reused by Phase 3.
Scope
For call sites the Phase 0 classifier marks const-foldable:
Resolve the body (and any param-name args) to constant strings via the existing const-prop pass.
Parse the body with SWC as a function body.
Lower it to HIR exactly as if the user had written the equivalent function literal.
Emit native code; replace the new Function call with a reference to it.
Note new Function has no access to local scope (globals only), so there is no closure capture to model — the lowered function is a plain top-level function referencing globals.
Covers: new Function('a','b','return a + b'), the (0, eval)('this') → globalThis idiom, trivial generated accessors with literal bodies.
Activity
feat(hir): classify new Function/eval call sites + refusal diagnostic (…
feat(hir): const-fold literal new Function bodies to native functions (…
fix(hir): #5579 — fold module-top indirect eval of a declaration-free…