From 98f6cf8af3e9b4f0e0138cabf72e2ab1dafb6e70 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Fri, 7 Jun 2024 10:18:51 +0200 Subject: [PATCH 01/23] add test cases --- .../analyzer/shared-and-side-effects/input.js | 9 + .../shared-and-side-effects/output.md | 416 ++++++++++++++++++ .../split-chunks-shared-state/input/a.js | 3 + .../split-chunks-shared-state/input/b.js | 3 + .../split-chunks-shared-state/input/index.js | 14 + .../split-chunks-shared-state/input/module.js | 9 + .../split-chunks-shared-state/input/order.js | 3 + .../split-chunks-shared-state/options.json | 3 + 8 files changed, 460 insertions(+) create mode 100644 crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/input.js create mode 100644 crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/output.md create mode 100644 crates/turbopack-tests/tests/execution/turbopack/tree-shaking/split-chunks-shared-state/input/a.js create mode 100644 crates/turbopack-tests/tests/execution/turbopack/tree-shaking/split-chunks-shared-state/input/b.js create mode 100644 crates/turbopack-tests/tests/execution/turbopack/tree-shaking/split-chunks-shared-state/input/index.js create mode 100644 crates/turbopack-tests/tests/execution/turbopack/tree-shaking/split-chunks-shared-state/input/module.js create mode 100644 crates/turbopack-tests/tests/execution/turbopack/tree-shaking/split-chunks-shared-state/input/order.js create mode 100644 crates/turbopack-tests/tests/execution/turbopack/tree-shaking/split-chunks-shared-state/options.json diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/input.js b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/input.js new file mode 100644 index 0000000000000..553decfadb15e --- /dev/null +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/input.js @@ -0,0 +1,9 @@ +console.log("Hello"); +const value = externalFunction(); +const value2 = externalObject.propertyWithGetter; +externalObject.propertyWithSetter = 42; +const shared = { value, value2 }; +console.log(shared); + +export const a = { shared, a: "aaaaaaaaaaa" }; +export const b = { shared, b: "bbbbbbbbbbb" }; diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/output.md new file mode 100644 index 0000000000000..86506a66631b1 --- /dev/null +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/output.md @@ -0,0 +1,416 @@ +# Items + +Count: 11 + +## Item 1: Stmt 0, `Normal` + +```js +console.log("Hello"); + +``` + +- Side effects +- Reads: `console` + +## Item 2: Stmt 1, `VarDeclarator(0)` + +```js +const value = externalFunction(); + +``` + +- Declares: `value` +- Reads: `externalFunction` +- Write: `value` + +## Item 3: Stmt 2, `VarDeclarator(0)` + +```js +const value2 = externalObject.propertyWithGetter; + +``` + +- Declares: `value2` +- Reads: `externalObject` +- Write: `value2` + +## Item 4: Stmt 3, `Normal` + +```js +externalObject.propertyWithSetter = 42; + +``` + +- Side effects +- Reads: `externalObject` + +## Item 5: Stmt 4, `VarDeclarator(0)` + +```js +const shared = { + value, + value2 +}; + +``` + +- Declares: `shared` +- Reads: `value`, `value2` +- Write: `shared` + +## Item 6: Stmt 5, `Normal` + +```js +console.log(shared); + +``` + +- Side effects +- Reads: `console`, `shared` + +## Item 7: Stmt 6, `VarDeclarator(0)` + +```js +export const a = { + shared, + a: "aaaaaaaaaaa" +}; + +``` + +- Declares: `a` +- Reads: `shared` +- Write: `a` + +## Item 8: Stmt 7, `VarDeclarator(0)` + +```js +export const b = { + shared, + b: "bbbbbbbbbbb" +}; + +``` + +- Declares: `b` +- Reads: `shared` +- Write: `b` + +# Phase 1 +```mermaid +graph TD + Item1; + Item2; + Item3; + Item4; + Item5; + Item6; + Item7; + Item8; + Item9; + Item9["ModuleEvaluation"]; + Item10; + Item10["export a"]; + Item11; + Item11["export b"]; +``` +# Phase 2 +```mermaid +graph TD + Item1; + Item2; + Item3; + Item4; + Item5; + Item6; + Item7; + Item8; + Item9; + Item9["ModuleEvaluation"]; + Item10; + Item10["export a"]; + Item11; + Item11["export b"]; + Item4 --> Item1; + Item5 --> Item2; + Item5 --> Item3; + Item6 --> Item5; + Item6 --> Item1; + Item6 --> Item4; + Item7 --> Item5; + Item8 --> Item5; +``` +# Phase 3 +```mermaid +graph TD + Item1; + Item2; + Item3; + Item4; + Item5; + Item6; + Item7; + Item8; + Item9; + Item9["ModuleEvaluation"]; + Item10; + Item10["export a"]; + Item11; + Item11["export b"]; + Item4 --> Item1; + Item5 --> Item2; + Item5 --> Item3; + Item6 --> Item5; + Item6 --> Item1; + Item6 --> Item4; + Item7 --> Item5; + Item8 --> Item5; +``` +# Phase 4 +```mermaid +graph TD + Item1; + Item2; + Item3; + Item4; + Item5; + Item6; + Item7; + Item8; + Item9; + Item9["ModuleEvaluation"]; + Item10; + Item10["export a"]; + Item11; + Item11["export b"]; + Item4 --> Item1; + Item5 --> Item2; + Item5 --> Item3; + Item6 --> Item5; + Item6 --> Item1; + Item6 --> Item4; + Item7 --> Item5; + Item8 --> Item5; + Item9 --> Item1; + Item9 --> Item4; + Item9 --> Item6; + Item10 --> Item7; + Item11 --> Item8; +``` +# Final +```mermaid +graph TD + N0["Items: [ItemId(ModuleEvaluation), ItemId(0, Normal), ItemId(3, Normal), ItemId(5, Normal)]"]; + N1["Items: [ItemId(Export(("a", #2), "a")), ItemId(6, VarDeclarator(0))]"]; + N2["Items: [ItemId(Export(("b", #2), "b")), ItemId(7, VarDeclarator(0))]"]; + N3["Items: [ItemId(1, VarDeclarator(0))]"]; + N4["Items: [ItemId(2, VarDeclarator(0))]"]; + N5["Items: [ItemId(4, VarDeclarator(0))]"]; + N0 --> N5; + N1 --> N5; + N2 --> N5; + N5 --> N3; + N5 --> N4; +``` +# Entrypoints + +``` +{ + ModuleEvaluation: 0, + Export( + "b", + ): 2, + Export( + "a", + ): 1, +} +``` + + +# Modules (dev) +## Part 0 +```js +import { shared } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +"module evaluation"; +console.log("Hello"); +externalObject.propertyWithSetter = 42; +console.log(shared); + +``` +## Part 1 +```js +import { shared } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +export { a }; +const a = { + shared, + a: "aaaaaaaaaaa" +}; +export { a } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 2 +```js +import { shared } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +export { b }; +const b = { + shared, + b: "bbbbbbbbbbb" +}; +export { b } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 3 +```js +const value = externalFunction(); +export { value } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 4 +```js +const value2 = externalObject.propertyWithGetter; +export { value2 } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 5 +```js +import { value } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import { value2 } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +const shared = { + value, + value2 +}; +export { shared } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Merged (module eval) +```js +import { shared } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +"module evaluation"; +console.log("Hello"); +externalObject.propertyWithSetter = 42; +console.log(shared); + +``` +# Entrypoints + +``` +{ + ModuleEvaluation: 0, + Export( + "b", + ): 2, + Export( + "a", + ): 1, +} +``` + + +# Modules (prod) +## Part 0 +```js +import { shared } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +"module evaluation"; +console.log("Hello"); +externalObject.propertyWithSetter = 42; +console.log(shared); + +``` +## Part 1 +```js +import { shared } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +export { a }; +const a = { + shared, + a: "aaaaaaaaaaa" +}; +export { a } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 2 +```js +import { shared } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +export { b }; +const b = { + shared, + b: "bbbbbbbbbbb" +}; +export { b } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 3 +```js +const value = externalFunction(); +export { value } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 4 +```js +const value2 = externalObject.propertyWithGetter; +export { value2 } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 5 +```js +import { value } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import { value2 } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +const shared = { + value, + value2 +}; +export { shared } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Merged (module eval) +```js +import { shared } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +"module evaluation"; +console.log("Hello"); +externalObject.propertyWithSetter = 42; +console.log(shared); + +``` diff --git a/crates/turbopack-tests/tests/execution/turbopack/tree-shaking/split-chunks-shared-state/input/a.js b/crates/turbopack-tests/tests/execution/turbopack/tree-shaking/split-chunks-shared-state/input/a.js new file mode 100644 index 0000000000000..fd18d3bf7d373 --- /dev/null +++ b/crates/turbopack-tests/tests/execution/turbopack/tree-shaking/split-chunks-shared-state/input/a.js @@ -0,0 +1,3 @@ +import { a } from "./module"; + +export default a; diff --git a/crates/turbopack-tests/tests/execution/turbopack/tree-shaking/split-chunks-shared-state/input/b.js b/crates/turbopack-tests/tests/execution/turbopack/tree-shaking/split-chunks-shared-state/input/b.js new file mode 100644 index 0000000000000..bd9f02cc977cd --- /dev/null +++ b/crates/turbopack-tests/tests/execution/turbopack/tree-shaking/split-chunks-shared-state/input/b.js @@ -0,0 +1,3 @@ +import { b } from "./module"; + +export default b; diff --git a/crates/turbopack-tests/tests/execution/turbopack/tree-shaking/split-chunks-shared-state/input/index.js b/crates/turbopack-tests/tests/execution/turbopack/tree-shaking/split-chunks-shared-state/input/index.js new file mode 100644 index 0000000000000..9760696a5c287 --- /dev/null +++ b/crates/turbopack-tests/tests/execution/turbopack/tree-shaking/split-chunks-shared-state/input/index.js @@ -0,0 +1,14 @@ +it("should load chunk a and b with shared state", async () => { + let a = await import("./a"); + expect(a.default).toHaveProperty("a", "aaaaaaaaaaa"); + let b = await import("./b"); + expect(b.default).toHaveProperty("b", "bbbbbbbbbbb"); + let aShared = a.shared; + let bShared = b.shared; + expect(aShared).toBe(bShared); +}); + +it("should execute side effects in the correct order", async () => { + let module = await import("./module"); + expect(module.order).toEqual(["a", "b", "c"]); +}); diff --git a/crates/turbopack-tests/tests/execution/turbopack/tree-shaking/split-chunks-shared-state/input/module.js b/crates/turbopack-tests/tests/execution/turbopack/tree-shaking/split-chunks-shared-state/input/module.js new file mode 100644 index 0000000000000..74a6147c0837a --- /dev/null +++ b/crates/turbopack-tests/tests/execution/turbopack/tree-shaking/split-chunks-shared-state/input/module.js @@ -0,0 +1,9 @@ +export const order = []; + +order.push("a"); +const random = Math.random(); +const shared = { random, effect: order.push("b") }; +order.push("c"); + +export const a = { shared, a: "aaaaaaaaaaa" }; +export const b = { shared, b: "bbbbbbbbbbb" }; diff --git a/crates/turbopack-tests/tests/execution/turbopack/tree-shaking/split-chunks-shared-state/input/order.js b/crates/turbopack-tests/tests/execution/turbopack/tree-shaking/split-chunks-shared-state/input/order.js new file mode 100644 index 0000000000000..0ec382c3decc1 --- /dev/null +++ b/crates/turbopack-tests/tests/execution/turbopack/tree-shaking/split-chunks-shared-state/input/order.js @@ -0,0 +1,3 @@ +import { order } from "./module"; + +export default order; diff --git a/crates/turbopack-tests/tests/execution/turbopack/tree-shaking/split-chunks-shared-state/options.json b/crates/turbopack-tests/tests/execution/turbopack/tree-shaking/split-chunks-shared-state/options.json new file mode 100644 index 0000000000000..000d78a6b3cbb --- /dev/null +++ b/crates/turbopack-tests/tests/execution/turbopack/tree-shaking/split-chunks-shared-state/options.json @@ -0,0 +1,3 @@ +{ + "treeShakingMode": "module-fragments" +} From 3292cf1252be7e0af8be09664cd6a1a0509fb627 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Fri, 7 Jun 2024 10:22:02 +0200 Subject: [PATCH 02/23] add pure case --- .../analyzer/shared-and-side-effects/input.js | 4 +- .../shared-and-side-effects/output.md | 157 +++++++++++------- 2 files changed, 104 insertions(+), 57 deletions(-) diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/input.js b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/input.js index 553decfadb15e..077dd8009d6cf 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/input.js +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/input.js @@ -2,7 +2,9 @@ console.log("Hello"); const value = externalFunction(); const value2 = externalObject.propertyWithGetter; externalObject.propertyWithSetter = 42; -const shared = { value, value2 }; +const value3 = /*#__PURE__*/ externalFunction(); + +const shared = { value, value2, value3 }; console.log(shared); export const a = { shared, a: "aaaaaaaaaaa" }; diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/output.md index 86506a66631b1..1ad672da28964 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/output.md @@ -1,6 +1,6 @@ # Items -Count: 11 +Count: 12 ## Item 1: Stmt 0, `Normal` @@ -46,19 +46,31 @@ externalObject.propertyWithSetter = 42; ## Item 5: Stmt 4, `VarDeclarator(0)` +```js +const value3 = externalFunction(); + +``` + +- Declares: `value3` +- Reads: `externalFunction` +- Write: `value3` + +## Item 6: Stmt 5, `VarDeclarator(0)` + ```js const shared = { value, - value2 + value2, + value3 }; ``` - Declares: `shared` -- Reads: `value`, `value2` +- Reads: `value`, `value2`, `value3` - Write: `shared` -## Item 6: Stmt 5, `Normal` +## Item 7: Stmt 6, `Normal` ```js console.log(shared); @@ -68,7 +80,7 @@ console.log(shared); - Side effects - Reads: `console`, `shared` -## Item 7: Stmt 6, `VarDeclarator(0)` +## Item 8: Stmt 7, `VarDeclarator(0)` ```js export const a = { @@ -82,7 +94,7 @@ export const a = { - Reads: `shared` - Write: `a` -## Item 8: Stmt 7, `VarDeclarator(0)` +## Item 9: Stmt 8, `VarDeclarator(0)` ```js export const b = { @@ -108,11 +120,12 @@ graph TD Item7; Item8; Item9; - Item9["ModuleEvaluation"]; Item10; - Item10["export a"]; + Item10["ModuleEvaluation"]; Item11; - Item11["export b"]; + Item11["export a"]; + Item12; + Item12["export b"]; ``` # Phase 2 ```mermaid @@ -126,19 +139,21 @@ graph TD Item7; Item8; Item9; - Item9["ModuleEvaluation"]; Item10; - Item10["export a"]; + Item10["ModuleEvaluation"]; Item11; - Item11["export b"]; + Item11["export a"]; + Item12; + Item12["export b"]; Item4 --> Item1; - Item5 --> Item2; - Item5 --> Item3; + Item6 --> Item2; + Item6 --> Item3; Item6 --> Item5; - Item6 --> Item1; - Item6 --> Item4; - Item7 --> Item5; - Item8 --> Item5; + Item7 --> Item6; + Item7 --> Item1; + Item7 --> Item4; + Item8 --> Item6; + Item9 --> Item6; ``` # Phase 3 ```mermaid @@ -152,19 +167,21 @@ graph TD Item7; Item8; Item9; - Item9["ModuleEvaluation"]; Item10; - Item10["export a"]; + Item10["ModuleEvaluation"]; Item11; - Item11["export b"]; + Item11["export a"]; + Item12; + Item12["export b"]; Item4 --> Item1; - Item5 --> Item2; - Item5 --> Item3; + Item6 --> Item2; + Item6 --> Item3; Item6 --> Item5; - Item6 --> Item1; - Item6 --> Item4; - Item7 --> Item5; - Item8 --> Item5; + Item7 --> Item6; + Item7 --> Item1; + Item7 --> Item4; + Item8 --> Item6; + Item9 --> Item6; ``` # Phase 4 ```mermaid @@ -178,39 +195,43 @@ graph TD Item7; Item8; Item9; - Item9["ModuleEvaluation"]; Item10; - Item10["export a"]; + Item10["ModuleEvaluation"]; Item11; - Item11["export b"]; + Item11["export a"]; + Item12; + Item12["export b"]; Item4 --> Item1; - Item5 --> Item2; - Item5 --> Item3; + Item6 --> Item2; + Item6 --> Item3; Item6 --> Item5; - Item6 --> Item1; - Item6 --> Item4; - Item7 --> Item5; - Item8 --> Item5; - Item9 --> Item1; - Item9 --> Item4; + Item7 --> Item6; + Item7 --> Item1; + Item7 --> Item4; + Item8 --> Item6; Item9 --> Item6; + Item10 --> Item1; + Item10 --> Item4; Item10 --> Item7; Item11 --> Item8; + Item12 --> Item9; ``` # Final ```mermaid graph TD - N0["Items: [ItemId(ModuleEvaluation), ItemId(0, Normal), ItemId(3, Normal), ItemId(5, Normal)]"]; - N1["Items: [ItemId(Export(("a", #2), "a")), ItemId(6, VarDeclarator(0))]"]; - N2["Items: [ItemId(Export(("b", #2), "b")), ItemId(7, VarDeclarator(0))]"]; + N0["Items: [ItemId(ModuleEvaluation), ItemId(0, Normal), ItemId(3, Normal), ItemId(6, Normal)]"]; + N1["Items: [ItemId(Export(("a", #2), "a")), ItemId(7, VarDeclarator(0))]"]; + N2["Items: [ItemId(Export(("b", #2), "b")), ItemId(8, VarDeclarator(0))]"]; N3["Items: [ItemId(1, VarDeclarator(0))]"]; N4["Items: [ItemId(2, VarDeclarator(0))]"]; N5["Items: [ItemId(4, VarDeclarator(0))]"]; - N0 --> N5; - N1 --> N5; - N2 --> N5; - N5 --> N3; - N5 --> N4; + N6["Items: [ItemId(5, VarDeclarator(0))]"]; + N0 --> N6; + N1 --> N6; + N2 --> N6; + N6 --> N3; + N6 --> N4; + N6 --> N5; ``` # Entrypoints @@ -231,7 +252,7 @@ graph TD ## Part 0 ```js import { shared } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 5 + __turbopack_part__: 6 }; "module evaluation"; console.log("Hello"); @@ -242,7 +263,7 @@ console.log(shared); ## Part 1 ```js import { shared } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 5 + __turbopack_part__: 6 }; export { a }; const a = { @@ -257,7 +278,7 @@ export { a } from "__TURBOPACK_VAR__" assert { ## Part 2 ```js import { shared } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 5 + __turbopack_part__: 6 }; export { b }; const b = { @@ -287,15 +308,27 @@ export { value2 } from "__TURBOPACK_VAR__" assert { ``` ## Part 5 ```js +const value3 = externalFunction(); +export { value3 } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 6 +```js import { value } from "__TURBOPACK_PART__" assert { __turbopack_part__: 3 }; import { value2 } from "__TURBOPACK_PART__" assert { __turbopack_part__: 4 }; +import { value3 } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; const shared = { value, - value2 + value2, + value3 }; export { shared } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true @@ -305,7 +338,7 @@ export { shared } from "__TURBOPACK_VAR__" assert { ## Merged (module eval) ```js import { shared } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 5 + __turbopack_part__: 6 }; "module evaluation"; console.log("Hello"); @@ -332,7 +365,7 @@ console.log(shared); ## Part 0 ```js import { shared } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 5 + __turbopack_part__: 6 }; "module evaluation"; console.log("Hello"); @@ -343,7 +376,7 @@ console.log(shared); ## Part 1 ```js import { shared } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 5 + __turbopack_part__: 6 }; export { a }; const a = { @@ -358,7 +391,7 @@ export { a } from "__TURBOPACK_VAR__" assert { ## Part 2 ```js import { shared } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 5 + __turbopack_part__: 6 }; export { b }; const b = { @@ -388,15 +421,27 @@ export { value2 } from "__TURBOPACK_VAR__" assert { ``` ## Part 5 ```js +const value3 = externalFunction(); +export { value3 } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 6 +```js import { value } from "__TURBOPACK_PART__" assert { __turbopack_part__: 3 }; import { value2 } from "__TURBOPACK_PART__" assert { __turbopack_part__: 4 }; +import { value3 } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; const shared = { value, - value2 + value2, + value3 }; export { shared } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true @@ -406,7 +451,7 @@ export { shared } from "__TURBOPACK_VAR__" assert { ## Merged (module eval) ```js import { shared } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 5 + __turbopack_part__: 6 }; "module evaluation"; console.log("Hello"); From fd78a994d6a7d29564323745f956cb2dfe24112c Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Mon, 10 Jun 2024 10:03:19 +0200 Subject: [PATCH 03/23] add test case --- .../tree-shaker/analyzer/write-order/input.js | 11 + .../analyzer/write-order/output.md | 376 ++++++++++++++++++ 2 files changed, 387 insertions(+) create mode 100644 crates/turbopack-ecmascript/tests/tree-shaker/analyzer/write-order/input.js create mode 100644 crates/turbopack-ecmascript/tests/tree-shaker/analyzer/write-order/output.md diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/write-order/input.js b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/write-order/input.js new file mode 100644 index 0000000000000..afc7c9f573e75 --- /dev/null +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/write-order/input.js @@ -0,0 +1,11 @@ +export const order = []; + +export function func() { + order.push("d"); +} + +order.push("a"); +const x1 = externalFunction(); +const x2 = externalFunction(); +export const shared = { effect: order.push("b") }; +order.push("c"); diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/write-order/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/write-order/output.md new file mode 100644 index 0000000000000..871df19a5d67f --- /dev/null +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/write-order/output.md @@ -0,0 +1,376 @@ +# Items + +Count: 11 + +## Item 1: Stmt 0, `VarDeclarator(0)` + +```js +export const order = []; + +``` + +- Declares: `order` +- Write: `order` + +## Item 2: Stmt 1, `Normal` + +```js +export function func() { + order.push("d"); +} + +``` + +- Hoisted +- Declares: `func` +- Reads (eventual): `order` +- Write: `func` + +## Item 3: Stmt 2, `Normal` + +```js +order.push("a"); + +``` + +- Side effects +- Reads: `order` + +## Item 4: Stmt 3, `VarDeclarator(0)` + +```js +const x1 = externalFunction(); + +``` + +- Declares: `x1` +- Reads: `externalFunction` +- Write: `x1` + +## Item 5: Stmt 4, `VarDeclarator(0)` + +```js +const x2 = externalFunction(); + +``` + +- Declares: `x2` +- Reads: `externalFunction` +- Write: `x2` + +## Item 6: Stmt 5, `VarDeclarator(0)` + +```js +export const shared = { + effect: order.push("b") +}; + +``` + +- Declares: `shared` +- Reads: `order` +- Write: `shared` + +## Item 7: Stmt 6, `Normal` + +```js +order.push("c"); + +``` + +- Side effects +- Reads: `order` + +# Phase 1 +```mermaid +graph TD + Item1; + Item2; + Item3; + Item4; + Item5; + Item6; + Item7; + Item8; + Item8["ModuleEvaluation"]; + Item9; + Item9["export order"]; + Item10; + Item10["export func"]; + Item11; + Item11["export shared"]; +``` +# Phase 2 +```mermaid +graph TD + Item1; + Item2; + Item3; + Item4; + Item5; + Item6; + Item7; + Item8; + Item8["ModuleEvaluation"]; + Item9; + Item9["export order"]; + Item10; + Item10["export func"]; + Item11; + Item11["export shared"]; + Item3 --> Item1; + Item6 --> Item1; + Item7 --> Item1; + Item7 --> Item3; + Item7 -.-> Item6; +``` +# Phase 3 +```mermaid +graph TD + Item1; + Item2; + Item3; + Item4; + Item5; + Item6; + Item7; + Item8; + Item8["ModuleEvaluation"]; + Item9; + Item9["export order"]; + Item10; + Item10["export func"]; + Item11; + Item11["export shared"]; + Item3 --> Item1; + Item6 --> Item1; + Item7 --> Item1; + Item7 --> Item3; + Item7 -.-> Item6; + Item2 --> Item1; +``` +# Phase 4 +```mermaid +graph TD + Item1; + Item2; + Item3; + Item4; + Item5; + Item6; + Item7; + Item8; + Item8["ModuleEvaluation"]; + Item9; + Item9["export order"]; + Item10; + Item10["export func"]; + Item11; + Item11["export shared"]; + Item3 --> Item1; + Item6 --> Item1; + Item7 --> Item1; + Item7 --> Item3; + Item7 -.-> Item6; + Item2 --> Item1; + Item8 --> Item3; + Item8 --> Item7; + Item9 --> Item1; + Item10 --> Item2; + Item11 --> Item6; +``` +# Final +```mermaid +graph TD + N0["Items: [ItemId(ModuleEvaluation), ItemId(2, Normal), ItemId(6, Normal)]"]; + N1["Items: [ItemId(Export(("order", #2), "order"))]"]; + N2["Items: [ItemId(Export(("func", #2), "func")), ItemId(1, Normal)]"]; + N3["Items: [ItemId(Export(("shared", #2), "shared"))]"]; + N4["Items: [ItemId(0, VarDeclarator(0))]"]; + N5["Items: [ItemId(5, VarDeclarator(0))]"]; + N0 --> N4; + N0 --> N5; + N1 --> N4; + N2 --> N4; + N3 --> N5; + N5 --> N4; +``` +# Entrypoints + +``` +{ + ModuleEvaluation: 0, + Export( + "order", + ): 1, + Export( + "func", + ): 2, + Export( + "shared", + ): 3, +} +``` + + +# Modules (dev) +## Part 0 +```js +import { order } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +"module evaluation"; +order.push("a"); +order.push("c"); + +``` +## Part 1 +```js +import { order } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +export { order }; + +``` +## Part 2 +```js +import { order } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +export { func }; +function func() { + order.push("d"); +} +export { func } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 3 +```js +import { shared } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +export { shared }; + +``` +## Part 4 +```js +const order = []; +export { order } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 5 +```js +import { order } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +const shared = { + effect: order.push("b") +}; +export { shared } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Merged (module eval) +```js +import { order } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +"module evaluation"; +order.push("a"); +order.push("c"); + +``` +# Entrypoints + +``` +{ + ModuleEvaluation: 0, + Export( + "order", + ): 1, + Export( + "func", + ): 2, + Export( + "shared", + ): 3, +} +``` + + +# Modules (prod) +## Part 0 +```js +import { order } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +"module evaluation"; +order.push("a"); +order.push("c"); + +``` +## Part 1 +```js +import { order } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +export { order }; + +``` +## Part 2 +```js +import { order } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +export { func }; +function func() { + order.push("d"); +} +export { func } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 3 +```js +import { order } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +export { shared }; +const shared = { + effect: order.push("b") +}; +export { shared } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 4 +```js +const order = []; +export { order } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Merged (module eval) +```js +import { order } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +"module evaluation"; +order.push("a"); +order.push("c"); + +``` From b0ac8ffaa0109815078b3728462ffca27dabb3c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Mon, 10 Jun 2024 17:01:15 +0900 Subject: [PATCH 04/23] Treat obj of member expr as write --- crates/turbopack-ecmascript/src/tree_shake/util.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/turbopack-ecmascript/src/tree_shake/util.rs b/crates/turbopack-ecmascript/src/tree_shake/util.rs index 15d4e92f493a6..a49e9725fd9d5 100644 --- a/crates/turbopack-ecmascript/src/tree_shake/util.rs +++ b/crates/turbopack-ecmascript/src/tree_shake/util.rs @@ -7,7 +7,7 @@ use swc_core::{ ecma::{ ast::{ AssignTarget, BlockStmtOrExpr, Constructor, ExportNamedSpecifier, ExportSpecifier, - Expr, Function, Id, Ident, MemberProp, NamedExport, Pat, PropName, + Expr, Function, Id, Ident, MemberExpr, MemberProp, NamedExport, Pat, PropName, }, visit::{noop_visit_type, visit_obj_and_computed, Visit, VisitWith}, }, @@ -102,6 +102,15 @@ impl Visit for IdentUsageCollector { } } + fn visit_member_expr(&mut self, e: &MemberExpr) { + self.with_mode(Mode::Write, |this| { + // Skip visit_expr + e.obj.visit_children_with(this); + }); + + e.prop.visit_with(self); + } + fn visit_member_prop(&mut self, n: &MemberProp) { if let MemberProp::Computed(..) = n { n.visit_children_with(self); @@ -129,8 +138,6 @@ impl Visit for IdentUsageCollector { } noop_visit_type!(); - - visit_obj_and_computed!(); } /// A visitor which collects variables which are read or written, but not at the From 051bbcb6ee113e9fb07a3d4b91d4da1457214860 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Mon, 10 Jun 2024 17:08:27 +0900 Subject: [PATCH 05/23] side_effects for unresolved --- crates/turbopack-ecmascript/src/tree_shake/graph.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crates/turbopack-ecmascript/src/tree_shake/graph.rs b/crates/turbopack-ecmascript/src/tree_shake/graph.rs index fa31ae5ceff7b..9d2677c14d76c 100644 --- a/crates/turbopack-ecmascript/src/tree_shake/graph.rs +++ b/crates/turbopack-ecmascript/src/tree_shake/graph.rs @@ -940,6 +940,12 @@ impl DepGraph { let eventual_vars = ids_captured_by(&decl.init, [unresolved_ctxt, top_level_ctxt]); + let side_effects = vars + .read + .iter() + .chain(vars.write.iter()) + .any(|id| id.1 == unresolved_ctxt); + let var_decl = Box::new(VarDecl { decls: vec![decl.clone()], ..*v.clone() @@ -954,6 +960,7 @@ impl DepGraph { write_vars: decl_ids.into_iter().chain(vars.write).collect(), eventual_write_vars: eventual_vars.write, content, + side_effects, ..Default::default() }, ); From 8c489b474d484d7c915a11d9c77a52e890bae1ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Mon, 10 Jun 2024 17:08:46 +0900 Subject: [PATCH 06/23] Update test refs --- .../tests/tree-shaker/analyzer/1/output.md | 15 +- .../tests/tree-shaker/analyzer/2/output.md | 15 +- .../tree-shaker/analyzer/app-route/output.md | 276 ++++++++-- .../tree-shaker/analyzer/complex/output.md | 22 +- .../tree-shaker/analyzer/failed-1/output.md | 45 +- .../tree-shaker/analyzer/failed-2/output.md | 48 +- .../tree-shaker/analyzer/failed-3/output.md | 488 +++++++++++++----- .../analyzer/node-globals/output.md | 14 +- .../shared-and-side-effects/output.md | 283 ++++++++-- .../analyzer/template-pages/output.md | 17 +- .../analyzer/test-config-1/output.md | 15 +- .../tree-shaker/analyzer/tla-1/output.md | 59 +-- .../analyzer/write-order/output.md | 270 ++++++++-- 13 files changed, 1164 insertions(+), 403 deletions(-) diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/1/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/1/output.md index 0b92f964586ee..4a45d71eebcbf 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/1/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/1/output.md @@ -92,7 +92,8 @@ console.log(foobarCopy); ``` - Side effects -- Reads: `console`, `foobarCopy` +- Reads: `foobarCopy` +- Write: `console` ## Item 10: Stmt 8, `Normal` @@ -398,6 +399,9 @@ import "__TURBOPACK_PART__" assert { import "module"; import { upper } from "module"; console.log(foobarCopy); +export { console } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` ## Part 1 @@ -557,6 +561,9 @@ import "module"; import { upper } from "module"; "module evaluation"; console.log(foobarCopy); +export { console } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` # Entrypoints @@ -593,6 +600,9 @@ console.log(foobarCopy); export { foobarCopy } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; +export { console } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` ## Part 1 @@ -700,5 +710,8 @@ console.log(foobarCopy); export { foobarCopy } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; +export { console } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/2/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/2/output.md index ef2fc1ea5d109..bdfecbf570796 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/2/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/2/output.md @@ -106,7 +106,8 @@ console.log(foobarCopy); ``` - Side effects -- Reads: `console`, `foobarCopy` +- Reads: `foobarCopy` +- Write: `console` ## Item 11: Stmt 9, `Normal` @@ -421,6 +422,9 @@ import "module"; import { upper } from "module"; console.log(foobarCopy); import "other"; +export { console } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` ## Part 1 @@ -581,6 +585,9 @@ import { upper } from "module"; import "other"; "module evaluation"; console.log(foobarCopy); +export { console } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` # Entrypoints @@ -618,6 +625,9 @@ import "other"; export { foobarCopy } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; +export { console } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` ## Part 1 @@ -726,5 +736,8 @@ console.log(foobarCopy); export { foobarCopy } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; +export { console } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/app-route/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/app-route/output.md index e9ff4664bdaad..91caaf0660054 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/app-route/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/app-route/output.md @@ -100,9 +100,10 @@ const routeModule = new AppRouteRouteModule({ ``` +- Side effects - Declares: `routeModule` -- Reads: `AppRouteRouteModule`, `RouteKind`, `nextConfigOutput`, `userland` -- Write: `routeModule` +- Reads: `AppRouteRouteModule`, `nextConfigOutput`, `userland` +- Write: `routeModule`, `RouteKind` ## Item 10: Stmt 5, `VarDeclarator(0)` @@ -214,8 +215,12 @@ graph TD Item4 --> Item2; Item4 --> Item3; Item9 --> Item5; - Item9 --> Item6; Item9 --> Item8; + Item9 --> Item1; + Item9 --> Item2; + Item9 --> Item3; + Item9 --> Item4; + Item9 -.-> Item7; Item10 --> Item9; ``` # Phase 3 @@ -254,8 +259,12 @@ graph TD Item4 --> Item2; Item4 --> Item3; Item9 --> Item5; - Item9 --> Item6; Item9 --> Item8; + Item9 --> Item1; + Item9 --> Item2; + Item9 --> Item3; + Item9 --> Item4; + Item9 -.-> Item7; Item10 --> Item9; Item12 --> Item7; Item12 --> Item10; @@ -296,8 +305,12 @@ graph TD Item4 --> Item2; Item4 --> Item3; Item9 --> Item5; - Item9 --> Item6; Item9 --> Item8; + Item9 --> Item1; + Item9 --> Item2; + Item9 --> Item3; + Item9 --> Item4; + Item9 -.-> Item7; Item10 --> Item9; Item12 --> Item7; Item12 --> Item10; @@ -305,6 +318,7 @@ graph TD Item13 --> Item2; Item13 --> Item3; Item13 --> Item4; + Item13 --> Item9; Item14 --> Item9; Item15 --> Item10; Item16 --> Item10; @@ -315,21 +329,41 @@ graph TD # Final ```mermaid graph TD - N0["Items: [ItemId(ModuleEvaluation), ItemId(0, ImportOfModule), ItemId(1, ImportOfModule), ItemId(2, ImportOfModule), ItemId(3, ImportOfModule)]"]; + N0["Items: [ItemId(ModuleEvaluation)]"]; N1["Items: [ItemId(Export(("routeModule", #2), "routeModule"))]"]; N2["Items: [ItemId(Export(("requestAsyncStorage", #2), "requestAsyncStorage"))]"]; N3["Items: [ItemId(Export(("staticGenerationAsyncStorage", #2), "staticGenerationAsyncStorage"))]"]; N4["Items: [ItemId(Export(("serverHooks", #2), "serverHooks"))]"]; N5["Items: [ItemId(Export(("originalPathname", #2), "originalPathname")), ItemId(6, VarDeclarator(0))]"]; N6["Items: [ItemId(Export(("patchFetch", #2), "patchFetch")), ItemId(2, ImportBinding(0)), ItemId(7, Normal)]"]; - N7["Items: [ItemId(0, ImportBinding(0)), ItemId(1, ImportBinding(0)), ItemId(3, ImportBinding(0)), ItemId(4, VarDeclarator(0))]"]; - N8["Items: [ItemId(5, VarDeclarator(0))]"]; - N1 --> N7; - N2 --> N8; - N3 --> N8; - N4 --> N8; - N6 --> N8; + N7["Items: [ItemId(0, ImportOfModule)]"]; + N8["Items: [ItemId(1, ImportOfModule)]"]; + N9["Items: [ItemId(2, ImportOfModule)]"]; + N10["Items: [ItemId(3, ImportOfModule)]"]; + N11["Items: [ItemId(0, ImportBinding(0)), ItemId(2, ImportBinding(0)), ItemId(3, ImportBinding(0)), ItemId(4, VarDeclarator(0))]"]; + N12["Items: [ItemId(5, VarDeclarator(0))]"]; + N0 --> N7; + N0 --> N8; + N0 --> N9; + N0 --> N10; + N0 --> N11; + N1 --> N11; + N2 --> N12; + N3 --> N12; + N4 --> N12; + N6 --> N11; + N6 --> N12; N8 --> N7; + N9 --> N7; + N9 --> N8; + N10 --> N7; + N10 --> N8; + N10 --> N9; + N11 --> N7; + N11 --> N8; + N11 --> N9; + N11 --> N10; + N12 --> N11; ``` # Entrypoints @@ -361,17 +395,28 @@ graph TD # Modules (dev) ## Part 0 ```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 7 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 10 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 11 +}; "module evaluation"; -import '../../server/future/route-modules/app-route/module.compiled'; -import '../../server/future/route-kind'; -import '../../server/lib/patch-fetch'; -import 'VAR_USERLAND'; ``` ## Part 1 ```js import { routeModule } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 7 + __turbopack_part__: 11 }; export { routeModule as routeModule }; @@ -379,7 +424,7 @@ export { routeModule as routeModule }; ## Part 2 ```js import { requestAsyncStorage } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 8 + __turbopack_part__: 12 }; export { requestAsyncStorage as requestAsyncStorage }; @@ -387,7 +432,7 @@ export { requestAsyncStorage as requestAsyncStorage }; ## Part 3 ```js import { staticGenerationAsyncStorage } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 8 + __turbopack_part__: 12 }; export { staticGenerationAsyncStorage as staticGenerationAsyncStorage }; @@ -395,7 +440,7 @@ export { staticGenerationAsyncStorage as staticGenerationAsyncStorage }; ## Part 4 ```js import { serverHooks } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 8 + __turbopack_part__: 12 }; export { serverHooks as serverHooks }; @@ -411,8 +456,11 @@ export { originalPathname } from "__TURBOPACK_VAR__" assert { ``` ## Part 6 ```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 11 +}; import { staticGenerationAsyncStorage, serverHooks } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 8 + __turbopack_part__: 12 }; export { patchFetch as patchFetch }; import { patchFetch as _patchFetch } from '../../server/lib/patch-fetch'; @@ -429,8 +477,58 @@ export { patchFetch } from "__TURBOPACK_VAR__" assert { ``` ## Part 7 ```js +import '../../server/future/route-modules/app-route/module.compiled'; + +``` +## Part 8 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 7 +}; +import '../../server/future/route-kind'; + +``` +## Part 9 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 7 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; +import '../../server/lib/patch-fetch'; + +``` +## Part 10 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 7 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; +import 'VAR_USERLAND'; + +``` +## Part 11 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 7 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 10 +}; import { AppRouteRouteModule } from '../../server/future/route-modules/app-route/module.compiled'; -import { RouteKind } from '../../server/future/route-kind'; +import { patchFetch as _patchFetch } from '../../server/lib/patch-fetch'; import * as userland from 'VAR_USERLAND'; const routeModule = new AppRouteRouteModule({ definition: { @@ -447,12 +545,15 @@ const routeModule = new AppRouteRouteModule({ export { routeModule } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; +export { RouteKind } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` -## Part 8 +## Part 12 ```js import { routeModule } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 7 + __turbopack_part__: 11 }; const { requestAsyncStorage, staticGenerationAsyncStorage, serverHooks } = routeModule; export { requestAsyncStorage } from "__TURBOPACK_VAR__" assert { @@ -468,10 +569,21 @@ export { serverHooks } from "__TURBOPACK_VAR__" assert { ``` ## Merged (module eval) ```js -import '../../server/future/route-modules/app-route/module.compiled'; -import '../../server/future/route-kind'; -import '../../server/lib/patch-fetch'; -import 'VAR_USERLAND'; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 7 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 10 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 11 +}; "module evaluation"; ``` @@ -505,17 +617,28 @@ import 'VAR_USERLAND'; # Modules (prod) ## Part 0 ```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 7 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 10 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 11 +}; "module evaluation"; -import '../../server/future/route-modules/app-route/module.compiled'; -import '../../server/future/route-kind'; -import '../../server/lib/patch-fetch'; -import 'VAR_USERLAND'; ``` ## Part 1 ```js import { routeModule } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 7 + __turbopack_part__: 11 }; export { routeModule as routeModule }; @@ -523,7 +646,7 @@ export { routeModule as routeModule }; ## Part 2 ```js import { requestAsyncStorage } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 8 + __turbopack_part__: 12 }; export { requestAsyncStorage as requestAsyncStorage }; @@ -531,7 +654,7 @@ export { requestAsyncStorage as requestAsyncStorage }; ## Part 3 ```js import { staticGenerationAsyncStorage } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 8 + __turbopack_part__: 12 }; export { staticGenerationAsyncStorage as staticGenerationAsyncStorage }; @@ -539,7 +662,7 @@ export { staticGenerationAsyncStorage as staticGenerationAsyncStorage }; ## Part 4 ```js import { serverHooks } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 8 + __turbopack_part__: 12 }; export { serverHooks as serverHooks }; @@ -556,7 +679,7 @@ export { originalPathname } from "__TURBOPACK_VAR__" assert { ## Part 6 ```js import { staticGenerationAsyncStorage, serverHooks } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 8 + __turbopack_part__: 12 }; export { patchFetch as patchFetch }; import { patchFetch as _patchFetch } from '../../server/lib/patch-fetch'; @@ -573,8 +696,57 @@ export { patchFetch } from "__TURBOPACK_VAR__" assert { ``` ## Part 7 ```js +import '../../server/future/route-modules/app-route/module.compiled'; + +``` +## Part 8 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 7 +}; +import '../../server/future/route-kind'; + +``` +## Part 9 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 7 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; +import '../../server/lib/patch-fetch'; + +``` +## Part 10 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 7 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; +import 'VAR_USERLAND'; + +``` +## Part 11 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 7 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 10 +}; import { AppRouteRouteModule } from '../../server/future/route-modules/app-route/module.compiled'; -import { RouteKind } from '../../server/future/route-kind'; import * as userland from 'VAR_USERLAND'; const routeModule = new AppRouteRouteModule({ definition: { @@ -591,12 +763,15 @@ const routeModule = new AppRouteRouteModule({ export { routeModule } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; +export { RouteKind } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` -## Part 8 +## Part 12 ```js import { routeModule } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 7 + __turbopack_part__: 11 }; const { requestAsyncStorage, staticGenerationAsyncStorage, serverHooks } = routeModule; export { requestAsyncStorage } from "__TURBOPACK_VAR__" assert { @@ -612,10 +787,21 @@ export { serverHooks } from "__TURBOPACK_VAR__" assert { ``` ## Merged (module eval) ```js -import '../../server/future/route-modules/app-route/module.compiled'; -import '../../server/future/route-kind'; -import '../../server/lib/patch-fetch'; -import 'VAR_USERLAND'; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 7 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 10 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 11 +}; "module evaluation"; ``` diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/complex/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/complex/output.md index 80e4cdf3c3c32..3e63f9511840e 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/complex/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/complex/output.md @@ -30,7 +30,8 @@ console.log(dog); ``` - Side effects -- Reads: `console`, `dog` +- Reads: `dog` +- Write: `console` ## Item 4: Stmt 3, `Normal` @@ -64,7 +65,8 @@ console.log(dog); ``` - Side effects -- Reads: `console`, `dog` +- Reads: `dog` +- Write: `console` ## Item 7: Stmt 6, `Normal` @@ -98,7 +100,8 @@ console.log(dog); ``` - Side effects -- Reads: `console`, `dog` +- Reads: `dog` +- Write: `console` ## Item 10: Stmt 9, `VarDeclarator(0)` @@ -495,6 +498,9 @@ import { dog } from "__TURBOPACK_PART__" assert { __turbopack_part__: 7 }; console.log(dog); +export { console } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` ## Part 9 @@ -529,7 +535,7 @@ export { dog } from "__TURBOPACK_VAR__" assert { import { dog } from "__TURBOPACK_PART__" assert { __turbopack_part__: 10 }; -import "__TURBOPACK_PART__" assert { +import { console } from "__TURBOPACK_PART__" assert { __turbopack_part__: 8 }; console.log(dog); @@ -554,7 +560,7 @@ export { dog } from "__TURBOPACK_VAR__" assert { import { dog } from "__TURBOPACK_PART__" assert { __turbopack_part__: 12 }; -import "__TURBOPACK_PART__" assert { +import { console } from "__TURBOPACK_PART__" assert { __turbopack_part__: 8 }; import "__TURBOPACK_PART__" assert { @@ -622,6 +628,9 @@ import "__TURBOPACK_PART__" assert { console.log(dog); console.log(dog); console.log(dog); +export { console } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` ## Part 1 @@ -753,5 +762,8 @@ import "__TURBOPACK_PART__" assert { console.log(dog); console.log(dog); console.log(dog); +export { console } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-1/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-1/output.md index f6fe3c1915364..b72ab350856b7 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-1/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-1/output.md @@ -37,8 +37,9 @@ function getSocketProtocol(assetPrefix) { - Hoisted - Declares: `getSocketProtocol` -- Reads (eventual): `location`, `URL` +- Reads (eventual): `URL` - Write: `getSocketProtocol` +- Write (eventual): `location` ## Item 4: Stmt 3, `Normal` @@ -51,8 +52,8 @@ export function addMessageListener(cb) { - Hoisted - Declares: `addMessageListener` -- Reads (eventual): `eventCallbacks` - Write: `addMessageListener` +- Write (eventual): `eventCallbacks` ## Item 5: Stmt 4, `Normal` @@ -68,6 +69,7 @@ export function sendMessage(data) { - Declares: `sendMessage` - Reads (eventual): `source` - Write: `sendMessage` +- Write (eventual): `source` ## Item 6: Stmt 5, `Normal` @@ -118,9 +120,9 @@ export function connectHMR(options) { - Hoisted - Declares: `connectHMR` -- Reads (eventual): `source`, `console`, `eventCallbacks`, `JSON`, `setTimeout`, `location`, `getSocketProtocol`, `window` +- Reads (eventual): `source`, `setTimeout`, `location`, `getSocketProtocol` - Write: `connectHMR` -- Write (eventual): `source` +- Write (eventual): `source`, `console`, `eventCallbacks`, `JSON`, `window` # Phase 1 ```mermaid @@ -175,10 +177,8 @@ graph TD Item9["export sendMessage"]; Item10; Item10["export connectHMR"]; - Item4 --> Item2; Item5 --> Item1; Item6 --> Item1; - Item6 --> Item2; Item6 --> Item3; ``` # Phase 4 @@ -198,10 +198,8 @@ graph TD Item9["export sendMessage"]; Item10; Item10["export connectHMR"]; - Item4 --> Item2; Item5 --> Item1; Item6 --> Item1; - Item6 --> Item2; Item6 --> Item3; Item8 --> Item4; Item9 --> Item5; @@ -215,11 +213,8 @@ graph TD N2["Items: [ItemId(Export(("sendMessage", #2), "sendMessage")), ItemId(4, Normal)]"]; N3["Items: [ItemId(Export(("connectHMR", #2), "connectHMR")), ItemId(2, Normal), ItemId(5, Normal)]"]; N4["Items: [ItemId(0, VarDeclarator(0))]"]; - N5["Items: [ItemId(1, VarDeclarator(0))]"]; - N1 --> N5; N2 --> N4; N3 --> N4; - N3 --> N5; ``` # Entrypoints @@ -247,9 +242,6 @@ graph TD ``` ## Part 1 ```js -import { eventCallbacks } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 5 -}; export { addMessageListener }; function addMessageListener(cb) { eventCallbacks.push(cb); @@ -279,9 +271,6 @@ export { sendMessage } from "__TURBOPACK_VAR__" assert { import { source } from "__TURBOPACK_PART__" assert { __turbopack_part__: 4 }; -import { eventCallbacks } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 5 -}; export { connectHMR }; function getSocketProtocol(assetPrefix) { let protocol = location.protocol; @@ -346,14 +335,6 @@ export { source } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; -``` -## Part 5 -```js -const eventCallbacks = []; -export { eventCallbacks } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; - ``` ## Merged (module eval) ```js @@ -386,9 +367,6 @@ export { eventCallbacks } from "__TURBOPACK_VAR__" assert { ``` ## Part 1 ```js -import { eventCallbacks } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 5 -}; export { addMessageListener }; function addMessageListener(cb) { eventCallbacks.push(cb); @@ -418,9 +396,6 @@ export { sendMessage } from "__TURBOPACK_VAR__" assert { import { source } from "__TURBOPACK_PART__" assert { __turbopack_part__: 4 }; -import { eventCallbacks } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 5 -}; export { connectHMR }; function getSocketProtocol(assetPrefix) { let protocol = location.protocol; @@ -485,14 +460,6 @@ export { source } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; -``` -## Part 5 -```js -const eventCallbacks = []; -export { eventCallbacks } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; - ``` ## Merged (module eval) ```js diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-2/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-2/output.md index 7ab4874e5634d..9a19285c3fd02 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-2/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-2/output.md @@ -90,8 +90,7 @@ const hasPostpone = typeof React.unstable_postpone === 'function'; ``` - Declares: `hasPostpone` -- Reads: `React` -- Write: `hasPostpone` +- Write: `hasPostpone`, `React` ## Item 10: Stmt 5, `Normal` @@ -213,8 +212,9 @@ function postponeWithTracking(prerenderState, expression, pathname) { - Hoisted - Declares: `postponeWithTracking` -- Reads (eventual): `assertPostpone`, `Error`, `undefined`, `React` +- Reads (eventual): `assertPostpone`, `Error`, `undefined` - Write: `postponeWithTracking` +- Write (eventual): `React` ## Item 16: Stmt 11, `Normal` @@ -290,8 +290,9 @@ export function createPostponedAbortSignal(reason) { - Hoisted - Declares: `createPostponedAbortSignal` -- Reads (eventual): `assertPostpone`, `AbortController`, `React` +- Reads (eventual): `assertPostpone`, `AbortController` - Write: `createPostponedAbortSignal` +- Write (eventual): `React` # Phase 1 ```mermaid @@ -386,7 +387,6 @@ graph TD Item4 --> Item1; Item4 --> Item2; Item4 --> Item3; - Item9 --> Item5; ``` # Phase 3 ```mermaid @@ -434,7 +434,6 @@ graph TD Item4 --> Item1; Item4 --> Item2; Item4 --> Item3; - Item9 --> Item5; Item11 --> Item8; Item11 --> Item7; Item11 --> Item15; @@ -446,10 +445,8 @@ graph TD Item13 --> Item15; Item14 --> Item15; Item15 --> Item18; - Item15 --> Item5; Item18 --> Item9; Item19 --> Item18; - Item19 --> Item5; ``` # Phase 4 ```mermaid @@ -497,7 +494,6 @@ graph TD Item4 --> Item1; Item4 --> Item2; Item4 --> Item3; - Item9 --> Item5; Item11 --> Item8; Item11 --> Item7; Item11 --> Item15; @@ -509,10 +505,8 @@ graph TD Item13 --> Item15; Item14 --> Item15; Item15 --> Item18; - Item15 --> Item5; Item18 --> Item9; Item19 --> Item18; - Item19 --> Item5; Item20 --> Item1; Item20 --> Item2; Item20 --> Item3; @@ -537,9 +531,9 @@ graph TD N5["Items: [ItemId(Export(("trackDynamicFetch", #2), "trackDynamicFetch")), ItemId(9, Normal)]"]; N6["Items: [ItemId(Export(("usedDynamicAPIs", #2), "usedDynamicAPIs")), ItemId(11, Normal)]"]; N7["Items: [ItemId(Export(("formatDynamicAPIAccesses", #2), "formatDynamicAPIAccesses")), ItemId(12, Normal)]"]; - N8["Items: [ItemId(Export(("createPostponedAbortSignal", #2), "createPostponedAbortSignal")), ItemId(0, ImportBinding(0)), ItemId(14, Normal)]"]; - N9["Items: [ItemId(0, ImportBinding(0)), ItemId(4, VarDeclarator(0))]"]; - N10["Items: [ItemId(0, ImportBinding(0)), ItemId(10, Normal)]"]; + N8["Items: [ItemId(Export(("createPostponedAbortSignal", #2), "createPostponedAbortSignal")), ItemId(14, Normal)]"]; + N9["Items: [ItemId(4, VarDeclarator(0))]"]; + N10["Items: [ItemId(10, Normal)]"]; N11["Items: [ItemId(13, Normal)]"]; N2 --> N3; N2 --> N10; @@ -547,8 +541,6 @@ graph TD N4 --> N10; N5 --> N10; N8 --> N11; - N8 --> N10; - N9 --> N10; N10 --> N11; N11 --> N9; ``` @@ -746,11 +738,7 @@ export { formatDynamicAPIAccesses } from "__TURBOPACK_VAR__" assert { import { assertPostpone } from "__TURBOPACK_PART__" assert { __turbopack_part__: 11 }; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 10 -}; export { createPostponedAbortSignal }; -import React from 'react'; function createPostponedAbortSignal(reason) { assertPostpone(); const controller = new AbortController(); @@ -768,14 +756,13 @@ export { createPostponedAbortSignal } from "__TURBOPACK_VAR__" assert { ``` ## Part 9 ```js -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 10 -}; -import React from 'react'; const hasPostpone = typeof React.unstable_postpone === 'function'; export { hasPostpone } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; +export { React } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` ## Part 10 @@ -783,7 +770,6 @@ export { hasPostpone } from "__TURBOPACK_VAR__" assert { import { assertPostpone } from "__TURBOPACK_PART__" assert { __turbopack_part__: 11 }; -import React from 'react'; function postponeWithTracking(prerenderState, expression, pathname) { assertPostpone(); const reason = `Route ${pathname} needs to bail out of prerendering at this point because it used ${expression}. ` + `React throws this special object to indicate where. It should not be caught by ` + `your own try/catch. Learn more: https://nextjs.org/docs/messages/ppr-caught-error`; @@ -1016,11 +1002,7 @@ export { formatDynamicAPIAccesses } from "__TURBOPACK_VAR__" assert { import { assertPostpone } from "__TURBOPACK_PART__" assert { __turbopack_part__: 11 }; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 10 -}; export { createPostponedAbortSignal }; -import React from 'react'; function createPostponedAbortSignal(reason) { assertPostpone(); const controller = new AbortController(); @@ -1038,14 +1020,13 @@ export { createPostponedAbortSignal } from "__TURBOPACK_VAR__" assert { ``` ## Part 9 ```js -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 10 -}; -import React from 'react'; const hasPostpone = typeof React.unstable_postpone === 'function'; export { hasPostpone } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; +export { React } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` ## Part 10 @@ -1053,7 +1034,6 @@ export { hasPostpone } from "__TURBOPACK_VAR__" assert { import { assertPostpone } from "__TURBOPACK_PART__" assert { __turbopack_part__: 11 }; -import React from 'react'; function postponeWithTracking(prerenderState, expression, pathname) { assertPostpone(); const reason = `Route ${pathname} needs to bail out of prerendering at this point because it used ${expression}. ` + `React throws this special object to indicate where. It should not be caught by ` + `your own try/catch. Learn more: https://nextjs.org/docs/messages/ppr-caught-error`; diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-3/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-3/output.md index dd4ee200bda38..7f1ad72785c96 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-3/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-3/output.md @@ -215,8 +215,9 @@ function createIpc(port) { - Hoisted - Declares: `createIpc` -- Reads (eventual): `createConnection`, `JSON`, `Buffer`, `loop`, `process`, `Promise`, `structuredError`, `console` +- Reads (eventual): `createConnection`, `loop`, `Promise`, `structuredError` - Write: `createIpc` +- Write (eventual): `JSON`, `Buffer`, `process`, `console` ## Item 9: Stmt 5, `VarDeclarator(0)` @@ -225,9 +226,9 @@ const PORT = process.argv[2]; ``` +- Side effects - Declares: `PORT` -- Reads: `process` -- Write: `PORT` +- Write: `PORT`, `process` ## Item 10: Stmt 6, `VarDeclarator(0)` @@ -236,6 +237,7 @@ export const IPC = createIpc(parseInt(PORT, 10)); ``` +- Side effects - Declares: `IPC` - Reads: `createIpc`, `parseInt`, `PORT` - Write: `IPC` @@ -250,8 +252,8 @@ process.on("uncaughtException", (err)=>{ ``` - Side effects -- Reads: `process` - Reads (eventual): `IPC` +- Write: `process` ## Item 12: Stmt 8, `VarDeclarator(0)` @@ -518,57 +520,73 @@ graph TD Item2 --> Item1; Item3 --> Item1; Item3 --> Item2; + Item9 --> Item1; + Item9 --> Item2; + Item9 --> Item3; + Item9 -.-> Item6; + Item9 -.-> Item5; + Item9 -.-> Item4; + Item9 -.-> Item7; Item10 --> Item8; Item10 --> Item9; + Item10 --> Item1; + Item10 --> Item2; + Item10 --> Item3; + Item10 -.-> Item6; + Item10 -.-> Item5; + Item10 -.-> Item4; + Item10 -.-> Item7; Item11 --> Item1; Item11 --> Item2; Item11 --> Item3; + Item11 --> Item9; + Item11 --> Item10; Item11 -.-> Item6; Item11 -.-> Item5; Item11 -.-> Item4; - Item11 -.-> Item9; Item11 -.-> Item7; - Item11 -.-> Item10; Item13 --> Item12; Item13 --> Item1; Item13 --> Item2; Item13 --> Item3; + Item13 --> Item9; + Item13 --> Item10; Item13 --> Item11; Item13 -.-> Item6; Item13 -.-> Item5; Item13 -.-> Item4; - Item13 -.-> Item9; Item13 -.-> Item7; - Item13 -.-> Item10; Item14 --> Item12; Item14 --> Item1; Item14 --> Item2; Item14 --> Item3; + Item14 --> Item9; + Item14 --> Item10; Item14 --> Item11; Item14 --> Item13; Item14 -.-> Item6; Item14 -.-> Item5; Item14 -.-> Item4; - Item14 -.-> Item9; Item14 -.-> Item7; - Item14 -.-> Item10; Item15 --> Item12; Item15 --> Item1; Item15 --> Item2; Item15 --> Item3; + Item15 --> Item9; + Item15 --> Item10; Item15 --> Item11; Item15 --> Item13; Item15 --> Item14; Item15 -.-> Item6; Item15 -.-> Item5; Item15 -.-> Item4; - Item15 -.-> Item9; Item15 -.-> Item7; - Item15 -.-> Item10; Item16 --> Item12; Item16 --> Item1; Item16 --> Item2; Item16 --> Item3; + Item16 --> Item9; + Item16 --> Item10; Item16 --> Item11; Item16 --> Item13; Item16 --> Item14; @@ -576,13 +594,13 @@ graph TD Item16 -.-> Item6; Item16 -.-> Item5; Item16 -.-> Item4; - Item16 -.-> Item9; Item16 -.-> Item7; - Item16 -.-> Item10; Item17 --> Item12; Item17 --> Item1; Item17 --> Item2; Item17 --> Item3; + Item17 --> Item9; + Item17 --> Item10; Item17 --> Item11; Item17 --> Item13; Item17 --> Item14; @@ -591,13 +609,13 @@ graph TD Item17 -.-> Item6; Item17 -.-> Item5; Item17 -.-> Item4; - Item17 -.-> Item9; Item17 -.-> Item7; - Item17 -.-> Item10; Item18 --> Item12; Item18 --> Item1; Item18 --> Item2; Item18 --> Item3; + Item18 --> Item9; + Item18 --> Item10; Item18 --> Item11; Item18 --> Item13; Item18 --> Item14; @@ -607,13 +625,13 @@ graph TD Item18 -.-> Item6; Item18 -.-> Item5; Item18 -.-> Item4; - Item18 -.-> Item9; Item18 -.-> Item7; - Item18 -.-> Item10; Item19 --> Item12; Item19 --> Item1; Item19 --> Item2; Item19 --> Item3; + Item19 --> Item9; + Item19 --> Item10; Item19 --> Item11; Item19 --> Item13; Item19 --> Item14; @@ -624,13 +642,13 @@ graph TD Item19 -.-> Item6; Item19 -.-> Item5; Item19 -.-> Item4; - Item19 -.-> Item9; Item19 -.-> Item7; - Item19 -.-> Item10; Item20 --> Item12; Item20 --> Item1; Item20 --> Item2; Item20 --> Item3; + Item20 --> Item9; + Item20 --> Item10; Item20 --> Item11; Item20 --> Item13; Item20 --> Item14; @@ -642,13 +660,13 @@ graph TD Item20 -.-> Item6; Item20 -.-> Item5; Item20 -.-> Item4; - Item20 -.-> Item9; Item20 -.-> Item7; - Item20 -.-> Item10; Item21 --> Item12; Item21 --> Item1; Item21 --> Item2; Item21 --> Item3; + Item21 --> Item9; + Item21 --> Item10; Item21 --> Item11; Item21 --> Item13; Item21 --> Item14; @@ -661,13 +679,13 @@ graph TD Item21 -.-> Item6; Item21 -.-> Item5; Item21 -.-> Item4; - Item21 -.-> Item9; Item21 -.-> Item7; - Item21 -.-> Item10; Item22 --> Item12; Item22 --> Item1; Item22 --> Item2; Item22 --> Item3; + Item22 --> Item9; + Item22 --> Item10; Item22 --> Item11; Item22 --> Item13; Item22 --> Item14; @@ -681,13 +699,13 @@ graph TD Item22 -.-> Item6; Item22 -.-> Item5; Item22 -.-> Item4; - Item22 -.-> Item9; Item22 -.-> Item7; - Item22 -.-> Item10; Item23 --> Item12; Item23 --> Item1; Item23 --> Item2; Item23 --> Item3; + Item23 --> Item9; + Item23 --> Item10; Item23 --> Item11; Item23 --> Item13; Item23 --> Item14; @@ -702,13 +720,13 @@ graph TD Item23 -.-> Item6; Item23 -.-> Item5; Item23 -.-> Item4; - Item23 -.-> Item9; Item23 -.-> Item7; - Item23 -.-> Item10; Item24 --> Item12; Item24 --> Item1; Item24 --> Item2; Item24 --> Item3; + Item24 --> Item9; + Item24 --> Item10; Item24 --> Item11; Item24 --> Item13; Item24 --> Item14; @@ -724,13 +742,13 @@ graph TD Item24 -.-> Item6; Item24 -.-> Item5; Item24 -.-> Item4; - Item24 -.-> Item9; Item24 -.-> Item7; - Item24 -.-> Item10; Item25 --> Item12; Item25 --> Item1; Item25 --> Item2; Item25 --> Item3; + Item25 --> Item9; + Item25 --> Item10; Item25 --> Item11; Item25 --> Item13; Item25 --> Item14; @@ -747,13 +765,13 @@ graph TD Item25 -.-> Item6; Item25 -.-> Item5; Item25 -.-> Item4; - Item25 -.-> Item9; Item25 -.-> Item7; - Item25 -.-> Item10; Item26 --> Item12; Item26 --> Item1; Item26 --> Item2; Item26 --> Item3; + Item26 --> Item9; + Item26 --> Item10; Item26 --> Item11; Item26 --> Item13; Item26 --> Item14; @@ -771,13 +789,13 @@ graph TD Item26 -.-> Item6; Item26 -.-> Item5; Item26 -.-> Item4; - Item26 -.-> Item9; Item26 -.-> Item7; - Item26 -.-> Item10; Item27 --> Item12; Item27 --> Item1; Item27 --> Item2; Item27 --> Item3; + Item27 --> Item9; + Item27 --> Item10; Item27 --> Item11; Item27 --> Item13; Item27 --> Item14; @@ -796,13 +814,13 @@ graph TD Item27 -.-> Item6; Item27 -.-> Item5; Item27 -.-> Item4; - Item27 -.-> Item9; Item27 -.-> Item7; - Item27 -.-> Item10; Item28 --> Item12; Item28 --> Item1; Item28 --> Item2; Item28 --> Item3; + Item28 --> Item9; + Item28 --> Item10; Item28 --> Item11; Item28 --> Item13; Item28 --> Item14; @@ -822,9 +840,7 @@ graph TD Item28 -.-> Item6; Item28 -.-> Item5; Item28 -.-> Item4; - Item28 -.-> Item9; Item28 -.-> Item7; - Item28 -.-> Item10; ``` # Phase 3 ```mermaid @@ -866,57 +882,73 @@ graph TD Item2 --> Item1; Item3 --> Item1; Item3 --> Item2; + Item9 --> Item1; + Item9 --> Item2; + Item9 --> Item3; + Item9 -.-> Item6; + Item9 -.-> Item5; + Item9 -.-> Item4; + Item9 -.-> Item7; Item10 --> Item8; Item10 --> Item9; + Item10 --> Item1; + Item10 --> Item2; + Item10 --> Item3; + Item10 -.-> Item6; + Item10 -.-> Item5; + Item10 -.-> Item4; + Item10 -.-> Item7; Item11 --> Item1; Item11 --> Item2; Item11 --> Item3; + Item11 --> Item9; + Item11 --> Item10; Item11 -.-> Item6; Item11 -.-> Item5; Item11 -.-> Item4; - Item11 -.-> Item9; Item11 -.-> Item7; - Item11 --> Item10; Item13 --> Item12; Item13 --> Item1; Item13 --> Item2; Item13 --> Item3; + Item13 --> Item9; + Item13 --> Item10; Item13 --> Item11; Item13 -.-> Item6; Item13 -.-> Item5; Item13 -.-> Item4; - Item13 -.-> Item9; Item13 -.-> Item7; - Item13 -.-> Item10; Item14 --> Item12; Item14 --> Item1; Item14 --> Item2; Item14 --> Item3; + Item14 --> Item9; + Item14 --> Item10; Item14 --> Item11; Item14 --> Item13; Item14 -.-> Item6; Item14 -.-> Item5; Item14 -.-> Item4; - Item14 -.-> Item9; Item14 -.-> Item7; - Item14 -.-> Item10; Item15 --> Item12; Item15 --> Item1; Item15 --> Item2; Item15 --> Item3; + Item15 --> Item9; + Item15 --> Item10; Item15 --> Item11; Item15 --> Item13; Item15 --> Item14; Item15 -.-> Item6; Item15 -.-> Item5; Item15 -.-> Item4; - Item15 -.-> Item9; Item15 -.-> Item7; - Item15 -.-> Item10; Item16 --> Item12; Item16 --> Item1; Item16 --> Item2; Item16 --> Item3; + Item16 --> Item9; + Item16 --> Item10; Item16 --> Item11; Item16 --> Item13; Item16 --> Item14; @@ -924,13 +956,13 @@ graph TD Item16 -.-> Item6; Item16 -.-> Item5; Item16 -.-> Item4; - Item16 -.-> Item9; Item16 -.-> Item7; - Item16 -.-> Item10; Item17 --> Item12; Item17 --> Item1; Item17 --> Item2; Item17 --> Item3; + Item17 --> Item9; + Item17 --> Item10; Item17 --> Item11; Item17 --> Item13; Item17 --> Item14; @@ -939,13 +971,13 @@ graph TD Item17 -.-> Item6; Item17 -.-> Item5; Item17 -.-> Item4; - Item17 -.-> Item9; Item17 -.-> Item7; - Item17 -.-> Item10; Item18 --> Item12; Item18 --> Item1; Item18 --> Item2; Item18 --> Item3; + Item18 --> Item9; + Item18 --> Item10; Item18 --> Item11; Item18 --> Item13; Item18 --> Item14; @@ -955,13 +987,13 @@ graph TD Item18 -.-> Item6; Item18 -.-> Item5; Item18 -.-> Item4; - Item18 -.-> Item9; Item18 -.-> Item7; - Item18 -.-> Item10; Item19 --> Item12; Item19 --> Item1; Item19 --> Item2; Item19 --> Item3; + Item19 --> Item9; + Item19 --> Item10; Item19 --> Item11; Item19 --> Item13; Item19 --> Item14; @@ -972,13 +1004,13 @@ graph TD Item19 -.-> Item6; Item19 -.-> Item5; Item19 -.-> Item4; - Item19 -.-> Item9; Item19 -.-> Item7; - Item19 -.-> Item10; Item20 --> Item12; Item20 --> Item1; Item20 --> Item2; Item20 --> Item3; + Item20 --> Item9; + Item20 --> Item10; Item20 --> Item11; Item20 --> Item13; Item20 --> Item14; @@ -990,13 +1022,13 @@ graph TD Item20 -.-> Item6; Item20 -.-> Item5; Item20 -.-> Item4; - Item20 -.-> Item9; Item20 -.-> Item7; - Item20 -.-> Item10; Item21 --> Item12; Item21 --> Item1; Item21 --> Item2; Item21 --> Item3; + Item21 --> Item9; + Item21 --> Item10; Item21 --> Item11; Item21 --> Item13; Item21 --> Item14; @@ -1009,13 +1041,13 @@ graph TD Item21 -.-> Item6; Item21 -.-> Item5; Item21 -.-> Item4; - Item21 -.-> Item9; Item21 -.-> Item7; - Item21 -.-> Item10; Item22 --> Item12; Item22 --> Item1; Item22 --> Item2; Item22 --> Item3; + Item22 --> Item9; + Item22 --> Item10; Item22 --> Item11; Item22 --> Item13; Item22 --> Item14; @@ -1029,13 +1061,13 @@ graph TD Item22 -.-> Item6; Item22 -.-> Item5; Item22 -.-> Item4; - Item22 -.-> Item9; Item22 -.-> Item7; - Item22 -.-> Item10; Item23 --> Item12; Item23 --> Item1; Item23 --> Item2; Item23 --> Item3; + Item23 --> Item9; + Item23 --> Item10; Item23 --> Item11; Item23 --> Item13; Item23 --> Item14; @@ -1050,13 +1082,13 @@ graph TD Item23 -.-> Item6; Item23 -.-> Item5; Item23 -.-> Item4; - Item23 -.-> Item9; Item23 -.-> Item7; - Item23 -.-> Item10; Item24 --> Item12; Item24 --> Item1; Item24 --> Item2; Item24 --> Item3; + Item24 --> Item9; + Item24 --> Item10; Item24 --> Item11; Item24 --> Item13; Item24 --> Item14; @@ -1072,13 +1104,13 @@ graph TD Item24 -.-> Item6; Item24 -.-> Item5; Item24 -.-> Item4; - Item24 -.-> Item9; Item24 -.-> Item7; - Item24 -.-> Item10; Item25 --> Item12; Item25 --> Item1; Item25 --> Item2; Item25 --> Item3; + Item25 --> Item9; + Item25 --> Item10; Item25 --> Item11; Item25 --> Item13; Item25 --> Item14; @@ -1095,13 +1127,13 @@ graph TD Item25 -.-> Item6; Item25 -.-> Item5; Item25 -.-> Item4; - Item25 -.-> Item9; Item25 -.-> Item7; - Item25 -.-> Item10; Item26 --> Item12; Item26 --> Item1; Item26 --> Item2; Item26 --> Item3; + Item26 --> Item9; + Item26 --> Item10; Item26 --> Item11; Item26 --> Item13; Item26 --> Item14; @@ -1119,13 +1151,13 @@ graph TD Item26 -.-> Item6; Item26 -.-> Item5; Item26 -.-> Item4; - Item26 -.-> Item9; Item26 -.-> Item7; - Item26 -.-> Item10; Item27 --> Item12; Item27 --> Item1; Item27 --> Item2; Item27 --> Item3; + Item27 --> Item9; + Item27 --> Item10; Item27 --> Item11; Item27 --> Item13; Item27 --> Item14; @@ -1144,13 +1176,13 @@ graph TD Item27 -.-> Item6; Item27 -.-> Item5; Item27 -.-> Item4; - Item27 -.-> Item9; Item27 -.-> Item7; - Item27 -.-> Item10; Item28 --> Item12; Item28 --> Item1; Item28 --> Item2; Item28 --> Item3; + Item28 --> Item9; + Item28 --> Item10; Item28 --> Item11; Item28 --> Item13; Item28 --> Item14; @@ -1170,13 +1202,12 @@ graph TD Item28 -.-> Item6; Item28 -.-> Item5; Item28 -.-> Item4; - Item28 -.-> Item9; Item28 -.-> Item7; - Item28 -.-> Item10; Item7 --> Item6; Item7 --> Item5; Item8 --> Item4; Item8 --> Item7; + Item12 --> Item11; ``` # Phase 4 ```mermaid @@ -1218,57 +1249,73 @@ graph TD Item2 --> Item1; Item3 --> Item1; Item3 --> Item2; + Item9 --> Item1; + Item9 --> Item2; + Item9 --> Item3; + Item9 -.-> Item6; + Item9 -.-> Item5; + Item9 -.-> Item4; + Item9 -.-> Item7; Item10 --> Item8; Item10 --> Item9; + Item10 --> Item1; + Item10 --> Item2; + Item10 --> Item3; + Item10 -.-> Item6; + Item10 -.-> Item5; + Item10 -.-> Item4; + Item10 -.-> Item7; Item11 --> Item1; Item11 --> Item2; Item11 --> Item3; + Item11 --> Item9; + Item11 --> Item10; Item11 -.-> Item6; Item11 -.-> Item5; Item11 -.-> Item4; - Item11 -.-> Item9; Item11 -.-> Item7; - Item11 --> Item10; Item13 --> Item12; Item13 --> Item1; Item13 --> Item2; Item13 --> Item3; + Item13 --> Item9; + Item13 --> Item10; Item13 --> Item11; Item13 -.-> Item6; Item13 -.-> Item5; Item13 -.-> Item4; - Item13 -.-> Item9; Item13 -.-> Item7; - Item13 -.-> Item10; Item14 --> Item12; Item14 --> Item1; Item14 --> Item2; Item14 --> Item3; + Item14 --> Item9; + Item14 --> Item10; Item14 --> Item11; Item14 --> Item13; Item14 -.-> Item6; Item14 -.-> Item5; Item14 -.-> Item4; - Item14 -.-> Item9; Item14 -.-> Item7; - Item14 -.-> Item10; Item15 --> Item12; Item15 --> Item1; Item15 --> Item2; Item15 --> Item3; + Item15 --> Item9; + Item15 --> Item10; Item15 --> Item11; Item15 --> Item13; Item15 --> Item14; Item15 -.-> Item6; Item15 -.-> Item5; Item15 -.-> Item4; - Item15 -.-> Item9; Item15 -.-> Item7; - Item15 -.-> Item10; Item16 --> Item12; Item16 --> Item1; Item16 --> Item2; Item16 --> Item3; + Item16 --> Item9; + Item16 --> Item10; Item16 --> Item11; Item16 --> Item13; Item16 --> Item14; @@ -1276,13 +1323,13 @@ graph TD Item16 -.-> Item6; Item16 -.-> Item5; Item16 -.-> Item4; - Item16 -.-> Item9; Item16 -.-> Item7; - Item16 -.-> Item10; Item17 --> Item12; Item17 --> Item1; Item17 --> Item2; Item17 --> Item3; + Item17 --> Item9; + Item17 --> Item10; Item17 --> Item11; Item17 --> Item13; Item17 --> Item14; @@ -1291,13 +1338,13 @@ graph TD Item17 -.-> Item6; Item17 -.-> Item5; Item17 -.-> Item4; - Item17 -.-> Item9; Item17 -.-> Item7; - Item17 -.-> Item10; Item18 --> Item12; Item18 --> Item1; Item18 --> Item2; Item18 --> Item3; + Item18 --> Item9; + Item18 --> Item10; Item18 --> Item11; Item18 --> Item13; Item18 --> Item14; @@ -1307,13 +1354,13 @@ graph TD Item18 -.-> Item6; Item18 -.-> Item5; Item18 -.-> Item4; - Item18 -.-> Item9; Item18 -.-> Item7; - Item18 -.-> Item10; Item19 --> Item12; Item19 --> Item1; Item19 --> Item2; Item19 --> Item3; + Item19 --> Item9; + Item19 --> Item10; Item19 --> Item11; Item19 --> Item13; Item19 --> Item14; @@ -1324,13 +1371,13 @@ graph TD Item19 -.-> Item6; Item19 -.-> Item5; Item19 -.-> Item4; - Item19 -.-> Item9; Item19 -.-> Item7; - Item19 -.-> Item10; Item20 --> Item12; Item20 --> Item1; Item20 --> Item2; Item20 --> Item3; + Item20 --> Item9; + Item20 --> Item10; Item20 --> Item11; Item20 --> Item13; Item20 --> Item14; @@ -1342,13 +1389,13 @@ graph TD Item20 -.-> Item6; Item20 -.-> Item5; Item20 -.-> Item4; - Item20 -.-> Item9; Item20 -.-> Item7; - Item20 -.-> Item10; Item21 --> Item12; Item21 --> Item1; Item21 --> Item2; Item21 --> Item3; + Item21 --> Item9; + Item21 --> Item10; Item21 --> Item11; Item21 --> Item13; Item21 --> Item14; @@ -1361,13 +1408,13 @@ graph TD Item21 -.-> Item6; Item21 -.-> Item5; Item21 -.-> Item4; - Item21 -.-> Item9; Item21 -.-> Item7; - Item21 -.-> Item10; Item22 --> Item12; Item22 --> Item1; Item22 --> Item2; Item22 --> Item3; + Item22 --> Item9; + Item22 --> Item10; Item22 --> Item11; Item22 --> Item13; Item22 --> Item14; @@ -1381,13 +1428,13 @@ graph TD Item22 -.-> Item6; Item22 -.-> Item5; Item22 -.-> Item4; - Item22 -.-> Item9; Item22 -.-> Item7; - Item22 -.-> Item10; Item23 --> Item12; Item23 --> Item1; Item23 --> Item2; Item23 --> Item3; + Item23 --> Item9; + Item23 --> Item10; Item23 --> Item11; Item23 --> Item13; Item23 --> Item14; @@ -1402,13 +1449,13 @@ graph TD Item23 -.-> Item6; Item23 -.-> Item5; Item23 -.-> Item4; - Item23 -.-> Item9; Item23 -.-> Item7; - Item23 -.-> Item10; Item24 --> Item12; Item24 --> Item1; Item24 --> Item2; Item24 --> Item3; + Item24 --> Item9; + Item24 --> Item10; Item24 --> Item11; Item24 --> Item13; Item24 --> Item14; @@ -1424,13 +1471,13 @@ graph TD Item24 -.-> Item6; Item24 -.-> Item5; Item24 -.-> Item4; - Item24 -.-> Item9; Item24 -.-> Item7; - Item24 -.-> Item10; Item25 --> Item12; Item25 --> Item1; Item25 --> Item2; Item25 --> Item3; + Item25 --> Item9; + Item25 --> Item10; Item25 --> Item11; Item25 --> Item13; Item25 --> Item14; @@ -1447,13 +1494,13 @@ graph TD Item25 -.-> Item6; Item25 -.-> Item5; Item25 -.-> Item4; - Item25 -.-> Item9; Item25 -.-> Item7; - Item25 -.-> Item10; Item26 --> Item12; Item26 --> Item1; Item26 --> Item2; Item26 --> Item3; + Item26 --> Item9; + Item26 --> Item10; Item26 --> Item11; Item26 --> Item13; Item26 --> Item14; @@ -1471,13 +1518,13 @@ graph TD Item26 -.-> Item6; Item26 -.-> Item5; Item26 -.-> Item4; - Item26 -.-> Item9; Item26 -.-> Item7; - Item26 -.-> Item10; Item27 --> Item12; Item27 --> Item1; Item27 --> Item2; Item27 --> Item3; + Item27 --> Item9; + Item27 --> Item10; Item27 --> Item11; Item27 --> Item13; Item27 --> Item14; @@ -1496,13 +1543,13 @@ graph TD Item27 -.-> Item6; Item27 -.-> Item5; Item27 -.-> Item4; - Item27 -.-> Item9; Item27 -.-> Item7; - Item27 -.-> Item10; Item28 --> Item12; Item28 --> Item1; Item28 --> Item2; Item28 --> Item3; + Item28 --> Item9; + Item28 --> Item10; Item28 --> Item11; Item28 --> Item13; Item28 --> Item14; @@ -1522,16 +1569,17 @@ graph TD Item28 -.-> Item6; Item28 -.-> Item5; Item28 -.-> Item4; - Item28 -.-> Item9; Item28 -.-> Item7; - Item28 -.-> Item10; Item7 --> Item6; Item7 --> Item5; Item8 --> Item4; Item8 --> Item7; + Item12 --> Item11; Item29 --> Item1; Item29 --> Item2; Item29 --> Item3; + Item29 --> Item9; + Item29 --> Item10; Item29 --> Item11; Item29 --> Item13; Item29 --> Item14; @@ -1555,22 +1603,41 @@ graph TD # Final ```mermaid graph TD - N0["Items: [ItemId(ModuleEvaluation), ItemId(0, ImportOfModule), ItemId(0, ImportBinding(0)), ItemId(1, ImportOfModule), ItemId(1, ImportBinding(0)), ItemId(2, ImportOfModule), ItemId(2, ImportBinding(0)), ItemId(7, Normal), ItemId(8, VarDeclarator(0)), ItemId(9, Normal), ItemId(10, Normal), ItemId(11, Normal), ItemId(12, Normal), ItemId(13, Normal), ItemId(14, Normal), ItemId(15, Normal), ItemId(16, Normal), ItemId(17, Normal), ItemId(18, Normal), ItemId(19, Normal), ItemId(20, Normal), ItemId(21, Normal), ItemId(22, Normal), ItemId(23, Normal), ItemId(24, Normal)]"]; + N0["Items: [ItemId(ModuleEvaluation), ItemId(0, ImportBinding(0)), ItemId(1, ImportBinding(0)), ItemId(2, ImportBinding(0)), ItemId(7, Normal), ItemId(8, VarDeclarator(0)), ItemId(9, Normal), ItemId(10, Normal), ItemId(11, Normal), ItemId(12, Normal), ItemId(13, Normal), ItemId(14, Normal), ItemId(15, Normal), ItemId(16, Normal), ItemId(17, Normal), ItemId(18, Normal), ItemId(19, Normal), ItemId(20, Normal), ItemId(21, Normal), ItemId(22, Normal), ItemId(23, Normal), ItemId(24, Normal)]"]; N1["Items: [ItemId(Export(("structuredError", #2), "structuredError"))]"]; N2["Items: [ItemId(Export(("IPC", #2), "IPC"))]"]; - N3["Items: [ItemId(1, ImportBinding(0)), ItemId(2, ImportBinding(0)), ItemId(3, Normal)]"]; - N4["Items: [ItemId(0, ImportBinding(0)), ItemId(4, Normal)]"]; - N5["Items: [ItemId(5, VarDeclarator(0))]"]; - N6["Items: [ItemId(6, VarDeclarator(0))]"]; + N3["Items: [ItemId(0, ImportOfModule)]"]; + N4["Items: [ItemId(1, ImportOfModule)]"]; + N5["Items: [ItemId(2, ImportOfModule)]"]; + N6["Items: [ItemId(1, ImportBinding(0)), ItemId(2, ImportBinding(0)), ItemId(3, Normal)]"]; + N7["Items: [ItemId(0, ImportBinding(0)), ItemId(4, Normal)]"]; + N8["Items: [ItemId(0, ImportBinding(0)), ItemId(1, ImportBinding(0)), ItemId(2, ImportBinding(0)), ItemId(5, VarDeclarator(0))]"]; + N9["Items: [ItemId(0, ImportBinding(0)), ItemId(1, ImportBinding(0)), ItemId(2, ImportBinding(0)), ItemId(6, VarDeclarator(0))]"]; N0 --> N3; N0 --> N4; N0 --> N5; + N0 --> N8; + N0 --> N9; N0 --> N6; - N1 --> N3; - N2 --> N6; + N1 --> N6; + N2 --> N9; N4 --> N3; - N6 --> N4; - N6 --> N5; + N5 --> N3; + N5 --> N4; + N6 --> N9; + N7 --> N9; + N7 --> N6; + N8 --> N3; + N8 --> N4; + N8 --> N5; + N8 --> N9; + N8 --> N6; + N9 --> N7; + N9 --> N8; + N9 --> N3; + N9 --> N4; + N9 --> N5; + N9 --> N6; ``` # Entrypoints @@ -1599,15 +1666,18 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; +import { process } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; import { IPC } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; +import "__TURBOPACK_PART__" assert { __turbopack_part__: 6 }; "module evaluation"; -import "node:net"; import { createConnection } from "node:net"; -import "../compiled/stacktrace-parser"; import { parse as parseStackTrace } from "../compiled/stacktrace-parser"; -import "./error"; import { getProperError } from "./error"; process.on("uncaughtException", (err)=>{ IPC.sendError(err); @@ -1650,7 +1720,7 @@ export { improveConsole } from "__TURBOPACK_VAR__" assert { ## Part 1 ```js import { structuredError } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 3 + __turbopack_part__: 6 }; export { structuredError }; @@ -1658,13 +1728,40 @@ export { structuredError }; ## Part 2 ```js import { IPC } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 6 + __turbopack_part__: 9 }; export { IPC }; ``` ## Part 3 ```js +import "node:net"; + +``` +## Part 4 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "../compiled/stacktrace-parser"; + +``` +## Part 5 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "./error"; + +``` +## Part 6 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; import { parse as parseStackTrace } from "../compiled/stacktrace-parser"; import { getProperError } from "./error"; function structuredError(e) { @@ -1680,10 +1777,13 @@ export { structuredError } from "__TURBOPACK_VAR__" assert { }; ``` -## Part 4 +## Part 7 ```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; import { structuredError } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 3 + __turbopack_part__: 6 }; import { createConnection } from "node:net"; function createIpc(port) { @@ -1817,22 +1917,58 @@ export { createIpc } from "__TURBOPACK_VAR__" assert { }; ``` -## Part 5 +## Part 8 ```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; +import { createConnection } from "node:net"; +import { parse as parseStackTrace } from "../compiled/stacktrace-parser"; +import { getProperError } from "./error"; const PORT = process.argv[2]; export { PORT } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; +export { process } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` -## Part 6 +## Part 9 ```js import { createIpc } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 4 + __turbopack_part__: 7 }; import { PORT } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; +import { createConnection } from "node:net"; +import { parse as parseStackTrace } from "../compiled/stacktrace-parser"; +import { getProperError } from "./error"; const IPC = createIpc(parseInt(PORT, 10)); export { IPC } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true @@ -1850,14 +1986,17 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; +import { process } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; import { IPC } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; +import "__TURBOPACK_PART__" assert { __turbopack_part__: 6 }; -import "node:net"; import { createConnection } from "node:net"; -import "../compiled/stacktrace-parser"; import { parse as parseStackTrace } from "../compiled/stacktrace-parser"; -import "./error"; import { getProperError } from "./error"; "module evaluation"; process.on("uncaughtException", (err)=>{ @@ -1916,13 +2055,22 @@ export { improveConsole } from "__TURBOPACK_VAR__" assert { # Modules (prod) ## Part 0 ```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +import { process } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; import { IPC } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 6 + __turbopack_part__: 9 }; "module evaluation"; -import "node:net"; -import "../compiled/stacktrace-parser"; -import "./error"; process.on("uncaughtException", (err)=>{ IPC.sendError(err); }); @@ -1964,7 +2112,7 @@ export { improveConsole } from "__TURBOPACK_VAR__" assert { ## Part 1 ```js import { structuredError } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 3 + __turbopack_part__: 6 }; export { structuredError }; @@ -1972,13 +2120,37 @@ export { structuredError }; ## Part 2 ```js import { IPC } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 6 + __turbopack_part__: 9 }; export { IPC }; ``` ## Part 3 ```js +import "node:net"; + +``` +## Part 4 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "../compiled/stacktrace-parser"; + +``` +## Part 5 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "./error"; + +``` +## Part 6 +```js import { parse as parseStackTrace } from "../compiled/stacktrace-parser"; import { getProperError } from "./error"; function structuredError(e) { @@ -1994,10 +2166,10 @@ export { structuredError } from "__TURBOPACK_VAR__" assert { }; ``` -## Part 4 +## Part 7 ```js import { structuredError } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 3 + __turbopack_part__: 6 }; import { createConnection } from "node:net"; function createIpc(port) { @@ -2131,20 +2303,41 @@ export { createIpc } from "__TURBOPACK_VAR__" assert { }; ``` -## Part 5 +## Part 8 ```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; const PORT = process.argv[2]; export { PORT } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; +export { process } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` -## Part 6 +## Part 9 ```js import { createIpc } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 4 + __turbopack_part__: 7 }; import { PORT } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; const IPC = createIpc(parseInt(PORT, 10)); @@ -2155,12 +2348,21 @@ export { IPC } from "__TURBOPACK_VAR__" assert { ``` ## Merged (module eval) ```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +import { process } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; import { IPC } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 6 + __turbopack_part__: 9 }; -import "node:net"; -import "../compiled/stacktrace-parser"; -import "./error"; "module evaluation"; process.on("uncaughtException", (err)=>{ IPC.sendError(err); diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/node-globals/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/node-globals/output.md index ab622fe1df812..9adf74dd970cb 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/node-globals/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/node-globals/output.md @@ -10,7 +10,7 @@ process.turbopack = {}; ``` - Side effects -- Reads: `process` +- Write: `process` # Phase 1 ```mermaid @@ -60,12 +60,18 @@ graph TD ```js "module evaluation"; process.turbopack = {}; +export { process } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` ## Merged (module eval) ```js "module evaluation"; process.turbopack = {}; +export { process } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` # Entrypoints @@ -82,11 +88,17 @@ process.turbopack = {}; ```js "module evaluation"; process.turbopack = {}; +export { process } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` ## Merged (module eval) ```js "module evaluation"; process.turbopack = {}; +export { process } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/output.md index 1ad672da28964..d051d8b61270e 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/output.md @@ -10,7 +10,7 @@ console.log("Hello"); ``` - Side effects -- Reads: `console` +- Write: `console` ## Item 2: Stmt 1, `VarDeclarator(0)` @@ -19,6 +19,7 @@ const value = externalFunction(); ``` +- Side effects - Declares: `value` - Reads: `externalFunction` - Write: `value` @@ -30,9 +31,9 @@ const value2 = externalObject.propertyWithGetter; ``` +- Side effects - Declares: `value2` -- Reads: `externalObject` -- Write: `value2` +- Write: `value2`, `externalObject` ## Item 4: Stmt 3, `Normal` @@ -42,7 +43,7 @@ externalObject.propertyWithSetter = 42; ``` - Side effects -- Reads: `externalObject` +- Write: `externalObject` ## Item 5: Stmt 4, `VarDeclarator(0)` @@ -51,6 +52,7 @@ const value3 = externalFunction(); ``` +- Side effects - Declares: `value3` - Reads: `externalFunction` - Write: `value3` @@ -78,7 +80,8 @@ console.log(shared); ``` - Side effects -- Reads: `console`, `shared` +- Reads: `shared` +- Write: `console` ## Item 8: Stmt 7, `VarDeclarator(0)` @@ -145,13 +148,25 @@ graph TD Item11["export a"]; Item12; Item12["export b"]; + Item2 --> Item1; + Item3 --> Item1; + Item3 --> Item2; Item4 --> Item1; + Item4 --> Item2; + Item4 --> Item3; + Item5 --> Item1; + Item5 --> Item2; + Item5 --> Item3; + Item5 --> Item4; Item6 --> Item2; Item6 --> Item3; Item6 --> Item5; Item7 --> Item6; Item7 --> Item1; + Item7 --> Item2; + Item7 --> Item3; Item7 --> Item4; + Item7 --> Item5; Item8 --> Item6; Item9 --> Item6; ``` @@ -173,13 +188,25 @@ graph TD Item11["export a"]; Item12; Item12["export b"]; + Item2 --> Item1; + Item3 --> Item1; + Item3 --> Item2; Item4 --> Item1; + Item4 --> Item2; + Item4 --> Item3; + Item5 --> Item1; + Item5 --> Item2; + Item5 --> Item3; + Item5 --> Item4; Item6 --> Item2; Item6 --> Item3; Item6 --> Item5; Item7 --> Item6; Item7 --> Item1; + Item7 --> Item2; + Item7 --> Item3; Item7 --> Item4; + Item7 --> Item5; Item8 --> Item6; Item9 --> Item6; ``` @@ -201,17 +228,32 @@ graph TD Item11["export a"]; Item12; Item12["export b"]; + Item2 --> Item1; + Item3 --> Item1; + Item3 --> Item2; Item4 --> Item1; + Item4 --> Item2; + Item4 --> Item3; + Item5 --> Item1; + Item5 --> Item2; + Item5 --> Item3; + Item5 --> Item4; Item6 --> Item2; Item6 --> Item3; Item6 --> Item5; Item7 --> Item6; Item7 --> Item1; + Item7 --> Item2; + Item7 --> Item3; Item7 --> Item4; + Item7 --> Item5; Item8 --> Item6; Item9 --> Item6; Item10 --> Item1; + Item10 --> Item2; + Item10 --> Item3; Item10 --> Item4; + Item10 --> Item5; Item10 --> Item7; Item11 --> Item8; Item12 --> Item9; @@ -219,19 +261,36 @@ graph TD # Final ```mermaid graph TD - N0["Items: [ItemId(ModuleEvaluation), ItemId(0, Normal), ItemId(3, Normal), ItemId(6, Normal)]"]; + N0["Items: [ItemId(ModuleEvaluation), ItemId(6, Normal)]"]; N1["Items: [ItemId(Export(("a", #2), "a")), ItemId(7, VarDeclarator(0))]"]; N2["Items: [ItemId(Export(("b", #2), "b")), ItemId(8, VarDeclarator(0))]"]; - N3["Items: [ItemId(1, VarDeclarator(0))]"]; - N4["Items: [ItemId(2, VarDeclarator(0))]"]; - N5["Items: [ItemId(4, VarDeclarator(0))]"]; - N6["Items: [ItemId(5, VarDeclarator(0))]"]; + N3["Items: [ItemId(0, Normal)]"]; + N4["Items: [ItemId(1, VarDeclarator(0))]"]; + N5["Items: [ItemId(2, VarDeclarator(0))]"]; + N6["Items: [ItemId(3, Normal)]"]; + N7["Items: [ItemId(4, VarDeclarator(0))]"]; + N8["Items: [ItemId(5, VarDeclarator(0))]"]; + N0 --> N3; + N0 --> N4; + N0 --> N5; N0 --> N6; - N1 --> N6; - N2 --> N6; + N0 --> N7; + N0 --> N8; + N1 --> N8; + N2 --> N8; + N4 --> N3; + N5 --> N3; + N5 --> N4; N6 --> N3; N6 --> N4; N6 --> N5; + N7 --> N3; + N7 --> N4; + N7 --> N5; + N7 --> N6; + N8 --> N4; + N8 --> N5; + N8 --> N7; ``` # Entrypoints @@ -251,19 +310,32 @@ graph TD # Modules (dev) ## Part 0 ```js -import { shared } from "__TURBOPACK_PART__" assert { +import { console } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +import "__TURBOPACK_PART__" assert { __turbopack_part__: 6 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 7 +}; +import { shared } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; "module evaluation"; -console.log("Hello"); -externalObject.propertyWithSetter = 42; console.log(shared); ``` ## Part 1 ```js import { shared } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 6 + __turbopack_part__: 8 }; export { a }; const a = { @@ -278,7 +350,7 @@ export { a } from "__TURBOPACK_VAR__" assert { ## Part 2 ```js import { shared } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 6 + __turbopack_part__: 8 }; export { b }; const b = { @@ -292,38 +364,84 @@ export { b } from "__TURBOPACK_VAR__" assert { ``` ## Part 3 ```js +console.log("Hello"); +export { console } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 4 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; const value = externalFunction(); export { value } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; ``` -## Part 4 +## Part 5 ```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; const value2 = externalObject.propertyWithGetter; export { value2 } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; +export { externalObject } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` -## Part 5 +## Part 6 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import { externalObject } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +externalObject.propertyWithSetter = 42; + +``` +## Part 7 ```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; const value3 = externalFunction(); export { value3 } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; ``` -## Part 6 +## Part 8 ```js import { value } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 3 + __turbopack_part__: 4 }; import { value2 } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 4 + __turbopack_part__: 5 }; import { value3 } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 5 + __turbopack_part__: 7 }; const shared = { value, @@ -337,12 +455,25 @@ export { shared } from "__TURBOPACK_VAR__" assert { ``` ## Merged (module eval) ```js -import { shared } from "__TURBOPACK_PART__" assert { +import { console } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +import "__TURBOPACK_PART__" assert { __turbopack_part__: 6 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 7 +}; +import { shared } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; "module evaluation"; -console.log("Hello"); -externalObject.propertyWithSetter = 42; console.log(shared); ``` @@ -364,19 +495,32 @@ console.log(shared); # Modules (prod) ## Part 0 ```js -import { shared } from "__TURBOPACK_PART__" assert { +import { console } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +import "__TURBOPACK_PART__" assert { __turbopack_part__: 6 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 7 +}; +import { shared } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; "module evaluation"; -console.log("Hello"); -externalObject.propertyWithSetter = 42; console.log(shared); ``` ## Part 1 ```js import { shared } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 6 + __turbopack_part__: 8 }; export { a }; const a = { @@ -391,7 +535,7 @@ export { a } from "__TURBOPACK_VAR__" assert { ## Part 2 ```js import { shared } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 6 + __turbopack_part__: 8 }; export { b }; const b = { @@ -405,38 +549,84 @@ export { b } from "__TURBOPACK_VAR__" assert { ``` ## Part 3 ```js +console.log("Hello"); +export { console } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 4 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; const value = externalFunction(); export { value } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; ``` -## Part 4 +## Part 5 ```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; const value2 = externalObject.propertyWithGetter; export { value2 } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; +export { externalObject } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` -## Part 5 +## Part 6 ```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import { externalObject } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +externalObject.propertyWithSetter = 42; + +``` +## Part 7 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; const value3 = externalFunction(); export { value3 } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; ``` -## Part 6 +## Part 8 ```js import { value } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 3 + __turbopack_part__: 4 }; import { value2 } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 4 + __turbopack_part__: 5 }; import { value3 } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 5 + __turbopack_part__: 7 }; const shared = { value, @@ -450,12 +640,25 @@ export { shared } from "__TURBOPACK_VAR__" assert { ``` ## Merged (module eval) ```js -import { shared } from "__TURBOPACK_PART__" assert { +import { console } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +import "__TURBOPACK_PART__" assert { __turbopack_part__: 6 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 7 +}; +import { shared } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; "module evaluation"; -console.log("Hello"); -externalObject.propertyWithSetter = 42; console.log(shared); ``` diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/template-pages/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/template-pages/output.md index dccd4d458a3a4..c370c47876f5a 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/template-pages/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/template-pages/output.md @@ -265,8 +265,8 @@ export const routeModule = new PagesRouteModule({ ``` - Declares: `routeModule` -- Reads: `PagesRouteModule`, `RouteKind`, `App`, `Document`, `userland` -- Write: `routeModule` +- Reads: `PagesRouteModule`, `App`, `Document`, `userland` +- Write: `routeModule`, `RouteKind` # Phase 1 ```mermaid @@ -434,7 +434,6 @@ graph TD Item23 --> Item9; Item23 --> Item12; Item24 --> Item7; - Item24 --> Item8; Item24 --> Item11; Item24 --> Item10; Item24 --> Item12; @@ -536,7 +535,6 @@ graph TD Item23 --> Item9; Item23 --> Item12; Item24 --> Item7; - Item24 --> Item8; Item24 --> Item11; Item24 --> Item10; Item24 --> Item12; @@ -638,7 +636,6 @@ graph TD Item23 --> Item9; Item23 --> Item12; Item24 --> Item7; - Item24 --> Item8; Item24 --> Item11; Item24 --> Item10; Item24 --> Item12; @@ -677,7 +674,7 @@ graph TD N9["Items: [ItemId(Export(("unstable_getStaticParams", #2), "unstable_getStaticParams")), ItemId(2, ImportBinding(0)), ItemId(5, ImportBinding(0)), ItemId(14, VarDeclarator(0))]"]; N10["Items: [ItemId(Export(("unstable_getServerProps", #2), "unstable_getServerProps")), ItemId(2, ImportBinding(0)), ItemId(5, ImportBinding(0)), ItemId(15, VarDeclarator(0))]"]; N11["Items: [ItemId(Export(("unstable_getServerSideProps", #2), "unstable_getServerSideProps")), ItemId(2, ImportBinding(0)), ItemId(5, ImportBinding(0)), ItemId(16, VarDeclarator(0))]"]; - N12["Items: [ItemId(Export(("routeModule", #2), "routeModule")), ItemId(0, ImportBinding(0)), ItemId(1, ImportBinding(0)), ItemId(3, ImportBinding(0)), ItemId(4, ImportBinding(0)), ItemId(5, ImportBinding(0)), ItemId(17, VarDeclarator(0))]"]; + N12["Items: [ItemId(Export(("routeModule", #2), "routeModule")), ItemId(0, ImportBinding(0)), ItemId(3, ImportBinding(0)), ItemId(4, ImportBinding(0)), ItemId(5, ImportBinding(0)), ItemId(17, VarDeclarator(0))]"]; N13["Items: [ItemId(0, ImportOfModule)]"]; N14["Items: [ItemId(1, ImportOfModule)]"]; N15["Items: [ItemId(2, ImportOfModule)]"]; @@ -953,7 +950,6 @@ import "__TURBOPACK_PART__" assert { }; export { routeModule }; import { PagesRouteModule } from '../../server/future/route-modules/pages/module.compiled'; -import { RouteKind } from '../../server/future/route-kind'; import Document from 'VAR_MODULE_DOCUMENT'; import App from 'VAR_MODULE_APP'; import * as userland from 'VAR_USERLAND'; @@ -974,6 +970,9 @@ const routeModule = new PagesRouteModule({ export { routeModule } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; +export { RouteKind } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` ## Part 13 @@ -1332,7 +1331,6 @@ import "__TURBOPACK_PART__" assert { }; export { routeModule }; import { PagesRouteModule } from '../../server/future/route-modules/pages/module.compiled'; -import { RouteKind } from '../../server/future/route-kind'; import Document from 'VAR_MODULE_DOCUMENT'; import App from 'VAR_MODULE_APP'; import * as userland from 'VAR_USERLAND'; @@ -1353,6 +1351,9 @@ const routeModule = new PagesRouteModule({ export { routeModule } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; +export { RouteKind } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` ## Part 13 diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/test-config-1/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/test-config-1/output.md index a20d68147f5cf..c9b62c19098c1 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/test-config-1/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/test-config-1/output.md @@ -92,7 +92,8 @@ console.log(foobarCopy); ``` - Side effects -- Reads: `console`, `foobarCopy` +- Reads: `foobarCopy` +- Write: `console` ## Item 10: Stmt 8, `Normal` @@ -398,6 +399,9 @@ import "__TURBOPACK_PART__" assert { import "module"; import { upper } from "module"; console.log(foobarCopy); +export { console } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` ## Part 1 @@ -557,6 +561,9 @@ import "module"; import { upper } from "module"; "module evaluation"; console.log(foobarCopy); +export { console } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` # Entrypoints @@ -593,6 +600,9 @@ console.log(foobarCopy); export { foobarCopy } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; +export { console } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` ## Part 1 @@ -700,6 +710,9 @@ console.log(foobarCopy); export { foobarCopy } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; +export { console } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` # Entrypoints diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/tla-1/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/tla-1/output.md index 1f296f1665993..72fa65938ce2c 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/tla-1/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/tla-1/output.md @@ -10,7 +10,7 @@ await Promise.resolve(); ``` - Side effects -- Reads: `Promise` +- Write: `Promise` ## Item 2: Stmt 1, `VarDeclarator(0)` @@ -33,8 +33,8 @@ export function effect(name) { - Hoisted - Declares: `effect` -- Reads (eventual): `effects` - Write: `effect` +- Write (eventual): `effects` # Phase 1 ```mermaid @@ -74,7 +74,6 @@ graph TD Item5["export effects"]; Item6; Item6["export effect"]; - Item3 --> Item2; ``` # Phase 4 ```mermaid @@ -88,7 +87,6 @@ graph TD Item5["export effects"]; Item6; Item6["export effect"]; - Item3 --> Item2; Item4 --> Item1; Item5 --> Item2; Item6 --> Item3; @@ -97,11 +95,8 @@ graph TD ```mermaid graph TD N0["Items: [ItemId(ModuleEvaluation), ItemId(0, Normal)]"]; - N1["Items: [ItemId(Export(("effects", #2), "effects"))]"]; + N1["Items: [ItemId(Export(("effects", #2), "effects")), ItemId(1, VarDeclarator(0))]"]; N2["Items: [ItemId(Export(("effect", #2), "effect")), ItemId(2, Normal)]"]; - N3["Items: [ItemId(1, VarDeclarator(0))]"]; - N1 --> N3; - N2 --> N3; ``` # Entrypoints @@ -123,21 +118,22 @@ graph TD ```js "module evaluation"; await Promise.resolve(); +export { Promise } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` ## Part 1 ```js -import { effects } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 3 -}; export { effects }; +const effects = []; +export { effects } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` ## Part 2 ```js -import { effects } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 3 -}; export { effect }; function effect(name) { effects.push(name); @@ -146,19 +142,14 @@ export { effect } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; -``` -## Part 3 -```js -const effects = []; -export { effects } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; - ``` ## Merged (module eval) ```js "module evaluation"; await Promise.resolve(); +export { Promise } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` # Entrypoints @@ -181,21 +172,22 @@ await Promise.resolve(); ```js "module evaluation"; await Promise.resolve(); +export { Promise } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` ## Part 1 ```js -import { effects } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 3 -}; export { effects }; +const effects = []; +export { effects } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` ## Part 2 ```js -import { effects } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 3 -}; export { effect }; function effect(name) { effects.push(name); @@ -204,18 +196,13 @@ export { effect } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; -``` -## Part 3 -```js -const effects = []; -export { effects } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; - ``` ## Merged (module eval) ```js "module evaluation"; await Promise.resolve(); +export { Promise } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/write-order/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/write-order/output.md index 871df19a5d67f..4cbfb25396ff9 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/write-order/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/write-order/output.md @@ -23,8 +23,8 @@ export function func() { - Hoisted - Declares: `func` -- Reads (eventual): `order` - Write: `func` +- Write (eventual): `order` ## Item 3: Stmt 2, `Normal` @@ -34,7 +34,7 @@ order.push("a"); ``` - Side effects -- Reads: `order` +- Write: `order` ## Item 4: Stmt 3, `VarDeclarator(0)` @@ -43,6 +43,7 @@ const x1 = externalFunction(); ``` +- Side effects - Declares: `x1` - Reads: `externalFunction` - Write: `x1` @@ -54,6 +55,7 @@ const x2 = externalFunction(); ``` +- Side effects - Declares: `x2` - Reads: `externalFunction` - Write: `x2` @@ -68,8 +70,7 @@ export const shared = { ``` - Declares: `shared` -- Reads: `order` -- Write: `shared` +- Write: `shared`, `order` ## Item 7: Stmt 6, `Normal` @@ -79,7 +80,7 @@ order.push("c"); ``` - Side effects -- Reads: `order` +- Write: `order` # Phase 1 ```mermaid @@ -118,10 +119,16 @@ graph TD Item10["export func"]; Item11; Item11["export shared"]; - Item3 --> Item1; - Item6 --> Item1; - Item7 --> Item1; + Item3 -.-> Item1; + Item4 --> Item3; + Item4 -.-> Item1; + Item5 --> Item3; + Item5 --> Item4; + Item5 -.-> Item1; Item7 --> Item3; + Item7 --> Item4; + Item7 --> Item5; + Item7 -.-> Item1; Item7 -.-> Item6; ``` # Phase 3 @@ -142,12 +149,17 @@ graph TD Item10["export func"]; Item11; Item11["export shared"]; - Item3 --> Item1; - Item6 --> Item1; - Item7 --> Item1; + Item3 -.-> Item1; + Item4 --> Item3; + Item4 -.-> Item1; + Item5 --> Item3; + Item5 --> Item4; + Item5 -.-> Item1; Item7 --> Item3; + Item7 --> Item4; + Item7 --> Item5; + Item7 -.-> Item1; Item7 -.-> Item6; - Item2 --> Item1; ``` # Phase 4 ```mermaid @@ -167,33 +179,59 @@ graph TD Item10["export func"]; Item11; Item11["export shared"]; - Item3 --> Item1; - Item6 --> Item1; - Item7 --> Item1; + Item3 -.-> Item1; + Item4 --> Item3; + Item4 -.-> Item1; + Item5 --> Item3; + Item5 --> Item4; + Item5 -.-> Item1; Item7 --> Item3; + Item7 --> Item4; + Item7 --> Item5; + Item7 -.-> Item1; Item7 -.-> Item6; - Item2 --> Item1; Item8 --> Item3; + Item8 --> Item4; + Item8 --> Item5; Item8 --> Item7; Item9 --> Item1; + Item9 --> Item6; + Item9 --> Item7; Item10 --> Item2; Item11 --> Item6; ``` # Final ```mermaid graph TD - N0["Items: [ItemId(ModuleEvaluation), ItemId(2, Normal), ItemId(6, Normal)]"]; + N0["Items: [ItemId(ModuleEvaluation)]"]; N1["Items: [ItemId(Export(("order", #2), "order"))]"]; N2["Items: [ItemId(Export(("func", #2), "func")), ItemId(1, Normal)]"]; N3["Items: [ItemId(Export(("shared", #2), "shared"))]"]; N4["Items: [ItemId(0, VarDeclarator(0))]"]; - N5["Items: [ItemId(5, VarDeclarator(0))]"]; - N0 --> N4; + N5["Items: [ItemId(2, Normal)]"]; + N6["Items: [ItemId(3, VarDeclarator(0))]"]; + N7["Items: [ItemId(4, VarDeclarator(0))]"]; + N8["Items: [ItemId(5, VarDeclarator(0))]"]; + N9["Items: [ItemId(6, Normal)]"]; N0 --> N5; + N0 --> N6; + N0 --> N7; + N0 --> N9; N1 --> N4; - N2 --> N4; - N3 --> N5; + N1 --> N8; + N1 --> N9; + N3 --> N8; N5 --> N4; + N6 --> N5; + N6 --> N4; + N7 --> N5; + N7 --> N6; + N7 --> N4; + N9 --> N5; + N9 --> N6; + N9 --> N7; + N9 --> N4; + N9 --> N8; ``` # Entrypoints @@ -216,15 +254,19 @@ graph TD # Modules (dev) ## Part 0 ```js -import { order } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 4 -}; import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 7 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; "module evaluation"; -order.push("a"); -order.push("c"); ``` ## Part 1 @@ -232,14 +274,17 @@ order.push("c"); import { order } from "__TURBOPACK_PART__" assert { __turbopack_part__: 4 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; export { order }; ``` ## Part 2 ```js -import { order } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 4 -}; export { func }; function func() { order.push("d"); @@ -252,7 +297,7 @@ export { func } from "__TURBOPACK_VAR__" assert { ## Part 3 ```js import { shared } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 5 + __turbopack_part__: 8 }; export { shared }; @@ -270,25 +315,88 @@ export { order } from "__TURBOPACK_VAR__" assert { import { order } from "__TURBOPACK_PART__" assert { __turbopack_part__: 4 }; +order.push("a"); + +``` +## Part 6 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +const x1 = externalFunction(); +export { x1 } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 7 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +const x2 = externalFunction(); +export { x2 } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 8 +```js const shared = { effect: order.push("b") }; export { shared } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; +export { order } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` -## Merged (module eval) +## Part 9 ```js import { order } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 7 +}; +import "__TURBOPACK_PART__" assert { __turbopack_part__: 4 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; +order.push("c"); + +``` +## Merged (module eval) +```js import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 7 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; "module evaluation"; -order.push("a"); -order.push("c"); ``` # Entrypoints @@ -312,27 +420,38 @@ order.push("c"); # Modules (prod) ## Part 0 ```js -import { order } from "__TURBOPACK_PART__" assert { +import "__TURBOPACK_PART__" assert { __turbopack_part__: 4 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; "module evaluation"; -order.push("a"); -order.push("c"); ``` ## Part 1 ```js import { order } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 4 + __turbopack_part__: 7 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 }; export { order }; +const order = []; +export { order } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` ## Part 2 ```js -import { order } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 4 -}; export { func }; function func() { order.push("d"); @@ -344,33 +463,86 @@ export { func } from "__TURBOPACK_VAR__" assert { ``` ## Part 3 ```js -import { order } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 4 +import { shared } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 7 }; export { shared }; + +``` +## Part 4 +```js +order.push("a"); +export { order } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 5 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +const x1 = externalFunction(); +export { x1 } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 6 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +const x2 = externalFunction(); +export { x2 } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 7 +```js const shared = { effect: order.push("b") }; export { shared } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; +export { order } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` -## Part 4 +## Part 8 ```js -const order = []; -export { order } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true +import { order } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 }; +order.push("c"); ``` ## Merged (module eval) ```js -import { order } from "__TURBOPACK_PART__" assert { +import "__TURBOPACK_PART__" assert { __turbopack_part__: 4 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; "module evaluation"; -order.push("a"); -order.push("c"); ``` From 5a3efc279e4887ba53a00686acf697d7ec3e5a10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Mon, 10 Jun 2024 18:11:26 +0900 Subject: [PATCH 07/23] Read + Write --- .../src/tree_shake/util.rs | 57 ++++++++++++------- 1 file changed, 37 insertions(+), 20 deletions(-) diff --git a/crates/turbopack-ecmascript/src/tree_shake/util.rs b/crates/turbopack-ecmascript/src/tree_shake/util.rs index a49e9725fd9d5..8da6172ad5748 100644 --- a/crates/turbopack-ecmascript/src/tree_shake/util.rs +++ b/crates/turbopack-ecmascript/src/tree_shake/util.rs @@ -9,7 +9,7 @@ use swc_core::{ AssignTarget, BlockStmtOrExpr, Constructor, ExportNamedSpecifier, ExportSpecifier, Expr, Function, Id, Ident, MemberExpr, MemberProp, NamedExport, Pat, PropName, }, - visit::{noop_visit_type, visit_obj_and_computed, Visit, VisitWith}, + visit::{noop_visit_type, Visit, VisitWith}, }, }; @@ -26,11 +26,12 @@ pub(crate) struct IdentUsageCollector { only: [SyntaxContext; 2], vars: Vars, ignore_nested: bool, - mode: Mode, + /// None means both read and write + mode: Option, } impl IdentUsageCollector { - fn with_mode(&mut self, mode: Mode, f: impl FnOnce(&mut Self)) { + fn with_mode(&mut self, mode: Option, f: impl FnOnce(&mut Self)) { let old = self.mode; self.mode = mode; f(self); @@ -40,7 +41,7 @@ impl IdentUsageCollector { impl Visit for IdentUsageCollector { fn visit_assign_target(&mut self, n: &AssignTarget) { - self.with_mode(Mode::Write, |this| { + self.with_mode(Some(Mode::Write), |this| { n.visit_children_with(this); }) } @@ -66,13 +67,13 @@ impl Visit for IdentUsageCollector { } fn visit_export_specifier(&mut self, n: &ExportSpecifier) { - self.with_mode(Mode::Read, |this| { + self.with_mode(Some(Mode::Read), |this| { n.visit_children_with(this); }) } fn visit_expr(&mut self, e: &Expr) { - self.with_mode(Mode::Read, |this| { + self.with_mode(Some(Mode::Read), |this| { e.visit_children_with(this); }) } @@ -93,17 +94,21 @@ impl Visit for IdentUsageCollector { } match self.mode { - Mode::Read => { + Some(Mode::Read) => { self.vars.read.insert(n.to_id()); } - Mode::Write => { + Some(Mode::Write) => { + self.vars.write.insert(n.to_id()); + } + None => { + self.vars.read.insert(n.to_id()); self.vars.write.insert(n.to_id()); } } } fn visit_member_expr(&mut self, e: &MemberExpr) { - self.with_mode(Mode::Write, |this| { + self.with_mode(None, |this| { // Skip visit_expr e.obj.visit_children_with(this); }); @@ -126,7 +131,7 @@ impl Visit for IdentUsageCollector { } fn visit_pat(&mut self, p: &Pat) { - self.with_mode(Mode::Write, |this| { + self.with_mode(Some(Mode::Write), |this| { p.visit_children_with(this); }) } @@ -147,7 +152,8 @@ pub(crate) struct CapturedIdCollector { only: [SyntaxContext; 2], vars: Vars, is_nested: bool, - mode: Mode, + /// None means both read and write + mode: Option, } impl CapturedIdCollector { @@ -158,7 +164,7 @@ impl CapturedIdCollector { self.is_nested = old; } - fn with_mode(&mut self, mode: Mode, f: impl FnOnce(&mut Self)) { + fn with_mode(&mut self, mode: Option, f: impl FnOnce(&mut Self)) { let old = self.mode; self.mode = mode; f(self); @@ -168,7 +174,7 @@ impl CapturedIdCollector { impl Visit for CapturedIdCollector { fn visit_assign_target(&mut self, n: &AssignTarget) { - self.with_mode(Mode::Write, |this| { + self.with_mode(Some(Mode::Write), |this| { n.visit_children_with(this); }) } @@ -186,13 +192,13 @@ impl Visit for CapturedIdCollector { } fn visit_export_specifier(&mut self, n: &ExportSpecifier) { - self.with_mode(Mode::Read, |this| { + self.with_mode(Some(Mode::Read), |this| { n.visit_children_with(this); }) } fn visit_expr(&mut self, e: &Expr) { - self.with_mode(Mode::Read, |this| { + self.with_mode(Some(Mode::Read), |this| { e.visit_children_with(this); }) } @@ -215,17 +221,30 @@ impl Visit for CapturedIdCollector { } match self.mode { - Mode::Read => { + Some(Mode::Read) => { self.vars.read.insert(n.to_id()); } - Mode::Write => { + Some(Mode::Write) => { + self.vars.write.insert(n.to_id()); + } + None => { + self.vars.read.insert(n.to_id()); self.vars.write.insert(n.to_id()); } } } + fn visit_member_expr(&mut self, e: &MemberExpr) { + self.with_mode(None, |this| { + // Skip visit_expr + e.obj.visit_children_with(this); + }); + + e.prop.visit_with(self); + } + fn visit_pat(&mut self, p: &Pat) { - self.with_mode(Mode::Write, |this| { + self.with_mode(Some(Mode::Write), |this| { p.visit_children_with(this); }) } @@ -237,8 +256,6 @@ impl Visit for CapturedIdCollector { } noop_visit_type!(); - - visit_obj_and_computed!(); } /// The list of variables which are read or written. From 1c16cd4e5d948dd17272f194daf778f25d10b7ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Mon, 10 Jun 2024 18:16:26 +0900 Subject: [PATCH 08/23] Add unit tests --- .../tree-shaker/analyzer/ipc-index/input.js | 172 ++++++++++++++++++ .../tree-shaker/analyzer/shared-2/input.js | 9 + 2 files changed, 181 insertions(+) create mode 100644 crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-index/input.js create mode 100644 crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-2/input.js diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-index/input.js b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-index/input.js new file mode 100644 index 0000000000000..441b34ae57bca --- /dev/null +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-index/input.js @@ -0,0 +1,172 @@ +import { createConnection } from "node:net"; +import { parse as parseStackTrace } from "../compiled/stacktrace-parser"; +import { getProperError } from "./error"; +export function structuredError(e) { + e = getProperError(e); + return { + name: e.name, + message: e.message, + stack: typeof e.stack === "string" ? parseStackTrace(e.stack) : [] + }; +} +function createIpc(port) { + const socket = createConnection(port, "127.0.0.1"); + const packetQueue = []; + const recvPromiseResolveQueue = []; + function pushPacket(packet) { + const recvPromiseResolve = recvPromiseResolveQueue.shift(); + if (recvPromiseResolve != null) { + recvPromiseResolve(JSON.parse(packet.toString("utf8"))); + } else { + packetQueue.push(packet); + } + } + let state = { + type: "waiting" + }; + let buffer = Buffer.alloc(0); + socket.once("connect", ()=>{ + socket.on("data", (chunk)=>{ + buffer = Buffer.concat([ + buffer, + chunk + ]); + loop: while(true){ + switch(state.type){ + case "waiting": + { + if (buffer.length >= 4) { + const length = buffer.readUInt32BE(0); + buffer = buffer.subarray(4); + state = { + type: "packet", + length + }; + } else { + break loop; + } + break; + } + case "packet": + { + if (buffer.length >= state.length) { + const packet = buffer.subarray(0, state.length); + buffer = buffer.subarray(state.length); + state = { + type: "waiting" + }; + pushPacket(packet); + } else { + break loop; + } + break; + } + } + } + }); + }); + socket.once("close", ()=>{ + process.exit(0); + }); + function send(message) { + const packet = Buffer.from(JSON.stringify(message), "utf8"); + const length = Buffer.alloc(4); + length.writeUInt32BE(packet.length); + socket.write(length); + return new Promise((resolve, reject)=>{ + socket.write(packet, (err)=>{ + process.stderr.write(`TURBOPACK_OUTPUT_D\n`); + process.stdout.write(`TURBOPACK_OUTPUT_D\n`); + if (err != null) { + reject(err); + } else { + resolve(); + } + }); + }); + } + function sendReady() { + const length = Buffer.from([ + 0, + 0, + 0, + 0 + ]); + return new Promise((resolve, reject)=>{ + socket.write(length, (err)=>{ + process.stderr.write(`TURBOPACK_OUTPUT_D\n`); + process.stdout.write(`TURBOPACK_OUTPUT_D\n`); + if (err != null) { + reject(err); + } else { + resolve(); + } + }); + }); + } + return { + async recv () { + const packet = packetQueue.shift(); + if (packet != null) { + return JSON.parse(packet.toString("utf8")); + } + const result = await new Promise((resolve)=>{ + recvPromiseResolveQueue.push((result)=>{ + resolve(result); + }); + }); + return result; + }, + send (message) { + return send(message); + }, + sendReady, + async sendError (error) { + try { + await send({ + type: "error", + ...structuredError(error) + }); + } catch (err) { + console.error("failed to send error back to rust:", err); + process.exit(1); + } + process.exit(0); + } + }; +} +const PORT = process.argv[2]; +export const IPC = createIpc(parseInt(PORT, 10)); +process.on("uncaughtException", (err)=>{ + IPC.sendError(err); +}); +const improveConsole = (name, stream, addStack)=>{ + const original = console[name]; + const stdio = process[stream]; + console[name] = (...args)=>{ + stdio.write(`TURBOPACK_OUTPUT_B\n`); + original(...args); + if (addStack) { + const stack = new Error().stack?.replace(/^.+\n.+\n/, "") + "\n"; + stdio.write("TURBOPACK_OUTPUT_S\n"); + stdio.write(stack); + } + stdio.write("TURBOPACK_OUTPUT_E\n"); + }; +}; +improveConsole("error", "stderr", true); +improveConsole("warn", "stderr", true); +improveConsole("count", "stdout", true); +improveConsole("trace", "stderr", false); +improveConsole("log", "stdout", true); +improveConsole("group", "stdout", true); +improveConsole("groupCollapsed", "stdout", true); +improveConsole("table", "stdout", true); +improveConsole("debug", "stdout", true); +improveConsole("info", "stdout", true); +improveConsole("dir", "stdout", true); +improveConsole("dirxml", "stdout", true); +improveConsole("timeEnd", "stdout", true); +improveConsole("timeLog", "stdout", true); +improveConsole("timeStamp", "stdout", true); +improveConsole("assert", "stderr", true); diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-2/input.js b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-2/input.js new file mode 100644 index 0000000000000..74a6147c0837a --- /dev/null +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-2/input.js @@ -0,0 +1,9 @@ +export const order = []; + +order.push("a"); +const random = Math.random(); +const shared = { random, effect: order.push("b") }; +order.push("c"); + +export const a = { shared, a: "aaaaaaaaaaa" }; +export const b = { shared, b: "bbbbbbbbbbb" }; From 9529d2bda48ecf50666410f182bf669341339d9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Mon, 10 Jun 2024 18:17:14 +0900 Subject: [PATCH 09/23] revert visit_member_expr --- crates/turbopack-ecmascript/src/tree_shake/util.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/turbopack-ecmascript/src/tree_shake/util.rs b/crates/turbopack-ecmascript/src/tree_shake/util.rs index 8da6172ad5748..4351e7996ccf7 100644 --- a/crates/turbopack-ecmascript/src/tree_shake/util.rs +++ b/crates/turbopack-ecmascript/src/tree_shake/util.rs @@ -108,7 +108,7 @@ impl Visit for IdentUsageCollector { } fn visit_member_expr(&mut self, e: &MemberExpr) { - self.with_mode(None, |this| { + self.with_mode(Some(Mode::Write), |this| { // Skip visit_expr e.obj.visit_children_with(this); }); @@ -235,7 +235,7 @@ impl Visit for CapturedIdCollector { } fn visit_member_expr(&mut self, e: &MemberExpr) { - self.with_mode(None, |this| { + self.with_mode(Some(Mode::Write), |this| { // Skip visit_expr e.obj.visit_children_with(this); }); From 35a41cd3cf2980eac32be02d337766d100f71264 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Mon, 10 Jun 2024 18:17:24 +0900 Subject: [PATCH 10/23] Update test refs --- .../tree-shaker/analyzer/failed-3/output.md | 8 +- .../analyzer/ipc-evaluate/output.md | 27 +- .../tree-shaker/analyzer/ipc-index/output.md | 2404 +++++++++++++++++ .../tree-shaker/analyzer/shared-2/output.md | 496 ++++ 4 files changed, 2907 insertions(+), 28 deletions(-) create mode 100644 crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-index/output.md create mode 100644 crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-2/output.md diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-3/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-3/output.md index 7f1ad72785c96..4f44edf93f238 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-3/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-3/output.md @@ -252,8 +252,9 @@ process.on("uncaughtException", (err)=>{ ``` - Side effects -- Reads (eventual): `IPC` +- Reads (eventual): `sendError` - Write: `process` +- Write (eventual): `IPC` ## Item 12: Stmt 8, `VarDeclarator(0)` @@ -276,8 +277,9 @@ const improveConsole = (name, stream, addStack)=>{ ``` - Declares: `improveConsole` -- Reads (eventual): `console`, `process`, `Error` +- Reads (eventual): `write`, `Error`, `replace` - Write: `improveConsole` +- Write (eventual): `console`, `process`, `stack` ## Item 13: Stmt 9, `Normal` @@ -1207,7 +1209,6 @@ graph TD Item7 --> Item5; Item8 --> Item4; Item8 --> Item7; - Item12 --> Item11; ``` # Phase 4 ```mermaid @@ -1574,7 +1575,6 @@ graph TD Item7 --> Item5; Item8 --> Item4; Item8 --> Item7; - Item12 --> Item11; Item29 --> Item1; Item29 --> Item2; Item29 --> Item3; diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-evaluate/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-evaluate/output.md index 02e87dfd14ace..62e766a5b1783 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-evaluate/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-evaluate/output.md @@ -141,8 +141,9 @@ export const run = async (moduleFactory)=>{ ``` - Declares: `run` -- Reads (eventual): `Map`, `ipc`, `Promise`, `queue`, `undefined`, `JSON`, `Error`, `console`, `process` +- Reads (eventual): `Map`, `send`, `Promise`, `set`, `then`, `sendError`, `init`, `default`, `sendReady`, `length`, `shift`, `undefined`, `stringify`, `recv`, `type`, `push`, `args`, `get`, `id`, `delete`, `error`, `reject`, `Error`, `resolve`, `data`, `exit` - Write: `run` +- Write (eventual): `ipc`, `queue`, `JSON`, `console`, `process` # Phase 1 ```mermaid @@ -184,8 +185,6 @@ graph TD Item7; Item7["export run"]; Item3 --> Item2; - Item5 --> Item3; - Item5 --> Item4; ``` # Phase 4 ```mermaid @@ -200,8 +199,6 @@ graph TD Item7; Item7["export run"]; Item3 --> Item2; - Item5 --> Item3; - Item5 --> Item4; Item6 --> Item1; Item7 --> Item5; ``` @@ -209,7 +206,7 @@ graph TD ```mermaid graph TD N0["Items: [ItemId(ModuleEvaluation), ItemId(0, ImportOfModule)]"]; - N1["Items: [ItemId(Export(("run", #2), "run")), ItemId(0, ImportBinding(0)), ItemId(1, VarDeclarator(0)), ItemId(2, VarDeclarator(0)), ItemId(3, VarDeclarator(0))]"]; + N1["Items: [ItemId(Export(("run", #2), "run")), ItemId(3, VarDeclarator(0))]"]; ``` # Entrypoints @@ -233,9 +230,6 @@ import "./index"; ## Part 1 ```js export { run }; -import { IPC } from "./index"; -const ipc = IPC; -const queue = []; const run = async (moduleFactory)=>{ let nextId = 1; const requests = new Map(); @@ -327,12 +321,6 @@ const run = async (moduleFactory)=>{ } } }; -export { ipc } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; -export { queue } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; export { run } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; @@ -366,9 +354,6 @@ import "./index"; ## Part 1 ```js export { run }; -import { IPC } from "./index"; -const ipc = IPC; -const queue = []; const run = async (moduleFactory)=>{ let nextId = 1; const requests = new Map(); @@ -460,12 +445,6 @@ const run = async (moduleFactory)=>{ } } }; -export { ipc } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; -export { queue } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; export { run } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-index/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-index/output.md new file mode 100644 index 0000000000000..4f44edf93f238 --- /dev/null +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-index/output.md @@ -0,0 +1,2404 @@ +# Items + +Count: 31 + +## Item 1: Stmt 0, `ImportOfModule` + +```js +import { createConnection } from "node:net"; + +``` + +- Hoisted +- Side effects + +## Item 2: Stmt 0, `ImportBinding(0)` + +```js +import { createConnection } from "node:net"; + +``` + +- Hoisted +- Declares: `createConnection` + +## Item 3: Stmt 1, `ImportOfModule` + +```js +import { parse as parseStackTrace } from "../compiled/stacktrace-parser"; + +``` + +- Hoisted +- Side effects + +## Item 4: Stmt 1, `ImportBinding(0)` + +```js +import { parse as parseStackTrace } from "../compiled/stacktrace-parser"; + +``` + +- Hoisted +- Declares: `parseStackTrace` + +## Item 5: Stmt 2, `ImportOfModule` + +```js +import { getProperError } from "./error"; + +``` + +- Hoisted +- Side effects + +## Item 6: Stmt 2, `ImportBinding(0)` + +```js +import { getProperError } from "./error"; + +``` + +- Hoisted +- Declares: `getProperError` + +## Item 7: Stmt 3, `Normal` + +```js +export function structuredError(e) { + e = getProperError(e); + return { + name: e.name, + message: e.message, + stack: typeof e.stack === "string" ? parseStackTrace(e.stack) : [] + }; +} + +``` + +- Hoisted +- Declares: `structuredError` +- Reads (eventual): `getProperError`, `parseStackTrace` +- Write: `structuredError` + +## Item 8: Stmt 4, `Normal` + +```js +function createIpc(port) { + const socket = createConnection(port, "127.0.0.1"); + const packetQueue = []; + const recvPromiseResolveQueue = []; + function pushPacket(packet) { + const recvPromiseResolve = recvPromiseResolveQueue.shift(); + if (recvPromiseResolve != null) { + recvPromiseResolve(JSON.parse(packet.toString("utf8"))); + } else { + packetQueue.push(packet); + } + } + let state = { + type: "waiting" + }; + let buffer = Buffer.alloc(0); + socket.once("connect", ()=>{ + socket.on("data", (chunk)=>{ + buffer = Buffer.concat([ + buffer, + chunk + ]); + loop: while(true){ + switch(state.type){ + case "waiting": + { + if (buffer.length >= 4) { + const length = buffer.readUInt32BE(0); + buffer = buffer.subarray(4); + state = { + type: "packet", + length + }; + } else { + break loop; + } + break; + } + case "packet": + { + if (buffer.length >= state.length) { + const packet = buffer.subarray(0, state.length); + buffer = buffer.subarray(state.length); + state = { + type: "waiting" + }; + pushPacket(packet); + } else { + break loop; + } + break; + } + } + } + }); + }); + socket.once("close", ()=>{ + process.exit(0); + }); + function send(message) { + const packet = Buffer.from(JSON.stringify(message), "utf8"); + const length = Buffer.alloc(4); + length.writeUInt32BE(packet.length); + socket.write(length); + return new Promise((resolve, reject)=>{ + socket.write(packet, (err)=>{ + process.stderr.write(`TURBOPACK_OUTPUT_D\n`); + process.stdout.write(`TURBOPACK_OUTPUT_D\n`); + if (err != null) { + reject(err); + } else { + resolve(); + } + }); + }); + } + function sendReady() { + const length = Buffer.from([ + 0, + 0, + 0, + 0 + ]); + return new Promise((resolve, reject)=>{ + socket.write(length, (err)=>{ + process.stderr.write(`TURBOPACK_OUTPUT_D\n`); + process.stdout.write(`TURBOPACK_OUTPUT_D\n`); + if (err != null) { + reject(err); + } else { + resolve(); + } + }); + }); + } + return { + async recv () { + const packet = packetQueue.shift(); + if (packet != null) { + return JSON.parse(packet.toString("utf8")); + } + const result = await new Promise((resolve)=>{ + recvPromiseResolveQueue.push((result)=>{ + resolve(result); + }); + }); + return result; + }, + send (message) { + return send(message); + }, + sendReady, + async sendError (error) { + try { + await send({ + type: "error", + ...structuredError(error) + }); + } catch (err) { + console.error("failed to send error back to rust:", err); + process.exit(1); + } + process.exit(0); + } + }; +} + +``` + +- Hoisted +- Declares: `createIpc` +- Reads (eventual): `createConnection`, `loop`, `Promise`, `structuredError` +- Write: `createIpc` +- Write (eventual): `JSON`, `Buffer`, `process`, `console` + +## Item 9: Stmt 5, `VarDeclarator(0)` + +```js +const PORT = process.argv[2]; + +``` + +- Side effects +- Declares: `PORT` +- Write: `PORT`, `process` + +## Item 10: Stmt 6, `VarDeclarator(0)` + +```js +export const IPC = createIpc(parseInt(PORT, 10)); + +``` + +- Side effects +- Declares: `IPC` +- Reads: `createIpc`, `parseInt`, `PORT` +- Write: `IPC` + +## Item 11: Stmt 7, `Normal` + +```js +process.on("uncaughtException", (err)=>{ + IPC.sendError(err); +}); + +``` + +- Side effects +- Reads (eventual): `sendError` +- Write: `process` +- Write (eventual): `IPC` + +## Item 12: Stmt 8, `VarDeclarator(0)` + +```js +const improveConsole = (name, stream, addStack)=>{ + const original = console[name]; + const stdio = process[stream]; + console[name] = (...args)=>{ + stdio.write(`TURBOPACK_OUTPUT_B\n`); + original(...args); + if (addStack) { + const stack = new Error().stack?.replace(/^.+\n.+\n/, "") + "\n"; + stdio.write("TURBOPACK_OUTPUT_S\n"); + stdio.write(stack); + } + stdio.write("TURBOPACK_OUTPUT_E\n"); + }; +}; + +``` + +- Declares: `improveConsole` +- Reads (eventual): `write`, `Error`, `replace` +- Write: `improveConsole` +- Write (eventual): `console`, `process`, `stack` + +## Item 13: Stmt 9, `Normal` + +```js +improveConsole("error", "stderr", true); + +``` + +- Side effects +- Reads: `improveConsole` + +## Item 14: Stmt 10, `Normal` + +```js +improveConsole("warn", "stderr", true); + +``` + +- Side effects +- Reads: `improveConsole` + +## Item 15: Stmt 11, `Normal` + +```js +improveConsole("count", "stdout", true); + +``` + +- Side effects +- Reads: `improveConsole` + +## Item 16: Stmt 12, `Normal` + +```js +improveConsole("trace", "stderr", false); + +``` + +- Side effects +- Reads: `improveConsole` + +## Item 17: Stmt 13, `Normal` + +```js +improveConsole("log", "stdout", true); + +``` + +- Side effects +- Reads: `improveConsole` + +## Item 18: Stmt 14, `Normal` + +```js +improveConsole("group", "stdout", true); + +``` + +- Side effects +- Reads: `improveConsole` + +## Item 19: Stmt 15, `Normal` + +```js +improveConsole("groupCollapsed", "stdout", true); + +``` + +- Side effects +- Reads: `improveConsole` + +## Item 20: Stmt 16, `Normal` + +```js +improveConsole("table", "stdout", true); + +``` + +- Side effects +- Reads: `improveConsole` + +## Item 21: Stmt 17, `Normal` + +```js +improveConsole("debug", "stdout", true); + +``` + +- Side effects +- Reads: `improveConsole` + +## Item 22: Stmt 18, `Normal` + +```js +improveConsole("info", "stdout", true); + +``` + +- Side effects +- Reads: `improveConsole` + +## Item 23: Stmt 19, `Normal` + +```js +improveConsole("dir", "stdout", true); + +``` + +- Side effects +- Reads: `improveConsole` + +## Item 24: Stmt 20, `Normal` + +```js +improveConsole("dirxml", "stdout", true); + +``` + +- Side effects +- Reads: `improveConsole` + +## Item 25: Stmt 21, `Normal` + +```js +improveConsole("timeEnd", "stdout", true); + +``` + +- Side effects +- Reads: `improveConsole` + +## Item 26: Stmt 22, `Normal` + +```js +improveConsole("timeLog", "stdout", true); + +``` + +- Side effects +- Reads: `improveConsole` + +## Item 27: Stmt 23, `Normal` + +```js +improveConsole("timeStamp", "stdout", true); + +``` + +- Side effects +- Reads: `improveConsole` + +## Item 28: Stmt 24, `Normal` + +```js +improveConsole("assert", "stderr", true); + +``` + +- Side effects +- Reads: `improveConsole` + +# Phase 1 +```mermaid +graph TD + Item1; + Item4; + Item2; + Item5; + Item3; + Item6; + Item7; + Item8; + Item9; + Item10; + Item11; + Item12; + Item13; + Item14; + Item15; + Item16; + Item17; + Item18; + Item19; + Item20; + Item21; + Item22; + Item23; + Item24; + Item25; + Item26; + Item27; + Item28; + Item29; + Item29["ModuleEvaluation"]; + Item30; + Item30["export structuredError"]; + Item31; + Item31["export IPC"]; + Item2 --> Item1; + Item3 --> Item1; + Item3 --> Item2; +``` +# Phase 2 +```mermaid +graph TD + Item1; + Item4; + Item2; + Item5; + Item3; + Item6; + Item7; + Item8; + Item9; + Item10; + Item11; + Item12; + Item13; + Item14; + Item15; + Item16; + Item17; + Item18; + Item19; + Item20; + Item21; + Item22; + Item23; + Item24; + Item25; + Item26; + Item27; + Item28; + Item29; + Item29["ModuleEvaluation"]; + Item30; + Item30["export structuredError"]; + Item31; + Item31["export IPC"]; + Item2 --> Item1; + Item3 --> Item1; + Item3 --> Item2; + Item9 --> Item1; + Item9 --> Item2; + Item9 --> Item3; + Item9 -.-> Item6; + Item9 -.-> Item5; + Item9 -.-> Item4; + Item9 -.-> Item7; + Item10 --> Item8; + Item10 --> Item9; + Item10 --> Item1; + Item10 --> Item2; + Item10 --> Item3; + Item10 -.-> Item6; + Item10 -.-> Item5; + Item10 -.-> Item4; + Item10 -.-> Item7; + Item11 --> Item1; + Item11 --> Item2; + Item11 --> Item3; + Item11 --> Item9; + Item11 --> Item10; + Item11 -.-> Item6; + Item11 -.-> Item5; + Item11 -.-> Item4; + Item11 -.-> Item7; + Item13 --> Item12; + Item13 --> Item1; + Item13 --> Item2; + Item13 --> Item3; + Item13 --> Item9; + Item13 --> Item10; + Item13 --> Item11; + Item13 -.-> Item6; + Item13 -.-> Item5; + Item13 -.-> Item4; + Item13 -.-> Item7; + Item14 --> Item12; + Item14 --> Item1; + Item14 --> Item2; + Item14 --> Item3; + Item14 --> Item9; + Item14 --> Item10; + Item14 --> Item11; + Item14 --> Item13; + Item14 -.-> Item6; + Item14 -.-> Item5; + Item14 -.-> Item4; + Item14 -.-> Item7; + Item15 --> Item12; + Item15 --> Item1; + Item15 --> Item2; + Item15 --> Item3; + Item15 --> Item9; + Item15 --> Item10; + Item15 --> Item11; + Item15 --> Item13; + Item15 --> Item14; + Item15 -.-> Item6; + Item15 -.-> Item5; + Item15 -.-> Item4; + Item15 -.-> Item7; + Item16 --> Item12; + Item16 --> Item1; + Item16 --> Item2; + Item16 --> Item3; + Item16 --> Item9; + Item16 --> Item10; + Item16 --> Item11; + Item16 --> Item13; + Item16 --> Item14; + Item16 --> Item15; + Item16 -.-> Item6; + Item16 -.-> Item5; + Item16 -.-> Item4; + Item16 -.-> Item7; + Item17 --> Item12; + Item17 --> Item1; + Item17 --> Item2; + Item17 --> Item3; + Item17 --> Item9; + Item17 --> Item10; + Item17 --> Item11; + Item17 --> Item13; + Item17 --> Item14; + Item17 --> Item15; + Item17 --> Item16; + Item17 -.-> Item6; + Item17 -.-> Item5; + Item17 -.-> Item4; + Item17 -.-> Item7; + Item18 --> Item12; + Item18 --> Item1; + Item18 --> Item2; + Item18 --> Item3; + Item18 --> Item9; + Item18 --> Item10; + Item18 --> Item11; + Item18 --> Item13; + Item18 --> Item14; + Item18 --> Item15; + Item18 --> Item16; + Item18 --> Item17; + Item18 -.-> Item6; + Item18 -.-> Item5; + Item18 -.-> Item4; + Item18 -.-> Item7; + Item19 --> Item12; + Item19 --> Item1; + Item19 --> Item2; + Item19 --> Item3; + Item19 --> Item9; + Item19 --> Item10; + Item19 --> Item11; + Item19 --> Item13; + Item19 --> Item14; + Item19 --> Item15; + Item19 --> Item16; + Item19 --> Item17; + Item19 --> Item18; + Item19 -.-> Item6; + Item19 -.-> Item5; + Item19 -.-> Item4; + Item19 -.-> Item7; + Item20 --> Item12; + Item20 --> Item1; + Item20 --> Item2; + Item20 --> Item3; + Item20 --> Item9; + Item20 --> Item10; + Item20 --> Item11; + Item20 --> Item13; + Item20 --> Item14; + Item20 --> Item15; + Item20 --> Item16; + Item20 --> Item17; + Item20 --> Item18; + Item20 --> Item19; + Item20 -.-> Item6; + Item20 -.-> Item5; + Item20 -.-> Item4; + Item20 -.-> Item7; + Item21 --> Item12; + Item21 --> Item1; + Item21 --> Item2; + Item21 --> Item3; + Item21 --> Item9; + Item21 --> Item10; + Item21 --> Item11; + Item21 --> Item13; + Item21 --> Item14; + Item21 --> Item15; + Item21 --> Item16; + Item21 --> Item17; + Item21 --> Item18; + Item21 --> Item19; + Item21 --> Item20; + Item21 -.-> Item6; + Item21 -.-> Item5; + Item21 -.-> Item4; + Item21 -.-> Item7; + Item22 --> Item12; + Item22 --> Item1; + Item22 --> Item2; + Item22 --> Item3; + Item22 --> Item9; + Item22 --> Item10; + Item22 --> Item11; + Item22 --> Item13; + Item22 --> Item14; + Item22 --> Item15; + Item22 --> Item16; + Item22 --> Item17; + Item22 --> Item18; + Item22 --> Item19; + Item22 --> Item20; + Item22 --> Item21; + Item22 -.-> Item6; + Item22 -.-> Item5; + Item22 -.-> Item4; + Item22 -.-> Item7; + Item23 --> Item12; + Item23 --> Item1; + Item23 --> Item2; + Item23 --> Item3; + Item23 --> Item9; + Item23 --> Item10; + Item23 --> Item11; + Item23 --> Item13; + Item23 --> Item14; + Item23 --> Item15; + Item23 --> Item16; + Item23 --> Item17; + Item23 --> Item18; + Item23 --> Item19; + Item23 --> Item20; + Item23 --> Item21; + Item23 --> Item22; + Item23 -.-> Item6; + Item23 -.-> Item5; + Item23 -.-> Item4; + Item23 -.-> Item7; + Item24 --> Item12; + Item24 --> Item1; + Item24 --> Item2; + Item24 --> Item3; + Item24 --> Item9; + Item24 --> Item10; + Item24 --> Item11; + Item24 --> Item13; + Item24 --> Item14; + Item24 --> Item15; + Item24 --> Item16; + Item24 --> Item17; + Item24 --> Item18; + Item24 --> Item19; + Item24 --> Item20; + Item24 --> Item21; + Item24 --> Item22; + Item24 --> Item23; + Item24 -.-> Item6; + Item24 -.-> Item5; + Item24 -.-> Item4; + Item24 -.-> Item7; + Item25 --> Item12; + Item25 --> Item1; + Item25 --> Item2; + Item25 --> Item3; + Item25 --> Item9; + Item25 --> Item10; + Item25 --> Item11; + Item25 --> Item13; + Item25 --> Item14; + Item25 --> Item15; + Item25 --> Item16; + Item25 --> Item17; + Item25 --> Item18; + Item25 --> Item19; + Item25 --> Item20; + Item25 --> Item21; + Item25 --> Item22; + Item25 --> Item23; + Item25 --> Item24; + Item25 -.-> Item6; + Item25 -.-> Item5; + Item25 -.-> Item4; + Item25 -.-> Item7; + Item26 --> Item12; + Item26 --> Item1; + Item26 --> Item2; + Item26 --> Item3; + Item26 --> Item9; + Item26 --> Item10; + Item26 --> Item11; + Item26 --> Item13; + Item26 --> Item14; + Item26 --> Item15; + Item26 --> Item16; + Item26 --> Item17; + Item26 --> Item18; + Item26 --> Item19; + Item26 --> Item20; + Item26 --> Item21; + Item26 --> Item22; + Item26 --> Item23; + Item26 --> Item24; + Item26 --> Item25; + Item26 -.-> Item6; + Item26 -.-> Item5; + Item26 -.-> Item4; + Item26 -.-> Item7; + Item27 --> Item12; + Item27 --> Item1; + Item27 --> Item2; + Item27 --> Item3; + Item27 --> Item9; + Item27 --> Item10; + Item27 --> Item11; + Item27 --> Item13; + Item27 --> Item14; + Item27 --> Item15; + Item27 --> Item16; + Item27 --> Item17; + Item27 --> Item18; + Item27 --> Item19; + Item27 --> Item20; + Item27 --> Item21; + Item27 --> Item22; + Item27 --> Item23; + Item27 --> Item24; + Item27 --> Item25; + Item27 --> Item26; + Item27 -.-> Item6; + Item27 -.-> Item5; + Item27 -.-> Item4; + Item27 -.-> Item7; + Item28 --> Item12; + Item28 --> Item1; + Item28 --> Item2; + Item28 --> Item3; + Item28 --> Item9; + Item28 --> Item10; + Item28 --> Item11; + Item28 --> Item13; + Item28 --> Item14; + Item28 --> Item15; + Item28 --> Item16; + Item28 --> Item17; + Item28 --> Item18; + Item28 --> Item19; + Item28 --> Item20; + Item28 --> Item21; + Item28 --> Item22; + Item28 --> Item23; + Item28 --> Item24; + Item28 --> Item25; + Item28 --> Item26; + Item28 --> Item27; + Item28 -.-> Item6; + Item28 -.-> Item5; + Item28 -.-> Item4; + Item28 -.-> Item7; +``` +# Phase 3 +```mermaid +graph TD + Item1; + Item4; + Item2; + Item5; + Item3; + Item6; + Item7; + Item8; + Item9; + Item10; + Item11; + Item12; + Item13; + Item14; + Item15; + Item16; + Item17; + Item18; + Item19; + Item20; + Item21; + Item22; + Item23; + Item24; + Item25; + Item26; + Item27; + Item28; + Item29; + Item29["ModuleEvaluation"]; + Item30; + Item30["export structuredError"]; + Item31; + Item31["export IPC"]; + Item2 --> Item1; + Item3 --> Item1; + Item3 --> Item2; + Item9 --> Item1; + Item9 --> Item2; + Item9 --> Item3; + Item9 -.-> Item6; + Item9 -.-> Item5; + Item9 -.-> Item4; + Item9 -.-> Item7; + Item10 --> Item8; + Item10 --> Item9; + Item10 --> Item1; + Item10 --> Item2; + Item10 --> Item3; + Item10 -.-> Item6; + Item10 -.-> Item5; + Item10 -.-> Item4; + Item10 -.-> Item7; + Item11 --> Item1; + Item11 --> Item2; + Item11 --> Item3; + Item11 --> Item9; + Item11 --> Item10; + Item11 -.-> Item6; + Item11 -.-> Item5; + Item11 -.-> Item4; + Item11 -.-> Item7; + Item13 --> Item12; + Item13 --> Item1; + Item13 --> Item2; + Item13 --> Item3; + Item13 --> Item9; + Item13 --> Item10; + Item13 --> Item11; + Item13 -.-> Item6; + Item13 -.-> Item5; + Item13 -.-> Item4; + Item13 -.-> Item7; + Item14 --> Item12; + Item14 --> Item1; + Item14 --> Item2; + Item14 --> Item3; + Item14 --> Item9; + Item14 --> Item10; + Item14 --> Item11; + Item14 --> Item13; + Item14 -.-> Item6; + Item14 -.-> Item5; + Item14 -.-> Item4; + Item14 -.-> Item7; + Item15 --> Item12; + Item15 --> Item1; + Item15 --> Item2; + Item15 --> Item3; + Item15 --> Item9; + Item15 --> Item10; + Item15 --> Item11; + Item15 --> Item13; + Item15 --> Item14; + Item15 -.-> Item6; + Item15 -.-> Item5; + Item15 -.-> Item4; + Item15 -.-> Item7; + Item16 --> Item12; + Item16 --> Item1; + Item16 --> Item2; + Item16 --> Item3; + Item16 --> Item9; + Item16 --> Item10; + Item16 --> Item11; + Item16 --> Item13; + Item16 --> Item14; + Item16 --> Item15; + Item16 -.-> Item6; + Item16 -.-> Item5; + Item16 -.-> Item4; + Item16 -.-> Item7; + Item17 --> Item12; + Item17 --> Item1; + Item17 --> Item2; + Item17 --> Item3; + Item17 --> Item9; + Item17 --> Item10; + Item17 --> Item11; + Item17 --> Item13; + Item17 --> Item14; + Item17 --> Item15; + Item17 --> Item16; + Item17 -.-> Item6; + Item17 -.-> Item5; + Item17 -.-> Item4; + Item17 -.-> Item7; + Item18 --> Item12; + Item18 --> Item1; + Item18 --> Item2; + Item18 --> Item3; + Item18 --> Item9; + Item18 --> Item10; + Item18 --> Item11; + Item18 --> Item13; + Item18 --> Item14; + Item18 --> Item15; + Item18 --> Item16; + Item18 --> Item17; + Item18 -.-> Item6; + Item18 -.-> Item5; + Item18 -.-> Item4; + Item18 -.-> Item7; + Item19 --> Item12; + Item19 --> Item1; + Item19 --> Item2; + Item19 --> Item3; + Item19 --> Item9; + Item19 --> Item10; + Item19 --> Item11; + Item19 --> Item13; + Item19 --> Item14; + Item19 --> Item15; + Item19 --> Item16; + Item19 --> Item17; + Item19 --> Item18; + Item19 -.-> Item6; + Item19 -.-> Item5; + Item19 -.-> Item4; + Item19 -.-> Item7; + Item20 --> Item12; + Item20 --> Item1; + Item20 --> Item2; + Item20 --> Item3; + Item20 --> Item9; + Item20 --> Item10; + Item20 --> Item11; + Item20 --> Item13; + Item20 --> Item14; + Item20 --> Item15; + Item20 --> Item16; + Item20 --> Item17; + Item20 --> Item18; + Item20 --> Item19; + Item20 -.-> Item6; + Item20 -.-> Item5; + Item20 -.-> Item4; + Item20 -.-> Item7; + Item21 --> Item12; + Item21 --> Item1; + Item21 --> Item2; + Item21 --> Item3; + Item21 --> Item9; + Item21 --> Item10; + Item21 --> Item11; + Item21 --> Item13; + Item21 --> Item14; + Item21 --> Item15; + Item21 --> Item16; + Item21 --> Item17; + Item21 --> Item18; + Item21 --> Item19; + Item21 --> Item20; + Item21 -.-> Item6; + Item21 -.-> Item5; + Item21 -.-> Item4; + Item21 -.-> Item7; + Item22 --> Item12; + Item22 --> Item1; + Item22 --> Item2; + Item22 --> Item3; + Item22 --> Item9; + Item22 --> Item10; + Item22 --> Item11; + Item22 --> Item13; + Item22 --> Item14; + Item22 --> Item15; + Item22 --> Item16; + Item22 --> Item17; + Item22 --> Item18; + Item22 --> Item19; + Item22 --> Item20; + Item22 --> Item21; + Item22 -.-> Item6; + Item22 -.-> Item5; + Item22 -.-> Item4; + Item22 -.-> Item7; + Item23 --> Item12; + Item23 --> Item1; + Item23 --> Item2; + Item23 --> Item3; + Item23 --> Item9; + Item23 --> Item10; + Item23 --> Item11; + Item23 --> Item13; + Item23 --> Item14; + Item23 --> Item15; + Item23 --> Item16; + Item23 --> Item17; + Item23 --> Item18; + Item23 --> Item19; + Item23 --> Item20; + Item23 --> Item21; + Item23 --> Item22; + Item23 -.-> Item6; + Item23 -.-> Item5; + Item23 -.-> Item4; + Item23 -.-> Item7; + Item24 --> Item12; + Item24 --> Item1; + Item24 --> Item2; + Item24 --> Item3; + Item24 --> Item9; + Item24 --> Item10; + Item24 --> Item11; + Item24 --> Item13; + Item24 --> Item14; + Item24 --> Item15; + Item24 --> Item16; + Item24 --> Item17; + Item24 --> Item18; + Item24 --> Item19; + Item24 --> Item20; + Item24 --> Item21; + Item24 --> Item22; + Item24 --> Item23; + Item24 -.-> Item6; + Item24 -.-> Item5; + Item24 -.-> Item4; + Item24 -.-> Item7; + Item25 --> Item12; + Item25 --> Item1; + Item25 --> Item2; + Item25 --> Item3; + Item25 --> Item9; + Item25 --> Item10; + Item25 --> Item11; + Item25 --> Item13; + Item25 --> Item14; + Item25 --> Item15; + Item25 --> Item16; + Item25 --> Item17; + Item25 --> Item18; + Item25 --> Item19; + Item25 --> Item20; + Item25 --> Item21; + Item25 --> Item22; + Item25 --> Item23; + Item25 --> Item24; + Item25 -.-> Item6; + Item25 -.-> Item5; + Item25 -.-> Item4; + Item25 -.-> Item7; + Item26 --> Item12; + Item26 --> Item1; + Item26 --> Item2; + Item26 --> Item3; + Item26 --> Item9; + Item26 --> Item10; + Item26 --> Item11; + Item26 --> Item13; + Item26 --> Item14; + Item26 --> Item15; + Item26 --> Item16; + Item26 --> Item17; + Item26 --> Item18; + Item26 --> Item19; + Item26 --> Item20; + Item26 --> Item21; + Item26 --> Item22; + Item26 --> Item23; + Item26 --> Item24; + Item26 --> Item25; + Item26 -.-> Item6; + Item26 -.-> Item5; + Item26 -.-> Item4; + Item26 -.-> Item7; + Item27 --> Item12; + Item27 --> Item1; + Item27 --> Item2; + Item27 --> Item3; + Item27 --> Item9; + Item27 --> Item10; + Item27 --> Item11; + Item27 --> Item13; + Item27 --> Item14; + Item27 --> Item15; + Item27 --> Item16; + Item27 --> Item17; + Item27 --> Item18; + Item27 --> Item19; + Item27 --> Item20; + Item27 --> Item21; + Item27 --> Item22; + Item27 --> Item23; + Item27 --> Item24; + Item27 --> Item25; + Item27 --> Item26; + Item27 -.-> Item6; + Item27 -.-> Item5; + Item27 -.-> Item4; + Item27 -.-> Item7; + Item28 --> Item12; + Item28 --> Item1; + Item28 --> Item2; + Item28 --> Item3; + Item28 --> Item9; + Item28 --> Item10; + Item28 --> Item11; + Item28 --> Item13; + Item28 --> Item14; + Item28 --> Item15; + Item28 --> Item16; + Item28 --> Item17; + Item28 --> Item18; + Item28 --> Item19; + Item28 --> Item20; + Item28 --> Item21; + Item28 --> Item22; + Item28 --> Item23; + Item28 --> Item24; + Item28 --> Item25; + Item28 --> Item26; + Item28 --> Item27; + Item28 -.-> Item6; + Item28 -.-> Item5; + Item28 -.-> Item4; + Item28 -.-> Item7; + Item7 --> Item6; + Item7 --> Item5; + Item8 --> Item4; + Item8 --> Item7; +``` +# Phase 4 +```mermaid +graph TD + Item1; + Item4; + Item2; + Item5; + Item3; + Item6; + Item7; + Item8; + Item9; + Item10; + Item11; + Item12; + Item13; + Item14; + Item15; + Item16; + Item17; + Item18; + Item19; + Item20; + Item21; + Item22; + Item23; + Item24; + Item25; + Item26; + Item27; + Item28; + Item29; + Item29["ModuleEvaluation"]; + Item30; + Item30["export structuredError"]; + Item31; + Item31["export IPC"]; + Item2 --> Item1; + Item3 --> Item1; + Item3 --> Item2; + Item9 --> Item1; + Item9 --> Item2; + Item9 --> Item3; + Item9 -.-> Item6; + Item9 -.-> Item5; + Item9 -.-> Item4; + Item9 -.-> Item7; + Item10 --> Item8; + Item10 --> Item9; + Item10 --> Item1; + Item10 --> Item2; + Item10 --> Item3; + Item10 -.-> Item6; + Item10 -.-> Item5; + Item10 -.-> Item4; + Item10 -.-> Item7; + Item11 --> Item1; + Item11 --> Item2; + Item11 --> Item3; + Item11 --> Item9; + Item11 --> Item10; + Item11 -.-> Item6; + Item11 -.-> Item5; + Item11 -.-> Item4; + Item11 -.-> Item7; + Item13 --> Item12; + Item13 --> Item1; + Item13 --> Item2; + Item13 --> Item3; + Item13 --> Item9; + Item13 --> Item10; + Item13 --> Item11; + Item13 -.-> Item6; + Item13 -.-> Item5; + Item13 -.-> Item4; + Item13 -.-> Item7; + Item14 --> Item12; + Item14 --> Item1; + Item14 --> Item2; + Item14 --> Item3; + Item14 --> Item9; + Item14 --> Item10; + Item14 --> Item11; + Item14 --> Item13; + Item14 -.-> Item6; + Item14 -.-> Item5; + Item14 -.-> Item4; + Item14 -.-> Item7; + Item15 --> Item12; + Item15 --> Item1; + Item15 --> Item2; + Item15 --> Item3; + Item15 --> Item9; + Item15 --> Item10; + Item15 --> Item11; + Item15 --> Item13; + Item15 --> Item14; + Item15 -.-> Item6; + Item15 -.-> Item5; + Item15 -.-> Item4; + Item15 -.-> Item7; + Item16 --> Item12; + Item16 --> Item1; + Item16 --> Item2; + Item16 --> Item3; + Item16 --> Item9; + Item16 --> Item10; + Item16 --> Item11; + Item16 --> Item13; + Item16 --> Item14; + Item16 --> Item15; + Item16 -.-> Item6; + Item16 -.-> Item5; + Item16 -.-> Item4; + Item16 -.-> Item7; + Item17 --> Item12; + Item17 --> Item1; + Item17 --> Item2; + Item17 --> Item3; + Item17 --> Item9; + Item17 --> Item10; + Item17 --> Item11; + Item17 --> Item13; + Item17 --> Item14; + Item17 --> Item15; + Item17 --> Item16; + Item17 -.-> Item6; + Item17 -.-> Item5; + Item17 -.-> Item4; + Item17 -.-> Item7; + Item18 --> Item12; + Item18 --> Item1; + Item18 --> Item2; + Item18 --> Item3; + Item18 --> Item9; + Item18 --> Item10; + Item18 --> Item11; + Item18 --> Item13; + Item18 --> Item14; + Item18 --> Item15; + Item18 --> Item16; + Item18 --> Item17; + Item18 -.-> Item6; + Item18 -.-> Item5; + Item18 -.-> Item4; + Item18 -.-> Item7; + Item19 --> Item12; + Item19 --> Item1; + Item19 --> Item2; + Item19 --> Item3; + Item19 --> Item9; + Item19 --> Item10; + Item19 --> Item11; + Item19 --> Item13; + Item19 --> Item14; + Item19 --> Item15; + Item19 --> Item16; + Item19 --> Item17; + Item19 --> Item18; + Item19 -.-> Item6; + Item19 -.-> Item5; + Item19 -.-> Item4; + Item19 -.-> Item7; + Item20 --> Item12; + Item20 --> Item1; + Item20 --> Item2; + Item20 --> Item3; + Item20 --> Item9; + Item20 --> Item10; + Item20 --> Item11; + Item20 --> Item13; + Item20 --> Item14; + Item20 --> Item15; + Item20 --> Item16; + Item20 --> Item17; + Item20 --> Item18; + Item20 --> Item19; + Item20 -.-> Item6; + Item20 -.-> Item5; + Item20 -.-> Item4; + Item20 -.-> Item7; + Item21 --> Item12; + Item21 --> Item1; + Item21 --> Item2; + Item21 --> Item3; + Item21 --> Item9; + Item21 --> Item10; + Item21 --> Item11; + Item21 --> Item13; + Item21 --> Item14; + Item21 --> Item15; + Item21 --> Item16; + Item21 --> Item17; + Item21 --> Item18; + Item21 --> Item19; + Item21 --> Item20; + Item21 -.-> Item6; + Item21 -.-> Item5; + Item21 -.-> Item4; + Item21 -.-> Item7; + Item22 --> Item12; + Item22 --> Item1; + Item22 --> Item2; + Item22 --> Item3; + Item22 --> Item9; + Item22 --> Item10; + Item22 --> Item11; + Item22 --> Item13; + Item22 --> Item14; + Item22 --> Item15; + Item22 --> Item16; + Item22 --> Item17; + Item22 --> Item18; + Item22 --> Item19; + Item22 --> Item20; + Item22 --> Item21; + Item22 -.-> Item6; + Item22 -.-> Item5; + Item22 -.-> Item4; + Item22 -.-> Item7; + Item23 --> Item12; + Item23 --> Item1; + Item23 --> Item2; + Item23 --> Item3; + Item23 --> Item9; + Item23 --> Item10; + Item23 --> Item11; + Item23 --> Item13; + Item23 --> Item14; + Item23 --> Item15; + Item23 --> Item16; + Item23 --> Item17; + Item23 --> Item18; + Item23 --> Item19; + Item23 --> Item20; + Item23 --> Item21; + Item23 --> Item22; + Item23 -.-> Item6; + Item23 -.-> Item5; + Item23 -.-> Item4; + Item23 -.-> Item7; + Item24 --> Item12; + Item24 --> Item1; + Item24 --> Item2; + Item24 --> Item3; + Item24 --> Item9; + Item24 --> Item10; + Item24 --> Item11; + Item24 --> Item13; + Item24 --> Item14; + Item24 --> Item15; + Item24 --> Item16; + Item24 --> Item17; + Item24 --> Item18; + Item24 --> Item19; + Item24 --> Item20; + Item24 --> Item21; + Item24 --> Item22; + Item24 --> Item23; + Item24 -.-> Item6; + Item24 -.-> Item5; + Item24 -.-> Item4; + Item24 -.-> Item7; + Item25 --> Item12; + Item25 --> Item1; + Item25 --> Item2; + Item25 --> Item3; + Item25 --> Item9; + Item25 --> Item10; + Item25 --> Item11; + Item25 --> Item13; + Item25 --> Item14; + Item25 --> Item15; + Item25 --> Item16; + Item25 --> Item17; + Item25 --> Item18; + Item25 --> Item19; + Item25 --> Item20; + Item25 --> Item21; + Item25 --> Item22; + Item25 --> Item23; + Item25 --> Item24; + Item25 -.-> Item6; + Item25 -.-> Item5; + Item25 -.-> Item4; + Item25 -.-> Item7; + Item26 --> Item12; + Item26 --> Item1; + Item26 --> Item2; + Item26 --> Item3; + Item26 --> Item9; + Item26 --> Item10; + Item26 --> Item11; + Item26 --> Item13; + Item26 --> Item14; + Item26 --> Item15; + Item26 --> Item16; + Item26 --> Item17; + Item26 --> Item18; + Item26 --> Item19; + Item26 --> Item20; + Item26 --> Item21; + Item26 --> Item22; + Item26 --> Item23; + Item26 --> Item24; + Item26 --> Item25; + Item26 -.-> Item6; + Item26 -.-> Item5; + Item26 -.-> Item4; + Item26 -.-> Item7; + Item27 --> Item12; + Item27 --> Item1; + Item27 --> Item2; + Item27 --> Item3; + Item27 --> Item9; + Item27 --> Item10; + Item27 --> Item11; + Item27 --> Item13; + Item27 --> Item14; + Item27 --> Item15; + Item27 --> Item16; + Item27 --> Item17; + Item27 --> Item18; + Item27 --> Item19; + Item27 --> Item20; + Item27 --> Item21; + Item27 --> Item22; + Item27 --> Item23; + Item27 --> Item24; + Item27 --> Item25; + Item27 --> Item26; + Item27 -.-> Item6; + Item27 -.-> Item5; + Item27 -.-> Item4; + Item27 -.-> Item7; + Item28 --> Item12; + Item28 --> Item1; + Item28 --> Item2; + Item28 --> Item3; + Item28 --> Item9; + Item28 --> Item10; + Item28 --> Item11; + Item28 --> Item13; + Item28 --> Item14; + Item28 --> Item15; + Item28 --> Item16; + Item28 --> Item17; + Item28 --> Item18; + Item28 --> Item19; + Item28 --> Item20; + Item28 --> Item21; + Item28 --> Item22; + Item28 --> Item23; + Item28 --> Item24; + Item28 --> Item25; + Item28 --> Item26; + Item28 --> Item27; + Item28 -.-> Item6; + Item28 -.-> Item5; + Item28 -.-> Item4; + Item28 -.-> Item7; + Item7 --> Item6; + Item7 --> Item5; + Item8 --> Item4; + Item8 --> Item7; + Item29 --> Item1; + Item29 --> Item2; + Item29 --> Item3; + Item29 --> Item9; + Item29 --> Item10; + Item29 --> Item11; + Item29 --> Item13; + Item29 --> Item14; + Item29 --> Item15; + Item29 --> Item16; + Item29 --> Item17; + Item29 --> Item18; + Item29 --> Item19; + Item29 --> Item20; + Item29 --> Item21; + Item29 --> Item22; + Item29 --> Item23; + Item29 --> Item24; + Item29 --> Item25; + Item29 --> Item26; + Item29 --> Item27; + Item29 --> Item28; + Item30 --> Item7; + Item31 --> Item10; +``` +# Final +```mermaid +graph TD + N0["Items: [ItemId(ModuleEvaluation), ItemId(0, ImportBinding(0)), ItemId(1, ImportBinding(0)), ItemId(2, ImportBinding(0)), ItemId(7, Normal), ItemId(8, VarDeclarator(0)), ItemId(9, Normal), ItemId(10, Normal), ItemId(11, Normal), ItemId(12, Normal), ItemId(13, Normal), ItemId(14, Normal), ItemId(15, Normal), ItemId(16, Normal), ItemId(17, Normal), ItemId(18, Normal), ItemId(19, Normal), ItemId(20, Normal), ItemId(21, Normal), ItemId(22, Normal), ItemId(23, Normal), ItemId(24, Normal)]"]; + N1["Items: [ItemId(Export(("structuredError", #2), "structuredError"))]"]; + N2["Items: [ItemId(Export(("IPC", #2), "IPC"))]"]; + N3["Items: [ItemId(0, ImportOfModule)]"]; + N4["Items: [ItemId(1, ImportOfModule)]"]; + N5["Items: [ItemId(2, ImportOfModule)]"]; + N6["Items: [ItemId(1, ImportBinding(0)), ItemId(2, ImportBinding(0)), ItemId(3, Normal)]"]; + N7["Items: [ItemId(0, ImportBinding(0)), ItemId(4, Normal)]"]; + N8["Items: [ItemId(0, ImportBinding(0)), ItemId(1, ImportBinding(0)), ItemId(2, ImportBinding(0)), ItemId(5, VarDeclarator(0))]"]; + N9["Items: [ItemId(0, ImportBinding(0)), ItemId(1, ImportBinding(0)), ItemId(2, ImportBinding(0)), ItemId(6, VarDeclarator(0))]"]; + N0 --> N3; + N0 --> N4; + N0 --> N5; + N0 --> N8; + N0 --> N9; + N0 --> N6; + N1 --> N6; + N2 --> N9; + N4 --> N3; + N5 --> N3; + N5 --> N4; + N6 --> N9; + N7 --> N9; + N7 --> N6; + N8 --> N3; + N8 --> N4; + N8 --> N5; + N8 --> N9; + N8 --> N6; + N9 --> N7; + N9 --> N8; + N9 --> N3; + N9 --> N4; + N9 --> N5; + N9 --> N6; +``` +# Entrypoints + +``` +{ + ModuleEvaluation: 0, + Export( + "structuredError", + ): 1, + Export( + "IPC", + ): 2, +} +``` + + +# Modules (dev) +## Part 0 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +import { process } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; +import { IPC } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; +"module evaluation"; +import { createConnection } from "node:net"; +import { parse as parseStackTrace } from "../compiled/stacktrace-parser"; +import { getProperError } from "./error"; +process.on("uncaughtException", (err)=>{ + IPC.sendError(err); +}); +const improveConsole = (name, stream, addStack)=>{ + const original = console[name]; + const stdio = process[stream]; + console[name] = (...args)=>{ + stdio.write(`TURBOPACK_OUTPUT_B\n`); + original(...args); + if (addStack) { + const stack = new Error().stack?.replace(/^.+\n.+\n/, "") + "\n"; + stdio.write("TURBOPACK_OUTPUT_S\n"); + stdio.write(stack); + } + stdio.write("TURBOPACK_OUTPUT_E\n"); + }; +}; +improveConsole("error", "stderr", true); +improveConsole("warn", "stderr", true); +improveConsole("count", "stdout", true); +improveConsole("trace", "stderr", false); +improveConsole("log", "stdout", true); +improveConsole("group", "stdout", true); +improveConsole("groupCollapsed", "stdout", true); +improveConsole("table", "stdout", true); +improveConsole("debug", "stdout", true); +improveConsole("info", "stdout", true); +improveConsole("dir", "stdout", true); +improveConsole("dirxml", "stdout", true); +improveConsole("timeEnd", "stdout", true); +improveConsole("timeLog", "stdout", true); +improveConsole("timeStamp", "stdout", true); +improveConsole("assert", "stderr", true); +export { improveConsole } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 1 +```js +import { structuredError } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; +export { structuredError }; + +``` +## Part 2 +```js +import { IPC } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; +export { IPC }; + +``` +## Part 3 +```js +import "node:net"; + +``` +## Part 4 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "../compiled/stacktrace-parser"; + +``` +## Part 5 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "./error"; + +``` +## Part 6 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; +import { parse as parseStackTrace } from "../compiled/stacktrace-parser"; +import { getProperError } from "./error"; +function structuredError(e) { + e = getProperError(e); + return { + name: e.name, + message: e.message, + stack: typeof e.stack === "string" ? parseStackTrace(e.stack) : [] + }; +} +export { structuredError } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 7 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; +import { structuredError } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; +import { createConnection } from "node:net"; +function createIpc(port) { + const socket = createConnection(port, "127.0.0.1"); + const packetQueue = []; + const recvPromiseResolveQueue = []; + function pushPacket(packet) { + const recvPromiseResolve = recvPromiseResolveQueue.shift(); + if (recvPromiseResolve != null) { + recvPromiseResolve(JSON.parse(packet.toString("utf8"))); + } else { + packetQueue.push(packet); + } + } + let state = { + type: "waiting" + }; + let buffer = Buffer.alloc(0); + socket.once("connect", ()=>{ + socket.on("data", (chunk)=>{ + buffer = Buffer.concat([ + buffer, + chunk + ]); + loop: while(true){ + switch(state.type){ + case "waiting": + { + if (buffer.length >= 4) { + const length = buffer.readUInt32BE(0); + buffer = buffer.subarray(4); + state = { + type: "packet", + length + }; + } else { + break loop; + } + break; + } + case "packet": + { + if (buffer.length >= state.length) { + const packet = buffer.subarray(0, state.length); + buffer = buffer.subarray(state.length); + state = { + type: "waiting" + }; + pushPacket(packet); + } else { + break loop; + } + break; + } + } + } + }); + }); + socket.once("close", ()=>{ + process.exit(0); + }); + function send(message) { + const packet = Buffer.from(JSON.stringify(message), "utf8"); + const length = Buffer.alloc(4); + length.writeUInt32BE(packet.length); + socket.write(length); + return new Promise((resolve, reject)=>{ + socket.write(packet, (err)=>{ + process.stderr.write(`TURBOPACK_OUTPUT_D\n`); + process.stdout.write(`TURBOPACK_OUTPUT_D\n`); + if (err != null) { + reject(err); + } else { + resolve(); + } + }); + }); + } + function sendReady() { + const length = Buffer.from([ + 0, + 0, + 0, + 0 + ]); + return new Promise((resolve, reject)=>{ + socket.write(length, (err)=>{ + process.stderr.write(`TURBOPACK_OUTPUT_D\n`); + process.stdout.write(`TURBOPACK_OUTPUT_D\n`); + if (err != null) { + reject(err); + } else { + resolve(); + } + }); + }); + } + return { + async recv () { + const packet = packetQueue.shift(); + if (packet != null) { + return JSON.parse(packet.toString("utf8")); + } + const result = await new Promise((resolve)=>{ + recvPromiseResolveQueue.push((result)=>{ + resolve(result); + }); + }); + return result; + }, + send (message) { + return send(message); + }, + sendReady, + async sendError (error) { + try { + await send({ + type: "error", + ...structuredError(error) + }); + } catch (err) { + console.error("failed to send error back to rust:", err); + process.exit(1); + } + process.exit(0); + } + }; +} +export { createIpc } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 8 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; +import { createConnection } from "node:net"; +import { parse as parseStackTrace } from "../compiled/stacktrace-parser"; +import { getProperError } from "./error"; +const PORT = process.argv[2]; +export { PORT } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; +export { process } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 9 +```js +import { createIpc } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 7 +}; +import { PORT } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; +import { createConnection } from "node:net"; +import { parse as parseStackTrace } from "../compiled/stacktrace-parser"; +import { getProperError } from "./error"; +const IPC = createIpc(parseInt(PORT, 10)); +export { IPC } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Merged (module eval) +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +import { process } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; +import { IPC } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; +import { createConnection } from "node:net"; +import { parse as parseStackTrace } from "../compiled/stacktrace-parser"; +import { getProperError } from "./error"; +"module evaluation"; +process.on("uncaughtException", (err)=>{ + IPC.sendError(err); +}); +const improveConsole = (name, stream, addStack)=>{ + const original = console[name]; + const stdio = process[stream]; + console[name] = (...args)=>{ + stdio.write(`TURBOPACK_OUTPUT_B\n`); + original(...args); + if (addStack) { + const stack = new Error().stack?.replace(/^.+\n.+\n/, "") + "\n"; + stdio.write("TURBOPACK_OUTPUT_S\n"); + stdio.write(stack); + } + stdio.write("TURBOPACK_OUTPUT_E\n"); + }; +}; +improveConsole("error", "stderr", true); +improveConsole("warn", "stderr", true); +improveConsole("count", "stdout", true); +improveConsole("trace", "stderr", false); +improveConsole("log", "stdout", true); +improveConsole("group", "stdout", true); +improveConsole("groupCollapsed", "stdout", true); +improveConsole("table", "stdout", true); +improveConsole("debug", "stdout", true); +improveConsole("info", "stdout", true); +improveConsole("dir", "stdout", true); +improveConsole("dirxml", "stdout", true); +improveConsole("timeEnd", "stdout", true); +improveConsole("timeLog", "stdout", true); +improveConsole("timeStamp", "stdout", true); +improveConsole("assert", "stderr", true); +export { improveConsole } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +# Entrypoints + +``` +{ + ModuleEvaluation: 0, + Export( + "structuredError", + ): 1, + Export( + "IPC", + ): 2, +} +``` + + +# Modules (prod) +## Part 0 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +import { process } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; +import { IPC } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; +"module evaluation"; +process.on("uncaughtException", (err)=>{ + IPC.sendError(err); +}); +const improveConsole = (name, stream, addStack)=>{ + const original = console[name]; + const stdio = process[stream]; + console[name] = (...args)=>{ + stdio.write(`TURBOPACK_OUTPUT_B\n`); + original(...args); + if (addStack) { + const stack = new Error().stack?.replace(/^.+\n.+\n/, "") + "\n"; + stdio.write("TURBOPACK_OUTPUT_S\n"); + stdio.write(stack); + } + stdio.write("TURBOPACK_OUTPUT_E\n"); + }; +}; +improveConsole("error", "stderr", true); +improveConsole("warn", "stderr", true); +improveConsole("count", "stdout", true); +improveConsole("trace", "stderr", false); +improveConsole("log", "stdout", true); +improveConsole("group", "stdout", true); +improveConsole("groupCollapsed", "stdout", true); +improveConsole("table", "stdout", true); +improveConsole("debug", "stdout", true); +improveConsole("info", "stdout", true); +improveConsole("dir", "stdout", true); +improveConsole("dirxml", "stdout", true); +improveConsole("timeEnd", "stdout", true); +improveConsole("timeLog", "stdout", true); +improveConsole("timeStamp", "stdout", true); +improveConsole("assert", "stderr", true); +export { improveConsole } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 1 +```js +import { structuredError } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; +export { structuredError }; + +``` +## Part 2 +```js +import { IPC } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; +export { IPC }; + +``` +## Part 3 +```js +import "node:net"; + +``` +## Part 4 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "../compiled/stacktrace-parser"; + +``` +## Part 5 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "./error"; + +``` +## Part 6 +```js +import { parse as parseStackTrace } from "../compiled/stacktrace-parser"; +import { getProperError } from "./error"; +function structuredError(e) { + e = getProperError(e); + return { + name: e.name, + message: e.message, + stack: typeof e.stack === "string" ? parseStackTrace(e.stack) : [] + }; +} +export { structuredError } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 7 +```js +import { structuredError } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; +import { createConnection } from "node:net"; +function createIpc(port) { + const socket = createConnection(port, "127.0.0.1"); + const packetQueue = []; + const recvPromiseResolveQueue = []; + function pushPacket(packet) { + const recvPromiseResolve = recvPromiseResolveQueue.shift(); + if (recvPromiseResolve != null) { + recvPromiseResolve(JSON.parse(packet.toString("utf8"))); + } else { + packetQueue.push(packet); + } + } + let state = { + type: "waiting" + }; + let buffer = Buffer.alloc(0); + socket.once("connect", ()=>{ + socket.on("data", (chunk)=>{ + buffer = Buffer.concat([ + buffer, + chunk + ]); + loop: while(true){ + switch(state.type){ + case "waiting": + { + if (buffer.length >= 4) { + const length = buffer.readUInt32BE(0); + buffer = buffer.subarray(4); + state = { + type: "packet", + length + }; + } else { + break loop; + } + break; + } + case "packet": + { + if (buffer.length >= state.length) { + const packet = buffer.subarray(0, state.length); + buffer = buffer.subarray(state.length); + state = { + type: "waiting" + }; + pushPacket(packet); + } else { + break loop; + } + break; + } + } + } + }); + }); + socket.once("close", ()=>{ + process.exit(0); + }); + function send(message) { + const packet = Buffer.from(JSON.stringify(message), "utf8"); + const length = Buffer.alloc(4); + length.writeUInt32BE(packet.length); + socket.write(length); + return new Promise((resolve, reject)=>{ + socket.write(packet, (err)=>{ + process.stderr.write(`TURBOPACK_OUTPUT_D\n`); + process.stdout.write(`TURBOPACK_OUTPUT_D\n`); + if (err != null) { + reject(err); + } else { + resolve(); + } + }); + }); + } + function sendReady() { + const length = Buffer.from([ + 0, + 0, + 0, + 0 + ]); + return new Promise((resolve, reject)=>{ + socket.write(length, (err)=>{ + process.stderr.write(`TURBOPACK_OUTPUT_D\n`); + process.stdout.write(`TURBOPACK_OUTPUT_D\n`); + if (err != null) { + reject(err); + } else { + resolve(); + } + }); + }); + } + return { + async recv () { + const packet = packetQueue.shift(); + if (packet != null) { + return JSON.parse(packet.toString("utf8")); + } + const result = await new Promise((resolve)=>{ + recvPromiseResolveQueue.push((result)=>{ + resolve(result); + }); + }); + return result; + }, + send (message) { + return send(message); + }, + sendReady, + async sendError (error) { + try { + await send({ + type: "error", + ...structuredError(error) + }); + } catch (err) { + console.error("failed to send error back to rust:", err); + process.exit(1); + } + process.exit(0); + } + }; +} +export { createIpc } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 8 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +const PORT = process.argv[2]; +export { PORT } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; +export { process } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 9 +```js +import { createIpc } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 7 +}; +import { PORT } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +const IPC = createIpc(parseInt(PORT, 10)); +export { IPC } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Merged (module eval) +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +import { process } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; +import { IPC } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; +"module evaluation"; +process.on("uncaughtException", (err)=>{ + IPC.sendError(err); +}); +const improveConsole = (name, stream, addStack)=>{ + const original = console[name]; + const stdio = process[stream]; + console[name] = (...args)=>{ + stdio.write(`TURBOPACK_OUTPUT_B\n`); + original(...args); + if (addStack) { + const stack = new Error().stack?.replace(/^.+\n.+\n/, "") + "\n"; + stdio.write("TURBOPACK_OUTPUT_S\n"); + stdio.write(stack); + } + stdio.write("TURBOPACK_OUTPUT_E\n"); + }; +}; +improveConsole("error", "stderr", true); +improveConsole("warn", "stderr", true); +improveConsole("count", "stdout", true); +improveConsole("trace", "stderr", false); +improveConsole("log", "stdout", true); +improveConsole("group", "stdout", true); +improveConsole("groupCollapsed", "stdout", true); +improveConsole("table", "stdout", true); +improveConsole("debug", "stdout", true); +improveConsole("info", "stdout", true); +improveConsole("dir", "stdout", true); +improveConsole("dirxml", "stdout", true); +improveConsole("timeEnd", "stdout", true); +improveConsole("timeLog", "stdout", true); +improveConsole("timeStamp", "stdout", true); +improveConsole("assert", "stderr", true); +export { improveConsole } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-2/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-2/output.md new file mode 100644 index 0000000000000..22b8790269bc3 --- /dev/null +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-2/output.md @@ -0,0 +1,496 @@ +# Items + +Count: 11 + +## Item 1: Stmt 0, `VarDeclarator(0)` + +```js +export const order = []; + +``` + +- Declares: `order` +- Write: `order` + +## Item 2: Stmt 1, `Normal` + +```js +order.push("a"); + +``` + +- Side effects +- Write: `order` + +## Item 3: Stmt 2, `VarDeclarator(0)` + +```js +const random = Math.random(); + +``` + +- Side effects +- Declares: `random` +- Write: `random`, `Math` + +## Item 4: Stmt 3, `VarDeclarator(0)` + +```js +const shared = { + random, + effect: order.push("b") +}; + +``` + +- Declares: `shared` +- Reads: `random` +- Write: `shared`, `order` + +## Item 5: Stmt 4, `Normal` + +```js +order.push("c"); + +``` + +- Side effects +- Write: `order` + +## Item 6: Stmt 5, `VarDeclarator(0)` + +```js +export const a = { + shared, + a: "aaaaaaaaaaa" +}; + +``` + +- Declares: `a` +- Reads: `shared` +- Write: `a` + +## Item 7: Stmt 6, `VarDeclarator(0)` + +```js +export const b = { + shared, + b: "bbbbbbbbbbb" +}; + +``` + +- Declares: `b` +- Reads: `shared` +- Write: `b` + +# Phase 1 +```mermaid +graph TD + Item1; + Item2; + Item3; + Item4; + Item5; + Item6; + Item7; + Item8; + Item8["ModuleEvaluation"]; + Item9; + Item9["export order"]; + Item10; + Item10["export a"]; + Item11; + Item11["export b"]; +``` +# Phase 2 +```mermaid +graph TD + Item1; + Item2; + Item3; + Item4; + Item5; + Item6; + Item7; + Item8; + Item8["ModuleEvaluation"]; + Item9; + Item9["export order"]; + Item10; + Item10["export a"]; + Item11; + Item11["export b"]; + Item3 --> Item2; + Item4 --> Item3; + Item5 --> Item2; + Item5 --> Item3; + Item6 --> Item4; + Item7 --> Item4; +``` +# Phase 3 +```mermaid +graph TD + Item1; + Item2; + Item3; + Item4; + Item5; + Item6; + Item7; + Item8; + Item8["ModuleEvaluation"]; + Item9; + Item9["export order"]; + Item10; + Item10["export a"]; + Item11; + Item11["export b"]; + Item3 --> Item2; + Item4 --> Item3; + Item5 --> Item2; + Item5 --> Item3; + Item6 --> Item4; + Item7 --> Item4; +``` +# Phase 4 +```mermaid +graph TD + Item1; + Item2; + Item3; + Item4; + Item5; + Item6; + Item7; + Item8; + Item8["ModuleEvaluation"]; + Item9; + Item9["export order"]; + Item10; + Item10["export a"]; + Item11; + Item11["export b"]; + Item3 --> Item2; + Item4 --> Item3; + Item5 --> Item2; + Item5 --> Item3; + Item6 --> Item4; + Item7 --> Item4; + Item8 --> Item2; + Item8 --> Item3; + Item8 --> Item5; + Item9 --> Item1; + Item9 --> Item4; + Item9 --> Item5; + Item10 --> Item6; + Item11 --> Item7; +``` +# Final +```mermaid +graph TD + N0["Items: [ItemId(ModuleEvaluation)]"]; + N1["Items: [ItemId(Export(("order", #2), "order")), ItemId(0, VarDeclarator(0))]"]; + N2["Items: [ItemId(Export(("a", #2), "a")), ItemId(5, VarDeclarator(0))]"]; + N3["Items: [ItemId(Export(("b", #2), "b")), ItemId(6, VarDeclarator(0))]"]; + N4["Items: [ItemId(1, Normal)]"]; + N5["Items: [ItemId(2, VarDeclarator(0))]"]; + N6["Items: [ItemId(3, VarDeclarator(0))]"]; + N7["Items: [ItemId(4, Normal)]"]; + N0 --> N4; + N0 --> N5; + N0 --> N7; + N1 --> N6; + N1 --> N7; + N2 --> N6; + N3 --> N6; + N5 --> N4; + N6 --> N5; + N7 --> N4; + N7 --> N5; +``` +# Entrypoints + +``` +{ + ModuleEvaluation: 0, + Export( + "order", + ): 1, + Export( + "b", + ): 3, + Export( + "a", + ): 2, +} +``` + + +# Modules (dev) +## Part 0 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 7 +}; +"module evaluation"; + +``` +## Part 1 +```js +import { order } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 7 +}; +export { order }; +const order = []; +export { order } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 2 +```js +import { shared } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; +export { a }; +const a = { + shared, + a: "aaaaaaaaaaa" +}; +export { a } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 3 +```js +import { shared } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; +export { b }; +const b = { + shared, + b: "bbbbbbbbbbb" +}; +export { b } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 4 +```js +order.push("a"); +export { order } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 5 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +const random = Math.random(); +export { random } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; +export { Math } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 6 +```js +import { random } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +const shared = { + random, + effect: order.push("b") +}; +export { shared } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; +export { order } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 7 +```js +import { order } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +order.push("c"); + +``` +## Merged (module eval) +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 7 +}; +"module evaluation"; + +``` +# Entrypoints + +``` +{ + ModuleEvaluation: 0, + Export( + "order", + ): 1, + Export( + "b", + ): 3, + Export( + "a", + ): 2, +} +``` + + +# Modules (prod) +## Part 0 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 7 +}; +"module evaluation"; + +``` +## Part 1 +```js +import { order } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 7 +}; +export { order }; +const order = []; +export { order } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 2 +```js +import { shared } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; +export { a }; +const a = { + shared, + a: "aaaaaaaaaaa" +}; +export { a } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 3 +```js +import { shared } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; +export { b }; +const b = { + shared, + b: "bbbbbbbbbbb" +}; +export { b } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 4 +```js +order.push("a"); +export { order } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 5 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +const random = Math.random(); +export { random } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; +export { Math } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 6 +```js +import { random } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +const shared = { + random, + effect: order.push("b") +}; +export { shared } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; +export { order } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + +``` +## Part 7 +```js +import { order } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +order.push("c"); + +``` +## Merged (module eval) +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 7 +}; +"module evaluation"; + +``` From 5dc5c07a6b9bdcb5c12f2038df7994b7e288324c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Mon, 10 Jun 2024 18:17:41 +0900 Subject: [PATCH 11/23] visit_member_expr: Read + Write --- crates/turbopack-ecmascript/src/tree_shake/util.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/turbopack-ecmascript/src/tree_shake/util.rs b/crates/turbopack-ecmascript/src/tree_shake/util.rs index 4351e7996ccf7..8da6172ad5748 100644 --- a/crates/turbopack-ecmascript/src/tree_shake/util.rs +++ b/crates/turbopack-ecmascript/src/tree_shake/util.rs @@ -108,7 +108,7 @@ impl Visit for IdentUsageCollector { } fn visit_member_expr(&mut self, e: &MemberExpr) { - self.with_mode(Some(Mode::Write), |this| { + self.with_mode(None, |this| { // Skip visit_expr e.obj.visit_children_with(this); }); @@ -235,7 +235,7 @@ impl Visit for CapturedIdCollector { } fn visit_member_expr(&mut self, e: &MemberExpr) { - self.with_mode(Some(Mode::Write), |this| { + self.with_mode(None, |this| { // Skip visit_expr e.obj.visit_children_with(this); }); From 66693b0a026cff7f4e997f48cdf61bbc1c106c5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Mon, 10 Jun 2024 18:24:39 +0900 Subject: [PATCH 12/23] Ignore calls like console.log() --- .../src/tree_shake/graph.rs | 30 +++++++------ .../src/tree_shake/util.rs | 44 ++++++++++++++----- 2 files changed, 51 insertions(+), 23 deletions(-) diff --git a/crates/turbopack-ecmascript/src/tree_shake/graph.rs b/crates/turbopack-ecmascript/src/tree_shake/graph.rs index 9d2677c14d76c..a5a3db2e20314 100644 --- a/crates/turbopack-ecmascript/src/tree_shake/graph.rs +++ b/crates/turbopack-ecmascript/src/tree_shake/graph.rs @@ -698,10 +698,11 @@ impl DepGraph { { let used_ids = ids_used_by_ignoring_nested( &export.decl, - [unresolved_ctxt, top_level_ctxt], + unresolved_ctxt, + top_level_ctxt, ); let captured_ids = - ids_captured_by(&export.decl, [unresolved_ctxt, top_level_ctxt]); + ids_captured_by(&export.decl, unresolved_ctxt, top_level_ctxt); let data = ItemData { read_vars: used_ids.read, eventual_read_vars: captured_ids.read, @@ -736,10 +737,11 @@ impl DepGraph { let mut used_ids = ids_used_by_ignoring_nested( &export.expr, - [unresolved_ctxt, top_level_ctxt], + unresolved_ctxt, + top_level_ctxt, ); let captured_ids = - ids_captured_by(&export.expr, [unresolved_ctxt, top_level_ctxt]); + ids_captured_by(&export.expr, unresolved_ctxt, top_level_ctxt); used_ids.write.insert(default_var.to_id()); @@ -871,7 +873,7 @@ impl DepGraph { }; ids.push(id.clone()); - let vars = ids_used_by(&f.function, [unresolved_ctxt, top_level_ctxt]); + let vars = ids_used_by(&f.function, unresolved_ctxt, top_level_ctxt); let var_decls = { let mut v = IndexSet::with_capacity_and_hasher(1, Default::default()); v.insert(f.ident.to_id()); @@ -901,7 +903,7 @@ impl DepGraph { }; ids.push(id.clone()); - let vars = ids_used_by(&c.class, [unresolved_ctxt, top_level_ctxt]); + let vars = ids_used_by(&c.class, unresolved_ctxt, top_level_ctxt); let var_decls = { let mut v = IndexSet::with_capacity_and_hasher(1, Default::default()); v.insert(c.ident.to_id()); @@ -935,10 +937,11 @@ impl DepGraph { let decl_ids: Vec = find_pat_ids(&decl.name); let vars = ids_used_by_ignoring_nested( &decl.init, - [unresolved_ctxt, top_level_ctxt], + unresolved_ctxt, + top_level_ctxt, ); let eventual_vars = - ids_captured_by(&decl.init, [unresolved_ctxt, top_level_ctxt]); + ids_captured_by(&decl.init, unresolved_ctxt, top_level_ctxt); let side_effects = vars .read @@ -972,15 +975,16 @@ impl DepGraph { .. })) => { let mut used_ids = - ids_used_by_ignoring_nested(item, [unresolved_ctxt, top_level_ctxt]); - let captured_ids = ids_captured_by(item, [unresolved_ctxt, top_level_ctxt]); + ids_used_by_ignoring_nested(item, unresolved_ctxt, top_level_ctxt); + let captured_ids = ids_captured_by(item, unresolved_ctxt, top_level_ctxt); if assign.op != op!("=") { used_ids.read.extend(used_ids.write.iter().cloned()); let extra_ids = ids_used_by_ignoring_nested( &assign.left, - [unresolved_ctxt, top_level_ctxt], + unresolved_ctxt, + top_level_ctxt, ); used_ids.read.extend(extra_ids.read); used_ids.write.extend(extra_ids.write); @@ -1020,8 +1024,8 @@ impl DepGraph { // Default to normal let used_ids = - ids_used_by_ignoring_nested(item, [unresolved_ctxt, top_level_ctxt]); - let captured_ids = ids_captured_by(item, [unresolved_ctxt, top_level_ctxt]); + ids_used_by_ignoring_nested(item, unresolved_ctxt, top_level_ctxt); + let captured_ids = ids_captured_by(item, unresolved_ctxt, top_level_ctxt); let data = ItemData { read_vars: used_ids.read, eventual_read_vars: captured_ids.read, diff --git a/crates/turbopack-ecmascript/src/tree_shake/util.rs b/crates/turbopack-ecmascript/src/tree_shake/util.rs index 8da6172ad5748..e4967d47672e2 100644 --- a/crates/turbopack-ecmascript/src/tree_shake/util.rs +++ b/crates/turbopack-ecmascript/src/tree_shake/util.rs @@ -23,7 +23,8 @@ enum Mode { /// A visitor which collects variables which are read or written. #[derive(Default)] pub(crate) struct IdentUsageCollector { - only: [SyntaxContext; 2], + unresolved: SyntaxContext, + top_level: SyntaxContext, vars: Vars, ignore_nested: bool, /// None means both read and write @@ -89,7 +90,10 @@ impl Visit for IdentUsageCollector { fn visit_ident(&mut self, n: &Ident) { // We allow SyntaxContext::empty() because Some built-in files do not go into // resolver() - if !self.only.contains(&n.span.ctxt) && n.span.ctxt != SyntaxContext::empty() { + if n.span.ctxt != self.unresolved + && n.span.ctxt != self.top_level + && n.span.ctxt != SyntaxContext::empty() + { return; } @@ -101,6 +105,10 @@ impl Visit for IdentUsageCollector { self.vars.write.insert(n.to_id()); } None => { + // Ignore calls like console.log() + if n.span.ctxt == self.unresolved { + return; + } self.vars.read.insert(n.to_id()); self.vars.write.insert(n.to_id()); } @@ -149,7 +157,9 @@ impl Visit for IdentUsageCollector { /// evaluation time. #[derive(Default)] pub(crate) struct CapturedIdCollector { - only: [SyntaxContext; 2], + unresolved: SyntaxContext, + top_level: SyntaxContext, + vars: Vars, is_nested: bool, /// None means both read and write @@ -216,7 +226,10 @@ impl Visit for CapturedIdCollector { // We allow SyntaxContext::empty() because Some built-in files do not go into // resolver() - if !self.only.contains(&n.span.ctxt) && n.span.ctxt != SyntaxContext::empty() { + if n.span.ctxt != self.unresolved + && n.span.ctxt != self.top_level + && n.span.ctxt != SyntaxContext::empty() + { return; } @@ -228,6 +241,10 @@ impl Visit for CapturedIdCollector { self.vars.write.insert(n.to_id()); } None => { + // Ignore calls like console.log() + if n.span.ctxt == self.unresolved { + return; + } self.vars.read.insert(n.to_id()); self.vars.write.insert(n.to_id()); } @@ -271,12 +288,13 @@ pub(crate) struct Vars { /// /// Note: This functions accept `SyntaxContext` to filter out variables which /// are not interesting. We only need to analyze top-level variables. -pub(crate) fn ids_captured_by(n: &N, only: [SyntaxContext; 2]) -> Vars +pub(crate) fn ids_captured_by(n: &N, unresolved: SyntaxContext, top_level: SyntaxContext) -> Vars where N: VisitWith, { let mut v = CapturedIdCollector { - only, + unresolved, + top_level, is_nested: false, ..Default::default() }; @@ -288,12 +306,13 @@ where /// /// Note: This functions accept `SyntaxContext` to filter out variables which /// are not interesting. We only need to analyze top-level variables. -pub(crate) fn ids_used_by(n: &N, only: [SyntaxContext; 2]) -> Vars +pub(crate) fn ids_used_by(n: &N, unresolved: SyntaxContext, top_level: SyntaxContext) -> Vars where N: VisitWith, { let mut v = IdentUsageCollector { - only, + unresolved, + top_level, ignore_nested: false, ..Default::default() }; @@ -305,12 +324,17 @@ where /// /// Note: This functions accept `SyntaxContext` to filter out variables which /// are not interesting. We only need to analyze top-level variables. -pub(crate) fn ids_used_by_ignoring_nested(n: &N, only: [SyntaxContext; 2]) -> Vars +pub(crate) fn ids_used_by_ignoring_nested( + n: &N, + unresolved: SyntaxContext, + top_level: SyntaxContext, +) -> Vars where N: VisitWith, { let mut v = IdentUsageCollector { - only, + unresolved, + top_level, ignore_nested: true, ..Default::default() }; From 8f166e17e82c56204a772cd1ff2e5ff7675fb907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Mon, 10 Jun 2024 18:25:00 +0900 Subject: [PATCH 13/23] Update test refs --- .../tests/tree-shaker/analyzer/1/output.md | 13 -- .../tests/tree-shaker/analyzer/2/output.md | 13 -- .../tree-shaker/analyzer/app-route/output.md | 9 +- .../tree-shaker/analyzer/complex/output.md | 16 +- .../tree-shaker/analyzer/failed-1/output.md | 41 ++++- .../tree-shaker/analyzer/failed-2/output.md | 30 ++- .../tree-shaker/analyzer/failed-3/output.md | 137 +------------- .../analyzer/ipc-evaluate/output.md | 28 ++- .../tree-shaker/analyzer/ipc-index/output.md | 137 +------------- .../analyzer/node-globals/output.md | 21 +-- .../tree-shaker/analyzer/shared-2/output.md | 151 ++++++++------- .../shared-and-side-effects/output.md | 174 +++--------------- .../analyzer/template-pages/output.md | 9 +- .../analyzer/test-config-1/output.md | 13 -- .../tree-shaker/analyzer/tla-1/output.md | 57 +++--- .../analyzer/write-order/output.md | 140 +++++++------- 16 files changed, 321 insertions(+), 668 deletions(-) diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/1/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/1/output.md index 4a45d71eebcbf..c1e305852567f 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/1/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/1/output.md @@ -93,7 +93,6 @@ console.log(foobarCopy); - Side effects - Reads: `foobarCopy` -- Write: `console` ## Item 10: Stmt 8, `Normal` @@ -399,9 +398,6 @@ import "__TURBOPACK_PART__" assert { import "module"; import { upper } from "module"; console.log(foobarCopy); -export { console } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` ## Part 1 @@ -561,9 +557,6 @@ import "module"; import { upper } from "module"; "module evaluation"; console.log(foobarCopy); -export { console } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` # Entrypoints @@ -600,9 +593,6 @@ console.log(foobarCopy); export { foobarCopy } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; -export { console } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` ## Part 1 @@ -710,8 +700,5 @@ console.log(foobarCopy); export { foobarCopy } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; -export { console } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/2/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/2/output.md index bdfecbf570796..f533342357a53 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/2/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/2/output.md @@ -107,7 +107,6 @@ console.log(foobarCopy); - Side effects - Reads: `foobarCopy` -- Write: `console` ## Item 11: Stmt 9, `Normal` @@ -422,9 +421,6 @@ import "module"; import { upper } from "module"; console.log(foobarCopy); import "other"; -export { console } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` ## Part 1 @@ -585,9 +581,6 @@ import { upper } from "module"; import "other"; "module evaluation"; console.log(foobarCopy); -export { console } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` # Entrypoints @@ -625,9 +618,6 @@ import "other"; export { foobarCopy } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; -export { console } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` ## Part 1 @@ -736,8 +726,5 @@ console.log(foobarCopy); export { foobarCopy } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; -export { console } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/app-route/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/app-route/output.md index 91caaf0660054..74211b626cae8 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/app-route/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/app-route/output.md @@ -102,7 +102,7 @@ const routeModule = new AppRouteRouteModule({ - Side effects - Declares: `routeModule` -- Reads: `AppRouteRouteModule`, `nextConfigOutput`, `userland` +- Reads: `AppRouteRouteModule`, `RouteKind`, `nextConfigOutput`, `userland` - Write: `routeModule`, `RouteKind` ## Item 10: Stmt 5, `VarDeclarator(0)` @@ -215,6 +215,7 @@ graph TD Item4 --> Item2; Item4 --> Item3; Item9 --> Item5; + Item9 --> Item6; Item9 --> Item8; Item9 --> Item1; Item9 --> Item2; @@ -259,6 +260,7 @@ graph TD Item4 --> Item2; Item4 --> Item3; Item9 --> Item5; + Item9 --> Item6; Item9 --> Item8; Item9 --> Item1; Item9 --> Item2; @@ -305,6 +307,7 @@ graph TD Item4 --> Item2; Item4 --> Item3; Item9 --> Item5; + Item9 --> Item6; Item9 --> Item8; Item9 --> Item1; Item9 --> Item2; @@ -340,7 +343,7 @@ graph TD N8["Items: [ItemId(1, ImportOfModule)]"]; N9["Items: [ItemId(2, ImportOfModule)]"]; N10["Items: [ItemId(3, ImportOfModule)]"]; - N11["Items: [ItemId(0, ImportBinding(0)), ItemId(2, ImportBinding(0)), ItemId(3, ImportBinding(0)), ItemId(4, VarDeclarator(0))]"]; + N11["Items: [ItemId(0, ImportBinding(0)), ItemId(1, ImportBinding(0)), ItemId(2, ImportBinding(0)), ItemId(3, ImportBinding(0)), ItemId(4, VarDeclarator(0))]"]; N12["Items: [ItemId(5, VarDeclarator(0))]"]; N0 --> N7; N0 --> N8; @@ -528,6 +531,7 @@ import "__TURBOPACK_PART__" assert { __turbopack_part__: 10 }; import { AppRouteRouteModule } from '../../server/future/route-modules/app-route/module.compiled'; +import { RouteKind } from '../../server/future/route-kind'; import { patchFetch as _patchFetch } from '../../server/lib/patch-fetch'; import * as userland from 'VAR_USERLAND'; const routeModule = new AppRouteRouteModule({ @@ -747,6 +751,7 @@ import "__TURBOPACK_PART__" assert { __turbopack_part__: 10 }; import { AppRouteRouteModule } from '../../server/future/route-modules/app-route/module.compiled'; +import { RouteKind } from '../../server/future/route-kind'; import * as userland from 'VAR_USERLAND'; const routeModule = new AppRouteRouteModule({ definition: { diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/complex/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/complex/output.md index 3e63f9511840e..24ef3cab8c6be 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/complex/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/complex/output.md @@ -31,7 +31,6 @@ console.log(dog); - Side effects - Reads: `dog` -- Write: `console` ## Item 4: Stmt 3, `Normal` @@ -66,7 +65,6 @@ console.log(dog); - Side effects - Reads: `dog` -- Write: `console` ## Item 7: Stmt 6, `Normal` @@ -101,7 +99,6 @@ console.log(dog); - Side effects - Reads: `dog` -- Write: `console` ## Item 10: Stmt 9, `VarDeclarator(0)` @@ -498,9 +495,6 @@ import { dog } from "__TURBOPACK_PART__" assert { __turbopack_part__: 7 }; console.log(dog); -export { console } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` ## Part 9 @@ -535,7 +529,7 @@ export { dog } from "__TURBOPACK_VAR__" assert { import { dog } from "__TURBOPACK_PART__" assert { __turbopack_part__: 10 }; -import { console } from "__TURBOPACK_PART__" assert { +import "__TURBOPACK_PART__" assert { __turbopack_part__: 8 }; console.log(dog); @@ -560,7 +554,7 @@ export { dog } from "__TURBOPACK_VAR__" assert { import { dog } from "__TURBOPACK_PART__" assert { __turbopack_part__: 12 }; -import { console } from "__TURBOPACK_PART__" assert { +import "__TURBOPACK_PART__" assert { __turbopack_part__: 8 }; import "__TURBOPACK_PART__" assert { @@ -628,9 +622,6 @@ import "__TURBOPACK_PART__" assert { console.log(dog); console.log(dog); console.log(dog); -export { console } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` ## Part 1 @@ -762,8 +753,5 @@ import "__TURBOPACK_PART__" assert { console.log(dog); console.log(dog); console.log(dog); -export { console } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-1/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-1/output.md index b72ab350856b7..17ce0fa61a14c 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-1/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-1/output.md @@ -39,7 +39,6 @@ function getSocketProtocol(assetPrefix) { - Declares: `getSocketProtocol` - Reads (eventual): `URL` - Write: `getSocketProtocol` -- Write (eventual): `location` ## Item 4: Stmt 3, `Normal` @@ -52,6 +51,7 @@ export function addMessageListener(cb) { - Hoisted - Declares: `addMessageListener` +- Reads (eventual): `eventCallbacks` - Write: `addMessageListener` - Write (eventual): `eventCallbacks` @@ -120,9 +120,9 @@ export function connectHMR(options) { - Hoisted - Declares: `connectHMR` -- Reads (eventual): `source`, `setTimeout`, `location`, `getSocketProtocol` +- Reads (eventual): `source`, `eventCallbacks`, `setTimeout`, `location`, `getSocketProtocol` - Write: `connectHMR` -- Write (eventual): `source`, `console`, `eventCallbacks`, `JSON`, `window` +- Write (eventual): `source`, `eventCallbacks` # Phase 1 ```mermaid @@ -177,8 +177,10 @@ graph TD Item9["export sendMessage"]; Item10; Item10["export connectHMR"]; + Item4 --> Item2; Item5 --> Item1; Item6 --> Item1; + Item6 --> Item2; Item6 --> Item3; ``` # Phase 4 @@ -198,8 +200,10 @@ graph TD Item9["export sendMessage"]; Item10; Item10["export connectHMR"]; + Item4 --> Item2; Item5 --> Item1; Item6 --> Item1; + Item6 --> Item2; Item6 --> Item3; Item8 --> Item4; Item9 --> Item5; @@ -213,8 +217,11 @@ graph TD N2["Items: [ItemId(Export(("sendMessage", #2), "sendMessage")), ItemId(4, Normal)]"]; N3["Items: [ItemId(Export(("connectHMR", #2), "connectHMR")), ItemId(2, Normal), ItemId(5, Normal)]"]; N4["Items: [ItemId(0, VarDeclarator(0))]"]; + N5["Items: [ItemId(1, VarDeclarator(0))]"]; + N1 --> N5; N2 --> N4; N3 --> N4; + N3 --> N5; ``` # Entrypoints @@ -242,6 +249,9 @@ graph TD ``` ## Part 1 ```js +import { eventCallbacks } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; export { addMessageListener }; function addMessageListener(cb) { eventCallbacks.push(cb); @@ -271,6 +281,9 @@ export { sendMessage } from "__TURBOPACK_VAR__" assert { import { source } from "__TURBOPACK_PART__" assert { __turbopack_part__: 4 }; +import { eventCallbacks } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; export { connectHMR }; function getSocketProtocol(assetPrefix) { let protocol = location.protocol; @@ -335,6 +348,14 @@ export { source } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; +``` +## Part 5 +```js +const eventCallbacks = []; +export { eventCallbacks } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + ``` ## Merged (module eval) ```js @@ -367,6 +388,9 @@ export { source } from "__TURBOPACK_VAR__" assert { ``` ## Part 1 ```js +import { eventCallbacks } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; export { addMessageListener }; function addMessageListener(cb) { eventCallbacks.push(cb); @@ -396,6 +420,9 @@ export { sendMessage } from "__TURBOPACK_VAR__" assert { import { source } from "__TURBOPACK_PART__" assert { __turbopack_part__: 4 }; +import { eventCallbacks } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; export { connectHMR }; function getSocketProtocol(assetPrefix) { let protocol = location.protocol; @@ -460,6 +487,14 @@ export { source } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; +``` +## Part 5 +```js +const eventCallbacks = []; +export { eventCallbacks } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + ``` ## Merged (module eval) ```js diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-2/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-2/output.md index 9a19285c3fd02..dd6f52b236744 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-2/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-2/output.md @@ -90,6 +90,7 @@ const hasPostpone = typeof React.unstable_postpone === 'function'; ``` - Declares: `hasPostpone` +- Reads: `React` - Write: `hasPostpone`, `React` ## Item 10: Stmt 5, `Normal` @@ -212,7 +213,7 @@ function postponeWithTracking(prerenderState, expression, pathname) { - Hoisted - Declares: `postponeWithTracking` -- Reads (eventual): `assertPostpone`, `Error`, `undefined` +- Reads (eventual): `assertPostpone`, `Error`, `undefined`, `React` - Write: `postponeWithTracking` - Write (eventual): `React` @@ -290,7 +291,7 @@ export function createPostponedAbortSignal(reason) { - Hoisted - Declares: `createPostponedAbortSignal` -- Reads (eventual): `assertPostpone`, `AbortController` +- Reads (eventual): `assertPostpone`, `AbortController`, `React` - Write: `createPostponedAbortSignal` - Write (eventual): `React` @@ -387,6 +388,7 @@ graph TD Item4 --> Item1; Item4 --> Item2; Item4 --> Item3; + Item9 --> Item5; ``` # Phase 3 ```mermaid @@ -434,6 +436,7 @@ graph TD Item4 --> Item1; Item4 --> Item2; Item4 --> Item3; + Item9 --> Item5; Item11 --> Item8; Item11 --> Item7; Item11 --> Item15; @@ -445,8 +448,10 @@ graph TD Item13 --> Item15; Item14 --> Item15; Item15 --> Item18; + Item15 --> Item9; Item18 --> Item9; Item19 --> Item18; + Item19 --> Item9; ``` # Phase 4 ```mermaid @@ -494,6 +499,7 @@ graph TD Item4 --> Item1; Item4 --> Item2; Item4 --> Item3; + Item9 --> Item5; Item11 --> Item8; Item11 --> Item7; Item11 --> Item15; @@ -505,8 +511,10 @@ graph TD Item13 --> Item15; Item14 --> Item15; Item15 --> Item18; + Item15 --> Item9; Item18 --> Item9; Item19 --> Item18; + Item19 --> Item9; Item20 --> Item1; Item20 --> Item2; Item20 --> Item3; @@ -532,7 +540,7 @@ graph TD N6["Items: [ItemId(Export(("usedDynamicAPIs", #2), "usedDynamicAPIs")), ItemId(11, Normal)]"]; N7["Items: [ItemId(Export(("formatDynamicAPIAccesses", #2), "formatDynamicAPIAccesses")), ItemId(12, Normal)]"]; N8["Items: [ItemId(Export(("createPostponedAbortSignal", #2), "createPostponedAbortSignal")), ItemId(14, Normal)]"]; - N9["Items: [ItemId(4, VarDeclarator(0))]"]; + N9["Items: [ItemId(0, ImportBinding(0)), ItemId(4, VarDeclarator(0))]"]; N10["Items: [ItemId(10, Normal)]"]; N11["Items: [ItemId(13, Normal)]"]; N2 --> N3; @@ -541,7 +549,9 @@ graph TD N4 --> N10; N5 --> N10; N8 --> N11; + N8 --> N9; N10 --> N11; + N10 --> N9; N11 --> N9; ``` # Entrypoints @@ -738,6 +748,9 @@ export { formatDynamicAPIAccesses } from "__TURBOPACK_VAR__" assert { import { assertPostpone } from "__TURBOPACK_PART__" assert { __turbopack_part__: 11 }; +import { React } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; export { createPostponedAbortSignal }; function createPostponedAbortSignal(reason) { assertPostpone(); @@ -756,6 +769,7 @@ export { createPostponedAbortSignal } from "__TURBOPACK_VAR__" assert { ``` ## Part 9 ```js +import React from 'react'; const hasPostpone = typeof React.unstable_postpone === 'function'; export { hasPostpone } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true @@ -770,6 +784,9 @@ export { React } from "__TURBOPACK_VAR__" assert { import { assertPostpone } from "__TURBOPACK_PART__" assert { __turbopack_part__: 11 }; +import { React } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; function postponeWithTracking(prerenderState, expression, pathname) { assertPostpone(); const reason = `Route ${pathname} needs to bail out of prerendering at this point because it used ${expression}. ` + `React throws this special object to indicate where. It should not be caught by ` + `your own try/catch. Learn more: https://nextjs.org/docs/messages/ppr-caught-error`; @@ -1002,6 +1019,9 @@ export { formatDynamicAPIAccesses } from "__TURBOPACK_VAR__" assert { import { assertPostpone } from "__TURBOPACK_PART__" assert { __turbopack_part__: 11 }; +import { React } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; export { createPostponedAbortSignal }; function createPostponedAbortSignal(reason) { assertPostpone(); @@ -1020,6 +1040,7 @@ export { createPostponedAbortSignal } from "__TURBOPACK_VAR__" assert { ``` ## Part 9 ```js +import React from 'react'; const hasPostpone = typeof React.unstable_postpone === 'function'; export { hasPostpone } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true @@ -1034,6 +1055,9 @@ export { React } from "__TURBOPACK_VAR__" assert { import { assertPostpone } from "__TURBOPACK_PART__" assert { __turbopack_part__: 11 }; +import { React } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; function postponeWithTracking(prerenderState, expression, pathname) { assertPostpone(); const reason = `Route ${pathname} needs to bail out of prerendering at this point because it used ${expression}. ` + `React throws this special object to indicate where. It should not be caught by ` + `your own try/catch. Learn more: https://nextjs.org/docs/messages/ppr-caught-error`; diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-3/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-3/output.md index 4f44edf93f238..4c4044f21de55 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-3/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-3/output.md @@ -217,7 +217,6 @@ function createIpc(port) { - Declares: `createIpc` - Reads (eventual): `createConnection`, `loop`, `Promise`, `structuredError` - Write: `createIpc` -- Write (eventual): `JSON`, `Buffer`, `process`, `console` ## Item 9: Stmt 5, `VarDeclarator(0)` @@ -226,9 +225,8 @@ const PORT = process.argv[2]; ``` -- Side effects - Declares: `PORT` -- Write: `PORT`, `process` +- Write: `PORT` ## Item 10: Stmt 6, `VarDeclarator(0)` @@ -252,8 +250,7 @@ process.on("uncaughtException", (err)=>{ ``` - Side effects -- Reads (eventual): `sendError` -- Write: `process` +- Reads (eventual): `IPC`, `sendError` - Write (eventual): `IPC` ## Item 12: Stmt 8, `VarDeclarator(0)` @@ -277,9 +274,9 @@ const improveConsole = (name, stream, addStack)=>{ ``` - Declares: `improveConsole` -- Reads (eventual): `write`, `Error`, `replace` +- Reads (eventual): `write`, `Error`, `stack`, `replace` - Write: `improveConsole` -- Write (eventual): `console`, `process`, `stack` +- Write (eventual): `stack` ## Item 13: Stmt 9, `Normal` @@ -522,13 +519,6 @@ graph TD Item2 --> Item1; Item3 --> Item1; Item3 --> Item2; - Item9 --> Item1; - Item9 --> Item2; - Item9 --> Item3; - Item9 -.-> Item6; - Item9 -.-> Item5; - Item9 -.-> Item4; - Item9 -.-> Item7; Item10 --> Item8; Item10 --> Item9; Item10 --> Item1; @@ -541,7 +531,6 @@ graph TD Item11 --> Item1; Item11 --> Item2; Item11 --> Item3; - Item11 --> Item9; Item11 --> Item10; Item11 -.-> Item6; Item11 -.-> Item5; @@ -551,7 +540,6 @@ graph TD Item13 --> Item1; Item13 --> Item2; Item13 --> Item3; - Item13 --> Item9; Item13 --> Item10; Item13 --> Item11; Item13 -.-> Item6; @@ -562,7 +550,6 @@ graph TD Item14 --> Item1; Item14 --> Item2; Item14 --> Item3; - Item14 --> Item9; Item14 --> Item10; Item14 --> Item11; Item14 --> Item13; @@ -574,7 +561,6 @@ graph TD Item15 --> Item1; Item15 --> Item2; Item15 --> Item3; - Item15 --> Item9; Item15 --> Item10; Item15 --> Item11; Item15 --> Item13; @@ -587,7 +573,6 @@ graph TD Item16 --> Item1; Item16 --> Item2; Item16 --> Item3; - Item16 --> Item9; Item16 --> Item10; Item16 --> Item11; Item16 --> Item13; @@ -601,7 +586,6 @@ graph TD Item17 --> Item1; Item17 --> Item2; Item17 --> Item3; - Item17 --> Item9; Item17 --> Item10; Item17 --> Item11; Item17 --> Item13; @@ -616,7 +600,6 @@ graph TD Item18 --> Item1; Item18 --> Item2; Item18 --> Item3; - Item18 --> Item9; Item18 --> Item10; Item18 --> Item11; Item18 --> Item13; @@ -632,7 +615,6 @@ graph TD Item19 --> Item1; Item19 --> Item2; Item19 --> Item3; - Item19 --> Item9; Item19 --> Item10; Item19 --> Item11; Item19 --> Item13; @@ -649,7 +631,6 @@ graph TD Item20 --> Item1; Item20 --> Item2; Item20 --> Item3; - Item20 --> Item9; Item20 --> Item10; Item20 --> Item11; Item20 --> Item13; @@ -667,7 +648,6 @@ graph TD Item21 --> Item1; Item21 --> Item2; Item21 --> Item3; - Item21 --> Item9; Item21 --> Item10; Item21 --> Item11; Item21 --> Item13; @@ -686,7 +666,6 @@ graph TD Item22 --> Item1; Item22 --> Item2; Item22 --> Item3; - Item22 --> Item9; Item22 --> Item10; Item22 --> Item11; Item22 --> Item13; @@ -706,7 +685,6 @@ graph TD Item23 --> Item1; Item23 --> Item2; Item23 --> Item3; - Item23 --> Item9; Item23 --> Item10; Item23 --> Item11; Item23 --> Item13; @@ -727,7 +705,6 @@ graph TD Item24 --> Item1; Item24 --> Item2; Item24 --> Item3; - Item24 --> Item9; Item24 --> Item10; Item24 --> Item11; Item24 --> Item13; @@ -749,7 +726,6 @@ graph TD Item25 --> Item1; Item25 --> Item2; Item25 --> Item3; - Item25 --> Item9; Item25 --> Item10; Item25 --> Item11; Item25 --> Item13; @@ -772,7 +748,6 @@ graph TD Item26 --> Item1; Item26 --> Item2; Item26 --> Item3; - Item26 --> Item9; Item26 --> Item10; Item26 --> Item11; Item26 --> Item13; @@ -796,7 +771,6 @@ graph TD Item27 --> Item1; Item27 --> Item2; Item27 --> Item3; - Item27 --> Item9; Item27 --> Item10; Item27 --> Item11; Item27 --> Item13; @@ -821,7 +795,6 @@ graph TD Item28 --> Item1; Item28 --> Item2; Item28 --> Item3; - Item28 --> Item9; Item28 --> Item10; Item28 --> Item11; Item28 --> Item13; @@ -884,13 +857,6 @@ graph TD Item2 --> Item1; Item3 --> Item1; Item3 --> Item2; - Item9 --> Item1; - Item9 --> Item2; - Item9 --> Item3; - Item9 -.-> Item6; - Item9 -.-> Item5; - Item9 -.-> Item4; - Item9 -.-> Item7; Item10 --> Item8; Item10 --> Item9; Item10 --> Item1; @@ -903,7 +869,6 @@ graph TD Item11 --> Item1; Item11 --> Item2; Item11 --> Item3; - Item11 --> Item9; Item11 --> Item10; Item11 -.-> Item6; Item11 -.-> Item5; @@ -913,7 +878,6 @@ graph TD Item13 --> Item1; Item13 --> Item2; Item13 --> Item3; - Item13 --> Item9; Item13 --> Item10; Item13 --> Item11; Item13 -.-> Item6; @@ -924,7 +888,6 @@ graph TD Item14 --> Item1; Item14 --> Item2; Item14 --> Item3; - Item14 --> Item9; Item14 --> Item10; Item14 --> Item11; Item14 --> Item13; @@ -936,7 +899,6 @@ graph TD Item15 --> Item1; Item15 --> Item2; Item15 --> Item3; - Item15 --> Item9; Item15 --> Item10; Item15 --> Item11; Item15 --> Item13; @@ -949,7 +911,6 @@ graph TD Item16 --> Item1; Item16 --> Item2; Item16 --> Item3; - Item16 --> Item9; Item16 --> Item10; Item16 --> Item11; Item16 --> Item13; @@ -963,7 +924,6 @@ graph TD Item17 --> Item1; Item17 --> Item2; Item17 --> Item3; - Item17 --> Item9; Item17 --> Item10; Item17 --> Item11; Item17 --> Item13; @@ -978,7 +938,6 @@ graph TD Item18 --> Item1; Item18 --> Item2; Item18 --> Item3; - Item18 --> Item9; Item18 --> Item10; Item18 --> Item11; Item18 --> Item13; @@ -994,7 +953,6 @@ graph TD Item19 --> Item1; Item19 --> Item2; Item19 --> Item3; - Item19 --> Item9; Item19 --> Item10; Item19 --> Item11; Item19 --> Item13; @@ -1011,7 +969,6 @@ graph TD Item20 --> Item1; Item20 --> Item2; Item20 --> Item3; - Item20 --> Item9; Item20 --> Item10; Item20 --> Item11; Item20 --> Item13; @@ -1029,7 +986,6 @@ graph TD Item21 --> Item1; Item21 --> Item2; Item21 --> Item3; - Item21 --> Item9; Item21 --> Item10; Item21 --> Item11; Item21 --> Item13; @@ -1048,7 +1004,6 @@ graph TD Item22 --> Item1; Item22 --> Item2; Item22 --> Item3; - Item22 --> Item9; Item22 --> Item10; Item22 --> Item11; Item22 --> Item13; @@ -1068,7 +1023,6 @@ graph TD Item23 --> Item1; Item23 --> Item2; Item23 --> Item3; - Item23 --> Item9; Item23 --> Item10; Item23 --> Item11; Item23 --> Item13; @@ -1089,7 +1043,6 @@ graph TD Item24 --> Item1; Item24 --> Item2; Item24 --> Item3; - Item24 --> Item9; Item24 --> Item10; Item24 --> Item11; Item24 --> Item13; @@ -1111,7 +1064,6 @@ graph TD Item25 --> Item1; Item25 --> Item2; Item25 --> Item3; - Item25 --> Item9; Item25 --> Item10; Item25 --> Item11; Item25 --> Item13; @@ -1134,7 +1086,6 @@ graph TD Item26 --> Item1; Item26 --> Item2; Item26 --> Item3; - Item26 --> Item9; Item26 --> Item10; Item26 --> Item11; Item26 --> Item13; @@ -1158,7 +1109,6 @@ graph TD Item27 --> Item1; Item27 --> Item2; Item27 --> Item3; - Item27 --> Item9; Item27 --> Item10; Item27 --> Item11; Item27 --> Item13; @@ -1183,7 +1133,6 @@ graph TD Item28 --> Item1; Item28 --> Item2; Item28 --> Item3; - Item28 --> Item9; Item28 --> Item10; Item28 --> Item11; Item28 --> Item13; @@ -1250,13 +1199,6 @@ graph TD Item2 --> Item1; Item3 --> Item1; Item3 --> Item2; - Item9 --> Item1; - Item9 --> Item2; - Item9 --> Item3; - Item9 -.-> Item6; - Item9 -.-> Item5; - Item9 -.-> Item4; - Item9 -.-> Item7; Item10 --> Item8; Item10 --> Item9; Item10 --> Item1; @@ -1269,7 +1211,6 @@ graph TD Item11 --> Item1; Item11 --> Item2; Item11 --> Item3; - Item11 --> Item9; Item11 --> Item10; Item11 -.-> Item6; Item11 -.-> Item5; @@ -1279,7 +1220,6 @@ graph TD Item13 --> Item1; Item13 --> Item2; Item13 --> Item3; - Item13 --> Item9; Item13 --> Item10; Item13 --> Item11; Item13 -.-> Item6; @@ -1290,7 +1230,6 @@ graph TD Item14 --> Item1; Item14 --> Item2; Item14 --> Item3; - Item14 --> Item9; Item14 --> Item10; Item14 --> Item11; Item14 --> Item13; @@ -1302,7 +1241,6 @@ graph TD Item15 --> Item1; Item15 --> Item2; Item15 --> Item3; - Item15 --> Item9; Item15 --> Item10; Item15 --> Item11; Item15 --> Item13; @@ -1315,7 +1253,6 @@ graph TD Item16 --> Item1; Item16 --> Item2; Item16 --> Item3; - Item16 --> Item9; Item16 --> Item10; Item16 --> Item11; Item16 --> Item13; @@ -1329,7 +1266,6 @@ graph TD Item17 --> Item1; Item17 --> Item2; Item17 --> Item3; - Item17 --> Item9; Item17 --> Item10; Item17 --> Item11; Item17 --> Item13; @@ -1344,7 +1280,6 @@ graph TD Item18 --> Item1; Item18 --> Item2; Item18 --> Item3; - Item18 --> Item9; Item18 --> Item10; Item18 --> Item11; Item18 --> Item13; @@ -1360,7 +1295,6 @@ graph TD Item19 --> Item1; Item19 --> Item2; Item19 --> Item3; - Item19 --> Item9; Item19 --> Item10; Item19 --> Item11; Item19 --> Item13; @@ -1377,7 +1311,6 @@ graph TD Item20 --> Item1; Item20 --> Item2; Item20 --> Item3; - Item20 --> Item9; Item20 --> Item10; Item20 --> Item11; Item20 --> Item13; @@ -1395,7 +1328,6 @@ graph TD Item21 --> Item1; Item21 --> Item2; Item21 --> Item3; - Item21 --> Item9; Item21 --> Item10; Item21 --> Item11; Item21 --> Item13; @@ -1414,7 +1346,6 @@ graph TD Item22 --> Item1; Item22 --> Item2; Item22 --> Item3; - Item22 --> Item9; Item22 --> Item10; Item22 --> Item11; Item22 --> Item13; @@ -1434,7 +1365,6 @@ graph TD Item23 --> Item1; Item23 --> Item2; Item23 --> Item3; - Item23 --> Item9; Item23 --> Item10; Item23 --> Item11; Item23 --> Item13; @@ -1455,7 +1385,6 @@ graph TD Item24 --> Item1; Item24 --> Item2; Item24 --> Item3; - Item24 --> Item9; Item24 --> Item10; Item24 --> Item11; Item24 --> Item13; @@ -1477,7 +1406,6 @@ graph TD Item25 --> Item1; Item25 --> Item2; Item25 --> Item3; - Item25 --> Item9; Item25 --> Item10; Item25 --> Item11; Item25 --> Item13; @@ -1500,7 +1428,6 @@ graph TD Item26 --> Item1; Item26 --> Item2; Item26 --> Item3; - Item26 --> Item9; Item26 --> Item10; Item26 --> Item11; Item26 --> Item13; @@ -1524,7 +1451,6 @@ graph TD Item27 --> Item1; Item27 --> Item2; Item27 --> Item3; - Item27 --> Item9; Item27 --> Item10; Item27 --> Item11; Item27 --> Item13; @@ -1549,7 +1475,6 @@ graph TD Item28 --> Item1; Item28 --> Item2; Item28 --> Item3; - Item28 --> Item9; Item28 --> Item10; Item28 --> Item11; Item28 --> Item13; @@ -1578,7 +1503,6 @@ graph TD Item29 --> Item1; Item29 --> Item2; Item29 --> Item3; - Item29 --> Item9; Item29 --> Item10; Item29 --> Item11; Item29 --> Item13; @@ -1611,12 +1535,11 @@ graph TD N5["Items: [ItemId(2, ImportOfModule)]"]; N6["Items: [ItemId(1, ImportBinding(0)), ItemId(2, ImportBinding(0)), ItemId(3, Normal)]"]; N7["Items: [ItemId(0, ImportBinding(0)), ItemId(4, Normal)]"]; - N8["Items: [ItemId(0, ImportBinding(0)), ItemId(1, ImportBinding(0)), ItemId(2, ImportBinding(0)), ItemId(5, VarDeclarator(0))]"]; + N8["Items: [ItemId(5, VarDeclarator(0))]"]; N9["Items: [ItemId(0, ImportBinding(0)), ItemId(1, ImportBinding(0)), ItemId(2, ImportBinding(0)), ItemId(6, VarDeclarator(0))]"]; N0 --> N3; N0 --> N4; N0 --> N5; - N0 --> N8; N0 --> N9; N0 --> N6; N1 --> N6; @@ -1627,11 +1550,6 @@ graph TD N6 --> N9; N7 --> N9; N7 --> N6; - N8 --> N3; - N8 --> N4; - N8 --> N5; - N8 --> N9; - N8 --> N6; N9 --> N7; N9 --> N8; N9 --> N3; @@ -1666,9 +1584,6 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; -import { process } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 8 -}; import { IPC } from "__TURBOPACK_PART__" assert { __turbopack_part__: 9 }; @@ -1919,31 +1834,10 @@ export { createIpc } from "__TURBOPACK_VAR__" assert { ``` ## Part 8 ```js -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 3 -}; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 4 -}; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 5 -}; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 9 -}; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 6 -}; -import { createConnection } from "node:net"; -import { parse as parseStackTrace } from "../compiled/stacktrace-parser"; -import { getProperError } from "./error"; const PORT = process.argv[2]; export { PORT } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; -export { process } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` ## Part 9 @@ -1986,9 +1880,6 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; -import { process } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 8 -}; import { IPC } from "__TURBOPACK_PART__" assert { __turbopack_part__: 9 }; @@ -2064,9 +1955,6 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; -import { process } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 8 -}; import { IPC } from "__TURBOPACK_PART__" assert { __turbopack_part__: 9 }; @@ -2305,22 +2193,10 @@ export { createIpc } from "__TURBOPACK_VAR__" assert { ``` ## Part 8 ```js -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 3 -}; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 4 -}; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 5 -}; const PORT = process.argv[2]; export { PORT } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; -export { process } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` ## Part 9 @@ -2357,9 +2233,6 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; -import { process } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 8 -}; import { IPC } from "__TURBOPACK_PART__" assert { __turbopack_part__: 9 }; diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-evaluate/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-evaluate/output.md index 62e766a5b1783..67d8e4ab8afc7 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-evaluate/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-evaluate/output.md @@ -141,9 +141,9 @@ export const run = async (moduleFactory)=>{ ``` - Declares: `run` -- Reads (eventual): `Map`, `send`, `Promise`, `set`, `then`, `sendError`, `init`, `default`, `sendReady`, `length`, `shift`, `undefined`, `stringify`, `recv`, `type`, `push`, `args`, `get`, `id`, `delete`, `error`, `reject`, `Error`, `resolve`, `data`, `exit` +- Reads (eventual): `Map`, `ipc`, `send`, `Promise`, `set`, `then`, `sendError`, `init`, `default`, `sendReady`, `queue`, `length`, `shift`, `undefined`, `stringify`, `recv`, `type`, `push`, `args`, `get`, `id`, `delete`, `error`, `reject`, `Error`, `resolve`, `data`, `exit` - Write: `run` -- Write (eventual): `ipc`, `queue`, `JSON`, `console`, `process` +- Write (eventual): `ipc`, `queue` # Phase 1 ```mermaid @@ -185,6 +185,8 @@ graph TD Item7; Item7["export run"]; Item3 --> Item2; + Item5 --> Item3; + Item5 --> Item4; ``` # Phase 4 ```mermaid @@ -199,6 +201,8 @@ graph TD Item7; Item7["export run"]; Item3 --> Item2; + Item5 --> Item3; + Item5 --> Item4; Item6 --> Item1; Item7 --> Item5; ``` @@ -206,7 +210,7 @@ graph TD ```mermaid graph TD N0["Items: [ItemId(ModuleEvaluation), ItemId(0, ImportOfModule)]"]; - N1["Items: [ItemId(Export(("run", #2), "run")), ItemId(3, VarDeclarator(0))]"]; + N1["Items: [ItemId(Export(("run", #2), "run")), ItemId(0, ImportBinding(0)), ItemId(1, VarDeclarator(0)), ItemId(2, VarDeclarator(0)), ItemId(3, VarDeclarator(0))]"]; ``` # Entrypoints @@ -230,6 +234,9 @@ import "./index"; ## Part 1 ```js export { run }; +import { IPC } from "./index"; +const ipc = IPC; +const queue = []; const run = async (moduleFactory)=>{ let nextId = 1; const requests = new Map(); @@ -321,6 +328,12 @@ const run = async (moduleFactory)=>{ } } }; +export { ipc } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; +export { queue } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; export { run } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; @@ -354,6 +367,9 @@ import "./index"; ## Part 1 ```js export { run }; +import { IPC } from "./index"; +const ipc = IPC; +const queue = []; const run = async (moduleFactory)=>{ let nextId = 1; const requests = new Map(); @@ -445,6 +461,12 @@ const run = async (moduleFactory)=>{ } } }; +export { ipc } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; +export { queue } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; export { run } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-index/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-index/output.md index 4f44edf93f238..4c4044f21de55 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-index/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-index/output.md @@ -217,7 +217,6 @@ function createIpc(port) { - Declares: `createIpc` - Reads (eventual): `createConnection`, `loop`, `Promise`, `structuredError` - Write: `createIpc` -- Write (eventual): `JSON`, `Buffer`, `process`, `console` ## Item 9: Stmt 5, `VarDeclarator(0)` @@ -226,9 +225,8 @@ const PORT = process.argv[2]; ``` -- Side effects - Declares: `PORT` -- Write: `PORT`, `process` +- Write: `PORT` ## Item 10: Stmt 6, `VarDeclarator(0)` @@ -252,8 +250,7 @@ process.on("uncaughtException", (err)=>{ ``` - Side effects -- Reads (eventual): `sendError` -- Write: `process` +- Reads (eventual): `IPC`, `sendError` - Write (eventual): `IPC` ## Item 12: Stmt 8, `VarDeclarator(0)` @@ -277,9 +274,9 @@ const improveConsole = (name, stream, addStack)=>{ ``` - Declares: `improveConsole` -- Reads (eventual): `write`, `Error`, `replace` +- Reads (eventual): `write`, `Error`, `stack`, `replace` - Write: `improveConsole` -- Write (eventual): `console`, `process`, `stack` +- Write (eventual): `stack` ## Item 13: Stmt 9, `Normal` @@ -522,13 +519,6 @@ graph TD Item2 --> Item1; Item3 --> Item1; Item3 --> Item2; - Item9 --> Item1; - Item9 --> Item2; - Item9 --> Item3; - Item9 -.-> Item6; - Item9 -.-> Item5; - Item9 -.-> Item4; - Item9 -.-> Item7; Item10 --> Item8; Item10 --> Item9; Item10 --> Item1; @@ -541,7 +531,6 @@ graph TD Item11 --> Item1; Item11 --> Item2; Item11 --> Item3; - Item11 --> Item9; Item11 --> Item10; Item11 -.-> Item6; Item11 -.-> Item5; @@ -551,7 +540,6 @@ graph TD Item13 --> Item1; Item13 --> Item2; Item13 --> Item3; - Item13 --> Item9; Item13 --> Item10; Item13 --> Item11; Item13 -.-> Item6; @@ -562,7 +550,6 @@ graph TD Item14 --> Item1; Item14 --> Item2; Item14 --> Item3; - Item14 --> Item9; Item14 --> Item10; Item14 --> Item11; Item14 --> Item13; @@ -574,7 +561,6 @@ graph TD Item15 --> Item1; Item15 --> Item2; Item15 --> Item3; - Item15 --> Item9; Item15 --> Item10; Item15 --> Item11; Item15 --> Item13; @@ -587,7 +573,6 @@ graph TD Item16 --> Item1; Item16 --> Item2; Item16 --> Item3; - Item16 --> Item9; Item16 --> Item10; Item16 --> Item11; Item16 --> Item13; @@ -601,7 +586,6 @@ graph TD Item17 --> Item1; Item17 --> Item2; Item17 --> Item3; - Item17 --> Item9; Item17 --> Item10; Item17 --> Item11; Item17 --> Item13; @@ -616,7 +600,6 @@ graph TD Item18 --> Item1; Item18 --> Item2; Item18 --> Item3; - Item18 --> Item9; Item18 --> Item10; Item18 --> Item11; Item18 --> Item13; @@ -632,7 +615,6 @@ graph TD Item19 --> Item1; Item19 --> Item2; Item19 --> Item3; - Item19 --> Item9; Item19 --> Item10; Item19 --> Item11; Item19 --> Item13; @@ -649,7 +631,6 @@ graph TD Item20 --> Item1; Item20 --> Item2; Item20 --> Item3; - Item20 --> Item9; Item20 --> Item10; Item20 --> Item11; Item20 --> Item13; @@ -667,7 +648,6 @@ graph TD Item21 --> Item1; Item21 --> Item2; Item21 --> Item3; - Item21 --> Item9; Item21 --> Item10; Item21 --> Item11; Item21 --> Item13; @@ -686,7 +666,6 @@ graph TD Item22 --> Item1; Item22 --> Item2; Item22 --> Item3; - Item22 --> Item9; Item22 --> Item10; Item22 --> Item11; Item22 --> Item13; @@ -706,7 +685,6 @@ graph TD Item23 --> Item1; Item23 --> Item2; Item23 --> Item3; - Item23 --> Item9; Item23 --> Item10; Item23 --> Item11; Item23 --> Item13; @@ -727,7 +705,6 @@ graph TD Item24 --> Item1; Item24 --> Item2; Item24 --> Item3; - Item24 --> Item9; Item24 --> Item10; Item24 --> Item11; Item24 --> Item13; @@ -749,7 +726,6 @@ graph TD Item25 --> Item1; Item25 --> Item2; Item25 --> Item3; - Item25 --> Item9; Item25 --> Item10; Item25 --> Item11; Item25 --> Item13; @@ -772,7 +748,6 @@ graph TD Item26 --> Item1; Item26 --> Item2; Item26 --> Item3; - Item26 --> Item9; Item26 --> Item10; Item26 --> Item11; Item26 --> Item13; @@ -796,7 +771,6 @@ graph TD Item27 --> Item1; Item27 --> Item2; Item27 --> Item3; - Item27 --> Item9; Item27 --> Item10; Item27 --> Item11; Item27 --> Item13; @@ -821,7 +795,6 @@ graph TD Item28 --> Item1; Item28 --> Item2; Item28 --> Item3; - Item28 --> Item9; Item28 --> Item10; Item28 --> Item11; Item28 --> Item13; @@ -884,13 +857,6 @@ graph TD Item2 --> Item1; Item3 --> Item1; Item3 --> Item2; - Item9 --> Item1; - Item9 --> Item2; - Item9 --> Item3; - Item9 -.-> Item6; - Item9 -.-> Item5; - Item9 -.-> Item4; - Item9 -.-> Item7; Item10 --> Item8; Item10 --> Item9; Item10 --> Item1; @@ -903,7 +869,6 @@ graph TD Item11 --> Item1; Item11 --> Item2; Item11 --> Item3; - Item11 --> Item9; Item11 --> Item10; Item11 -.-> Item6; Item11 -.-> Item5; @@ -913,7 +878,6 @@ graph TD Item13 --> Item1; Item13 --> Item2; Item13 --> Item3; - Item13 --> Item9; Item13 --> Item10; Item13 --> Item11; Item13 -.-> Item6; @@ -924,7 +888,6 @@ graph TD Item14 --> Item1; Item14 --> Item2; Item14 --> Item3; - Item14 --> Item9; Item14 --> Item10; Item14 --> Item11; Item14 --> Item13; @@ -936,7 +899,6 @@ graph TD Item15 --> Item1; Item15 --> Item2; Item15 --> Item3; - Item15 --> Item9; Item15 --> Item10; Item15 --> Item11; Item15 --> Item13; @@ -949,7 +911,6 @@ graph TD Item16 --> Item1; Item16 --> Item2; Item16 --> Item3; - Item16 --> Item9; Item16 --> Item10; Item16 --> Item11; Item16 --> Item13; @@ -963,7 +924,6 @@ graph TD Item17 --> Item1; Item17 --> Item2; Item17 --> Item3; - Item17 --> Item9; Item17 --> Item10; Item17 --> Item11; Item17 --> Item13; @@ -978,7 +938,6 @@ graph TD Item18 --> Item1; Item18 --> Item2; Item18 --> Item3; - Item18 --> Item9; Item18 --> Item10; Item18 --> Item11; Item18 --> Item13; @@ -994,7 +953,6 @@ graph TD Item19 --> Item1; Item19 --> Item2; Item19 --> Item3; - Item19 --> Item9; Item19 --> Item10; Item19 --> Item11; Item19 --> Item13; @@ -1011,7 +969,6 @@ graph TD Item20 --> Item1; Item20 --> Item2; Item20 --> Item3; - Item20 --> Item9; Item20 --> Item10; Item20 --> Item11; Item20 --> Item13; @@ -1029,7 +986,6 @@ graph TD Item21 --> Item1; Item21 --> Item2; Item21 --> Item3; - Item21 --> Item9; Item21 --> Item10; Item21 --> Item11; Item21 --> Item13; @@ -1048,7 +1004,6 @@ graph TD Item22 --> Item1; Item22 --> Item2; Item22 --> Item3; - Item22 --> Item9; Item22 --> Item10; Item22 --> Item11; Item22 --> Item13; @@ -1068,7 +1023,6 @@ graph TD Item23 --> Item1; Item23 --> Item2; Item23 --> Item3; - Item23 --> Item9; Item23 --> Item10; Item23 --> Item11; Item23 --> Item13; @@ -1089,7 +1043,6 @@ graph TD Item24 --> Item1; Item24 --> Item2; Item24 --> Item3; - Item24 --> Item9; Item24 --> Item10; Item24 --> Item11; Item24 --> Item13; @@ -1111,7 +1064,6 @@ graph TD Item25 --> Item1; Item25 --> Item2; Item25 --> Item3; - Item25 --> Item9; Item25 --> Item10; Item25 --> Item11; Item25 --> Item13; @@ -1134,7 +1086,6 @@ graph TD Item26 --> Item1; Item26 --> Item2; Item26 --> Item3; - Item26 --> Item9; Item26 --> Item10; Item26 --> Item11; Item26 --> Item13; @@ -1158,7 +1109,6 @@ graph TD Item27 --> Item1; Item27 --> Item2; Item27 --> Item3; - Item27 --> Item9; Item27 --> Item10; Item27 --> Item11; Item27 --> Item13; @@ -1183,7 +1133,6 @@ graph TD Item28 --> Item1; Item28 --> Item2; Item28 --> Item3; - Item28 --> Item9; Item28 --> Item10; Item28 --> Item11; Item28 --> Item13; @@ -1250,13 +1199,6 @@ graph TD Item2 --> Item1; Item3 --> Item1; Item3 --> Item2; - Item9 --> Item1; - Item9 --> Item2; - Item9 --> Item3; - Item9 -.-> Item6; - Item9 -.-> Item5; - Item9 -.-> Item4; - Item9 -.-> Item7; Item10 --> Item8; Item10 --> Item9; Item10 --> Item1; @@ -1269,7 +1211,6 @@ graph TD Item11 --> Item1; Item11 --> Item2; Item11 --> Item3; - Item11 --> Item9; Item11 --> Item10; Item11 -.-> Item6; Item11 -.-> Item5; @@ -1279,7 +1220,6 @@ graph TD Item13 --> Item1; Item13 --> Item2; Item13 --> Item3; - Item13 --> Item9; Item13 --> Item10; Item13 --> Item11; Item13 -.-> Item6; @@ -1290,7 +1230,6 @@ graph TD Item14 --> Item1; Item14 --> Item2; Item14 --> Item3; - Item14 --> Item9; Item14 --> Item10; Item14 --> Item11; Item14 --> Item13; @@ -1302,7 +1241,6 @@ graph TD Item15 --> Item1; Item15 --> Item2; Item15 --> Item3; - Item15 --> Item9; Item15 --> Item10; Item15 --> Item11; Item15 --> Item13; @@ -1315,7 +1253,6 @@ graph TD Item16 --> Item1; Item16 --> Item2; Item16 --> Item3; - Item16 --> Item9; Item16 --> Item10; Item16 --> Item11; Item16 --> Item13; @@ -1329,7 +1266,6 @@ graph TD Item17 --> Item1; Item17 --> Item2; Item17 --> Item3; - Item17 --> Item9; Item17 --> Item10; Item17 --> Item11; Item17 --> Item13; @@ -1344,7 +1280,6 @@ graph TD Item18 --> Item1; Item18 --> Item2; Item18 --> Item3; - Item18 --> Item9; Item18 --> Item10; Item18 --> Item11; Item18 --> Item13; @@ -1360,7 +1295,6 @@ graph TD Item19 --> Item1; Item19 --> Item2; Item19 --> Item3; - Item19 --> Item9; Item19 --> Item10; Item19 --> Item11; Item19 --> Item13; @@ -1377,7 +1311,6 @@ graph TD Item20 --> Item1; Item20 --> Item2; Item20 --> Item3; - Item20 --> Item9; Item20 --> Item10; Item20 --> Item11; Item20 --> Item13; @@ -1395,7 +1328,6 @@ graph TD Item21 --> Item1; Item21 --> Item2; Item21 --> Item3; - Item21 --> Item9; Item21 --> Item10; Item21 --> Item11; Item21 --> Item13; @@ -1414,7 +1346,6 @@ graph TD Item22 --> Item1; Item22 --> Item2; Item22 --> Item3; - Item22 --> Item9; Item22 --> Item10; Item22 --> Item11; Item22 --> Item13; @@ -1434,7 +1365,6 @@ graph TD Item23 --> Item1; Item23 --> Item2; Item23 --> Item3; - Item23 --> Item9; Item23 --> Item10; Item23 --> Item11; Item23 --> Item13; @@ -1455,7 +1385,6 @@ graph TD Item24 --> Item1; Item24 --> Item2; Item24 --> Item3; - Item24 --> Item9; Item24 --> Item10; Item24 --> Item11; Item24 --> Item13; @@ -1477,7 +1406,6 @@ graph TD Item25 --> Item1; Item25 --> Item2; Item25 --> Item3; - Item25 --> Item9; Item25 --> Item10; Item25 --> Item11; Item25 --> Item13; @@ -1500,7 +1428,6 @@ graph TD Item26 --> Item1; Item26 --> Item2; Item26 --> Item3; - Item26 --> Item9; Item26 --> Item10; Item26 --> Item11; Item26 --> Item13; @@ -1524,7 +1451,6 @@ graph TD Item27 --> Item1; Item27 --> Item2; Item27 --> Item3; - Item27 --> Item9; Item27 --> Item10; Item27 --> Item11; Item27 --> Item13; @@ -1549,7 +1475,6 @@ graph TD Item28 --> Item1; Item28 --> Item2; Item28 --> Item3; - Item28 --> Item9; Item28 --> Item10; Item28 --> Item11; Item28 --> Item13; @@ -1578,7 +1503,6 @@ graph TD Item29 --> Item1; Item29 --> Item2; Item29 --> Item3; - Item29 --> Item9; Item29 --> Item10; Item29 --> Item11; Item29 --> Item13; @@ -1611,12 +1535,11 @@ graph TD N5["Items: [ItemId(2, ImportOfModule)]"]; N6["Items: [ItemId(1, ImportBinding(0)), ItemId(2, ImportBinding(0)), ItemId(3, Normal)]"]; N7["Items: [ItemId(0, ImportBinding(0)), ItemId(4, Normal)]"]; - N8["Items: [ItemId(0, ImportBinding(0)), ItemId(1, ImportBinding(0)), ItemId(2, ImportBinding(0)), ItemId(5, VarDeclarator(0))]"]; + N8["Items: [ItemId(5, VarDeclarator(0))]"]; N9["Items: [ItemId(0, ImportBinding(0)), ItemId(1, ImportBinding(0)), ItemId(2, ImportBinding(0)), ItemId(6, VarDeclarator(0))]"]; N0 --> N3; N0 --> N4; N0 --> N5; - N0 --> N8; N0 --> N9; N0 --> N6; N1 --> N6; @@ -1627,11 +1550,6 @@ graph TD N6 --> N9; N7 --> N9; N7 --> N6; - N8 --> N3; - N8 --> N4; - N8 --> N5; - N8 --> N9; - N8 --> N6; N9 --> N7; N9 --> N8; N9 --> N3; @@ -1666,9 +1584,6 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; -import { process } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 8 -}; import { IPC } from "__TURBOPACK_PART__" assert { __turbopack_part__: 9 }; @@ -1919,31 +1834,10 @@ export { createIpc } from "__TURBOPACK_VAR__" assert { ``` ## Part 8 ```js -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 3 -}; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 4 -}; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 5 -}; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 9 -}; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 6 -}; -import { createConnection } from "node:net"; -import { parse as parseStackTrace } from "../compiled/stacktrace-parser"; -import { getProperError } from "./error"; const PORT = process.argv[2]; export { PORT } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; -export { process } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` ## Part 9 @@ -1986,9 +1880,6 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; -import { process } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 8 -}; import { IPC } from "__TURBOPACK_PART__" assert { __turbopack_part__: 9 }; @@ -2064,9 +1955,6 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; -import { process } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 8 -}; import { IPC } from "__TURBOPACK_PART__" assert { __turbopack_part__: 9 }; @@ -2305,22 +2193,10 @@ export { createIpc } from "__TURBOPACK_VAR__" assert { ``` ## Part 8 ```js -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 3 -}; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 4 -}; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 5 -}; const PORT = process.argv[2]; export { PORT } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; -export { process } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` ## Part 9 @@ -2357,9 +2233,6 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; -import { process } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 8 -}; import { IPC } from "__TURBOPACK_PART__" assert { __turbopack_part__: 9 }; diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/node-globals/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/node-globals/output.md index 9adf74dd970cb..cd1acde0d3f31 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/node-globals/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/node-globals/output.md @@ -9,8 +9,6 @@ process.turbopack = {}; ``` -- Side effects -- Write: `process` # Phase 1 ```mermaid @@ -39,12 +37,11 @@ graph TD Item1; Item2; Item2["ModuleEvaluation"]; - Item2 --> Item1; ``` # Final ```mermaid graph TD - N0["Items: [ItemId(ModuleEvaluation), ItemId(0, Normal)]"]; + N0["Items: [ItemId(ModuleEvaluation)]"]; ``` # Entrypoints @@ -59,19 +56,11 @@ graph TD ## Part 0 ```js "module evaluation"; -process.turbopack = {}; -export { process } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` ## Merged (module eval) ```js "module evaluation"; -process.turbopack = {}; -export { process } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` # Entrypoints @@ -87,18 +76,10 @@ export { process } from "__TURBOPACK_VAR__" assert { ## Part 0 ```js "module evaluation"; -process.turbopack = {}; -export { process } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` ## Merged (module eval) ```js "module evaluation"; -process.turbopack = {}; -export { process } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-2/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-2/output.md index 22b8790269bc3..ce4fa59bb1df3 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-2/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-2/output.md @@ -20,6 +20,7 @@ order.push("a"); ``` - Side effects +- Reads: `order` - Write: `order` ## Item 3: Stmt 2, `VarDeclarator(0)` @@ -29,9 +30,8 @@ const random = Math.random(); ``` -- Side effects - Declares: `random` -- Write: `random`, `Math` +- Write: `random` ## Item 4: Stmt 3, `VarDeclarator(0)` @@ -44,7 +44,7 @@ const shared = { ``` - Declares: `shared` -- Reads: `random` +- Reads: `random`, `order` - Write: `shared`, `order` ## Item 5: Stmt 4, `Normal` @@ -55,6 +55,7 @@ order.push("c"); ``` - Side effects +- Reads: `order` - Write: `order` ## Item 6: Stmt 5, `VarDeclarator(0)` @@ -122,10 +123,11 @@ graph TD Item10["export a"]; Item11; Item11["export b"]; - Item3 --> Item2; + Item2 --> Item1; Item4 --> Item3; + Item4 --> Item2; + Item5 --> Item4; Item5 --> Item2; - Item5 --> Item3; Item6 --> Item4; Item7 --> Item4; ``` @@ -147,10 +149,11 @@ graph TD Item10["export a"]; Item11; Item11["export b"]; - Item3 --> Item2; + Item2 --> Item1; Item4 --> Item3; + Item4 --> Item2; + Item5 --> Item4; Item5 --> Item2; - Item5 --> Item3; Item6 --> Item4; Item7 --> Item4; ``` @@ -172,17 +175,15 @@ graph TD Item10["export a"]; Item11; Item11["export b"]; - Item3 --> Item2; + Item2 --> Item1; Item4 --> Item3; + Item4 --> Item2; + Item5 --> Item4; Item5 --> Item2; - Item5 --> Item3; Item6 --> Item4; Item7 --> Item4; Item8 --> Item2; - Item8 --> Item3; Item8 --> Item5; - Item9 --> Item1; - Item9 --> Item4; Item9 --> Item5; Item10 --> Item6; Item11 --> Item7; @@ -191,24 +192,24 @@ graph TD ```mermaid graph TD N0["Items: [ItemId(ModuleEvaluation)]"]; - N1["Items: [ItemId(Export(("order", #2), "order")), ItemId(0, VarDeclarator(0))]"]; + N1["Items: [ItemId(Export(("order", #2), "order"))]"]; N2["Items: [ItemId(Export(("a", #2), "a")), ItemId(5, VarDeclarator(0))]"]; N3["Items: [ItemId(Export(("b", #2), "b")), ItemId(6, VarDeclarator(0))]"]; - N4["Items: [ItemId(1, Normal)]"]; - N5["Items: [ItemId(2, VarDeclarator(0))]"]; - N6["Items: [ItemId(3, VarDeclarator(0))]"]; - N7["Items: [ItemId(4, Normal)]"]; - N0 --> N4; + N4["Items: [ItemId(0, VarDeclarator(0))]"]; + N5["Items: [ItemId(1, Normal)]"]; + N6["Items: [ItemId(2, VarDeclarator(0))]"]; + N7["Items: [ItemId(3, VarDeclarator(0))]"]; + N8["Items: [ItemId(4, Normal)]"]; N0 --> N5; - N0 --> N7; - N1 --> N6; - N1 --> N7; - N2 --> N6; - N3 --> N6; + N0 --> N8; + N1 --> N8; + N2 --> N7; + N3 --> N7; N5 --> N4; - N6 --> N5; - N7 --> N4; + N7 --> N6; N7 --> N5; + N8 --> N7; + N8 --> N5; ``` # Entrypoints @@ -231,14 +232,11 @@ graph TD # Modules (dev) ## Part 0 ```js -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 4 -}; import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; import "__TURBOPACK_PART__" assert { - __turbopack_part__: 7 + __turbopack_part__: 8 }; "module evaluation"; @@ -246,22 +244,15 @@ import "__TURBOPACK_PART__" assert { ## Part 1 ```js import { order } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 6 -}; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 7 + __turbopack_part__: 8 }; export { order }; -const order = []; -export { order } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` ## Part 2 ```js import { shared } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 6 + __turbopack_part__: 7 }; export { a }; const a = { @@ -276,7 +267,7 @@ export { a } from "__TURBOPACK_VAR__" assert { ## Part 3 ```js import { shared } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 6 + __turbopack_part__: 7 }; export { b }; const b = { @@ -290,7 +281,7 @@ export { b } from "__TURBOPACK_VAR__" assert { ``` ## Part 4 ```js -order.push("a"); +const order = []; export { order } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; @@ -298,21 +289,29 @@ export { order } from "__TURBOPACK_VAR__" assert { ``` ## Part 5 ```js -import "__TURBOPACK_PART__" assert { +import { order } from "__TURBOPACK_PART__" assert { __turbopack_part__: 4 }; -const random = Math.random(); -export { random } from "__TURBOPACK_VAR__" assert { +order.push("a"); +export { order } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; -export { Math } from "__TURBOPACK_VAR__" assert { + +``` +## Part 6 +```js +const random = Math.random(); +export { random } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; ``` -## Part 6 +## Part 7 ```js import { random } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; +import { order } from "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; const shared = { @@ -327,27 +326,27 @@ export { order } from "__TURBOPACK_VAR__" assert { }; ``` -## Part 7 +## Part 8 ```js import { order } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 4 + __turbopack_part__: 7 }; import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; order.push("c"); +export { order } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` ## Merged (module eval) ```js -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 4 -}; import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; import "__TURBOPACK_PART__" assert { - __turbopack_part__: 7 + __turbopack_part__: 8 }; "module evaluation"; @@ -373,14 +372,11 @@ import "__TURBOPACK_PART__" assert { # Modules (prod) ## Part 0 ```js -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 4 -}; import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; import "__TURBOPACK_PART__" assert { - __turbopack_part__: 7 + __turbopack_part__: 8 }; "module evaluation"; @@ -388,22 +384,15 @@ import "__TURBOPACK_PART__" assert { ## Part 1 ```js import { order } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 6 -}; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 7 + __turbopack_part__: 8 }; export { order }; -const order = []; -export { order } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` ## Part 2 ```js import { shared } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 6 + __turbopack_part__: 7 }; export { a }; const a = { @@ -418,7 +407,7 @@ export { a } from "__TURBOPACK_VAR__" assert { ## Part 3 ```js import { shared } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 6 + __turbopack_part__: 7 }; export { b }; const b = { @@ -432,7 +421,7 @@ export { b } from "__TURBOPACK_VAR__" assert { ``` ## Part 4 ```js -order.push("a"); +const order = []; export { order } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; @@ -440,21 +429,29 @@ export { order } from "__TURBOPACK_VAR__" assert { ``` ## Part 5 ```js -import "__TURBOPACK_PART__" assert { +import { order } from "__TURBOPACK_PART__" assert { __turbopack_part__: 4 }; -const random = Math.random(); -export { random } from "__TURBOPACK_VAR__" assert { +order.push("a"); +export { order } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; -export { Math } from "__TURBOPACK_VAR__" assert { + +``` +## Part 6 +```js +const random = Math.random(); +export { random } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; ``` -## Part 6 +## Part 7 ```js import { random } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; +import { order } from "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; const shared = { @@ -469,27 +466,27 @@ export { order } from "__TURBOPACK_VAR__" assert { }; ``` -## Part 7 +## Part 8 ```js import { order } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 4 + __turbopack_part__: 7 }; import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; order.push("c"); +export { order } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` ## Merged (module eval) ```js -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 4 -}; import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; import "__TURBOPACK_PART__" assert { - __turbopack_part__: 7 + __turbopack_part__: 8 }; "module evaluation"; diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/output.md index d051d8b61270e..e593712c926a4 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/output.md @@ -10,7 +10,6 @@ console.log("Hello"); ``` - Side effects -- Write: `console` ## Item 2: Stmt 1, `VarDeclarator(0)` @@ -31,9 +30,8 @@ const value2 = externalObject.propertyWithGetter; ``` -- Side effects - Declares: `value2` -- Write: `value2`, `externalObject` +- Write: `value2` ## Item 4: Stmt 3, `Normal` @@ -42,8 +40,6 @@ externalObject.propertyWithSetter = 42; ``` -- Side effects -- Write: `externalObject` ## Item 5: Stmt 4, `VarDeclarator(0)` @@ -81,7 +77,6 @@ console.log(shared); - Side effects - Reads: `shared` -- Write: `console` ## Item 8: Stmt 7, `VarDeclarator(0)` @@ -149,23 +144,14 @@ graph TD Item12; Item12["export b"]; Item2 --> Item1; - Item3 --> Item1; - Item3 --> Item2; - Item4 --> Item1; - Item4 --> Item2; - Item4 --> Item3; Item5 --> Item1; Item5 --> Item2; - Item5 --> Item3; - Item5 --> Item4; Item6 --> Item2; Item6 --> Item3; Item6 --> Item5; Item7 --> Item6; Item7 --> Item1; Item7 --> Item2; - Item7 --> Item3; - Item7 --> Item4; Item7 --> Item5; Item8 --> Item6; Item9 --> Item6; @@ -189,23 +175,14 @@ graph TD Item12; Item12["export b"]; Item2 --> Item1; - Item3 --> Item1; - Item3 --> Item2; - Item4 --> Item1; - Item4 --> Item2; - Item4 --> Item3; Item5 --> Item1; Item5 --> Item2; - Item5 --> Item3; - Item5 --> Item4; Item6 --> Item2; Item6 --> Item3; Item6 --> Item5; Item7 --> Item6; Item7 --> Item1; Item7 --> Item2; - Item7 --> Item3; - Item7 --> Item4; Item7 --> Item5; Item8 --> Item6; Item9 --> Item6; @@ -229,30 +206,19 @@ graph TD Item12; Item12["export b"]; Item2 --> Item1; - Item3 --> Item1; - Item3 --> Item2; - Item4 --> Item1; - Item4 --> Item2; - Item4 --> Item3; Item5 --> Item1; Item5 --> Item2; - Item5 --> Item3; - Item5 --> Item4; Item6 --> Item2; Item6 --> Item3; Item6 --> Item5; Item7 --> Item6; Item7 --> Item1; Item7 --> Item2; - Item7 --> Item3; - Item7 --> Item4; Item7 --> Item5; Item8 --> Item6; Item9 --> Item6; Item10 --> Item1; Item10 --> Item2; - Item10 --> Item3; - Item10 --> Item4; Item10 --> Item5; Item10 --> Item7; Item11 --> Item8; @@ -267,30 +233,20 @@ graph TD N3["Items: [ItemId(0, Normal)]"]; N4["Items: [ItemId(1, VarDeclarator(0))]"]; N5["Items: [ItemId(2, VarDeclarator(0))]"]; - N6["Items: [ItemId(3, Normal)]"]; - N7["Items: [ItemId(4, VarDeclarator(0))]"]; - N8["Items: [ItemId(5, VarDeclarator(0))]"]; + N6["Items: [ItemId(4, VarDeclarator(0))]"]; + N7["Items: [ItemId(5, VarDeclarator(0))]"]; N0 --> N3; N0 --> N4; - N0 --> N5; N0 --> N6; N0 --> N7; - N0 --> N8; - N1 --> N8; - N2 --> N8; + N1 --> N7; + N2 --> N7; N4 --> N3; - N5 --> N3; - N5 --> N4; N6 --> N3; N6 --> N4; - N6 --> N5; - N7 --> N3; N7 --> N4; N7 --> N5; N7 --> N6; - N8 --> N4; - N8 --> N5; - N8 --> N7; ``` # Entrypoints @@ -310,23 +266,17 @@ graph TD # Modules (dev) ## Part 0 ```js -import { console } from "__TURBOPACK_PART__" assert { +import "__TURBOPACK_PART__" assert { __turbopack_part__: 3 }; import "__TURBOPACK_PART__" assert { __turbopack_part__: 4 }; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 5 -}; import "__TURBOPACK_PART__" assert { __turbopack_part__: 6 }; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 7 -}; import { shared } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 8 + __turbopack_part__: 7 }; "module evaluation"; console.log(shared); @@ -335,7 +285,7 @@ console.log(shared); ## Part 1 ```js import { shared } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 8 + __turbopack_part__: 7 }; export { a }; const a = { @@ -350,7 +300,7 @@ export { a } from "__TURBOPACK_VAR__" assert { ## Part 2 ```js import { shared } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 8 + __turbopack_part__: 7 }; export { b }; const b = { @@ -365,9 +315,6 @@ export { b } from "__TURBOPACK_VAR__" assert { ## Part 3 ```js console.log("Hello"); -export { console } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` ## Part 4 @@ -383,19 +330,10 @@ export { value } from "__TURBOPACK_VAR__" assert { ``` ## Part 5 ```js -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 3 -}; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 4 -}; const value2 = externalObject.propertyWithGetter; export { value2 } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; -export { externalObject } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` ## Part 6 @@ -406,33 +344,13 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 4 }; -import { externalObject } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 5 -}; -externalObject.propertyWithSetter = 42; - -``` -## Part 7 -```js -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 3 -}; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 4 -}; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 5 -}; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 6 -}; const value3 = externalFunction(); export { value3 } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; ``` -## Part 8 +## Part 7 ```js import { value } from "__TURBOPACK_PART__" assert { __turbopack_part__: 4 @@ -441,7 +359,7 @@ import { value2 } from "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; import { value3 } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 7 + __turbopack_part__: 6 }; const shared = { value, @@ -455,23 +373,17 @@ export { shared } from "__TURBOPACK_VAR__" assert { ``` ## Merged (module eval) ```js -import { console } from "__TURBOPACK_PART__" assert { +import "__TURBOPACK_PART__" assert { __turbopack_part__: 3 }; import "__TURBOPACK_PART__" assert { __turbopack_part__: 4 }; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 5 -}; import "__TURBOPACK_PART__" assert { __turbopack_part__: 6 }; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 7 -}; import { shared } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 8 + __turbopack_part__: 7 }; "module evaluation"; console.log(shared); @@ -495,23 +407,17 @@ console.log(shared); # Modules (prod) ## Part 0 ```js -import { console } from "__TURBOPACK_PART__" assert { +import "__TURBOPACK_PART__" assert { __turbopack_part__: 3 }; import "__TURBOPACK_PART__" assert { __turbopack_part__: 4 }; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 5 -}; import "__TURBOPACK_PART__" assert { __turbopack_part__: 6 }; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 7 -}; import { shared } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 8 + __turbopack_part__: 7 }; "module evaluation"; console.log(shared); @@ -520,7 +426,7 @@ console.log(shared); ## Part 1 ```js import { shared } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 8 + __turbopack_part__: 7 }; export { a }; const a = { @@ -535,7 +441,7 @@ export { a } from "__TURBOPACK_VAR__" assert { ## Part 2 ```js import { shared } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 8 + __turbopack_part__: 7 }; export { b }; const b = { @@ -550,9 +456,6 @@ export { b } from "__TURBOPACK_VAR__" assert { ## Part 3 ```js console.log("Hello"); -export { console } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` ## Part 4 @@ -568,19 +471,10 @@ export { value } from "__TURBOPACK_VAR__" assert { ``` ## Part 5 ```js -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 3 -}; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 4 -}; const value2 = externalObject.propertyWithGetter; export { value2 } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; -export { externalObject } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` ## Part 6 @@ -591,33 +485,13 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 4 }; -import { externalObject } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 5 -}; -externalObject.propertyWithSetter = 42; - -``` -## Part 7 -```js -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 3 -}; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 4 -}; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 5 -}; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 6 -}; const value3 = externalFunction(); export { value3 } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; ``` -## Part 8 +## Part 7 ```js import { value } from "__TURBOPACK_PART__" assert { __turbopack_part__: 4 @@ -626,7 +500,7 @@ import { value2 } from "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; import { value3 } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 7 + __turbopack_part__: 6 }; const shared = { value, @@ -640,23 +514,17 @@ export { shared } from "__TURBOPACK_VAR__" assert { ``` ## Merged (module eval) ```js -import { console } from "__TURBOPACK_PART__" assert { +import "__TURBOPACK_PART__" assert { __turbopack_part__: 3 }; import "__TURBOPACK_PART__" assert { __turbopack_part__: 4 }; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 5 -}; import "__TURBOPACK_PART__" assert { __turbopack_part__: 6 }; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 7 -}; import { shared } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 8 + __turbopack_part__: 7 }; "module evaluation"; console.log(shared); diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/template-pages/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/template-pages/output.md index c370c47876f5a..14e41fb23f247 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/template-pages/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/template-pages/output.md @@ -265,7 +265,7 @@ export const routeModule = new PagesRouteModule({ ``` - Declares: `routeModule` -- Reads: `PagesRouteModule`, `App`, `Document`, `userland` +- Reads: `PagesRouteModule`, `RouteKind`, `App`, `Document`, `userland` - Write: `routeModule`, `RouteKind` # Phase 1 @@ -434,6 +434,7 @@ graph TD Item23 --> Item9; Item23 --> Item12; Item24 --> Item7; + Item24 --> Item8; Item24 --> Item11; Item24 --> Item10; Item24 --> Item12; @@ -535,6 +536,7 @@ graph TD Item23 --> Item9; Item23 --> Item12; Item24 --> Item7; + Item24 --> Item8; Item24 --> Item11; Item24 --> Item10; Item24 --> Item12; @@ -636,6 +638,7 @@ graph TD Item23 --> Item9; Item23 --> Item12; Item24 --> Item7; + Item24 --> Item8; Item24 --> Item11; Item24 --> Item10; Item24 --> Item12; @@ -674,7 +677,7 @@ graph TD N9["Items: [ItemId(Export(("unstable_getStaticParams", #2), "unstable_getStaticParams")), ItemId(2, ImportBinding(0)), ItemId(5, ImportBinding(0)), ItemId(14, VarDeclarator(0))]"]; N10["Items: [ItemId(Export(("unstable_getServerProps", #2), "unstable_getServerProps")), ItemId(2, ImportBinding(0)), ItemId(5, ImportBinding(0)), ItemId(15, VarDeclarator(0))]"]; N11["Items: [ItemId(Export(("unstable_getServerSideProps", #2), "unstable_getServerSideProps")), ItemId(2, ImportBinding(0)), ItemId(5, ImportBinding(0)), ItemId(16, VarDeclarator(0))]"]; - N12["Items: [ItemId(Export(("routeModule", #2), "routeModule")), ItemId(0, ImportBinding(0)), ItemId(3, ImportBinding(0)), ItemId(4, ImportBinding(0)), ItemId(5, ImportBinding(0)), ItemId(17, VarDeclarator(0))]"]; + N12["Items: [ItemId(Export(("routeModule", #2), "routeModule")), ItemId(0, ImportBinding(0)), ItemId(1, ImportBinding(0)), ItemId(3, ImportBinding(0)), ItemId(4, ImportBinding(0)), ItemId(5, ImportBinding(0)), ItemId(17, VarDeclarator(0))]"]; N13["Items: [ItemId(0, ImportOfModule)]"]; N14["Items: [ItemId(1, ImportOfModule)]"]; N15["Items: [ItemId(2, ImportOfModule)]"]; @@ -950,6 +953,7 @@ import "__TURBOPACK_PART__" assert { }; export { routeModule }; import { PagesRouteModule } from '../../server/future/route-modules/pages/module.compiled'; +import { RouteKind } from '../../server/future/route-kind'; import Document from 'VAR_MODULE_DOCUMENT'; import App from 'VAR_MODULE_APP'; import * as userland from 'VAR_USERLAND'; @@ -1331,6 +1335,7 @@ import "__TURBOPACK_PART__" assert { }; export { routeModule }; import { PagesRouteModule } from '../../server/future/route-modules/pages/module.compiled'; +import { RouteKind } from '../../server/future/route-kind'; import Document from 'VAR_MODULE_DOCUMENT'; import App from 'VAR_MODULE_APP'; import * as userland from 'VAR_USERLAND'; diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/test-config-1/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/test-config-1/output.md index c9b62c19098c1..1530453c6b408 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/test-config-1/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/test-config-1/output.md @@ -93,7 +93,6 @@ console.log(foobarCopy); - Side effects - Reads: `foobarCopy` -- Write: `console` ## Item 10: Stmt 8, `Normal` @@ -399,9 +398,6 @@ import "__TURBOPACK_PART__" assert { import "module"; import { upper } from "module"; console.log(foobarCopy); -export { console } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` ## Part 1 @@ -561,9 +557,6 @@ import "module"; import { upper } from "module"; "module evaluation"; console.log(foobarCopy); -export { console } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` # Entrypoints @@ -600,9 +593,6 @@ console.log(foobarCopy); export { foobarCopy } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; -export { console } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` ## Part 1 @@ -710,9 +700,6 @@ console.log(foobarCopy); export { foobarCopy } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; -export { console } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` # Entrypoints diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/tla-1/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/tla-1/output.md index 72fa65938ce2c..1303a9b07f86a 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/tla-1/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/tla-1/output.md @@ -10,7 +10,6 @@ await Promise.resolve(); ``` - Side effects -- Write: `Promise` ## Item 2: Stmt 1, `VarDeclarator(0)` @@ -33,6 +32,7 @@ export function effect(name) { - Hoisted - Declares: `effect` +- Reads (eventual): `effects` - Write: `effect` - Write (eventual): `effects` @@ -74,6 +74,7 @@ graph TD Item5["export effects"]; Item6; Item6["export effect"]; + Item3 --> Item2; ``` # Phase 4 ```mermaid @@ -87,6 +88,7 @@ graph TD Item5["export effects"]; Item6; Item6["export effect"]; + Item3 --> Item2; Item4 --> Item1; Item5 --> Item2; Item6 --> Item3; @@ -95,8 +97,11 @@ graph TD ```mermaid graph TD N0["Items: [ItemId(ModuleEvaluation), ItemId(0, Normal)]"]; - N1["Items: [ItemId(Export(("effects", #2), "effects")), ItemId(1, VarDeclarator(0))]"]; + N1["Items: [ItemId(Export(("effects", #2), "effects"))]"]; N2["Items: [ItemId(Export(("effect", #2), "effect")), ItemId(2, Normal)]"]; + N3["Items: [ItemId(1, VarDeclarator(0))]"]; + N1 --> N3; + N2 --> N3; ``` # Entrypoints @@ -118,22 +123,21 @@ graph TD ```js "module evaluation"; await Promise.resolve(); -export { Promise } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` ## Part 1 ```js -export { effects }; -const effects = []; -export { effects } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true +import { effects } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 }; +export { effects }; ``` ## Part 2 ```js +import { effects } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; export { effect }; function effect(name) { effects.push(name); @@ -142,14 +146,19 @@ export { effect } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; +``` +## Part 3 +```js +const effects = []; +export { effects } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + ``` ## Merged (module eval) ```js "module evaluation"; await Promise.resolve(); -export { Promise } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` # Entrypoints @@ -172,22 +181,21 @@ export { Promise } from "__TURBOPACK_VAR__" assert { ```js "module evaluation"; await Promise.resolve(); -export { Promise } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` ## Part 1 ```js -export { effects }; -const effects = []; -export { effects } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true +import { effects } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 }; +export { effects }; ``` ## Part 2 ```js +import { effects } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; export { effect }; function effect(name) { effects.push(name); @@ -196,13 +204,18 @@ export { effect } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; +``` +## Part 3 +```js +const effects = []; +export { effects } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; + ``` ## Merged (module eval) ```js "module evaluation"; await Promise.resolve(); -export { Promise } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/write-order/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/write-order/output.md index 4cbfb25396ff9..13cbcb532f335 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/write-order/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/write-order/output.md @@ -23,6 +23,7 @@ export function func() { - Hoisted - Declares: `func` +- Reads (eventual): `order` - Write: `func` - Write (eventual): `order` @@ -34,6 +35,7 @@ order.push("a"); ``` - Side effects +- Reads: `order` - Write: `order` ## Item 4: Stmt 3, `VarDeclarator(0)` @@ -70,6 +72,7 @@ export const shared = { ``` - Declares: `shared` +- Reads: `order` - Write: `shared`, `order` ## Item 7: Stmt 6, `Normal` @@ -80,6 +83,7 @@ order.push("c"); ``` - Side effects +- Reads: `order` - Write: `order` # Phase 1 @@ -119,17 +123,15 @@ graph TD Item10["export func"]; Item11; Item11["export shared"]; - Item3 -.-> Item1; + Item3 --> Item1; Item4 --> Item3; - Item4 -.-> Item1; Item5 --> Item3; Item5 --> Item4; - Item5 -.-> Item1; + Item6 --> Item3; + Item7 --> Item6; Item7 --> Item3; Item7 --> Item4; Item7 --> Item5; - Item7 -.-> Item1; - Item7 -.-> Item6; ``` # Phase 3 ```mermaid @@ -149,17 +151,16 @@ graph TD Item10["export func"]; Item11; Item11["export shared"]; - Item3 -.-> Item1; + Item3 --> Item1; Item4 --> Item3; - Item4 -.-> Item1; Item5 --> Item3; Item5 --> Item4; - Item5 -.-> Item1; + Item6 --> Item3; + Item7 --> Item6; Item7 --> Item3; Item7 --> Item4; Item7 --> Item5; - Item7 -.-> Item1; - Item7 -.-> Item6; + Item2 --> Item7; ``` # Phase 4 ```mermaid @@ -179,23 +180,20 @@ graph TD Item10["export func"]; Item11; Item11["export shared"]; - Item3 -.-> Item1; + Item3 --> Item1; Item4 --> Item3; - Item4 -.-> Item1; Item5 --> Item3; Item5 --> Item4; - Item5 -.-> Item1; + Item6 --> Item3; + Item7 --> Item6; Item7 --> Item3; Item7 --> Item4; Item7 --> Item5; - Item7 -.-> Item1; - Item7 -.-> Item6; + Item2 --> Item7; Item8 --> Item3; Item8 --> Item4; Item8 --> Item5; Item8 --> Item7; - Item9 --> Item1; - Item9 --> Item6; Item9 --> Item7; Item10 --> Item2; Item11 --> Item6; @@ -217,21 +215,18 @@ graph TD N0 --> N6; N0 --> N7; N0 --> N9; - N1 --> N4; - N1 --> N8; N1 --> N9; + N2 --> N9; N3 --> N8; N5 --> N4; N6 --> N5; - N6 --> N4; N7 --> N5; N7 --> N6; - N7 --> N4; + N8 --> N5; + N9 --> N8; N9 --> N5; N9 --> N6; N9 --> N7; - N9 --> N4; - N9 --> N8; ``` # Entrypoints @@ -272,12 +267,6 @@ import "__TURBOPACK_PART__" assert { ## Part 1 ```js import { order } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 4 -}; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 8 -}; -import "__TURBOPACK_PART__" assert { __turbopack_part__: 9 }; export { order }; @@ -285,6 +274,9 @@ export { order }; ``` ## Part 2 ```js +import { order } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; export { func }; function func() { order.push("d"); @@ -316,6 +308,9 @@ import { order } from "__TURBOPACK_PART__" assert { __turbopack_part__: 4 }; order.push("a"); +export { order } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` ## Part 6 @@ -323,9 +318,6 @@ order.push("a"); import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 4 -}; const x1 = externalFunction(); export { x1 } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true @@ -340,9 +332,6 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 6 }; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 4 -}; const x2 = externalFunction(); export { x2 } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true @@ -351,6 +340,9 @@ export { x2 } from "__TURBOPACK_VAR__" assert { ``` ## Part 8 ```js +import { order } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; const shared = { effect: order.push("b") }; @@ -365,6 +357,9 @@ export { order } from "__TURBOPACK_VAR__" assert { ## Part 9 ```js import { order } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; +import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; import "__TURBOPACK_PART__" assert { @@ -373,13 +368,10 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 7 }; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 4 -}; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 8 -}; order.push("c"); +export { order } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` ## Merged (module eval) @@ -420,9 +412,6 @@ import "__TURBOPACK_PART__" assert { # Modules (prod) ## Part 0 ```js -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 4 -}; import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; @@ -430,7 +419,10 @@ import "__TURBOPACK_PART__" assert { __turbopack_part__: 6 }; import "__TURBOPACK_PART__" assert { - __turbopack_part__: 8 + __turbopack_part__: 7 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 }; "module evaluation"; @@ -438,20 +430,16 @@ import "__TURBOPACK_PART__" assert { ## Part 1 ```js import { order } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 7 -}; -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 8 + __turbopack_part__: 9 }; export { order }; -const order = []; -export { order } from "__TURBOPACK_VAR__" assert { - __turbopack_var__: true -}; ``` ## Part 2 ```js +import { order } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; export { func }; function func() { order.push("d"); @@ -464,14 +452,14 @@ export { func } from "__TURBOPACK_VAR__" assert { ## Part 3 ```js import { shared } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 7 + __turbopack_part__: 8 }; export { shared }; ``` ## Part 4 ```js -order.push("a"); +const order = []; export { order } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; @@ -479,11 +467,11 @@ export { order } from "__TURBOPACK_VAR__" assert { ``` ## Part 5 ```js -import "__TURBOPACK_PART__" assert { +import { order } from "__TURBOPACK_PART__" assert { __turbopack_part__: 4 }; -const x1 = externalFunction(); -export { x1 } from "__TURBOPACK_VAR__" assert { +order.push("a"); +export { order } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; @@ -491,19 +479,33 @@ export { x1 } from "__TURBOPACK_VAR__" assert { ## Part 6 ```js import "__TURBOPACK_PART__" assert { - __turbopack_part__: 4 + __turbopack_part__: 5 +}; +const x1 = externalFunction(); +export { x1 } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true }; + +``` +## Part 7 +```js import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; const x2 = externalFunction(); export { x2 } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; ``` -## Part 7 +## Part 8 ```js +import { order } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; const shared = { effect: order.push("b") }; @@ -515,10 +517,10 @@ export { order } from "__TURBOPACK_VAR__" assert { }; ``` -## Part 8 +## Part 9 ```js import { order } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 4 + __turbopack_part__: 8 }; import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 @@ -526,14 +528,17 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 6 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 7 +}; order.push("c"); +export { order } from "__TURBOPACK_VAR__" assert { + __turbopack_var__: true +}; ``` ## Merged (module eval) ```js -import "__TURBOPACK_PART__" assert { - __turbopack_part__: 4 -}; import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; @@ -541,7 +546,10 @@ import "__TURBOPACK_PART__" assert { __turbopack_part__: 6 }; import "__TURBOPACK_PART__" assert { - __turbopack_part__: 8 + __turbopack_part__: 7 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 }; "module evaluation"; From b9bbbfa678865112de603ae7501aa6662ee010c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Mon, 10 Jun 2024 18:25:21 +0900 Subject: [PATCH 14/23] Update test refs --- ...ot_basic-tree-shake_export-namespace_input_b8c6d3._.js | 8 +++++++- ...asic-tree-shake_export-namespace_input_b8c6d3._.js.map | 8 ++++---- ...ot_basic-tree-shake_import-namespace_input_66459d._.js | 5 ++++- ...asic-tree-shake_import-namespace_input_66459d._.js.map | 8 ++++---- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/crates/turbopack-tests/tests/snapshot/basic-tree-shake/export-namespace/output/79fb1_turbopack-tests_tests_snapshot_basic-tree-shake_export-namespace_input_b8c6d3._.js b/crates/turbopack-tests/tests/snapshot/basic-tree-shake/export-namespace/output/79fb1_turbopack-tests_tests_snapshot_basic-tree-shake_export-namespace_input_b8c6d3._.js index 9127fa1befccc..c15a56152aa43 100644 --- a/crates/turbopack-tests/tests/snapshot/basic-tree-shake/export-namespace/output/79fb1_turbopack-tests_tests_snapshot_basic-tree-shake_export-namespace_input_b8c6d3._.js +++ b/crates/turbopack-tests/tests/snapshot/basic-tree-shake/export-namespace/output/79fb1_turbopack-tests_tests_snapshot_basic-tree-shake_export-namespace_input_b8c6d3._.js @@ -239,7 +239,12 @@ var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests "[project]/crates/turbopack-tests/tests/snapshot/basic-tree-shake/export-namespace/input/index.js [test] (ecmascript) ": (({ r: __turbopack_require__, f: __turbopack_module_context__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, n: __turbopack_export_namespace__, c: __turbopack_cache__, M: __turbopack_modules__, l: __turbopack_load__, j: __turbopack_dynamic__, P: __turbopack_resolve_absolute_path__, U: __turbopack_relative_url__, R: __turbopack_resolve_module_id_path__, g: global, __dirname }) => (() => { "use strict"; -__turbopack_esm__({}); +__turbopack_esm__({ + "lib": [ + ()=>__TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$basic$2d$tree$2d$shake$2f$export$2d$namespace$2f$input$2f$module$2e$js__$5b$test$5d$__$28$ecmascript$29$__$3c$export__lib$3e$__["lib"], + (v)=>$expr = v + ] +}); var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$basic$2d$tree$2d$shake$2f$export$2d$namespace$2f$input$2f$module$2e$js__$5b$test$5d$__$28$ecmascript$29$__$3c$module__evaluation$3e$__ = __turbopack_import__("[project]/crates/turbopack-tests/tests/snapshot/basic-tree-shake/export-namespace/input/module.js [test] (ecmascript) "); var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$basic$2d$tree$2d$shake$2f$export$2d$namespace$2f$input$2f$module$2e$js__$5b$test$5d$__$28$ecmascript$29$__$3c$export__lib$3e$__ = __turbopack_import__("[project]/crates/turbopack-tests/tests/snapshot/basic-tree-shake/export-namespace/input/module.js [test] (ecmascript) "); "__TURBOPACK__ecmascript__hoisting__location__"; @@ -247,6 +252,7 @@ var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests ; ; console.log(__TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$basic$2d$tree$2d$shake$2f$export$2d$namespace$2f$input$2f$module$2e$js__$5b$test$5d$__$28$ecmascript$29$__$3c$export__lib$3e$__["lib"].cat); +; })()), "[project]/crates/turbopack-tests/tests/snapshot/basic-tree-shake/export-namespace/input/index.js [test] (ecmascript) ": (({ r: __turbopack_require__, f: __turbopack_module_context__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, n: __turbopack_export_namespace__, c: __turbopack_cache__, M: __turbopack_modules__, l: __turbopack_load__, j: __turbopack_dynamic__, P: __turbopack_resolve_absolute_path__, U: __turbopack_relative_url__, R: __turbopack_resolve_module_id_path__, g: global, __dirname }) => (() => { diff --git a/crates/turbopack-tests/tests/snapshot/basic-tree-shake/export-namespace/output/79fb1_turbopack-tests_tests_snapshot_basic-tree-shake_export-namespace_input_b8c6d3._.js.map b/crates/turbopack-tests/tests/snapshot/basic-tree-shake/export-namespace/output/79fb1_turbopack-tests_tests_snapshot_basic-tree-shake_export-namespace_input_b8c6d3._.js.map index 2acbe6be5743a..b07be5d60c241 100644 --- a/crates/turbopack-tests/tests/snapshot/basic-tree-shake/export-namespace/output/79fb1_turbopack-tests_tests_snapshot_basic-tree-shake_export-namespace_input_b8c6d3._.js.map +++ b/crates/turbopack-tests/tests/snapshot/basic-tree-shake/export-namespace/output/79fb1_turbopack-tests_tests_snapshot_basic-tree-shake_export-namespace_input_b8c6d3._.js.map @@ -30,8 +30,8 @@ {"offset": {"line": 223, "column": 0}, "map": {"version":3,"sources":[],"names":[],"mappings":"A"}}, {"offset": {"line": 228, "column": 0}, "map": {"version":3,"sources":[],"names":[],"mappings":""}}, {"offset": {"line": 236, "column": 0}, "map": {"version":3,"sources":[],"names":[],"mappings":"A"}}, - {"offset": {"line": 241, "column": 0}, "map": {"version":3,"sources":["turbopack://[project]/crates/turbopack-tests/tests/snapshot/basic-tree-shake/export-namespace/input/index.js"],"sourcesContent":["import {lib} from './module'\n\nconsole.log(lib.cat)\n"],"names":[],"mappings":";;;;;;;AAEA,QAAQ,GAAG,CAAC,oOAAA,CAAA,MAAG,CAAC,GAAG"}}, - {"offset": {"line": 249, "column": 0}, "map": {"version":3,"sources":[],"names":[],"mappings":"A"}}, - {"offset": {"line": 254, "column": 0}, "map": {"version":3,"sources":[],"names":[],"mappings":""}}, - {"offset": {"line": 259, "column": 0}, "map": {"version":3,"sources":[],"names":[],"mappings":"A"}}] + {"offset": {"line": 241, "column": 0}, "map": {"version":3,"sources":["turbopack://[project]/crates/turbopack-tests/tests/snapshot/basic-tree-shake/export-namespace/input/index.js"],"sourcesContent":["import {lib} from './module'\n\nconsole.log(lib.cat)\n"],"names":[],"mappings":";;;;;;;;;;;;AAEA,QAAQ,GAAG,CAAC,oOAAA,CAAA,MAAG,CAAC,GAAG"}}, + {"offset": {"line": 255, "column": 0}, "map": {"version":3,"sources":[],"names":[],"mappings":"A"}}, + {"offset": {"line": 260, "column": 0}, "map": {"version":3,"sources":[],"names":[],"mappings":""}}, + {"offset": {"line": 265, "column": 0}, "map": {"version":3,"sources":[],"names":[],"mappings":"A"}}] } \ No newline at end of file diff --git a/crates/turbopack-tests/tests/snapshot/basic-tree-shake/import-namespace/output/79fb1_turbopack-tests_tests_snapshot_basic-tree-shake_import-namespace_input_66459d._.js b/crates/turbopack-tests/tests/snapshot/basic-tree-shake/import-namespace/output/79fb1_turbopack-tests_tests_snapshot_basic-tree-shake_import-namespace_input_66459d._.js index 586a085aaf639..14444d876882d 100644 --- a/crates/turbopack-tests/tests/snapshot/basic-tree-shake/import-namespace/output/79fb1_turbopack-tests_tests_snapshot_basic-tree-shake_import-namespace_input_66459d._.js +++ b/crates/turbopack-tests/tests/snapshot/basic-tree-shake/import-namespace/output/79fb1_turbopack-tests_tests_snapshot_basic-tree-shake_import-namespace_input_66459d._.js @@ -217,7 +217,9 @@ var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests "[project]/crates/turbopack-tests/tests/snapshot/basic-tree-shake/import-namespace/input/index.js [test] (ecmascript) ": (({ r: __turbopack_require__, f: __turbopack_module_context__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, n: __turbopack_export_namespace__, c: __turbopack_cache__, M: __turbopack_modules__, l: __turbopack_load__, j: __turbopack_dynamic__, P: __turbopack_resolve_absolute_path__, U: __turbopack_relative_url__, R: __turbopack_resolve_module_id_path__, g: global, __dirname }) => (() => { "use strict"; -__turbopack_esm__({}); +__turbopack_esm__({ + "lib": ()=>__TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$basic$2d$tree$2d$shake$2f$import$2d$namespace$2f$input$2f$lib$2e$js__$5b$test$5d$__$28$ecmascript$29$__$3c$facade$3e$__ +}); var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$basic$2d$tree$2d$shake$2f$import$2d$namespace$2f$input$2f$lib$2e$js__$5b$test$5d$__$28$ecmascript$29$__$3c$module__evaluation$3e$__ = __turbopack_import__("[project]/crates/turbopack-tests/tests/snapshot/basic-tree-shake/import-namespace/input/lib.js [test] (ecmascript) "); var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$basic$2d$tree$2d$shake$2f$import$2d$namespace$2f$input$2f$lib$2e$js__$5b$test$5d$__$28$ecmascript$29$__$3c$facade$3e$__ = __turbopack_import__("[project]/crates/turbopack-tests/tests/snapshot/basic-tree-shake/import-namespace/input/lib.js [test] (ecmascript) "); "__TURBOPACK__ecmascript__hoisting__location__"; @@ -225,6 +227,7 @@ var __TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests ; ; console.log(__TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$basic$2d$tree$2d$shake$2f$import$2d$namespace$2f$input$2f$lib$2e$js__$5b$test$5d$__$28$ecmascript$29$__$3c$facade$3e$__.cat); +; })()), "[project]/crates/turbopack-tests/tests/snapshot/basic-tree-shake/import-namespace/input/index.js [test] (ecmascript) ": (({ r: __turbopack_require__, f: __turbopack_module_context__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, n: __turbopack_export_namespace__, c: __turbopack_cache__, M: __turbopack_modules__, l: __turbopack_load__, j: __turbopack_dynamic__, P: __turbopack_resolve_absolute_path__, U: __turbopack_relative_url__, R: __turbopack_resolve_module_id_path__, g: global, __dirname }) => (() => { diff --git a/crates/turbopack-tests/tests/snapshot/basic-tree-shake/import-namespace/output/79fb1_turbopack-tests_tests_snapshot_basic-tree-shake_import-namespace_input_66459d._.js.map b/crates/turbopack-tests/tests/snapshot/basic-tree-shake/import-namespace/output/79fb1_turbopack-tests_tests_snapshot_basic-tree-shake_import-namespace_input_66459d._.js.map index 457f75f4443cd..9654e0f6e3f4d 100644 --- a/crates/turbopack-tests/tests/snapshot/basic-tree-shake/import-namespace/output/79fb1_turbopack-tests_tests_snapshot_basic-tree-shake_import-namespace_input_66459d._.js.map +++ b/crates/turbopack-tests/tests/snapshot/basic-tree-shake/import-namespace/output/79fb1_turbopack-tests_tests_snapshot_basic-tree-shake_import-namespace_input_66459d._.js.map @@ -26,8 +26,8 @@ {"offset": {"line": 198, "column": 0}, "map": {"version":3,"sources":[],"names":[],"mappings":"A"}}, {"offset": {"line": 203, "column": 0}, "map": {"version":3,"sources":[],"names":[],"mappings":""}}, {"offset": {"line": 214, "column": 0}, "map": {"version":3,"sources":[],"names":[],"mappings":"A"}}, - {"offset": {"line": 219, "column": 0}, "map": {"version":3,"sources":["turbopack://[project]/crates/turbopack-tests/tests/snapshot/basic-tree-shake/import-namespace/input/index.js"],"sourcesContent":["import * as lib from './lib'\n\nconsole.log(lib.cat)\n"],"names":[],"mappings":";;;;;;;AAEA,QAAQ,GAAG,CAAC,6NAAI,GAAG"}}, - {"offset": {"line": 227, "column": 0}, "map": {"version":3,"sources":[],"names":[],"mappings":"A"}}, - {"offset": {"line": 232, "column": 0}, "map": {"version":3,"sources":[],"names":[],"mappings":""}}, - {"offset": {"line": 237, "column": 0}, "map": {"version":3,"sources":[],"names":[],"mappings":"A"}}] + {"offset": {"line": 219, "column": 0}, "map": {"version":3,"sources":["turbopack://[project]/crates/turbopack-tests/tests/snapshot/basic-tree-shake/import-namespace/input/index.js"],"sourcesContent":["import * as lib from './lib'\n\nconsole.log(lib.cat)\n"],"names":[],"mappings":";;;;;;;;;AAEA,QAAQ,GAAG,CAAC,6NAAI,GAAG"}}, + {"offset": {"line": 230, "column": 0}, "map": {"version":3,"sources":[],"names":[],"mappings":"A"}}, + {"offset": {"line": 235, "column": 0}, "map": {"version":3,"sources":[],"names":[],"mappings":""}}, + {"offset": {"line": 240, "column": 0}, "map": {"version":3,"sources":[],"names":[],"mappings":"A"}}] } \ No newline at end of file From 9326e1c9fefcce4df4da95185ce4f70e2861885e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Mon, 10 Jun 2024 18:26:48 +0900 Subject: [PATCH 15/23] visit_member_prop --- crates/turbopack-ecmascript/src/tree_shake/util.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/turbopack-ecmascript/src/tree_shake/util.rs b/crates/turbopack-ecmascript/src/tree_shake/util.rs index e4967d47672e2..60249f5c8a941 100644 --- a/crates/turbopack-ecmascript/src/tree_shake/util.rs +++ b/crates/turbopack-ecmascript/src/tree_shake/util.rs @@ -260,6 +260,12 @@ impl Visit for CapturedIdCollector { e.prop.visit_with(self); } + fn visit_member_prop(&mut self, n: &MemberProp) { + if let MemberProp::Computed(..) = n { + n.visit_children_with(self); + } + } + fn visit_pat(&mut self, p: &Pat) { self.with_mode(Some(Mode::Write), |this| { p.visit_children_with(this); From 4de570d34e91f4ab167f36a124af298fae93098f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Mon, 10 Jun 2024 18:27:17 +0900 Subject: [PATCH 16/23] Update test refs --- .../tests/tree-shaker/analyzer/failed-3/output.md | 5 ++--- .../tests/tree-shaker/analyzer/ipc-evaluate/output.md | 2 +- .../tests/tree-shaker/analyzer/ipc-index/output.md | 5 ++--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-3/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-3/output.md index 4c4044f21de55..ade1f8ab37a11 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-3/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-3/output.md @@ -250,7 +250,7 @@ process.on("uncaughtException", (err)=>{ ``` - Side effects -- Reads (eventual): `IPC`, `sendError` +- Reads (eventual): `IPC` - Write (eventual): `IPC` ## Item 12: Stmt 8, `VarDeclarator(0)` @@ -274,9 +274,8 @@ const improveConsole = (name, stream, addStack)=>{ ``` - Declares: `improveConsole` -- Reads (eventual): `write`, `Error`, `stack`, `replace` +- Reads (eventual): `Error` - Write: `improveConsole` -- Write (eventual): `stack` ## Item 13: Stmt 9, `Normal` diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-evaluate/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-evaluate/output.md index 67d8e4ab8afc7..b2bdeb61bcd13 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-evaluate/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-evaluate/output.md @@ -141,7 +141,7 @@ export const run = async (moduleFactory)=>{ ``` - Declares: `run` -- Reads (eventual): `Map`, `ipc`, `send`, `Promise`, `set`, `then`, `sendError`, `init`, `default`, `sendReady`, `queue`, `length`, `shift`, `undefined`, `stringify`, `recv`, `type`, `push`, `args`, `get`, `id`, `delete`, `error`, `reject`, `Error`, `resolve`, `data`, `exit` +- Reads (eventual): `Map`, `ipc`, `Promise`, `queue`, `undefined`, `Error` - Write: `run` - Write (eventual): `ipc`, `queue` diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-index/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-index/output.md index 4c4044f21de55..ade1f8ab37a11 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-index/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-index/output.md @@ -250,7 +250,7 @@ process.on("uncaughtException", (err)=>{ ``` - Side effects -- Reads (eventual): `IPC`, `sendError` +- Reads (eventual): `IPC` - Write (eventual): `IPC` ## Item 12: Stmt 8, `VarDeclarator(0)` @@ -274,9 +274,8 @@ const improveConsole = (name, stream, addStack)=>{ ``` - Declares: `improveConsole` -- Reads (eventual): `write`, `Error`, `stack`, `replace` +- Reads (eventual): `Error` - Write: `improveConsole` -- Write (eventual): `stack` ## Item 13: Stmt 9, `Normal` From 08aa8b3c02d09aed92c85347c5ce1b4bcb9b00fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Mon, 10 Jun 2024 21:16:57 +0900 Subject: [PATCH 17/23] vars.found_unresolved --- .../src/tree_shake/graph.rs | 6 +---- .../src/tree_shake/util.rs | 26 ++++++++++--------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/crates/turbopack-ecmascript/src/tree_shake/graph.rs b/crates/turbopack-ecmascript/src/tree_shake/graph.rs index a5a3db2e20314..9d89cc35ba714 100644 --- a/crates/turbopack-ecmascript/src/tree_shake/graph.rs +++ b/crates/turbopack-ecmascript/src/tree_shake/graph.rs @@ -943,11 +943,7 @@ impl DepGraph { let eventual_vars = ids_captured_by(&decl.init, unresolved_ctxt, top_level_ctxt); - let side_effects = vars - .read - .iter() - .chain(vars.write.iter()) - .any(|id| id.1 == unresolved_ctxt); + let side_effects = vars.found_unresolved; let var_decl = Box::new(VarDecl { decls: vec![decl.clone()], diff --git a/crates/turbopack-ecmascript/src/tree_shake/util.rs b/crates/turbopack-ecmascript/src/tree_shake/util.rs index 60249f5c8a941..be3d42082b599 100644 --- a/crates/turbopack-ecmascript/src/tree_shake/util.rs +++ b/crates/turbopack-ecmascript/src/tree_shake/util.rs @@ -88,12 +88,14 @@ impl Visit for IdentUsageCollector { } fn visit_ident(&mut self, n: &Ident) { + if n.span.ctxt == self.unresolved { + self.vars.found_unresolved = true; + return; + } + // We allow SyntaxContext::empty() because Some built-in files do not go into // resolver() - if n.span.ctxt != self.unresolved - && n.span.ctxt != self.top_level - && n.span.ctxt != SyntaxContext::empty() - { + if n.span.ctxt != self.top_level && n.span.ctxt != SyntaxContext::empty() { return; } @@ -224,12 +226,14 @@ impl Visit for CapturedIdCollector { return; } + if n.span.ctxt == self.unresolved { + self.vars.found_unresolved = true; + return; + } + // We allow SyntaxContext::empty() because Some built-in files do not go into // resolver() - if n.span.ctxt != self.unresolved - && n.span.ctxt != self.top_level - && n.span.ctxt != SyntaxContext::empty() - { + if n.span.ctxt != self.top_level && n.span.ctxt != SyntaxContext::empty() { return; } @@ -241,10 +245,6 @@ impl Visit for CapturedIdCollector { self.vars.write.insert(n.to_id()); } None => { - // Ignore calls like console.log() - if n.span.ctxt == self.unresolved { - return; - } self.vars.read.insert(n.to_id()); self.vars.write.insert(n.to_id()); } @@ -288,6 +288,8 @@ pub(crate) struct Vars { pub read: IndexSet>, /// Variables which are written. pub write: IndexSet>, + + pub found_unresolved: bool, } /// Returns `(read, write)` From 89b3bdf3e4b4aa4d6019ced9974b230f3688cb89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Mon, 10 Jun 2024 21:17:28 +0900 Subject: [PATCH 18/23] Update test refs --- .../tree-shaker/analyzer/app-route/output.md | 2 +- .../tree-shaker/analyzer/failed-1/output.md | 3 +- .../tree-shaker/analyzer/failed-2/output.md | 8 +- .../tree-shaker/analyzer/failed-3/output.md | 126 +++++++++++++++++- .../analyzer/ipc-evaluate/output.md | 2 +- .../tree-shaker/analyzer/ipc-index/output.md | 126 +++++++++++++++++- .../tree-shaker/analyzer/shared-2/output.md | 35 +++++ .../shared-and-side-effects/output.md | 50 ++++++- .../analyzer/write-order/output.md | 2 - 9 files changed, 334 insertions(+), 20 deletions(-) diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/app-route/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/app-route/output.md index 74211b626cae8..274c48e394ca7 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/app-route/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/app-route/output.md @@ -102,7 +102,7 @@ const routeModule = new AppRouteRouteModule({ - Side effects - Declares: `routeModule` -- Reads: `AppRouteRouteModule`, `RouteKind`, `nextConfigOutput`, `userland` +- Reads: `AppRouteRouteModule`, `RouteKind`, `userland` - Write: `routeModule`, `RouteKind` ## Item 10: Stmt 5, `VarDeclarator(0)` diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-1/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-1/output.md index 17ce0fa61a14c..a3258db90ac52 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-1/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-1/output.md @@ -37,7 +37,6 @@ function getSocketProtocol(assetPrefix) { - Hoisted - Declares: `getSocketProtocol` -- Reads (eventual): `URL` - Write: `getSocketProtocol` ## Item 4: Stmt 3, `Normal` @@ -120,7 +119,7 @@ export function connectHMR(options) { - Hoisted - Declares: `connectHMR` -- Reads (eventual): `source`, `eventCallbacks`, `setTimeout`, `location`, `getSocketProtocol` +- Reads (eventual): `source`, `eventCallbacks`, `getSocketProtocol` - Write: `connectHMR` - Write (eventual): `source`, `eventCallbacks` diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-2/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-2/output.md index dd6f52b236744..4c5bf993d6932 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-2/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-2/output.md @@ -164,7 +164,7 @@ export function trackDynamicDataAccessed(store, expression) { - Hoisted - Declares: `trackDynamicDataAccessed` -- Reads (eventual): `getPathname`, `Error`, `StaticGenBailoutError`, `postponeWithTracking`, `DynamicServerError` +- Reads (eventual): `getPathname`, `StaticGenBailoutError`, `postponeWithTracking`, `DynamicServerError` - Write: `trackDynamicDataAccessed` ## Item 13: Stmt 8, `Normal` @@ -213,7 +213,7 @@ function postponeWithTracking(prerenderState, expression, pathname) { - Hoisted - Declares: `postponeWithTracking` -- Reads (eventual): `assertPostpone`, `Error`, `undefined`, `React` +- Reads (eventual): `assertPostpone`, `React` - Write: `postponeWithTracking` - Write (eventual): `React` @@ -270,7 +270,7 @@ function assertPostpone() { - Hoisted - Declares: `assertPostpone` -- Reads (eventual): `hasPostpone`, `Error` +- Reads (eventual): `hasPostpone` - Write: `assertPostpone` ## Item 19: Stmt 14, `Normal` @@ -291,7 +291,7 @@ export function createPostponedAbortSignal(reason) { - Hoisted - Declares: `createPostponedAbortSignal` -- Reads (eventual): `assertPostpone`, `AbortController`, `React` +- Reads (eventual): `assertPostpone`, `React` - Write: `createPostponedAbortSignal` - Write (eventual): `React` diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-3/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-3/output.md index ade1f8ab37a11..824cc244e1042 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-3/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/failed-3/output.md @@ -215,7 +215,7 @@ function createIpc(port) { - Hoisted - Declares: `createIpc` -- Reads (eventual): `createConnection`, `loop`, `Promise`, `structuredError` +- Reads (eventual): `createConnection`, `loop`, `structuredError` - Write: `createIpc` ## Item 9: Stmt 5, `VarDeclarator(0)` @@ -225,6 +225,7 @@ const PORT = process.argv[2]; ``` +- Side effects - Declares: `PORT` - Write: `PORT` @@ -237,7 +238,7 @@ export const IPC = createIpc(parseInt(PORT, 10)); - Side effects - Declares: `IPC` -- Reads: `createIpc`, `parseInt`, `PORT` +- Reads: `createIpc`, `PORT` - Write: `IPC` ## Item 11: Stmt 7, `Normal` @@ -274,7 +275,6 @@ const improveConsole = (name, stream, addStack)=>{ ``` - Declares: `improveConsole` -- Reads (eventual): `Error` - Write: `improveConsole` ## Item 13: Stmt 9, `Normal` @@ -518,6 +518,13 @@ graph TD Item2 --> Item1; Item3 --> Item1; Item3 --> Item2; + Item9 --> Item1; + Item9 --> Item2; + Item9 --> Item3; + Item9 -.-> Item6; + Item9 -.-> Item5; + Item9 -.-> Item4; + Item9 -.-> Item7; Item10 --> Item8; Item10 --> Item9; Item10 --> Item1; @@ -530,6 +537,7 @@ graph TD Item11 --> Item1; Item11 --> Item2; Item11 --> Item3; + Item11 --> Item9; Item11 --> Item10; Item11 -.-> Item6; Item11 -.-> Item5; @@ -539,6 +547,7 @@ graph TD Item13 --> Item1; Item13 --> Item2; Item13 --> Item3; + Item13 --> Item9; Item13 --> Item10; Item13 --> Item11; Item13 -.-> Item6; @@ -549,6 +558,7 @@ graph TD Item14 --> Item1; Item14 --> Item2; Item14 --> Item3; + Item14 --> Item9; Item14 --> Item10; Item14 --> Item11; Item14 --> Item13; @@ -560,6 +570,7 @@ graph TD Item15 --> Item1; Item15 --> Item2; Item15 --> Item3; + Item15 --> Item9; Item15 --> Item10; Item15 --> Item11; Item15 --> Item13; @@ -572,6 +583,7 @@ graph TD Item16 --> Item1; Item16 --> Item2; Item16 --> Item3; + Item16 --> Item9; Item16 --> Item10; Item16 --> Item11; Item16 --> Item13; @@ -585,6 +597,7 @@ graph TD Item17 --> Item1; Item17 --> Item2; Item17 --> Item3; + Item17 --> Item9; Item17 --> Item10; Item17 --> Item11; Item17 --> Item13; @@ -599,6 +612,7 @@ graph TD Item18 --> Item1; Item18 --> Item2; Item18 --> Item3; + Item18 --> Item9; Item18 --> Item10; Item18 --> Item11; Item18 --> Item13; @@ -614,6 +628,7 @@ graph TD Item19 --> Item1; Item19 --> Item2; Item19 --> Item3; + Item19 --> Item9; Item19 --> Item10; Item19 --> Item11; Item19 --> Item13; @@ -630,6 +645,7 @@ graph TD Item20 --> Item1; Item20 --> Item2; Item20 --> Item3; + Item20 --> Item9; Item20 --> Item10; Item20 --> Item11; Item20 --> Item13; @@ -647,6 +663,7 @@ graph TD Item21 --> Item1; Item21 --> Item2; Item21 --> Item3; + Item21 --> Item9; Item21 --> Item10; Item21 --> Item11; Item21 --> Item13; @@ -665,6 +682,7 @@ graph TD Item22 --> Item1; Item22 --> Item2; Item22 --> Item3; + Item22 --> Item9; Item22 --> Item10; Item22 --> Item11; Item22 --> Item13; @@ -684,6 +702,7 @@ graph TD Item23 --> Item1; Item23 --> Item2; Item23 --> Item3; + Item23 --> Item9; Item23 --> Item10; Item23 --> Item11; Item23 --> Item13; @@ -704,6 +723,7 @@ graph TD Item24 --> Item1; Item24 --> Item2; Item24 --> Item3; + Item24 --> Item9; Item24 --> Item10; Item24 --> Item11; Item24 --> Item13; @@ -725,6 +745,7 @@ graph TD Item25 --> Item1; Item25 --> Item2; Item25 --> Item3; + Item25 --> Item9; Item25 --> Item10; Item25 --> Item11; Item25 --> Item13; @@ -747,6 +768,7 @@ graph TD Item26 --> Item1; Item26 --> Item2; Item26 --> Item3; + Item26 --> Item9; Item26 --> Item10; Item26 --> Item11; Item26 --> Item13; @@ -770,6 +792,7 @@ graph TD Item27 --> Item1; Item27 --> Item2; Item27 --> Item3; + Item27 --> Item9; Item27 --> Item10; Item27 --> Item11; Item27 --> Item13; @@ -794,6 +817,7 @@ graph TD Item28 --> Item1; Item28 --> Item2; Item28 --> Item3; + Item28 --> Item9; Item28 --> Item10; Item28 --> Item11; Item28 --> Item13; @@ -856,6 +880,13 @@ graph TD Item2 --> Item1; Item3 --> Item1; Item3 --> Item2; + Item9 --> Item1; + Item9 --> Item2; + Item9 --> Item3; + Item9 -.-> Item6; + Item9 -.-> Item5; + Item9 -.-> Item4; + Item9 -.-> Item7; Item10 --> Item8; Item10 --> Item9; Item10 --> Item1; @@ -868,6 +899,7 @@ graph TD Item11 --> Item1; Item11 --> Item2; Item11 --> Item3; + Item11 --> Item9; Item11 --> Item10; Item11 -.-> Item6; Item11 -.-> Item5; @@ -877,6 +909,7 @@ graph TD Item13 --> Item1; Item13 --> Item2; Item13 --> Item3; + Item13 --> Item9; Item13 --> Item10; Item13 --> Item11; Item13 -.-> Item6; @@ -887,6 +920,7 @@ graph TD Item14 --> Item1; Item14 --> Item2; Item14 --> Item3; + Item14 --> Item9; Item14 --> Item10; Item14 --> Item11; Item14 --> Item13; @@ -898,6 +932,7 @@ graph TD Item15 --> Item1; Item15 --> Item2; Item15 --> Item3; + Item15 --> Item9; Item15 --> Item10; Item15 --> Item11; Item15 --> Item13; @@ -910,6 +945,7 @@ graph TD Item16 --> Item1; Item16 --> Item2; Item16 --> Item3; + Item16 --> Item9; Item16 --> Item10; Item16 --> Item11; Item16 --> Item13; @@ -923,6 +959,7 @@ graph TD Item17 --> Item1; Item17 --> Item2; Item17 --> Item3; + Item17 --> Item9; Item17 --> Item10; Item17 --> Item11; Item17 --> Item13; @@ -937,6 +974,7 @@ graph TD Item18 --> Item1; Item18 --> Item2; Item18 --> Item3; + Item18 --> Item9; Item18 --> Item10; Item18 --> Item11; Item18 --> Item13; @@ -952,6 +990,7 @@ graph TD Item19 --> Item1; Item19 --> Item2; Item19 --> Item3; + Item19 --> Item9; Item19 --> Item10; Item19 --> Item11; Item19 --> Item13; @@ -968,6 +1007,7 @@ graph TD Item20 --> Item1; Item20 --> Item2; Item20 --> Item3; + Item20 --> Item9; Item20 --> Item10; Item20 --> Item11; Item20 --> Item13; @@ -985,6 +1025,7 @@ graph TD Item21 --> Item1; Item21 --> Item2; Item21 --> Item3; + Item21 --> Item9; Item21 --> Item10; Item21 --> Item11; Item21 --> Item13; @@ -1003,6 +1044,7 @@ graph TD Item22 --> Item1; Item22 --> Item2; Item22 --> Item3; + Item22 --> Item9; Item22 --> Item10; Item22 --> Item11; Item22 --> Item13; @@ -1022,6 +1064,7 @@ graph TD Item23 --> Item1; Item23 --> Item2; Item23 --> Item3; + Item23 --> Item9; Item23 --> Item10; Item23 --> Item11; Item23 --> Item13; @@ -1042,6 +1085,7 @@ graph TD Item24 --> Item1; Item24 --> Item2; Item24 --> Item3; + Item24 --> Item9; Item24 --> Item10; Item24 --> Item11; Item24 --> Item13; @@ -1063,6 +1107,7 @@ graph TD Item25 --> Item1; Item25 --> Item2; Item25 --> Item3; + Item25 --> Item9; Item25 --> Item10; Item25 --> Item11; Item25 --> Item13; @@ -1085,6 +1130,7 @@ graph TD Item26 --> Item1; Item26 --> Item2; Item26 --> Item3; + Item26 --> Item9; Item26 --> Item10; Item26 --> Item11; Item26 --> Item13; @@ -1108,6 +1154,7 @@ graph TD Item27 --> Item1; Item27 --> Item2; Item27 --> Item3; + Item27 --> Item9; Item27 --> Item10; Item27 --> Item11; Item27 --> Item13; @@ -1132,6 +1179,7 @@ graph TD Item28 --> Item1; Item28 --> Item2; Item28 --> Item3; + Item28 --> Item9; Item28 --> Item10; Item28 --> Item11; Item28 --> Item13; @@ -1198,6 +1246,13 @@ graph TD Item2 --> Item1; Item3 --> Item1; Item3 --> Item2; + Item9 --> Item1; + Item9 --> Item2; + Item9 --> Item3; + Item9 -.-> Item6; + Item9 -.-> Item5; + Item9 -.-> Item4; + Item9 -.-> Item7; Item10 --> Item8; Item10 --> Item9; Item10 --> Item1; @@ -1210,6 +1265,7 @@ graph TD Item11 --> Item1; Item11 --> Item2; Item11 --> Item3; + Item11 --> Item9; Item11 --> Item10; Item11 -.-> Item6; Item11 -.-> Item5; @@ -1219,6 +1275,7 @@ graph TD Item13 --> Item1; Item13 --> Item2; Item13 --> Item3; + Item13 --> Item9; Item13 --> Item10; Item13 --> Item11; Item13 -.-> Item6; @@ -1229,6 +1286,7 @@ graph TD Item14 --> Item1; Item14 --> Item2; Item14 --> Item3; + Item14 --> Item9; Item14 --> Item10; Item14 --> Item11; Item14 --> Item13; @@ -1240,6 +1298,7 @@ graph TD Item15 --> Item1; Item15 --> Item2; Item15 --> Item3; + Item15 --> Item9; Item15 --> Item10; Item15 --> Item11; Item15 --> Item13; @@ -1252,6 +1311,7 @@ graph TD Item16 --> Item1; Item16 --> Item2; Item16 --> Item3; + Item16 --> Item9; Item16 --> Item10; Item16 --> Item11; Item16 --> Item13; @@ -1265,6 +1325,7 @@ graph TD Item17 --> Item1; Item17 --> Item2; Item17 --> Item3; + Item17 --> Item9; Item17 --> Item10; Item17 --> Item11; Item17 --> Item13; @@ -1279,6 +1340,7 @@ graph TD Item18 --> Item1; Item18 --> Item2; Item18 --> Item3; + Item18 --> Item9; Item18 --> Item10; Item18 --> Item11; Item18 --> Item13; @@ -1294,6 +1356,7 @@ graph TD Item19 --> Item1; Item19 --> Item2; Item19 --> Item3; + Item19 --> Item9; Item19 --> Item10; Item19 --> Item11; Item19 --> Item13; @@ -1310,6 +1373,7 @@ graph TD Item20 --> Item1; Item20 --> Item2; Item20 --> Item3; + Item20 --> Item9; Item20 --> Item10; Item20 --> Item11; Item20 --> Item13; @@ -1327,6 +1391,7 @@ graph TD Item21 --> Item1; Item21 --> Item2; Item21 --> Item3; + Item21 --> Item9; Item21 --> Item10; Item21 --> Item11; Item21 --> Item13; @@ -1345,6 +1410,7 @@ graph TD Item22 --> Item1; Item22 --> Item2; Item22 --> Item3; + Item22 --> Item9; Item22 --> Item10; Item22 --> Item11; Item22 --> Item13; @@ -1364,6 +1430,7 @@ graph TD Item23 --> Item1; Item23 --> Item2; Item23 --> Item3; + Item23 --> Item9; Item23 --> Item10; Item23 --> Item11; Item23 --> Item13; @@ -1384,6 +1451,7 @@ graph TD Item24 --> Item1; Item24 --> Item2; Item24 --> Item3; + Item24 --> Item9; Item24 --> Item10; Item24 --> Item11; Item24 --> Item13; @@ -1405,6 +1473,7 @@ graph TD Item25 --> Item1; Item25 --> Item2; Item25 --> Item3; + Item25 --> Item9; Item25 --> Item10; Item25 --> Item11; Item25 --> Item13; @@ -1427,6 +1496,7 @@ graph TD Item26 --> Item1; Item26 --> Item2; Item26 --> Item3; + Item26 --> Item9; Item26 --> Item10; Item26 --> Item11; Item26 --> Item13; @@ -1450,6 +1520,7 @@ graph TD Item27 --> Item1; Item27 --> Item2; Item27 --> Item3; + Item27 --> Item9; Item27 --> Item10; Item27 --> Item11; Item27 --> Item13; @@ -1474,6 +1545,7 @@ graph TD Item28 --> Item1; Item28 --> Item2; Item28 --> Item3; + Item28 --> Item9; Item28 --> Item10; Item28 --> Item11; Item28 --> Item13; @@ -1502,6 +1574,7 @@ graph TD Item29 --> Item1; Item29 --> Item2; Item29 --> Item3; + Item29 --> Item9; Item29 --> Item10; Item29 --> Item11; Item29 --> Item13; @@ -1534,11 +1607,12 @@ graph TD N5["Items: [ItemId(2, ImportOfModule)]"]; N6["Items: [ItemId(1, ImportBinding(0)), ItemId(2, ImportBinding(0)), ItemId(3, Normal)]"]; N7["Items: [ItemId(0, ImportBinding(0)), ItemId(4, Normal)]"]; - N8["Items: [ItemId(5, VarDeclarator(0))]"]; + N8["Items: [ItemId(0, ImportBinding(0)), ItemId(1, ImportBinding(0)), ItemId(2, ImportBinding(0)), ItemId(5, VarDeclarator(0))]"]; N9["Items: [ItemId(0, ImportBinding(0)), ItemId(1, ImportBinding(0)), ItemId(2, ImportBinding(0)), ItemId(6, VarDeclarator(0))]"]; N0 --> N3; N0 --> N4; N0 --> N5; + N0 --> N8; N0 --> N9; N0 --> N6; N1 --> N6; @@ -1549,6 +1623,11 @@ graph TD N6 --> N9; N7 --> N9; N7 --> N6; + N8 --> N3; + N8 --> N4; + N8 --> N5; + N8 --> N9; + N8 --> N6; N9 --> N7; N9 --> N8; N9 --> N3; @@ -1583,6 +1662,9 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; import { IPC } from "__TURBOPACK_PART__" assert { __turbopack_part__: 9 }; @@ -1833,6 +1915,24 @@ export { createIpc } from "__TURBOPACK_VAR__" assert { ``` ## Part 8 ```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; +import { createConnection } from "node:net"; +import { parse as parseStackTrace } from "../compiled/stacktrace-parser"; +import { getProperError } from "./error"; const PORT = process.argv[2]; export { PORT } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true @@ -1879,6 +1979,9 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; import { IPC } from "__TURBOPACK_PART__" assert { __turbopack_part__: 9 }; @@ -1954,6 +2057,9 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; import { IPC } from "__TURBOPACK_PART__" assert { __turbopack_part__: 9 }; @@ -2192,6 +2298,15 @@ export { createIpc } from "__TURBOPACK_VAR__" assert { ``` ## Part 8 ```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; const PORT = process.argv[2]; export { PORT } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true @@ -2232,6 +2347,9 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; import { IPC } from "__TURBOPACK_PART__" assert { __turbopack_part__: 9 }; diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-evaluate/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-evaluate/output.md index b2bdeb61bcd13..59c53ec2487d4 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-evaluate/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-evaluate/output.md @@ -141,7 +141,7 @@ export const run = async (moduleFactory)=>{ ``` - Declares: `run` -- Reads (eventual): `Map`, `ipc`, `Promise`, `queue`, `undefined`, `Error` +- Reads (eventual): `ipc`, `queue` - Write: `run` - Write (eventual): `ipc`, `queue` diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-index/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-index/output.md index ade1f8ab37a11..824cc244e1042 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-index/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/ipc-index/output.md @@ -215,7 +215,7 @@ function createIpc(port) { - Hoisted - Declares: `createIpc` -- Reads (eventual): `createConnection`, `loop`, `Promise`, `structuredError` +- Reads (eventual): `createConnection`, `loop`, `structuredError` - Write: `createIpc` ## Item 9: Stmt 5, `VarDeclarator(0)` @@ -225,6 +225,7 @@ const PORT = process.argv[2]; ``` +- Side effects - Declares: `PORT` - Write: `PORT` @@ -237,7 +238,7 @@ export const IPC = createIpc(parseInt(PORT, 10)); - Side effects - Declares: `IPC` -- Reads: `createIpc`, `parseInt`, `PORT` +- Reads: `createIpc`, `PORT` - Write: `IPC` ## Item 11: Stmt 7, `Normal` @@ -274,7 +275,6 @@ const improveConsole = (name, stream, addStack)=>{ ``` - Declares: `improveConsole` -- Reads (eventual): `Error` - Write: `improveConsole` ## Item 13: Stmt 9, `Normal` @@ -518,6 +518,13 @@ graph TD Item2 --> Item1; Item3 --> Item1; Item3 --> Item2; + Item9 --> Item1; + Item9 --> Item2; + Item9 --> Item3; + Item9 -.-> Item6; + Item9 -.-> Item5; + Item9 -.-> Item4; + Item9 -.-> Item7; Item10 --> Item8; Item10 --> Item9; Item10 --> Item1; @@ -530,6 +537,7 @@ graph TD Item11 --> Item1; Item11 --> Item2; Item11 --> Item3; + Item11 --> Item9; Item11 --> Item10; Item11 -.-> Item6; Item11 -.-> Item5; @@ -539,6 +547,7 @@ graph TD Item13 --> Item1; Item13 --> Item2; Item13 --> Item3; + Item13 --> Item9; Item13 --> Item10; Item13 --> Item11; Item13 -.-> Item6; @@ -549,6 +558,7 @@ graph TD Item14 --> Item1; Item14 --> Item2; Item14 --> Item3; + Item14 --> Item9; Item14 --> Item10; Item14 --> Item11; Item14 --> Item13; @@ -560,6 +570,7 @@ graph TD Item15 --> Item1; Item15 --> Item2; Item15 --> Item3; + Item15 --> Item9; Item15 --> Item10; Item15 --> Item11; Item15 --> Item13; @@ -572,6 +583,7 @@ graph TD Item16 --> Item1; Item16 --> Item2; Item16 --> Item3; + Item16 --> Item9; Item16 --> Item10; Item16 --> Item11; Item16 --> Item13; @@ -585,6 +597,7 @@ graph TD Item17 --> Item1; Item17 --> Item2; Item17 --> Item3; + Item17 --> Item9; Item17 --> Item10; Item17 --> Item11; Item17 --> Item13; @@ -599,6 +612,7 @@ graph TD Item18 --> Item1; Item18 --> Item2; Item18 --> Item3; + Item18 --> Item9; Item18 --> Item10; Item18 --> Item11; Item18 --> Item13; @@ -614,6 +628,7 @@ graph TD Item19 --> Item1; Item19 --> Item2; Item19 --> Item3; + Item19 --> Item9; Item19 --> Item10; Item19 --> Item11; Item19 --> Item13; @@ -630,6 +645,7 @@ graph TD Item20 --> Item1; Item20 --> Item2; Item20 --> Item3; + Item20 --> Item9; Item20 --> Item10; Item20 --> Item11; Item20 --> Item13; @@ -647,6 +663,7 @@ graph TD Item21 --> Item1; Item21 --> Item2; Item21 --> Item3; + Item21 --> Item9; Item21 --> Item10; Item21 --> Item11; Item21 --> Item13; @@ -665,6 +682,7 @@ graph TD Item22 --> Item1; Item22 --> Item2; Item22 --> Item3; + Item22 --> Item9; Item22 --> Item10; Item22 --> Item11; Item22 --> Item13; @@ -684,6 +702,7 @@ graph TD Item23 --> Item1; Item23 --> Item2; Item23 --> Item3; + Item23 --> Item9; Item23 --> Item10; Item23 --> Item11; Item23 --> Item13; @@ -704,6 +723,7 @@ graph TD Item24 --> Item1; Item24 --> Item2; Item24 --> Item3; + Item24 --> Item9; Item24 --> Item10; Item24 --> Item11; Item24 --> Item13; @@ -725,6 +745,7 @@ graph TD Item25 --> Item1; Item25 --> Item2; Item25 --> Item3; + Item25 --> Item9; Item25 --> Item10; Item25 --> Item11; Item25 --> Item13; @@ -747,6 +768,7 @@ graph TD Item26 --> Item1; Item26 --> Item2; Item26 --> Item3; + Item26 --> Item9; Item26 --> Item10; Item26 --> Item11; Item26 --> Item13; @@ -770,6 +792,7 @@ graph TD Item27 --> Item1; Item27 --> Item2; Item27 --> Item3; + Item27 --> Item9; Item27 --> Item10; Item27 --> Item11; Item27 --> Item13; @@ -794,6 +817,7 @@ graph TD Item28 --> Item1; Item28 --> Item2; Item28 --> Item3; + Item28 --> Item9; Item28 --> Item10; Item28 --> Item11; Item28 --> Item13; @@ -856,6 +880,13 @@ graph TD Item2 --> Item1; Item3 --> Item1; Item3 --> Item2; + Item9 --> Item1; + Item9 --> Item2; + Item9 --> Item3; + Item9 -.-> Item6; + Item9 -.-> Item5; + Item9 -.-> Item4; + Item9 -.-> Item7; Item10 --> Item8; Item10 --> Item9; Item10 --> Item1; @@ -868,6 +899,7 @@ graph TD Item11 --> Item1; Item11 --> Item2; Item11 --> Item3; + Item11 --> Item9; Item11 --> Item10; Item11 -.-> Item6; Item11 -.-> Item5; @@ -877,6 +909,7 @@ graph TD Item13 --> Item1; Item13 --> Item2; Item13 --> Item3; + Item13 --> Item9; Item13 --> Item10; Item13 --> Item11; Item13 -.-> Item6; @@ -887,6 +920,7 @@ graph TD Item14 --> Item1; Item14 --> Item2; Item14 --> Item3; + Item14 --> Item9; Item14 --> Item10; Item14 --> Item11; Item14 --> Item13; @@ -898,6 +932,7 @@ graph TD Item15 --> Item1; Item15 --> Item2; Item15 --> Item3; + Item15 --> Item9; Item15 --> Item10; Item15 --> Item11; Item15 --> Item13; @@ -910,6 +945,7 @@ graph TD Item16 --> Item1; Item16 --> Item2; Item16 --> Item3; + Item16 --> Item9; Item16 --> Item10; Item16 --> Item11; Item16 --> Item13; @@ -923,6 +959,7 @@ graph TD Item17 --> Item1; Item17 --> Item2; Item17 --> Item3; + Item17 --> Item9; Item17 --> Item10; Item17 --> Item11; Item17 --> Item13; @@ -937,6 +974,7 @@ graph TD Item18 --> Item1; Item18 --> Item2; Item18 --> Item3; + Item18 --> Item9; Item18 --> Item10; Item18 --> Item11; Item18 --> Item13; @@ -952,6 +990,7 @@ graph TD Item19 --> Item1; Item19 --> Item2; Item19 --> Item3; + Item19 --> Item9; Item19 --> Item10; Item19 --> Item11; Item19 --> Item13; @@ -968,6 +1007,7 @@ graph TD Item20 --> Item1; Item20 --> Item2; Item20 --> Item3; + Item20 --> Item9; Item20 --> Item10; Item20 --> Item11; Item20 --> Item13; @@ -985,6 +1025,7 @@ graph TD Item21 --> Item1; Item21 --> Item2; Item21 --> Item3; + Item21 --> Item9; Item21 --> Item10; Item21 --> Item11; Item21 --> Item13; @@ -1003,6 +1044,7 @@ graph TD Item22 --> Item1; Item22 --> Item2; Item22 --> Item3; + Item22 --> Item9; Item22 --> Item10; Item22 --> Item11; Item22 --> Item13; @@ -1022,6 +1064,7 @@ graph TD Item23 --> Item1; Item23 --> Item2; Item23 --> Item3; + Item23 --> Item9; Item23 --> Item10; Item23 --> Item11; Item23 --> Item13; @@ -1042,6 +1085,7 @@ graph TD Item24 --> Item1; Item24 --> Item2; Item24 --> Item3; + Item24 --> Item9; Item24 --> Item10; Item24 --> Item11; Item24 --> Item13; @@ -1063,6 +1107,7 @@ graph TD Item25 --> Item1; Item25 --> Item2; Item25 --> Item3; + Item25 --> Item9; Item25 --> Item10; Item25 --> Item11; Item25 --> Item13; @@ -1085,6 +1130,7 @@ graph TD Item26 --> Item1; Item26 --> Item2; Item26 --> Item3; + Item26 --> Item9; Item26 --> Item10; Item26 --> Item11; Item26 --> Item13; @@ -1108,6 +1154,7 @@ graph TD Item27 --> Item1; Item27 --> Item2; Item27 --> Item3; + Item27 --> Item9; Item27 --> Item10; Item27 --> Item11; Item27 --> Item13; @@ -1132,6 +1179,7 @@ graph TD Item28 --> Item1; Item28 --> Item2; Item28 --> Item3; + Item28 --> Item9; Item28 --> Item10; Item28 --> Item11; Item28 --> Item13; @@ -1198,6 +1246,13 @@ graph TD Item2 --> Item1; Item3 --> Item1; Item3 --> Item2; + Item9 --> Item1; + Item9 --> Item2; + Item9 --> Item3; + Item9 -.-> Item6; + Item9 -.-> Item5; + Item9 -.-> Item4; + Item9 -.-> Item7; Item10 --> Item8; Item10 --> Item9; Item10 --> Item1; @@ -1210,6 +1265,7 @@ graph TD Item11 --> Item1; Item11 --> Item2; Item11 --> Item3; + Item11 --> Item9; Item11 --> Item10; Item11 -.-> Item6; Item11 -.-> Item5; @@ -1219,6 +1275,7 @@ graph TD Item13 --> Item1; Item13 --> Item2; Item13 --> Item3; + Item13 --> Item9; Item13 --> Item10; Item13 --> Item11; Item13 -.-> Item6; @@ -1229,6 +1286,7 @@ graph TD Item14 --> Item1; Item14 --> Item2; Item14 --> Item3; + Item14 --> Item9; Item14 --> Item10; Item14 --> Item11; Item14 --> Item13; @@ -1240,6 +1298,7 @@ graph TD Item15 --> Item1; Item15 --> Item2; Item15 --> Item3; + Item15 --> Item9; Item15 --> Item10; Item15 --> Item11; Item15 --> Item13; @@ -1252,6 +1311,7 @@ graph TD Item16 --> Item1; Item16 --> Item2; Item16 --> Item3; + Item16 --> Item9; Item16 --> Item10; Item16 --> Item11; Item16 --> Item13; @@ -1265,6 +1325,7 @@ graph TD Item17 --> Item1; Item17 --> Item2; Item17 --> Item3; + Item17 --> Item9; Item17 --> Item10; Item17 --> Item11; Item17 --> Item13; @@ -1279,6 +1340,7 @@ graph TD Item18 --> Item1; Item18 --> Item2; Item18 --> Item3; + Item18 --> Item9; Item18 --> Item10; Item18 --> Item11; Item18 --> Item13; @@ -1294,6 +1356,7 @@ graph TD Item19 --> Item1; Item19 --> Item2; Item19 --> Item3; + Item19 --> Item9; Item19 --> Item10; Item19 --> Item11; Item19 --> Item13; @@ -1310,6 +1373,7 @@ graph TD Item20 --> Item1; Item20 --> Item2; Item20 --> Item3; + Item20 --> Item9; Item20 --> Item10; Item20 --> Item11; Item20 --> Item13; @@ -1327,6 +1391,7 @@ graph TD Item21 --> Item1; Item21 --> Item2; Item21 --> Item3; + Item21 --> Item9; Item21 --> Item10; Item21 --> Item11; Item21 --> Item13; @@ -1345,6 +1410,7 @@ graph TD Item22 --> Item1; Item22 --> Item2; Item22 --> Item3; + Item22 --> Item9; Item22 --> Item10; Item22 --> Item11; Item22 --> Item13; @@ -1364,6 +1430,7 @@ graph TD Item23 --> Item1; Item23 --> Item2; Item23 --> Item3; + Item23 --> Item9; Item23 --> Item10; Item23 --> Item11; Item23 --> Item13; @@ -1384,6 +1451,7 @@ graph TD Item24 --> Item1; Item24 --> Item2; Item24 --> Item3; + Item24 --> Item9; Item24 --> Item10; Item24 --> Item11; Item24 --> Item13; @@ -1405,6 +1473,7 @@ graph TD Item25 --> Item1; Item25 --> Item2; Item25 --> Item3; + Item25 --> Item9; Item25 --> Item10; Item25 --> Item11; Item25 --> Item13; @@ -1427,6 +1496,7 @@ graph TD Item26 --> Item1; Item26 --> Item2; Item26 --> Item3; + Item26 --> Item9; Item26 --> Item10; Item26 --> Item11; Item26 --> Item13; @@ -1450,6 +1520,7 @@ graph TD Item27 --> Item1; Item27 --> Item2; Item27 --> Item3; + Item27 --> Item9; Item27 --> Item10; Item27 --> Item11; Item27 --> Item13; @@ -1474,6 +1545,7 @@ graph TD Item28 --> Item1; Item28 --> Item2; Item28 --> Item3; + Item28 --> Item9; Item28 --> Item10; Item28 --> Item11; Item28 --> Item13; @@ -1502,6 +1574,7 @@ graph TD Item29 --> Item1; Item29 --> Item2; Item29 --> Item3; + Item29 --> Item9; Item29 --> Item10; Item29 --> Item11; Item29 --> Item13; @@ -1534,11 +1607,12 @@ graph TD N5["Items: [ItemId(2, ImportOfModule)]"]; N6["Items: [ItemId(1, ImportBinding(0)), ItemId(2, ImportBinding(0)), ItemId(3, Normal)]"]; N7["Items: [ItemId(0, ImportBinding(0)), ItemId(4, Normal)]"]; - N8["Items: [ItemId(5, VarDeclarator(0))]"]; + N8["Items: [ItemId(0, ImportBinding(0)), ItemId(1, ImportBinding(0)), ItemId(2, ImportBinding(0)), ItemId(5, VarDeclarator(0))]"]; N9["Items: [ItemId(0, ImportBinding(0)), ItemId(1, ImportBinding(0)), ItemId(2, ImportBinding(0)), ItemId(6, VarDeclarator(0))]"]; N0 --> N3; N0 --> N4; N0 --> N5; + N0 --> N8; N0 --> N9; N0 --> N6; N1 --> N6; @@ -1549,6 +1623,11 @@ graph TD N6 --> N9; N7 --> N9; N7 --> N6; + N8 --> N3; + N8 --> N4; + N8 --> N5; + N8 --> N9; + N8 --> N6; N9 --> N7; N9 --> N8; N9 --> N3; @@ -1583,6 +1662,9 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; import { IPC } from "__TURBOPACK_PART__" assert { __turbopack_part__: 9 }; @@ -1833,6 +1915,24 @@ export { createIpc } from "__TURBOPACK_VAR__" assert { ``` ## Part 8 ```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 9 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; +import { createConnection } from "node:net"; +import { parse as parseStackTrace } from "../compiled/stacktrace-parser"; +import { getProperError } from "./error"; const PORT = process.argv[2]; export { PORT } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true @@ -1879,6 +1979,9 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; import { IPC } from "__TURBOPACK_PART__" assert { __turbopack_part__: 9 }; @@ -1954,6 +2057,9 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; import { IPC } from "__TURBOPACK_PART__" assert { __turbopack_part__: 9 }; @@ -2192,6 +2298,15 @@ export { createIpc } from "__TURBOPACK_VAR__" assert { ``` ## Part 8 ```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; const PORT = process.argv[2]; export { PORT } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true @@ -2232,6 +2347,9 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; import { IPC } from "__TURBOPACK_PART__" assert { __turbopack_part__: 9 }; diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-2/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-2/output.md index ce4fa59bb1df3..7ba712da2e884 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-2/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-2/output.md @@ -30,6 +30,7 @@ const random = Math.random(); ``` +- Side effects - Declares: `random` - Write: `random` @@ -124,10 +125,12 @@ graph TD Item11; Item11["export b"]; Item2 --> Item1; + Item3 --> Item2; Item4 --> Item3; Item4 --> Item2; Item5 --> Item4; Item5 --> Item2; + Item5 --> Item3; Item6 --> Item4; Item7 --> Item4; ``` @@ -150,10 +153,12 @@ graph TD Item11; Item11["export b"]; Item2 --> Item1; + Item3 --> Item2; Item4 --> Item3; Item4 --> Item2; Item5 --> Item4; Item5 --> Item2; + Item5 --> Item3; Item6 --> Item4; Item7 --> Item4; ``` @@ -176,13 +181,16 @@ graph TD Item11; Item11["export b"]; Item2 --> Item1; + Item3 --> Item2; Item4 --> Item3; Item4 --> Item2; Item5 --> Item4; Item5 --> Item2; + Item5 --> Item3; Item6 --> Item4; Item7 --> Item4; Item8 --> Item2; + Item8 --> Item3; Item8 --> Item5; Item9 --> Item5; Item10 --> Item6; @@ -201,15 +209,18 @@ graph TD N7["Items: [ItemId(3, VarDeclarator(0))]"]; N8["Items: [ItemId(4, Normal)]"]; N0 --> N5; + N0 --> N6; N0 --> N8; N1 --> N8; N2 --> N7; N3 --> N7; N5 --> N4; + N6 --> N5; N7 --> N6; N7 --> N5; N8 --> N7; N8 --> N5; + N8 --> N6; ``` # Entrypoints @@ -235,6 +246,9 @@ graph TD import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; import "__TURBOPACK_PART__" assert { __turbopack_part__: 8 }; @@ -300,6 +314,9 @@ export { order } from "__TURBOPACK_VAR__" assert { ``` ## Part 6 ```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; const random = Math.random(); export { random } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true @@ -334,6 +351,9 @@ import { order } from "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; order.push("c"); export { order } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true @@ -345,6 +365,9 @@ export { order } from "__TURBOPACK_VAR__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; import "__TURBOPACK_PART__" assert { __turbopack_part__: 8 }; @@ -375,6 +398,9 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; import "__TURBOPACK_PART__" assert { __turbopack_part__: 8 }; @@ -440,6 +466,9 @@ export { order } from "__TURBOPACK_VAR__" assert { ``` ## Part 6 ```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; const random = Math.random(); export { random } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true @@ -474,6 +503,9 @@ import { order } from "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; order.push("c"); export { order } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true @@ -485,6 +517,9 @@ export { order } from "__TURBOPACK_VAR__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; import "__TURBOPACK_PART__" assert { __turbopack_part__: 8 }; diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/output.md index e593712c926a4..49b122ce3b60d 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/output.md @@ -20,7 +20,6 @@ const value = externalFunction(); - Side effects - Declares: `value` -- Reads: `externalFunction` - Write: `value` ## Item 3: Stmt 2, `VarDeclarator(0)` @@ -30,6 +29,7 @@ const value2 = externalObject.propertyWithGetter; ``` +- Side effects - Declares: `value2` - Write: `value2` @@ -50,7 +50,6 @@ const value3 = externalFunction(); - Side effects - Declares: `value3` -- Reads: `externalFunction` - Write: `value3` ## Item 6: Stmt 5, `VarDeclarator(0)` @@ -144,14 +143,18 @@ graph TD Item12; Item12["export b"]; Item2 --> Item1; + Item3 --> Item1; + Item3 --> Item2; Item5 --> Item1; Item5 --> Item2; + Item5 --> Item3; Item6 --> Item2; Item6 --> Item3; Item6 --> Item5; Item7 --> Item6; Item7 --> Item1; Item7 --> Item2; + Item7 --> Item3; Item7 --> Item5; Item8 --> Item6; Item9 --> Item6; @@ -175,14 +178,18 @@ graph TD Item12; Item12["export b"]; Item2 --> Item1; + Item3 --> Item1; + Item3 --> Item2; Item5 --> Item1; Item5 --> Item2; + Item5 --> Item3; Item6 --> Item2; Item6 --> Item3; Item6 --> Item5; Item7 --> Item6; Item7 --> Item1; Item7 --> Item2; + Item7 --> Item3; Item7 --> Item5; Item8 --> Item6; Item9 --> Item6; @@ -206,19 +213,24 @@ graph TD Item12; Item12["export b"]; Item2 --> Item1; + Item3 --> Item1; + Item3 --> Item2; Item5 --> Item1; Item5 --> Item2; + Item5 --> Item3; Item6 --> Item2; Item6 --> Item3; Item6 --> Item5; Item7 --> Item6; Item7 --> Item1; Item7 --> Item2; + Item7 --> Item3; Item7 --> Item5; Item8 --> Item6; Item9 --> Item6; Item10 --> Item1; Item10 --> Item2; + Item10 --> Item3; Item10 --> Item5; Item10 --> Item7; Item11 --> Item8; @@ -237,13 +249,17 @@ graph TD N7["Items: [ItemId(5, VarDeclarator(0))]"]; N0 --> N3; N0 --> N4; + N0 --> N5; N0 --> N6; N0 --> N7; N1 --> N7; N2 --> N7; N4 --> N3; + N5 --> N3; + N5 --> N4; N6 --> N3; N6 --> N4; + N6 --> N5; N7 --> N4; N7 --> N5; N7 --> N6; @@ -272,6 +288,9 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 4 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; import "__TURBOPACK_PART__" assert { __turbopack_part__: 6 }; @@ -330,6 +349,12 @@ export { value } from "__TURBOPACK_VAR__" assert { ``` ## Part 5 ```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; const value2 = externalObject.propertyWithGetter; export { value2 } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true @@ -344,6 +369,9 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 4 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; const value3 = externalFunction(); export { value3 } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true @@ -379,6 +407,9 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 4 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; import "__TURBOPACK_PART__" assert { __turbopack_part__: 6 }; @@ -413,6 +444,9 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 4 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; import "__TURBOPACK_PART__" assert { __turbopack_part__: 6 }; @@ -471,6 +505,12 @@ export { value } from "__TURBOPACK_VAR__" assert { ``` ## Part 5 ```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; const value2 = externalObject.propertyWithGetter; export { value2 } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true @@ -485,6 +525,9 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 4 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; const value3 = externalFunction(); export { value3 } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true @@ -520,6 +563,9 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 4 }; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; import "__TURBOPACK_PART__" assert { __turbopack_part__: 6 }; diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/write-order/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/write-order/output.md index 13cbcb532f335..7505a3d1408c0 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/write-order/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/write-order/output.md @@ -47,7 +47,6 @@ const x1 = externalFunction(); - Side effects - Declares: `x1` -- Reads: `externalFunction` - Write: `x1` ## Item 5: Stmt 4, `VarDeclarator(0)` @@ -59,7 +58,6 @@ const x2 = externalFunction(); - Side effects - Declares: `x2` -- Reads: `externalFunction` - Write: `x2` ## Item 6: Stmt 5, `VarDeclarator(0)` From 0bc9de0993f42be4ab6e3fe848927af6841f7aff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Mon, 10 Jun 2024 21:33:03 +0900 Subject: [PATCH 19/23] Merge two visitors --- .../src/tree_shake/util.rs | 182 ++++-------------- 1 file changed, 38 insertions(+), 144 deletions(-) diff --git a/crates/turbopack-ecmascript/src/tree_shake/util.rs b/crates/turbopack-ecmascript/src/tree_shake/util.rs index be3d42082b599..d190ad64280fb 100644 --- a/crates/turbopack-ecmascript/src/tree_shake/util.rs +++ b/crates/turbopack-ecmascript/src/tree_shake/util.rs @@ -20,162 +20,36 @@ enum Mode { Write, } +#[derive(Default)] +struct Target { + direct: bool, + eventual: bool, +} + /// A visitor which collects variables which are read or written. #[derive(Default)] pub(crate) struct IdentUsageCollector { unresolved: SyntaxContext, top_level: SyntaxContext, vars: Vars, - ignore_nested: bool, + + is_nested: bool, + target: Target, /// None means both read and write mode: Option, } impl IdentUsageCollector { - fn with_mode(&mut self, mode: Option, f: impl FnOnce(&mut Self)) { - let old = self.mode; - self.mode = mode; - f(self); - self.mode = old; - } -} - -impl Visit for IdentUsageCollector { - fn visit_assign_target(&mut self, n: &AssignTarget) { - self.with_mode(Some(Mode::Write), |this| { - n.visit_children_with(this); - }) - } - - fn visit_block_stmt_or_expr(&mut self, n: &BlockStmtOrExpr) { - if self.ignore_nested { - return; - } - - n.visit_children_with(self); - } - - fn visit_constructor(&mut self, n: &Constructor) { - if self.ignore_nested { - return; - } - - n.visit_children_with(self); - } - - fn visit_export_named_specifier(&mut self, n: &ExportNamedSpecifier) { - n.orig.visit_with(self); - } - - fn visit_export_specifier(&mut self, n: &ExportSpecifier) { - self.with_mode(Some(Mode::Read), |this| { - n.visit_children_with(this); - }) - } - - fn visit_expr(&mut self, e: &Expr) { - self.with_mode(Some(Mode::Read), |this| { - e.visit_children_with(this); - }) - } - - fn visit_function(&mut self, n: &Function) { - if self.ignore_nested { - return; - } - - n.visit_children_with(self); - } - - fn visit_ident(&mut self, n: &Ident) { - if n.span.ctxt == self.unresolved { - self.vars.found_unresolved = true; - return; - } - - // We allow SyntaxContext::empty() because Some built-in files do not go into - // resolver() - if n.span.ctxt != self.top_level && n.span.ctxt != SyntaxContext::empty() { - return; - } - - match self.mode { - Some(Mode::Read) => { - self.vars.read.insert(n.to_id()); - } - Some(Mode::Write) => { - self.vars.write.insert(n.to_id()); - } - None => { - // Ignore calls like console.log() - if n.span.ctxt == self.unresolved { - return; - } - self.vars.read.insert(n.to_id()); - self.vars.write.insert(n.to_id()); - } - } - } - - fn visit_member_expr(&mut self, e: &MemberExpr) { - self.with_mode(None, |this| { - // Skip visit_expr - e.obj.visit_children_with(this); - }); - - e.prop.visit_with(self); - } - - fn visit_member_prop(&mut self, n: &MemberProp) { - if let MemberProp::Computed(..) = n { - n.visit_children_with(self); - } - } - - fn visit_named_export(&mut self, n: &NamedExport) { - if n.src.is_some() { + fn with_nested(&mut self, f: impl FnOnce(&mut Self)) { + if !self.target.eventual { return; } - n.visit_children_with(self); - } - - fn visit_pat(&mut self, p: &Pat) { - self.with_mode(Some(Mode::Write), |this| { - p.visit_children_with(this); - }) - } - - fn visit_prop_name(&mut self, n: &PropName) { - if let PropName::Computed(..) = n { - n.visit_children_with(self); - } - } - - noop_visit_type!(); -} - -/// A visitor which collects variables which are read or written, but not at the -/// evaluation time. -#[derive(Default)] -pub(crate) struct CapturedIdCollector { - unresolved: SyntaxContext, - top_level: SyntaxContext, - - vars: Vars, - is_nested: bool, - /// None means both read and write - mode: Option, -} - -impl CapturedIdCollector { - fn with_nested(&mut self, f: impl FnOnce(&mut Self)) { let old = self.is_nested; self.is_nested = true; f(self); self.is_nested = old; } - fn with_mode(&mut self, mode: Option, f: impl FnOnce(&mut Self)) { let old = self.mode; self.mode = mode; @@ -184,7 +58,7 @@ impl CapturedIdCollector { } } -impl Visit for CapturedIdCollector { +impl Visit for IdentUsageCollector { fn visit_assign_target(&mut self, n: &AssignTarget) { self.with_mode(Some(Mode::Write), |this| { n.visit_children_with(this); @@ -203,6 +77,10 @@ impl Visit for CapturedIdCollector { }) } + fn visit_export_named_specifier(&mut self, n: &ExportNamedSpecifier) { + n.orig.visit_with(self); + } + fn visit_export_specifier(&mut self, n: &ExportSpecifier) { self.with_mode(Some(Mode::Read), |this| { n.visit_children_with(this); @@ -222,7 +100,7 @@ impl Visit for CapturedIdCollector { } fn visit_ident(&mut self, n: &Ident) { - if !self.is_nested { + if !self.target.direct && !self.is_nested { return; } @@ -265,6 +143,13 @@ impl Visit for CapturedIdCollector { n.visit_children_with(self); } } + fn visit_named_export(&mut self, n: &NamedExport) { + if n.src.is_some() { + return; + } + + n.visit_children_with(self); + } fn visit_pat(&mut self, p: &Pat) { self.with_mode(Some(Mode::Write), |this| { @@ -298,12 +183,15 @@ pub(crate) struct Vars { /// are not interesting. We only need to analyze top-level variables. pub(crate) fn ids_captured_by(n: &N, unresolved: SyntaxContext, top_level: SyntaxContext) -> Vars where - N: VisitWith, + N: VisitWith, { - let mut v = CapturedIdCollector { + let mut v = IdentUsageCollector { unresolved, top_level, - is_nested: false, + target: Target { + direct: false, + eventual: true, + }, ..Default::default() }; n.visit_with(&mut v); @@ -321,7 +209,10 @@ where let mut v = IdentUsageCollector { unresolved, top_level, - ignore_nested: false, + target: Target { + direct: true, + eventual: true, + }, ..Default::default() }; n.visit_with(&mut v); @@ -343,7 +234,10 @@ where let mut v = IdentUsageCollector { unresolved, top_level, - ignore_nested: true, + target: Target { + direct: true, + eventual: false, + }, ..Default::default() }; n.visit_with(&mut v); From cc179572190320b26716223e600d877aefd986d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Mon, 10 Jun 2024 21:37:16 +0900 Subject: [PATCH 20/23] fix visitor --- crates/turbopack-ecmascript/src/tree_shake/util.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/turbopack-ecmascript/src/tree_shake/util.rs b/crates/turbopack-ecmascript/src/tree_shake/util.rs index d190ad64280fb..546069b72efc5 100644 --- a/crates/turbopack-ecmascript/src/tree_shake/util.rs +++ b/crates/turbopack-ecmascript/src/tree_shake/util.rs @@ -104,14 +104,17 @@ impl Visit for IdentUsageCollector { return; } - if n.span.ctxt == self.unresolved { + if n.span.ctxt == self.unresolved && matches!(self.mode, Some(Mode::Read)) { self.vars.found_unresolved = true; return; } // We allow SyntaxContext::empty() because Some built-in files do not go into // resolver() - if n.span.ctxt != self.top_level && n.span.ctxt != SyntaxContext::empty() { + if n.span.ctxt != self.unresolved + && n.span.ctxt != self.top_level + && n.span.ctxt != SyntaxContext::empty() + { return; } @@ -140,7 +143,9 @@ impl Visit for IdentUsageCollector { fn visit_member_prop(&mut self, n: &MemberProp) { if let MemberProp::Computed(..) = n { - n.visit_children_with(self); + self.with_mode(Some(Mode::Read), |v| { + n.visit_children_with(v); + }) } } fn visit_named_export(&mut self, n: &NamedExport) { From f7d9936da2f5ba2313c0fab2a1ff2c8138f5ccac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Mon, 10 Jun 2024 21:41:06 +0900 Subject: [PATCH 21/23] revert visitor patch --- crates/turbopack-ecmascript/src/tree_shake/util.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/turbopack-ecmascript/src/tree_shake/util.rs b/crates/turbopack-ecmascript/src/tree_shake/util.rs index 546069b72efc5..79224046c7dd7 100644 --- a/crates/turbopack-ecmascript/src/tree_shake/util.rs +++ b/crates/turbopack-ecmascript/src/tree_shake/util.rs @@ -104,7 +104,7 @@ impl Visit for IdentUsageCollector { return; } - if n.span.ctxt == self.unresolved && matches!(self.mode, Some(Mode::Read)) { + if n.span.ctxt == self.unresolved { self.vars.found_unresolved = true; return; } From 9065c1d168f409f279a376448a3aa63fa75233a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Mon, 10 Jun 2024 21:41:19 +0900 Subject: [PATCH 22/23] side_effects of assign --- crates/turbopack-ecmascript/src/tree_shake/graph.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/crates/turbopack-ecmascript/src/tree_shake/graph.rs b/crates/turbopack-ecmascript/src/tree_shake/graph.rs index 9d89cc35ba714..c8b5b50dd2f0a 100644 --- a/crates/turbopack-ecmascript/src/tree_shake/graph.rs +++ b/crates/turbopack-ecmascript/src/tree_shake/graph.rs @@ -986,11 +986,7 @@ impl DepGraph { used_ids.write.extend(extra_ids.write); } - let side_effects = used_ids - .read - .iter() - .chain(used_ids.write.iter()) - .any(|id| id.1 == unresolved_ctxt); + let side_effects = used_ids.found_unresolved; let data = ItemData { read_vars: used_ids.read, From 83f895ed211f1bfc612557384af8393072c75b41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Mon, 10 Jun 2024 21:41:36 +0900 Subject: [PATCH 23/23] Update test refs --- .../analyzer/node-globals/output.md | 8 +- .../shared-and-side-effects/output.md | 101 +++++++++++++++--- 2 files changed, 92 insertions(+), 17 deletions(-) diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/node-globals/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/node-globals/output.md index cd1acde0d3f31..77cd4a23f2131 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/node-globals/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/node-globals/output.md @@ -9,6 +9,7 @@ process.turbopack = {}; ``` +- Side effects # Phase 1 ```mermaid @@ -37,11 +38,12 @@ graph TD Item1; Item2; Item2["ModuleEvaluation"]; + Item2 --> Item1; ``` # Final ```mermaid graph TD - N0["Items: [ItemId(ModuleEvaluation)]"]; + N0["Items: [ItemId(ModuleEvaluation), ItemId(0, Normal)]"]; ``` # Entrypoints @@ -56,11 +58,13 @@ graph TD ## Part 0 ```js "module evaluation"; +process.turbopack = {}; ``` ## Merged (module eval) ```js "module evaluation"; +process.turbopack = {}; ``` # Entrypoints @@ -76,10 +80,12 @@ graph TD ## Part 0 ```js "module evaluation"; +process.turbopack = {}; ``` ## Merged (module eval) ```js "module evaluation"; +process.turbopack = {}; ``` diff --git a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/output.md b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/output.md index 49b122ce3b60d..029fb89bcb0cf 100644 --- a/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/output.md +++ b/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/shared-and-side-effects/output.md @@ -40,6 +40,7 @@ externalObject.propertyWithSetter = 42; ``` +- Side effects ## Item 5: Stmt 4, `VarDeclarator(0)` @@ -145,9 +146,13 @@ graph TD Item2 --> Item1; Item3 --> Item1; Item3 --> Item2; + Item4 --> Item1; + Item4 --> Item2; + Item4 --> Item3; Item5 --> Item1; Item5 --> Item2; Item5 --> Item3; + Item5 --> Item4; Item6 --> Item2; Item6 --> Item3; Item6 --> Item5; @@ -155,6 +160,7 @@ graph TD Item7 --> Item1; Item7 --> Item2; Item7 --> Item3; + Item7 --> Item4; Item7 --> Item5; Item8 --> Item6; Item9 --> Item6; @@ -180,9 +186,13 @@ graph TD Item2 --> Item1; Item3 --> Item1; Item3 --> Item2; + Item4 --> Item1; + Item4 --> Item2; + Item4 --> Item3; Item5 --> Item1; Item5 --> Item2; Item5 --> Item3; + Item5 --> Item4; Item6 --> Item2; Item6 --> Item3; Item6 --> Item5; @@ -190,6 +200,7 @@ graph TD Item7 --> Item1; Item7 --> Item2; Item7 --> Item3; + Item7 --> Item4; Item7 --> Item5; Item8 --> Item6; Item9 --> Item6; @@ -215,9 +226,13 @@ graph TD Item2 --> Item1; Item3 --> Item1; Item3 --> Item2; + Item4 --> Item1; + Item4 --> Item2; + Item4 --> Item3; Item5 --> Item1; Item5 --> Item2; Item5 --> Item3; + Item5 --> Item4; Item6 --> Item2; Item6 --> Item3; Item6 --> Item5; @@ -225,12 +240,14 @@ graph TD Item7 --> Item1; Item7 --> Item2; Item7 --> Item3; + Item7 --> Item4; Item7 --> Item5; Item8 --> Item6; Item9 --> Item6; Item10 --> Item1; Item10 --> Item2; Item10 --> Item3; + Item10 --> Item4; Item10 --> Item5; Item10 --> Item7; Item11 --> Item8; @@ -245,24 +262,30 @@ graph TD N3["Items: [ItemId(0, Normal)]"]; N4["Items: [ItemId(1, VarDeclarator(0))]"]; N5["Items: [ItemId(2, VarDeclarator(0))]"]; - N6["Items: [ItemId(4, VarDeclarator(0))]"]; - N7["Items: [ItemId(5, VarDeclarator(0))]"]; + N6["Items: [ItemId(3, Normal)]"]; + N7["Items: [ItemId(4, VarDeclarator(0))]"]; + N8["Items: [ItemId(5, VarDeclarator(0))]"]; N0 --> N3; N0 --> N4; N0 --> N5; N0 --> N6; N0 --> N7; - N1 --> N7; - N2 --> N7; + N0 --> N8; + N1 --> N8; + N2 --> N8; N4 --> N3; N5 --> N3; N5 --> N4; N6 --> N3; N6 --> N4; N6 --> N5; + N7 --> N3; N7 --> N4; N7 --> N5; N7 --> N6; + N8 --> N4; + N8 --> N5; + N8 --> N7; ``` # Entrypoints @@ -294,9 +317,12 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 6 }; -import { shared } from "__TURBOPACK_PART__" assert { +import "__TURBOPACK_PART__" assert { __turbopack_part__: 7 }; +import { shared } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; "module evaluation"; console.log(shared); @@ -304,7 +330,7 @@ console.log(shared); ## Part 1 ```js import { shared } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 7 + __turbopack_part__: 8 }; export { a }; const a = { @@ -319,7 +345,7 @@ export { a } from "__TURBOPACK_VAR__" assert { ## Part 2 ```js import { shared } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 7 + __turbopack_part__: 8 }; export { b }; const b = { @@ -372,13 +398,30 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; +externalObject.propertyWithSetter = 42; + +``` +## Part 7 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; const value3 = externalFunction(); export { value3 } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; ``` -## Part 7 +## Part 8 ```js import { value } from "__TURBOPACK_PART__" assert { __turbopack_part__: 4 @@ -387,7 +430,7 @@ import { value2 } from "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; import { value3 } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 6 + __turbopack_part__: 7 }; const shared = { value, @@ -413,9 +456,12 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 6 }; -import { shared } from "__TURBOPACK_PART__" assert { +import "__TURBOPACK_PART__" assert { __turbopack_part__: 7 }; +import { shared } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; "module evaluation"; console.log(shared); @@ -450,9 +496,12 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 6 }; -import { shared } from "__TURBOPACK_PART__" assert { +import "__TURBOPACK_PART__" assert { __turbopack_part__: 7 }; +import { shared } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; "module evaluation"; console.log(shared); @@ -460,7 +509,7 @@ console.log(shared); ## Part 1 ```js import { shared } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 7 + __turbopack_part__: 8 }; export { a }; const a = { @@ -475,7 +524,7 @@ export { a } from "__TURBOPACK_VAR__" assert { ## Part 2 ```js import { shared } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 7 + __turbopack_part__: 8 }; export { b }; const b = { @@ -528,13 +577,30 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; +externalObject.propertyWithSetter = 42; + +``` +## Part 7 +```js +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 3 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 4 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 5 +}; +import "__TURBOPACK_PART__" assert { + __turbopack_part__: 6 +}; const value3 = externalFunction(); export { value3 } from "__TURBOPACK_VAR__" assert { __turbopack_var__: true }; ``` -## Part 7 +## Part 8 ```js import { value } from "__TURBOPACK_PART__" assert { __turbopack_part__: 4 @@ -543,7 +609,7 @@ import { value2 } from "__TURBOPACK_PART__" assert { __turbopack_part__: 5 }; import { value3 } from "__TURBOPACK_PART__" assert { - __turbopack_part__: 6 + __turbopack_part__: 7 }; const shared = { value, @@ -569,9 +635,12 @@ import "__TURBOPACK_PART__" assert { import "__TURBOPACK_PART__" assert { __turbopack_part__: 6 }; -import { shared } from "__TURBOPACK_PART__" assert { +import "__TURBOPACK_PART__" assert { __turbopack_part__: 7 }; +import { shared } from "__TURBOPACK_PART__" assert { + __turbopack_part__: 8 +}; "module evaluation"; console.log(shared);