Unverified Commit 428616e1 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Turbopack: refactor side effects optimization (#82466)

### What?

Refactors the side effects optimization.

* Gets rid of the `<module evaluation>` and the `<exports>` module.
* Only two modules: `<local>` and the facade.
* The local module has all the evaluation side effects and local exports.
* The facade reexports the local module and all reexports of the module.
* `require()` and `import *` will resolve to the facade module
* `import "..."` will resolve to the locals
* `import { x } from "..."` will follow reexports and finally imports from a locals module
parent 8f8c78e0
......@@ -2430,7 +2430,7 @@ describe('Cache Components Errors', () => {
| ^",
"stack": [
"{module evaluation} app/use-cache-private-in-unstable-cache/page.tsx (21:38)",
"<FIXME-file-protocol>",
"{module evaluation} .next-internal/server/app/use-cache-private-in-unstable-cache/page/actions.js (server actions loader) (1:1)",
"<FIXME-file-protocol>",
"<FIXME-next-dist-dir>",
],
......@@ -2487,8 +2487,8 @@ describe('Cache Components Errors', () => {
expect(output).toMatchInlineSnapshot(`
"Error: "use cache: private" must not be used within \`unstable_cache()\`.
at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-unstable-cache/page.tsx:21:38)
at __TURBOPACK__module__evaluation__ (bundler:///.next-internal/server/app/use-cache-private-in-unstable-cache/page/actions.js (server actions loader):1:1)
at a (<next-dist-dir>)
at b (<next-dist-dir>)
19 | }
20 |
> 21 | const getCachedData = unstable_cache(async () => {
......@@ -2506,6 +2506,7 @@ describe('Cache Components Errors', () => {
expect(output).toMatchInlineSnapshot(`
"Error: "use cache: private" must not be used within \`unstable_cache()\`.
at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-unstable-cache/page.tsx:21:38)
at __TURBOPACK__module__evaluation__ (bundler:///.next-internal/server/app/use-cache-private-in-unstable-cache/page/actions.js%20(server%20actions%20loader):1:1)
at a (<next-dist-dir>)
19 | }
20 |
......@@ -2574,7 +2575,7 @@ describe('Cache Components Errors', () => {
| ^",
"stack": [
"{module evaluation} app/use-cache-private-in-use-cache/page.tsx (15:1)",
"<FIXME-file-protocol>",
"{module evaluation} .next-internal/server/app/use-cache-private-in-use-cache/page/actions.js (server actions loader) (1:1)",
"<FIXME-file-protocol>",
"<FIXME-next-dist-dir>",
],
......@@ -2632,8 +2633,8 @@ describe('Cache Components Errors', () => {
expect(output).toMatchInlineSnapshot(`
"Error: "use cache: private" must not be used within "use cache". It can only be nested inside of another "use cache: private".
at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-use-cache/page.tsx:15:1)
at __TURBOPACK__module__evaluation__ (bundler:///.next-internal/server/app/use-cache-private-in-use-cache/page/actions.js (server actions loader):1:1)
at a (<next-dist-dir>)
at b (<next-dist-dir>)
13 | }
14 |
> 15 | async function Private() {
......@@ -2643,8 +2644,8 @@ describe('Cache Components Errors', () => {
18 | return <p>Private</p>
Error: "use cache: private" must not be used within "use cache". It can only be nested inside of another "use cache: private".
at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-use-cache/page.tsx:15:1)
at c (<next-dist-dir>)
at d (<next-dist-dir>)
at __TURBOPACK__module__evaluation__ (bundler:///.next-internal/server/app/use-cache-private-in-use-cache/page/actions.js (server actions loader):1:1)
at b (<next-dist-dir>)
13 | }
14 |
> 15 | async function Private() {
......@@ -2662,7 +2663,7 @@ describe('Cache Components Errors', () => {
expect(output).toMatchInlineSnapshot(`
"Error: "use cache: private" must not be used within "use cache". It can only be nested inside of another "use cache: private".
at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-use-cache/page.tsx:15:1)
at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-use-cache/page.tsx:15:16)
at __TURBOPACK__module__evaluation__ (bundler:///.next-internal/server/app/use-cache-private-in-use-cache/page/actions.js%20(server%20actions%20loader):1:1)
at a (<next-dist-dir>)
13 | }
14 |
......@@ -2673,7 +2674,7 @@ describe('Cache Components Errors', () => {
18 | return <p>Private</p>
Error: "use cache: private" must not be used within "use cache". It can only be nested inside of another "use cache: private".
at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-use-cache/page.tsx:15:1)
at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-use-cache/page.tsx:15:16)
at __TURBOPACK__module__evaluation__ (bundler:///.next-internal/server/app/use-cache-private-in-use-cache/page/actions.js%20(server%20actions%20loader):1:1)
at b (<next-dist-dir>)
13 | }
14 |
......
......@@ -230,7 +230,7 @@ pub enum EcmascriptExports {
#[turbo_tasks::value_impl]
impl EcmascriptExports {
#[turbo_tasks::function]
pub async fn needs_facade(&self) -> Result<Vc<bool>> {
pub async fn split_locals_and_reexports(&self) -> Result<Vc<bool>> {
Ok(match self {
EcmascriptExports::EsmExports(exports) => {
let exports = exports.await?;
......
......@@ -850,8 +850,8 @@ pub struct EcmascriptModuleContentOptions {
specified_module_type: SpecifiedModuleType,
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
references: ResolvedVc<ModuleReferences>,
esm_references: ResolvedVc<EsmAssetReferences>,
part_references: Vec<ResolvedVc<EcmascriptModulePartReference>>,
esm_references: ResolvedVc<EsmAssetReferences>,
code_generation: ResolvedVc<CodeGens>,
async_module: ResolvedVc<OptionAsyncModule>,
generate_source_map: bool,
......@@ -872,8 +872,8 @@ impl EcmascriptModuleContentOptions {
module,
chunking_context,
references,
esm_references,
part_references,
esm_references,
code_generation,
async_module,
exports,
......@@ -912,14 +912,14 @@ impl EcmascriptModuleContentOptions {
},
];
let esm_code_gens = esm_references
.await?
let part_code_gens = part_references
.iter()
.map(|r| r.code_generation(**chunking_context, scope_hoisting_context))
.try_join()
.await?;
let part_code_gens = part_references
let esm_code_gens = esm_references
.await?
.iter()
.map(|r| r.code_generation(**chunking_context, scope_hoisting_context))
.try_join()
......@@ -933,9 +933,9 @@ impl EcmascriptModuleContentOptions {
.await?;
anyhow::Ok(
esm_code_gens
part_code_gens
.into_iter()
.chain(part_code_gens.into_iter())
.chain(esm_code_gens.into_iter())
.chain(additional_code_gens.into_iter().flatten())
.chain(code_gens.into_iter())
.collect(),
......
......@@ -141,17 +141,8 @@ pub async fn follow_reexports(
side_effect_free_packages: Vc<Glob>,
ignore_side_effect_of_entry: bool,
) -> Result<Vc<FollowExportsResult>> {
if !ignore_side_effect_of_entry
&& !*module
.is_marked_as_side_effect_free(side_effect_free_packages)
.await?
{
return Ok(FollowExportsResult::cell(FollowExportsResult {
module,
export_name: Some(export_name),
ty: FoundExportType::SideEffects,
}));
}
let mut ignore_side_effects = ignore_side_effect_of_entry;
let mut module = module;
let mut export_name = export_name;
loop {
......@@ -164,12 +155,26 @@ pub async fn follow_reexports(
}));
};
if !ignore_side_effects
&& !*module
.is_marked_as_side_effect_free(side_effect_free_packages)
.await?
{
// TODO It's unfortunate that we have to use the whole module here.
// This is often the Facade module, which includes all reexports.
// Often we could use Locals + the followed reexports instead.
return Ok(FollowExportsResult::cell(FollowExportsResult {
module,
export_name: Some(export_name),
ty: FoundExportType::SideEffects,
}));
}
ignore_side_effects = false;
// Try to find the export in the local exports
let exports_ref = exports.await?;
if let Some(export) = exports_ref.exports.get(&export_name) {
match handle_declared_export(module, export_name, export, side_effect_free_packages)
.await?
{
match handle_declared_export(module, export_name, export).await? {
ControlFlow::Continue((m, n)) => {
module = m.to_resolved().await?;
export_name = n;
......@@ -222,23 +227,12 @@ async fn handle_declared_export(
module: ResolvedVc<Box<dyn EcmascriptChunkPlaceable>>,
export_name: RcStr,
export: &EsmExport,
side_effect_free_packages: Vc<Glob>,
) -> Result<ControlFlow<FollowExportsResult, (Vc<Box<dyn EcmascriptChunkPlaceable>>, RcStr)>> {
match export {
EsmExport::ImportedBinding(reference, name, _) => {
if let ReferencedAsset::Some(module) =
*ReferencedAsset::from_resolve_result(reference.resolve_reference()).await?
{
if !*module
.is_marked_as_side_effect_free(side_effect_free_packages)
.await?
{
return Ok(ControlFlow::Break(FollowExportsResult {
module,
export_name: Some(name.clone()),
ty: FoundExportType::SideEffects,
}));
}
return Ok(ControlFlow::Continue((*module, name.clone())));
}
}
......@@ -286,6 +280,7 @@ async fn find_export_from_reexports(
module: ResolvedVc<Box<dyn EcmascriptChunkPlaceable>>,
export_name: RcStr,
) -> Result<Vc<FindExportFromReexportsResult>> {
// TODO why do we need a special case for this?
if let Some(module) =
Vc::try_resolve_downcast_type::<EcmascriptModulePartAsset>(*module).await?
&& matches!(module.await?.part, ModulePart::Exports)
......
......@@ -171,7 +171,6 @@ pub struct AnalyzeEcmascriptModuleResult {
pub esm_references: ResolvedVc<EsmAssetReferences>,
pub esm_local_references: ResolvedVc<EsmAssetReferences>,
pub esm_reexport_references: ResolvedVc<EsmAssetReferences>,
pub esm_evaluation_references: ResolvedVc<EsmAssetReferences>,
pub code_generation: ResolvedVc<CodeGens>,
pub exports: ResolvedVc<EcmascriptExports>,
......@@ -217,7 +216,6 @@ pub struct AnalyzeEcmascriptModuleResultBuilder {
esm_references: FxHashSet<usize>,
esm_local_references: FxHashSet<usize>,
esm_reexport_references: FxHashSet<usize>,
esm_evaluation_references: FxHashSet<usize>,
esm_references_free_var: FxIndexMap<RcStr, ResolvedVc<EsmAssetReference>>,
// Ad-hoc created import references that are resolved `import * as x from ...; x.foo` accesses
......@@ -239,7 +237,6 @@ impl AnalyzeEcmascriptModuleResultBuilder {
esm_references: Default::default(),
esm_local_references: Default::default(),
esm_reexport_references: Default::default(),
esm_evaluation_references: Default::default(),
esm_references_rewritten: Default::default(),
esm_references_free_var: Default::default(),
code_gens: Default::default(),
......@@ -282,7 +279,6 @@ impl AnalyzeEcmascriptModuleResultBuilder {
pub fn add_esm_evaluation_reference(&mut self, idx: usize) {
self.esm_references.insert(idx);
self.esm_local_references.insert(idx);
self.esm_evaluation_references.insert(idx);
}
/// Adds a codegen to the analysis result.
......@@ -369,8 +365,6 @@ impl AnalyzeEcmascriptModuleResultBuilder {
});
let mut esm_reexport_references = track_reexport_references
.then(|| Vec::with_capacity(self.esm_reexport_references.len()));
let mut esm_evaluation_references = track_reexport_references
.then(|| Vec::with_capacity(self.esm_evaluation_references.len()));
for (i, reference) in import_references.iter().enumerate() {
if self.esm_references.contains(&i) {
esm_references.push(*reference);
......@@ -392,11 +386,6 @@ impl AnalyzeEcmascriptModuleResultBuilder {
.flat_map(|m| m.values().copied()),
);
}
if let Some(esm_evaluation_references) = &mut esm_evaluation_references
&& self.esm_evaluation_references.contains(&i)
{
esm_evaluation_references.push(*reference);
}
if let Some(esm_reexport_references) = &mut esm_reexport_references
&& self.esm_reexport_references.contains(&i)
{
......@@ -415,9 +404,6 @@ impl AnalyzeEcmascriptModuleResultBuilder {
esm_reexport_references: ResolvedVc::cell(
esm_reexport_references.unwrap_or_default(),
),
esm_evaluation_references: ResolvedVc::cell(
esm_evaluation_references.unwrap_or_default(),
),
code_generation: ResolvedVc::cell(self.code_gens),
exports: self.exports.resolved_cell(),
async_module: self.async_module,
......
......@@ -54,6 +54,13 @@ impl EcmascriptModulePartReference {
part: ModulePart,
export_usage: ResolvedVc<ExportUsage>,
) -> Vc<Self> {
debug_assert!(matches!(
part,
ModulePart::Locals
| ModulePart::Facade
| ModulePart::RenamedExport { .. }
| ModulePart::RenamedNamespace { .. }
));
EcmascriptModulePartReference {
module,
part,
......@@ -104,14 +111,12 @@ impl ModuleReference for EcmascriptModulePartReference {
};
Vc::upcast::<Box<dyn Module>>(EcmascriptModuleLocalsModule::new(*module))
}
ModulePart::Exports
| ModulePart::Evaluation
| ModulePart::Facade
ModulePart::Facade
| ModulePart::RenamedExport { .. }
| ModulePart::RenamedNamespace { .. } => Vc::upcast(
EcmascriptModuleFacadeModule::new(*self.module, self.part.clone()),
),
ModulePart::Export(..) | ModulePart::Internal(..) => {
_ => {
bail!(
"Unexpected ModulePart \"{}\" for EcmascriptModulePartReference",
self.part
......
......@@ -8,7 +8,7 @@ error - [bindings] /turbopack/crates/turbopack-tests/tests/execution/turbopack/e
4 | import * as X from './module'
5 |
The export Abc was not found in module [project]/turbopack/crates/turbopack-tests/tests/execution/turbopack/exports/invalid-export/input/invalid-export/module.js [test] (ecmascript) <exports>.
The export Abc was not found in module [project]/turbopack/crates/turbopack-tests/tests/execution/turbopack/exports/invalid-export/input/invalid-export/module.js [test] (ecmascript).
Did you mean to import Abd?
......
......@@ -2,10 +2,5 @@ import { something } from './main'
it('correct order', () => {
expect(something).toBe('inner')
expect(globalThis.order).toEqual([
// TODO Order should be 'inner throws', 'module'
'module',
'inner no-throws',
'main',
])
expect(globalThis.order).toEqual(['inner throws', 'module', 'main'])
})
(globalThis.TURBOPACK || (globalThis.TURBOPACK = [])).push(["output/4c35f_tests_snapshot_intermediate-tree-shake_reexport-with-locals_input_6ca4cc64._.js",
(globalThis.TURBOPACK || (globalThis.TURBOPACK = [])).push(["output/4c35f_tests_snapshot_intermediate-tree-shake_reexport-with-locals_input_e256c7f2._.js",
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/intermediate-tree-shake/reexport-with-locals/input/index.js [test] (ecmascript)", ((__turbopack_context__) => {
"use strict";
__turbopack_context__.s([]);
var __TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$intermediate$2d$tree$2d$shake$2f$reexport$2d$with$2d$locals$2f$input$2f$node_modules$2f$lib$2f$index$2e$js__$5b$test$5d$__$28$ecmascript$29$__$3c$module__evaluation$3e$__ = __turbopack_context__.i("[project]/turbopack/crates/turbopack-tests/tests/snapshot/intermediate-tree-shake/reexport-with-locals/input/node_modules/lib/index.js [test] (ecmascript) <module evaluation>");
var __TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$intermediate$2d$tree$2d$shake$2f$reexport$2d$with$2d$locals$2f$input$2f$node_modules$2f$lib$2f$index$2e$js__$5b$test$5d$__$28$ecmascript$29$__$3c$locals$3e$__ = __turbopack_context__.i("[project]/turbopack/crates/turbopack-tests/tests/snapshot/intermediate-tree-shake/reexport-with-locals/input/node_modules/lib/index.js [test] (ecmascript) <locals>");
;
(0, __TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$intermediate$2d$tree$2d$shake$2f$reexport$2d$with$2d$locals$2f$input$2f$node_modules$2f$lib$2f$index$2e$js__$5b$test$5d$__$28$ecmascript$29$__$3c$locals$3e$__["local"])();
......@@ -39,14 +38,6 @@ function localUnused() {
}
;
}),
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/intermediate-tree-shake/reexport-with-locals/input/node_modules/lib/index.js [test] (ecmascript) <module evaluation>", ((__turbopack_context__) => {
"use strict";
__turbopack_context__.s([]);
var __TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$intermediate$2d$tree$2d$shake$2f$reexport$2d$with$2d$locals$2f$input$2f$node_modules$2f$lib$2f$unused$2e$js__$5b$test$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/turbopack/crates/turbopack-tests/tests/snapshot/intermediate-tree-shake/reexport-with-locals/input/node_modules/lib/unused.js [test] (ecmascript)");
var __TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$intermediate$2d$tree$2d$shake$2f$reexport$2d$with$2d$locals$2f$input$2f$node_modules$2f$lib$2f$unused$2d$star$2e$js__$5b$test$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/turbopack/crates/turbopack-tests/tests/snapshot/intermediate-tree-shake/reexport-with-locals/input/node_modules/lib/unused-star.js [test] (ecmascript)");
var __TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$intermediate$2d$tree$2d$shake$2f$reexport$2d$with$2d$locals$2f$input$2f$node_modules$2f$lib$2f$index$2e$js__$5b$test$5d$__$28$ecmascript$29$__$3c$locals$3e$__ = __turbopack_context__.i("[project]/turbopack/crates/turbopack-tests/tests/snapshot/intermediate-tree-shake/reexport-with-locals/input/node_modules/lib/index.js [test] (ecmascript) <locals>");
}),
]);
//# sourceMappingURL=4c35f_tests_snapshot_intermediate-tree-shake_reexport-with-locals_input_6ca4cc64._.js.map
\ No newline at end of file
//# sourceMappingURL=4c35f_tests_snapshot_intermediate-tree-shake_reexport-with-locals_input_e256c7f2._.js.map
\ No newline at end of file
......@@ -2,8 +2,8 @@
"version": 3,
"sources": [],
"sections": [
{"offset": {"line": 4, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/intermediate-tree-shake/reexport-with-locals/input/index.js"],"sourcesContent":["import { local } from 'lib'\n\nlocal()\n"],"names":[],"mappings":";AAAA;AAAA;;AAEA,IAAA,yRAAK"}},
{"offset": {"line": 13, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/intermediate-tree-shake/reexport-with-locals/input/node_modules/lib/unused.js"],"sourcesContent":["export function unusedStar() {}\n"],"names":[],"mappings":";AAAO,SAAS,cAAc","ignoreList":[0]}},
{"offset": {"line": 19, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/intermediate-tree-shake/reexport-with-locals/input/node_modules/lib/unused-star.js"],"sourcesContent":["export function unused() {}\n"],"names":[],"mappings":";AAAO,SAAS,UAAU","ignoreList":[0]}},
{"offset": {"line": 25, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/intermediate-tree-shake/reexport-with-locals/input/node_modules/lib/index.js"],"sourcesContent":["export { unused } from './unused.js'\nexport * from './unused-star.js'\n\nfunction local() {\n console.log('This is a local function')\n}\nfunction localUnused() {\n console.log('This is a local unused function')\n}\n\nexport { local, localUnused }\n"],"names":[],"mappings":";;;;AAAA;AACA;;;AAEA,SAAS;IACP,QAAQ,GAAG,CAAC;AACd;AACA,SAAS;IACP,QAAQ,GAAG,CAAC;AACd","ignoreList":[0]}}]
{"offset": {"line": 4, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/intermediate-tree-shake/reexport-with-locals/input/index.js"],"sourcesContent":["import { local } from 'lib'\n\nlocal()\n"],"names":[],"mappings":";AAAA;;AAEA,IAAA,yRAAK"}},
{"offset": {"line": 12, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/intermediate-tree-shake/reexport-with-locals/input/node_modules/lib/unused.js"],"sourcesContent":["export function unusedStar() {}\n"],"names":[],"mappings":";AAAO,SAAS,cAAc","ignoreList":[0]}},
{"offset": {"line": 18, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/intermediate-tree-shake/reexport-with-locals/input/node_modules/lib/unused-star.js"],"sourcesContent":["export function unused() {}\n"],"names":[],"mappings":";AAAO,SAAS,UAAU","ignoreList":[0]}},
{"offset": {"line": 24, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/intermediate-tree-shake/reexport-with-locals/input/node_modules/lib/index.js"],"sourcesContent":["export { unused } from './unused.js'\nexport * from './unused-star.js'\n\nfunction local() {\n console.log('This is a local function')\n}\nfunction localUnused() {\n console.log('This is a local unused function')\n}\n\nexport { local, localUnused }\n"],"names":[],"mappings":";;;;AAAA;AACA;;;AAEA,SAAS;IACP,QAAQ,GAAG,CAAC;AACd;AACA,SAAS;IACP,QAAQ,GAAG,CAAC;AACd","ignoreList":[0]}}]
}
\ No newline at end of file
(globalThis.TURBOPACK || (globalThis.TURBOPACK = [])).push([
"output/85e3f_snapshot_intermediate-tree-shake_reexport-with-locals_input_index_ed1bdf14.js",
{"otherChunks":["output/4c35f_tests_snapshot_intermediate-tree-shake_reexport-with-locals_input_6ca4cc64._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/intermediate-tree-shake/reexport-with-locals/input/index.js [test] (ecmascript)"]}
"output/85e3f_snapshot_intermediate-tree-shake_reexport-with-locals_input_index_619a7955.js",
{"otherChunks":["output/4c35f_tests_snapshot_intermediate-tree-shake_reexport-with-locals_input_e256c7f2._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/intermediate-tree-shake/reexport-with-locals/input/index.js [test] (ecmascript)"]}
]);
// Dummy runtime
\ No newline at end of file
......@@ -55,6 +55,7 @@ use turbopack_ecmascript::{
references::external_module::{
CachedExternalModule, CachedExternalTracingMode, CachedExternalType,
},
side_effect_optimization::locals::module::EcmascriptModuleLocalsModule,
tree_shake::asset::EcmascriptModulePartAsset,
};
use turbopack_json::JsonModuleAsset;
......@@ -176,11 +177,8 @@ async fn apply_module_type(
if let Some(part) = part {
match part {
ModulePart::Evaluation => {
if *module.get_exports().needs_facade().await? {
Vc::upcast(EcmascriptModuleFacadeModule::new(
Vc::upcast(*module),
part,
))
if *module.get_exports().split_locals_and_reexports().await? {
Vc::upcast(EcmascriptModuleLocalsModule::new(*module))
} else {
Vc::upcast(*module)
}
......@@ -191,12 +189,12 @@ async fn apply_module_type(
.resolve()
.await?;
if *module.get_exports().needs_facade().await? {
if *module.get_exports().split_locals_and_reexports().await? {
apply_reexport_tree_shaking(
Vc::upcast(
EcmascriptModuleFacadeModule::new(
Vc::upcast(*module),
ModulePart::exports(),
ModulePart::facade(),
)
.resolve()
.await?,
......@@ -218,7 +216,7 @@ async fn apply_module_type(
part
),
}
} else if *module.get_exports().needs_facade().await? {
} else if *module.get_exports().split_locals_and_reexports().await? {
Vc::upcast(EcmascriptModuleFacadeModule::new(
Vc::upcast(*module),
ModulePart::facade(),
......@@ -287,7 +285,7 @@ async fn apply_reexport_tree_shaking(
module: final_module,
export_name: new_export,
..
} = &*follow_reexports(module, export.clone(), side_effect_free_packages, false).await?;
} = &*follow_reexports(module, export.clone(), side_effect_free_packages, true).await?;
let module = if let Some(new_export) = new_export {
if *new_export == *export {
Vc::upcast(**final_module)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment