ReviewOS

home-lang/home

fix(runtime): port known-global constructor minification

#761
Closed glennmichael123 opened this 9 days ago ·
9 days ago

Parent: #66

packages/runtime/src/ast/known_global.zig is 71 lines against Bun's 361: KnownGlobal.minifyGlobalConstructor always returns null, so --minify-syntax never rewrites new Array(n) → Array(n), new Array() → [], new Error(...) → Error(...) and the other known-global constructor forms. The caller is js_parser/visit/visit_expr.zig (gated on minify_syntax).

Port minifyGlobalConstructor and callFromNew from ~/Code/bun/src/ast/known_global.zig faithfully.

Verification: unchanged test/regression/issue/minify-new-array-with-if.test.ts (inline snapshot expects Array(...)) plus the bundler minify suites vs pinned Bun 4982b91e37.

9 days ago

Reopening: the commit used a Closes keyword, which auto-closed this. Evidence follows in the next comment; leaving the call to close to @chrisbbreuer.

9 days ago

Ported on origin/main in be7e7b961: minifyGlobalConstructor and callFromNew are taken from Bun's ast/known_global.zig, which Home's 71-line file was a subset of. The port differs from upstream only in the line.

Unchanged test/regression/issue/minify-new-array-with-if.test.ts, same JSC debug build, control = the same tree with the runtime changes stashed:

result
Home, unchanged parent(fail) minifying new Array(if (0) 1 else 2) works — 0 pass / 1 fail
Home, be7e7b9611 pass / 0 fail

No upstream fixture, snapshot or expectation changed.

9 days ago

Verified on current origin/main at c6ab9aeeb using the required native ReleaseFast binary.

The implementation remains the faithful pinned-Bun port from be7e7b961: KnownGlobal.minifyGlobalConstructor and callFromNew are active through the real parser/minifier path. The unchanged minify-new-array-with-if.test.ts passes 1/1, including its inline snapshot; no fixture, snapshot or expectation changed.

Closing after current-main acceptance verification.

Sign in to comment on this issue.