Skip to content

Commit cdecac9

Browse files
committed
docs: add examples for design decisions
1 parent 6d93148 commit cdecac9

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

README.md

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,39 @@ There is an **edge** from `v1` to `v2` if:
2727
2. `v2` is imported from another module as `v1`
2828
3. `v1` exports or re-exports `v2`
2929

30-
### Expanding Wildcard Imports and Re-Exports
30+
### Expanding Wildcard Re-Exports
3131

32-
Expanding wildcard import and re-export statements simplifies parallel module parsing. Without expansion, any module containing such a statement would need to be parsed first, creating a bottleneck. Additionally, it's common in JavaScript projects to have numerous index.js files dedicated to re-exports, making this approach even more important for efficient processing.
32+
```js
33+
// assume a module named exports 'Foo', 'Bar'
34+
// then this wildcard re-export statement gets turned into
35+
// export { Foo, Bar } from 'a'
36+
export * from "a";
37+
```
38+
39+
Expanding wildcard re-export statements simplifies parallel module parsing. Without expansion, any module containing such a statement would need to be parsed first, creating a bottleneck. Additionally, it's common in JavaScript projects to have numerous index.js files dedicated to re-exports, making this approach even more important for efficient processing.
40+
41+
### Duplicating Local Variable Symbols for Exports or Default Exports
42+
43+
```js
44+
// one named export symbol + one local variable symbol named "A"
45+
export const A = "A";
46+
47+
// one default export symbol + one local variable symbol named "B"
48+
export default B = "B";
49+
```
50+
51+
Duplicating local variable symbols when they are exported or re-exported as default will increase the size of the serialized output, but it avoids introducing new edge rules. This is another trade-off to consider.
3352

3453
### Creating a Local Variable Symbol for Anonymous Default Exports
3554

55+
```js
56+
// one default export symbol + one anonymous local variable symbol
57+
export default () => {}
58+
export default function () {}
59+
export default function* () {}
60+
export default class {}
61+
```
62+
3663
This decision involves a trade-off: either introduce a new rule for edges or create a local variable symbol with a unique, impossible-to-collide name for the anonymous default export.
3764

3865
### Depending on Namespace Imports Means Depending on All Named Exports
@@ -48,10 +75,6 @@ function B() {
4875

4976
This presents a trade-off: either create a more fine-grained dependency graph or keep it simpler for now.
5077

51-
### Duplicating Local Variable Symbols for Exports or Default Exports
52-
53-
Duplicating local variable symbols when they are exported or re-exported as default will increase the size of the serialized output, but it avoids introducing new edge rules. This is another trade-off to consider.
54-
5578
## Problem Overview
5679

5780
Imagine an application with two routes: `/home` and `/account`.

0 commit comments

Comments
 (0)