Files
Donny/강동윤andGitHub 3a5b73d2d6 perf(turbopack): Remove ImportBinding fragments (#78470)
### What?

Make the `ImportBinding` node a phantom node.

### Why?

Because they are not used. We have to import directly from the original
module because of the static analysis like `next/dynamic`. So I modified
the tree shaking to import directly with
https://github.com/vercel/next.js/pull/71704. But #71704 didn't remove
the concept of `ImportBinding`. This PR finishes the work of using
direct imports.

Additionally, this PR introduces `ReexportBinding` fragments because
these are not phantom nodes. I'll check if it would be possible to
remove `ReexportBinding` fragments with follow-up PRs.

### How?

 - Closes PACK-4366
2025-04-28 15:10:59 +00:00

14 KiB

Items

Count: 18

Item 1: Stmt 0, Normal

export function external1() {
    return internal() + foobar;
}

  • Hoisted
  • Declares: external1
  • Reads (eventual): internal, foobar
  • Write: external1

Item 2: Stmt 1, ImportOfModule

import { upper } from "module";

  • Hoisted
  • Side effects

Item 3: Stmt 1, ImportBinding(0)

import { upper } from "module";

  • Hoisted
  • Declares: upper

Item 4: Stmt 2, VarDeclarator(0)

export let foobar = "foo";

  • Declares: foobar
  • Write: foobar

Item 5: Stmt 3, VarDeclarator(0)

export const foo = foobar;

  • Declares: foo
  • Reads: foobar
  • Write: foo

Item 6: Stmt 4, VarDeclarator(0)

const bar = "bar";

  • Declares: bar
  • Write: bar

Item 7: Stmt 5, Normal

foobar += bar;

  • Reads: bar, foobar
  • Write: foobar

Item 8: Stmt 6, VarDeclarator(0)

let foobarCopy = foobar;

  • Declares: foobarCopy
  • Reads: foobar
  • Write: foobarCopy

Item 9: Stmt 7, Normal

foobar += "foo";

  • Reads: foobar
  • Write: foobar

Item 10: Stmt 8, Normal

console.log(foobarCopy);

  • Side effects
  • Reads: foobarCopy

Item 11: Stmt 9, Normal

foobarCopy += "Unused";

  • Reads: foobarCopy
  • Write: foobarCopy

Item 12: Stmt 10, Normal

function internal() {
    return upper(foobar);
}

  • Hoisted
  • Declares: internal
  • Reads (eventual): upper, foobar
  • Write: internal

Item 13: Stmt 11, Normal

export function external2() {
    foobar += ".";
}

  • Hoisted
  • Declares: external2
  • Write: external2
  • Write (eventual): foobar

Item 14: Stmt 12, ImportOfModule

import "other";

  • Hoisted
  • Side effects

Phase 1

graph TD
    Item3;
    Item1;
    Item4;
    Item5;
    Item6;
    Item7;
    Item8;
    Item9;
    Item10;
    Item11;
    Item12;
    Item13;
    Item14;
    Item2;
    Item15;
    Item15["export external1"];
    Item16;
    Item16["export foobar"];
    Item17;
    Item17["export foo"];
    Item18;
    Item18["export external2"];
    Item2 --> Item1;

Phase 2

graph TD
    Item3;
    Item1;
    Item4;
    Item5;
    Item6;
    Item7;
    Item8;
    Item9;
    Item10;
    Item11;
    Item12;
    Item13;
    Item14;
    Item2;
    Item15;
    Item15["export external1"];
    Item16;
    Item16["export foobar"];
    Item17;
    Item17["export foo"];
    Item18;
    Item18["export external2"];
    Item2 --> Item1;
    Item6 --> Item5;
    Item8 --> Item7;
    Item8 --> Item5;
    Item8 -.-> Item6;
    Item9 --> Item8;
    Item9 --> Item5;
    Item10 --> Item8;
    Item10 --> Item5;
    Item10 -.-> Item9;
    Item11 --> Item9;
    Item11 --> Item2;
    Item11 -.-> Item13;
    Item11 --> Item10;
    Item11 -.-> Item4;
    Item12 --> Item9;
    Item12 -.-> Item11;
    Item15 --> Item3;
    Item16 --> Item10;
    Item16 --> Item5;
    Item17 --> Item6;
    Item18 --> Item14;

Phase 3

graph TD
    Item3;
    Item1;
    Item4;
    Item5;
    Item6;
    Item7;
    Item8;
    Item9;
    Item10;
    Item11;
    Item12;
    Item13;
    Item14;
    Item2;
    Item15;
    Item15["export external1"];
    Item16;
    Item16["export foobar"];
    Item17;
    Item17["export foo"];
    Item18;
    Item18["export external2"];
    Item2 --> Item1;
    Item6 --> Item5;
    Item8 --> Item7;
    Item8 --> Item5;
    Item8 -.-> Item6;
    Item9 --> Item8;
    Item9 --> Item5;
    Item10 --> Item8;
    Item10 --> Item5;
    Item10 -.-> Item9;
    Item11 --> Item9;
    Item11 --> Item2;
    Item11 -.-> Item13;
    Item11 --> Item10;
    Item11 -.-> Item4;
    Item12 --> Item9;
    Item12 -.-> Item11;
    Item15 --> Item3;
    Item16 --> Item10;
    Item16 --> Item5;
    Item17 --> Item6;
    Item18 --> Item14;
    Item3 --> Item13;
    Item3 --> Item10;
    Item3 --> Item5;
    Item13 --> Item4;
    Item13 --> Item10;
    Item13 --> Item5;
    Item14 -.-> Item16;
    Item14 --> Item5;

Phase 4

graph TD
    Item3;
    Item1;
    Item4;
    Item5;
    Item6;
    Item7;
    Item8;
    Item9;
    Item10;
    Item11;
    Item12;
    Item13;
    Item14;
    Item2;
    Item15;
    Item15["export external1"];
    Item16;
    Item16["export foobar"];
    Item17;
    Item17["export foo"];
    Item18;
    Item18["export external2"];
    Item2 --> Item1;
    Item6 --> Item5;
    Item8 --> Item7;
    Item8 --> Item5;
    Item8 -.-> Item6;
    Item9 --> Item8;
    Item9 --> Item5;
    Item10 --> Item8;
    Item10 --> Item5;
    Item10 -.-> Item9;
    Item11 --> Item9;
    Item11 --> Item2;
    Item11 -.-> Item13;
    Item11 --> Item10;
    Item11 -.-> Item4;
    Item12 --> Item9;
    Item12 -.-> Item11;
    Item15 --> Item3;
    Item16 --> Item10;
    Item16 --> Item5;
    Item17 --> Item6;
    Item18 --> Item14;
    Item3 --> Item13;
    Item3 --> Item10;
    Item3 --> Item5;
    Item13 --> Item4;
    Item13 --> Item10;
    Item13 --> Item5;
    Item14 -.-> Item16;
    Item14 --> Item5;

Final

graph TD
    N0["Items: [ItemId(0, Normal), ItemId(Export(("external1", #2), "external1"))]"];
    N1["Items: [ItemId(1, ImportOfModule)]"];
    N2["Items: [ItemId(1, ImportBinding(0))]"];
    N3["Items: [ItemId(2, VarDeclarator(0))]"];
    N4["Items: [ItemId(3, VarDeclarator(0))]"];
    N5["Items: [ItemId(4, VarDeclarator(0)), ItemId(5, Normal)]"];
    N6["Items: [ItemId(6, VarDeclarator(0))]"];
    N7["Items: [ItemId(7, Normal)]"];
    N8["Items: [ItemId(8, Normal), ItemId(9, Normal), ItemId(12, ImportOfModule)]"];
    N9["Items: [ItemId(10, Normal)]"];
    N10["Items: [ItemId(11, Normal), ItemId(Export(("external2", #2), "external2")), ItemId(Export(("foobar", #2), "foobar"))]"];
    N11["Items: [ItemId(Export(("foo", #2), "foo"))]"];
    N0 --> N3;
    N4 --> N3;
    N9 --> N2;
    N5 --> N3;
    N5 -.-> N4;
    N6 --> N5;
    N6 --> N3;
    N7 --> N5;
    N7 --> N3;
    N7 -.-> N6;
    N0 --> N9;
    N2 --> N1;
    N8 -.-> N2;
    N8 --> N7;
    N8 -.-> N9;
    N8 --> N6;
    N0 --> N7;
    N9 --> N3;
    N9 --> N7;
    N10 --> N3;
    N11 --> N4;

Entrypoints

{
    ModuleEvaluation: 8,
    Export(
        "external1",
    ): 0,
    Export(
        "external2",
    ): 10,
    Export(
        "foo",
    ): 11,
    Export(
        "foobar",
    ): 10,
    Exports: 12,
}

Modules (dev)

Part 0

import { a as foobar } from "__TURBOPACK_PART__" assert {
    __turbopack_part__: -3
};
import { b as internal } from "__TURBOPACK_PART__" assert {
    __turbopack_part__: -9
};
import "__TURBOPACK_PART__" assert {
    __turbopack_part__: 7
};
function external1() {
    return internal() + foobar;
}
export { external1 };
export { external1 as c } from "__TURBOPACK_VAR__" assert {
    __turbopack_var__: true
};

Part 1

import "module";

Part 2

import "__TURBOPACK_PART__" assert {
    __turbopack_part__: 1
};

Part 3

let foobar = "foo";
export { foobar as a } from "__TURBOPACK_VAR__" assert {
    __turbopack_var__: true
};

Part 4

import { a as foobar } from "__TURBOPACK_PART__" assert {
    __turbopack_part__: -3
};
const foo = foobar;
export { foo as d } from "__TURBOPACK_VAR__" assert {
    __turbopack_var__: true
};

Part 5

import { a as foobar } from "__TURBOPACK_PART__" assert {
    __turbopack_part__: -3
};
import "__TURBOPACK_PART__" assert {
    __turbopack_part__: 4
};
const bar = "bar";
foobar += bar;
export { bar as e } from "__TURBOPACK_VAR__" assert {
    __turbopack_var__: true
};

Part 6

import { a as foobar } from "__TURBOPACK_PART__" assert {
    __turbopack_part__: -3
};
import "__TURBOPACK_PART__" assert {
    __turbopack_part__: 5
};
let foobarCopy = foobar;
export { foobarCopy as f } from "__TURBOPACK_VAR__" assert {
    __turbopack_var__: true
};

Part 7

import { a as foobar } from "__TURBOPACK_PART__" assert {
    __turbopack_part__: -3
};
import "__TURBOPACK_PART__" assert {
    __turbopack_part__: 5
};
import "__TURBOPACK_PART__" assert {
    __turbopack_part__: 6
};
foobar += "foo";

Part 8

import { f as foobarCopy } from "__TURBOPACK_PART__" assert {
    __turbopack_part__: -6
};
import "__TURBOPACK_PART__" assert {
    __turbopack_part__: 2
};
import "__TURBOPACK_PART__" assert {
    __turbopack_part__: 7
};
import "__TURBOPACK_PART__" assert {
    __turbopack_part__: 9
};
console.log(foobarCopy);
foobarCopy += "Unused";
import "other";
export { };

Part 9

import { a as foobar } from "__TURBOPACK_PART__" assert {
    __turbopack_part__: -3
};
import "__TURBOPACK_PART__" assert {
    __turbopack_part__: 1
};
import { upper } from "module";
import "__TURBOPACK_PART__" assert {
    __turbopack_part__: 7
};
function internal() {
    return upper(foobar);
}
export { internal as b } from "__TURBOPACK_VAR__" assert {
    __turbopack_var__: true
};

Part 10

import { a as foobar } from "__TURBOPACK_PART__" assert {
    __turbopack_part__: -3
};
function external2() {
    foobar += ".";
}
export { external2 };
export { foobar };
export { external2 as g } from "__TURBOPACK_VAR__" assert {
    __turbopack_var__: true
};

Part 11

import { d as foo } from "__TURBOPACK_PART__" assert {
    __turbopack_part__: -4
};
export { foo };

Part 12

export { external1 } from "__TURBOPACK_PART__" assert {
    __turbopack_part__: "export external1"
};
export { external2 } from "__TURBOPACK_PART__" assert {
    __turbopack_part__: "export external2"
};
export { foobar } from "__TURBOPACK_PART__" assert {
    __turbopack_part__: "export foobar"
};
export { foo } from "__TURBOPACK_PART__" assert {
    __turbopack_part__: "export foo"
};

Merged (module eval)

import { f as foobarCopy } from "__TURBOPACK_PART__" assert {
    __turbopack_part__: -6
};
import "__TURBOPACK_PART__" assert {
    __turbopack_part__: 2
};
import "__TURBOPACK_PART__" assert {
    __turbopack_part__: 7
};
import "__TURBOPACK_PART__" assert {
    __turbopack_part__: 9
};
import "other";
console.log(foobarCopy);
foobarCopy += "Unused";
export { };

Entrypoints

{
    ModuleEvaluation: 8,
    Export(
        "external1",
    ): 0,
    Export(
        "external2",
    ): 10,
    Export(
        "foo",
    ): 4,
    Export(
        "foobar",
    ): 11,
    Exports: 12,
}

Modules (prod)

Part 0

import "__TURBOPACK_PART__" assert {
    __turbopack_part__: 1
};
import { upper } from "module";
import { a as foobar } from "__TURBOPACK_PART__" assert {
    __turbopack_part__: -3
};
import "__TURBOPACK_PART__" assert {
    __turbopack_part__: 7
};
function external1() {
    return internal() + foobar;
}
function internal() {
    return upper(foobar);
}
export { external1 };
export { external1 as b } from "__TURBOPACK_VAR__" assert {
    __turbopack_var__: true
};
export { internal as c } from "__TURBOPACK_VAR__" assert {
    __turbopack_var__: true
};

Part 1

import "module";

Part 2

import "__TURBOPACK_PART__" assert {
    __turbopack_part__: 1
};

Part 3

let foobar = "foo";
export { foobar as a } from "__TURBOPACK_VAR__" assert {
    __turbopack_var__: true
};

Part 4

import { a as foobar } from "__TURBOPACK_PART__" assert {
    __turbopack_part__: -3
};
const foo = foobar;
export { foo };
export { foo as d } from "__TURBOPACK_VAR__" assert {
    __turbopack_var__: true
};

Part 5

import { a as foobar } from "__TURBOPACK_PART__" assert {
    __turbopack_part__: -3
};
const bar = "bar";
foobar += bar;
export { bar as e } from "__TURBOPACK_VAR__" assert {
    __turbopack_var__: true
};

Part 6

import { a as foobar } from "__TURBOPACK_PART__" assert {
    __turbopack_part__: -3
};
import "__TURBOPACK_PART__" assert {
    __turbopack_part__: 5
};
let foobarCopy = foobar;
export { foobarCopy as f } from "__TURBOPACK_VAR__" assert {
    __turbopack_var__: true
};

Part 7

import { a as foobar } from "__TURBOPACK_PART__" assert {
    __turbopack_part__: -3
};
import "__TURBOPACK_PART__" assert {
    __turbopack_part__: 5
};
foobar += "foo";

Part 8

import { f as foobarCopy } from "__TURBOPACK_PART__" assert {
    __turbopack_part__: -6
};
import "__TURBOPACK_PART__" assert {
    __turbopack_part__: 1
};
import "__TURBOPACK_PART__" assert {
    __turbopack_part__: 7
};
console.log(foobarCopy);
import "other";
export { };

Part 9

import { f as foobarCopy } from "__TURBOPACK_PART__" assert {
    __turbopack_part__: -6
};
foobarCopy += "Unused";

Part 10

import { a as foobar } from "__TURBOPACK_PART__" assert {
    __turbopack_part__: -3
};
function external2() {
    foobar += ".";
}
export { external2 };
export { external2 as g } from "__TURBOPACK_VAR__" assert {
    __turbopack_var__: true
};

Part 11

import { a as foobar } from "__TURBOPACK_PART__" assert {
    __turbopack_part__: -3
};
import "__TURBOPACK_PART__" assert {
    __turbopack_part__: 7
};
export { foobar };

Part 12

export { external1 } from "__TURBOPACK_PART__" assert {
    __turbopack_part__: "export external1"
};
export { foo } from "__TURBOPACK_PART__" assert {
    __turbopack_part__: "export foo"
};
export { external2 } from "__TURBOPACK_PART__" assert {
    __turbopack_part__: "export external2"
};
export { foobar } from "__TURBOPACK_PART__" assert {
    __turbopack_part__: "export foobar"
};

Merged (module eval)

import { f as foobarCopy } from "__TURBOPACK_PART__" assert {
    __turbopack_part__: -6
};
import "__TURBOPACK_PART__" assert {
    __turbopack_part__: 1
};
import "__TURBOPACK_PART__" assert {
    __turbopack_part__: 7
};
import "other";
console.log(foobarCopy);
export { };