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 { ...@@ -714,7 +714,21 @@ impl DepGraph {
} }
if chunk.body.is_empty() { 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); modules.push(chunk);
......
...@@ -80,7 +80,7 @@ graph TD ...@@ -80,7 +80,7 @@ graph TD
``` ```
{ {
ModuleEvaluation: 0, ModuleEvaluation: 0,
Exports: 1, Exports: 2,
} }
``` ```
...@@ -98,6 +98,11 @@ export { }; ...@@ -98,6 +98,11 @@ export { };
``` ```
## Part 1 ## Part 1
```js ```js
export { };
```
## Part 2
```js
``` ```
## Merged (module eval) ## Merged (module eval)
...@@ -115,7 +120,7 @@ export { }; ...@@ -115,7 +120,7 @@ export { };
``` ```
{ {
ModuleEvaluation: 0, ModuleEvaluation: 0,
Exports: 1, Exports: 2,
} }
``` ```
...@@ -133,6 +138,11 @@ export { }; ...@@ -133,6 +138,11 @@ export { };
``` ```
## Part 1 ## Part 1
```js ```js
export { };
```
## Part 2
```js
``` ```
## Merged (module eval) ## Merged (module eval)
......
...@@ -423,7 +423,7 @@ graph TD ...@@ -423,7 +423,7 @@ graph TD
Export( Export(
"NextResponse", "NextResponse",
): 0, ): 0,
Exports: 1, Exports: 7,
} }
``` ```
...@@ -570,6 +570,36 @@ export { }; ...@@ -570,6 +570,36 @@ export { };
``` ```
## Part 1 ## Part 1
```js ```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 { export { NextResponse } from "__TURBOPACK_PART__" assert {
__turbopack_part__: "export NextResponse" __turbopack_part__: "export NextResponse"
}; };
...@@ -722,7 +752,7 @@ export { }; ...@@ -722,7 +752,7 @@ export { };
Export( Export(
"NextResponse", "NextResponse",
): 0, ): 0,
Exports: 1, Exports: 7,
} }
``` ```
...@@ -869,6 +899,36 @@ export { }; ...@@ -869,6 +899,36 @@ export { };
``` ```
## Part 1 ## Part 1
```js ```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 { export { NextResponse } from "__TURBOPACK_PART__" assert {
__turbopack_part__: "export NextResponse" __turbopack_part__: "export NextResponse"
}; };
......
...@@ -123,7 +123,7 @@ graph TD ...@@ -123,7 +123,7 @@ graph TD
Export( Export(
"runtime", "runtime",
): 2, ): 2,
Exports: 2, Exports: 3,
} }
``` ```
...@@ -147,6 +147,11 @@ export { }; ...@@ -147,6 +147,11 @@ export { };
``` ```
## Part 1 ## Part 1
```js ```js
export { };
```
## Part 2
```js
const runtime = "edge"; const runtime = "edge";
export { runtime }; export { runtime };
export { runtime as b } from "__TURBOPACK_VAR__" assert { export { runtime as b } from "__TURBOPACK_VAR__" assert {
...@@ -154,7 +159,7 @@ 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 ```js
export { GET } from "__TURBOPACK_PART__" assert { export { GET } from "__TURBOPACK_PART__" assert {
__turbopack_part__: "export GET" __turbopack_part__: "export GET"
...@@ -191,7 +196,7 @@ export { }; ...@@ -191,7 +196,7 @@ export { };
Export( Export(
"runtime", "runtime",
): 2, ): 2,
Exports: 2, Exports: 3,
} }
``` ```
...@@ -215,6 +220,11 @@ export { }; ...@@ -215,6 +220,11 @@ export { };
``` ```
## Part 1 ## Part 1
```js ```js
export { };
```
## Part 2
```js
const runtime = "edge"; const runtime = "edge";
export { runtime }; export { runtime };
export { runtime as b } from "__TURBOPACK_VAR__" assert { export { runtime as b } from "__TURBOPACK_VAR__" assert {
...@@ -222,7 +232,7 @@ 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 ```js
export { GET } from "__TURBOPACK_PART__" assert { export { GET } from "__TURBOPACK_PART__" assert {
__turbopack_part__: "export GET" __turbopack_part__: "export GET"
......
...@@ -168,7 +168,7 @@ graph TD ...@@ -168,7 +168,7 @@ graph TD
Export( Export(
"GET", "GET",
): 0, ): 0,
Exports: 1, Exports: 4,
} }
``` ```
...@@ -197,6 +197,21 @@ export { }; ...@@ -197,6 +197,21 @@ export { };
``` ```
## Part 1 ## Part 1
```js ```js
export { };
```
## Part 2
```js
export { };
```
## Part 3
```js
export { };
```
## Part 4
```js
export { GET } from "__TURBOPACK_PART__" assert { export { GET } from "__TURBOPACK_PART__" assert {
__turbopack_part__: "export GET" __turbopack_part__: "export GET"
}; };
...@@ -231,7 +246,7 @@ export { }; ...@@ -231,7 +246,7 @@ export { };
Export( Export(
"GET", "GET",
): 0, ): 0,
Exports: 1, Exports: 4,
} }
``` ```
...@@ -260,6 +275,21 @@ export { }; ...@@ -260,6 +275,21 @@ export { };
``` ```
## Part 1 ## Part 1
```js ```js
export { };
```
## Part 2
```js
export { };
```
## Part 3
```js
export { };
```
## Part 4
```js
export { GET } from "__TURBOPACK_PART__" assert { export { GET } from "__TURBOPACK_PART__" assert {
__turbopack_part__: "export GET" __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