Unverified Commit 1219f499 authored by Jimmy Miller's avatar Jimmy Miller Committed by GitHub

Turbopack: fix empty tree-shake chunks desyncing part ids (#93424) (#95516)

split_module skipped chunks whose body ended up empty, but the group
index is used directly as a part id by outputs
(Key::Export/Key::ModuleEvaluation), part_deps, and the PartId::Internal
asserts embedded in the emitted chunk ASTs. Skipping shifted every later
module's position and desynced those indices, causing out-of-bounds
panics in split_module and wrong-fragment selection in part_of_module.
Always push a module for every group; use a well-formed side-effect-free
`export {}` placeholder when the body is empty.

Update tree-shaker analyzer snapshots to include the placeholder parts.
parent b2534bc4
......@@ -714,7 +714,21 @@ impl DepGraph {
}
if chunk.body.is_empty() {
continue;
// The rest of this code assumes ids match indexes
// so I am putting this placeholder here of an empty
// export so that nothing errors later on because
// of this mismatch
chunk
.body
.push(ModuleItem::ModuleDecl(ModuleDecl::ExportNamed(
NamedExport {
span: DUMMY_SP,
specifiers: Default::default(),
src: None,
type_only: false,
with: None,
},
)));
}
modules.push(chunk);
......
......@@ -80,7 +80,7 @@ graph TD
```
{
ModuleEvaluation: 0,
Exports: 1,
Exports: 2,
}
```
......@@ -98,6 +98,11 @@ export { };
```
## Part 1
```js
export { };
```
## Part 2
```js
```
## Merged (module eval)
......@@ -115,7 +120,7 @@ export { };
```
{
ModuleEvaluation: 0,
Exports: 1,
Exports: 2,
}
```
......@@ -133,6 +138,11 @@ export { };
```
## Part 1
```js
export { };
```
## Part 2
```js
```
## Merged (module eval)
......
......@@ -423,7 +423,7 @@ graph TD
Export(
"NextResponse",
): 0,
Exports: 1,
Exports: 7,
}
```
......@@ -570,6 +570,36 @@ export { };
```
## Part 1
```js
export { };
```
## Part 2
```js
export { };
```
## Part 3
```js
export { };
```
## Part 4
```js
export { };
```
## Part 5
```js
export { };
```
## Part 6
```js
export { };
```
## Part 7
```js
export { NextResponse } from "__TURBOPACK_PART__" assert {
__turbopack_part__: "export NextResponse"
};
......@@ -722,7 +752,7 @@ export { };
Export(
"NextResponse",
): 0,
Exports: 1,
Exports: 7,
}
```
......@@ -869,6 +899,36 @@ export { };
```
## Part 1
```js
export { };
```
## Part 2
```js
export { };
```
## Part 3
```js
export { };
```
## Part 4
```js
export { };
```
## Part 5
```js
export { };
```
## Part 6
```js
export { };
```
## Part 7
```js
export { NextResponse } from "__TURBOPACK_PART__" assert {
__turbopack_part__: "export NextResponse"
};
......
......@@ -123,7 +123,7 @@ graph TD
Export(
"runtime",
): 2,
Exports: 2,
Exports: 3,
}
```
......@@ -147,6 +147,11 @@ export { };
```
## Part 1
```js
export { };
```
## Part 2
```js
const runtime = "edge";
export { runtime };
export { runtime as b } from "__TURBOPACK_VAR__" assert {
......@@ -154,7 +159,7 @@ export { runtime as b } from "__TURBOPACK_VAR__" assert {
};
```
## Part 2
## Part 3
```js
export { GET } from "__TURBOPACK_PART__" assert {
__turbopack_part__: "export GET"
......@@ -191,7 +196,7 @@ export { };
Export(
"runtime",
): 2,
Exports: 2,
Exports: 3,
}
```
......@@ -215,6 +220,11 @@ export { };
```
## Part 1
```js
export { };
```
## Part 2
```js
const runtime = "edge";
export { runtime };
export { runtime as b } from "__TURBOPACK_VAR__" assert {
......@@ -222,7 +232,7 @@ export { runtime as b } from "__TURBOPACK_VAR__" assert {
};
```
## Part 2
## Part 3
```js
export { GET } from "__TURBOPACK_PART__" assert {
__turbopack_part__: "export GET"
......
......@@ -168,7 +168,7 @@ graph TD
Export(
"GET",
): 0,
Exports: 1,
Exports: 4,
}
```
......@@ -197,6 +197,21 @@ export { };
```
## Part 1
```js
export { };
```
## Part 2
```js
export { };
```
## Part 3
```js
export { };
```
## Part 4
```js
export { GET } from "__TURBOPACK_PART__" assert {
__turbopack_part__: "export GET"
};
......@@ -231,7 +246,7 @@ export { };
Export(
"GET",
): 0,
Exports: 1,
Exports: 4,
}
```
......@@ -260,6 +275,21 @@ export { };
```
## Part 1
```js
export { };
```
## Part 2
```js
export { };
```
## Part 3
```js
export { };
```
## Part 4
```js
export { GET } from "__TURBOPACK_PART__" assert {
__turbopack_part__: "export GET"
};
......
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