next.js
43c094c1 - Turbopack: fix `this` when accessing named properties of namespace (#80896)

Commit
215 days ago
Turbopack: fix `this` when accessing named properties of namespace (#80896) Previously, this namespace-import-to-named-import optimization always caused `this` to be unbound for function calls. Now, it is preserved (if possible. There's nothing we can do when this is scope hoisted together). ```js import * as R from "ramda"; import { pipe } from 'ramda' expect((0, R.pipe)()).toBe(false); expect(R.pipe()).toBe(true); expect(pipe()).toBe(false); ``` ```js var __TURBOPACK__imported__module__ramda = __turbopack_context__.i( "[project]/turbopack/crates/turbopack-tests/tests/execution/turbopack/side-effects-optimization/import-star/input/node_modules/ramda/pipe.js [test] (ecmascript)" ); it("should have the correct `this` context", () => { expect((0, __TURBOPACK__imported__module__ramda["pipe"])()).toBe(false); // this was previously also `(0, ns.pipe)()` expect(__TURBOPACK__imported__module__ramda["pipe"]()).toBe(true); expect((0, __TURBOPACK__imported__module__ramda["pipe"])()).toBe(false); }); ``` Also has a small bundle size benefit
Author
Parents
Loading