next.js
2aca54fe - Turbopack: scope hoisting bug with reexport-self-star (#86131)

Commit
64 days ago
Turbopack: scope hoisting bug with reexport-self-star (#86131) Closes PACK-5850 Closes https://github.com/vercel/next.js/issues/86132 Closes #86714 The problem was that you get this with scope hoisting: ```js "index.js": () => { // foo.js // exports object read here const self_import = turbopack_import("foo.js") // exports object created here __turbopack_esm__([...], "foo.js") // index.js .... } ``` without scope hoisting, that exports object is already initialized before the module factory runs ```js "foo.js": () => { // exports initialized here const self_import = turbopack_import("foo.js") __turbopack_esm__([....]); } .... ``` so let's fix it by making it hoist the `__turbopack_esm__` statement (just as we did before always) in the case of self-imports --- This bug is actually very similar to https://github.com/vercel/next.js/pull/82827. It also executes `data.js` twice. The problem is that if a module imports itself, ```js "[project]/input/data.js [test] (ecmascript)", ((__turbopack_context__) => { "use strict"; var __TURBOPACK__imported__module__$5b$project$2f$input$2f$data$2e$js__$5b$test$5d$__$28$ecmascript$29$__$3c$locals$3e$__ = __turbopack_context__.i("[project]/input/data.js [test] (ecmascript) <locals>"); var __TURBOPACK__imported__module__$5b$project$2f$input$2f$data$2e$js__$5b$test$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/input/data.js [test] (ecmascript)"); __turbopack_context__.s([ "Data", 0, __TURBOPACK__imported__module__$5b$project$2f$input$2f$data$2e$js__$5b$test$5d$__$28$ecmascript$29$__, "bar", ()=>__TURBOPACK__imported__module__$5b$project$2f$input$2f$data$2e$js__$5b$test$5d$__$28$ecmascript$29$__$3c$locals$3e$__["bar"], "foo", ()=>__TURBOPACK__imported__module__$5b$project$2f$input$2f$data$2e$js__$5b$test$5d$__$28$ecmascript$29$__$3c$locals$3e$__["foo"] ]); }), ``` and with scope hoisting, the `import("id")` happens before the `esm_export(..., "id")`: ```js module.exports = [ "[project]/index.js [test] (ecmascript)", ((__turbopack_context__) => { "use strict"; // MERGED MODULE: [project]/index.js [test] (ecmascript) ; // MERGED MODULE: [project]/data.js [test] (ecmascript) <locals> ; function foo() { return 'foo'; } function bar() { return 'bar'; } ; __turbopack_context__.s([ "bar", ()=>bar, "foo", ()=>foo ], "[project]/data.js [test] (ecmascript) <locals>"); // MERGED MODULE: [project]/data.js [test] (ecmascript) <export * as Data> ; // MERGED MODULE: [project]/data.js [test] (ecmascript) ; var __TURBOPACK__imported__module__$5b$project$2f$input$2f$data$2e$js__$5b$test$5d$__$28$ecmascript$29$__$3c$locals$3e$__ = __turbopack_context__.i("[project]/data.js [test] (ecmascript) <locals>"); var __TURBOPACK__imported__module__$5b$project$2f$input$2f$data$2e$js__$5b$test$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/data.js [test] (ecmascript)"); __turbopack_context__.s([ "Data", 0, __TURBOPACK__imported__module__$5b$project$2f$input$2f$data$2e$js__$5b$test$5d$__$28$ecmascript$29$__, "bar", ()=>bar, "foo", ()=>foo ], "[project]/data.js [test] (ecmascript)"); ```
Author
Parents
Loading