@backtickjs/bundler 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle/buildBundle.js +12 -19
- package/dist/bundle/buildBundle.js.map +1 -1
- package/dist/bundle/expandServerComponents.d.ts +2 -2
- package/dist/bundle/expandServerComponents.js +22 -23
- package/dist/bundle/expandServerComponents.js.map +1 -1
- package/dist/bundle/params.d.ts +0 -1
- package/dist/bundle/params.js +0 -9
- package/dist/bundle/params.js.map +1 -1
- package/package.json +2 -2
- package/src/bundle/buildBundle.ts +14 -24
- package/src/bundle/expandServerComponents.ts +32 -26
- package/src/bundle/params.ts +0 -12
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isClientExec, isClientImport, isClientScript, isJsxElement, } from "@backtickjs/core";
|
|
2
2
|
import { BundlerError } from "../errors.js";
|
|
3
3
|
import { expandServerComponents } from "./expandServerComponents.js";
|
|
4
|
-
import { bindingsOf, capturesOf
|
|
4
|
+
import { bindingsOf, capturesOf } from "./params.js";
|
|
5
5
|
import { sourceName } from "./bindingKey.js";
|
|
6
6
|
import { array, arrow, call, createNames, imported, literal, object, } from "../print/code.js";
|
|
7
7
|
// Names a binding may not take: what strict code cannot bind. Every name the
|
|
@@ -118,24 +118,22 @@ export async function buildBundle(spliceable, provided) {
|
|
|
118
118
|
}
|
|
119
119
|
return label;
|
|
120
120
|
};
|
|
121
|
-
// A
|
|
122
|
-
//
|
|
123
|
-
//
|
|
124
|
-
//
|
|
125
|
-
// two
|
|
121
|
+
// A script is one value, as a module-level `const` is: its code run at the
|
|
122
|
+
// top of the bundle, where nothing encloses it, and every read is that
|
|
123
|
+
// constant. One per script, not per code: two runs of a host function that
|
|
124
|
+
// each make a function are two functions, and two that each make a context
|
|
125
|
+
// two contexts, as in plain TypeScript.
|
|
126
126
|
//
|
|
127
|
-
// A
|
|
128
|
-
//
|
|
129
|
-
//
|
|
127
|
+
// A script that reads a variable of the scope it's read in, itself or
|
|
128
|
+
// through what it's handed, is made there instead, as one declared in a
|
|
129
|
+
// function is.
|
|
130
130
|
const values = new Map();
|
|
131
131
|
const valueOf = (script, scope) => {
|
|
132
132
|
let label = values.get(script);
|
|
133
133
|
if (label !== undefined) {
|
|
134
134
|
return label;
|
|
135
135
|
}
|
|
136
|
-
const at =
|
|
137
|
-
? rootScope()
|
|
138
|
-
: { bindings: scope.bindings, read: new Set() };
|
|
136
|
+
const at = { bindings: scope.bindings, read: new Set() };
|
|
139
137
|
const code = call(labelOf(scriptFor(script)), exprCallArgs(script, at));
|
|
140
138
|
const outside = [...at.read].filter((key) => scope.bindings.has(key));
|
|
141
139
|
if (outside.length > 0) {
|
|
@@ -154,10 +152,7 @@ export async function buildBundle(spliceable, provided) {
|
|
|
154
152
|
// reached each script. Expansion has refused cycles, so it ends.
|
|
155
153
|
const render = (spliceable, scope = rootScope()) => {
|
|
156
154
|
if (isClientScript(spliceable)) {
|
|
157
|
-
|
|
158
|
-
return valueOf(spliceable, scope);
|
|
159
|
-
}
|
|
160
|
-
return call(labelOf(scriptFor(spliceable)), exprCallArgs(spliceable, scope));
|
|
155
|
+
return valueOf(spliceable, scope);
|
|
161
156
|
}
|
|
162
157
|
if (isJsxElement(spliceable)) {
|
|
163
158
|
return renderJsx(spliceable);
|
|
@@ -234,9 +229,7 @@ export async function buildBundle(spliceable, provided) {
|
|
|
234
229
|
sourceName(key) +
|
|
235
230
|
"` shadows it: the binding is still there, but no longer reachable by " +
|
|
236
231
|
"name, and naming it anyway would mean emitting what the source " +
|
|
237
|
-
"couldn't say.
|
|
238
|
-
"outside every script, so a fragment spliced into one can't reach " +
|
|
239
|
-
"its binding either.");
|
|
232
|
+
"couldn't say.");
|
|
240
233
|
};
|
|
241
234
|
// The arguments of a call of a script: a thunk per splice, then its
|
|
242
235
|
// captures.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildBundle.js","sourceRoot":"","sources":["../../src/bundle/buildBundle.ts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f,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC7B,MAAM,IAAI,YAAY,CACpB,MAAM,IAAI,yDAAyD;gBACjE,QAAQ,IAAI,OAAO,IAAI,MAAM,CAChC,CAAC;QACJ,CAAC;QACD,MAAM,GAAG,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC;QACrE,MAAM,IAAI,YAAY,CACpB,GAAG,GAAG,4DAA4D;YAChE,8BAA8B,CACjC,CAAC;IACJ,CAAC,CAAC;IAEF,2EAA2E;IAC3E,wEAAwE;IACxE,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,sBAAsB,CAAC,UAAU,CAAC,CAAC,CAAC;IAC9D,0EAA0E;IAC1E,MAAM,OAAO,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CACrC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,CAAU,CACtD,CAAC;IACF,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AAC7C,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { type ClientScript } from "@backtickjs/core";
|
|
1
|
+
import { type ClientScript, type JsxElement } from "@backtickjs/core";
|
|
2
2
|
interface Ancestors {
|
|
3
3
|
readonly value: object;
|
|
4
4
|
readonly parent: Ancestors | null;
|
|
5
5
|
}
|
|
6
|
-
export declare function expandServerComponents(spliceable: unknown, ancestors?: Ancestors | null,
|
|
6
|
+
export declare function expandServerComponents(spliceable: unknown, ancestors?: Ancestors | null, shared?: Map<JsxElement | ClientScript, Promise<unknown>>): Promise<unknown>;
|
|
7
7
|
export {};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { isClientImport, isClientScript, isJsxElement, } from "@backtickjs/core";
|
|
2
2
|
import { BundlerError } from "../errors.js";
|
|
3
|
-
import { isValue } from "./params.js";
|
|
4
3
|
const CYCLE_ERROR = "Can't splice a value that contains itself: a bundle writes each value " +
|
|
5
4
|
"out in full, so a cycle never ends. Break the cycle before splicing it.";
|
|
6
5
|
const contains = (ancestors, value) => {
|
|
@@ -15,16 +14,16 @@ const contains = (ancestors, value) => {
|
|
|
15
14
|
// each element of one replaced by what its component drew, expanded in turn.
|
|
16
15
|
// Siblings expand at once, so two components awaiting data wait together.
|
|
17
16
|
//
|
|
18
|
-
// A component runs
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
// server component comes back as
|
|
17
|
+
// A component runs once per element, as React's server renderer runs one: one
|
|
18
|
+
// element drawn in two places runs once, and two elements run twice. The
|
|
19
|
+
// component itself never leaves the host, and only the client code it bottoms
|
|
20
|
+
// out in reaches the bundle. A value holding no server component comes back as
|
|
21
|
+
// the same object.
|
|
22
22
|
//
|
|
23
|
-
// A
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
export async function expandServerComponents(spliceable, ancestors = null, values = new Map()) {
|
|
23
|
+
// A script is one value, so what one splices is expanded once, however many
|
|
24
|
+
// places read it. `shared` holds each element's and each script's expansion
|
|
25
|
+
// for the call.
|
|
26
|
+
export async function expandServerComponents(spliceable, ancestors = null, shared = new Map()) {
|
|
28
27
|
if (typeof spliceable !== "object" || spliceable === null) {
|
|
29
28
|
return spliceable;
|
|
30
29
|
}
|
|
@@ -32,31 +31,31 @@ export async function expandServerComponents(spliceable, ancestors = null, value
|
|
|
32
31
|
throw new BundlerError(CYCLE_ERROR);
|
|
33
32
|
}
|
|
34
33
|
const inside = { value: spliceable, parent: ancestors };
|
|
35
|
-
const all = (entries) => Promise.all(entries.map((entry) => expandServerComponents(entry, inside,
|
|
34
|
+
const all = (entries) => Promise.all(entries.map((entry) => expandServerComponents(entry, inside, shared)));
|
|
35
|
+
// Each element and each script once, its expansion shared.
|
|
36
|
+
const once = (key, expand) => {
|
|
37
|
+
let made = shared.get(key);
|
|
38
|
+
if (made === undefined) {
|
|
39
|
+
made = expand();
|
|
40
|
+
shared.set(key, made);
|
|
41
|
+
}
|
|
42
|
+
return made;
|
|
43
|
+
};
|
|
36
44
|
if (isJsxElement(spliceable)) {
|
|
37
45
|
const { type } = spliceable;
|
|
38
46
|
// A tag the client draws is left for rendering to refuse.
|
|
39
47
|
if (typeof type !== "function" || isClientImport(type)) {
|
|
40
48
|
return spliceable;
|
|
41
49
|
}
|
|
42
|
-
return expandServerComponents(await type(spliceable.props), inside,
|
|
50
|
+
return once(spliceable, async () => expandServerComponents(await type(spliceable.props), inside, shared));
|
|
43
51
|
}
|
|
44
52
|
if (isClientScript(spliceable)) {
|
|
45
|
-
|
|
53
|
+
return once(spliceable, async () => {
|
|
46
54
|
const args = await all(spliceable.args);
|
|
47
55
|
return args.every((arg, index) => arg === spliceable.args[index])
|
|
48
56
|
? spliceable
|
|
49
57
|
: { ...spliceable, args };
|
|
50
|
-
};
|
|
51
|
-
if (!isValue(spliceable)) {
|
|
52
|
-
return expanded();
|
|
53
|
-
}
|
|
54
|
-
let made = values.get(spliceable);
|
|
55
|
-
if (made === undefined) {
|
|
56
|
-
made = expanded();
|
|
57
|
-
values.set(spliceable, made);
|
|
58
|
-
}
|
|
59
|
-
return made;
|
|
58
|
+
});
|
|
60
59
|
}
|
|
61
60
|
if (Array.isArray(spliceable)) {
|
|
62
61
|
const elements = await all(spliceable);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expandServerComponents.js","sourceRoot":"","sources":["../../src/bundle/expandServerComponents.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EACd,cAAc,EACd,YAAY,
|
|
1
|
+
{"version":3,"file":"expandServerComponents.js","sourceRoot":"","sources":["../../src/bundle/expandServerComponents.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EACd,cAAc,EACd,YAAY,GAEb,MAAM,kBAAkB,CAAC;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,GAAG,MAAM,GAAG,CAAC,UAAU,CAAC,CAAC;QACvC,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,UAAU,CAAC,KAAK,CAAC,CAAC;YACtE,CAAC,CAAC,UAAU;YACZ,CAAC,CAAC,QAAQ,CAAC;IACf,CAAC;IACD,6DAA6D;IAC7D,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;IACpD,IAAI,SAAS,KAAK,MAAM,CAAC,SAAS,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;QACzD,OAAO,UAAU,CAAC;IACpB,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAC3C,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAC9D,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,OAAO,CAAC,KAAK,CAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACnE,OAAO,UAAU,CAAC;IACpB,CAAC;IACD,2DAA2D;IAC3D,OAAO,MAAM,CAAC,WAAW,CACvB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CACtD,CAAC;AACJ,CAAC"}
|
package/dist/bundle/params.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { ClientScript, Param } from "@backtickjs/core";
|
|
2
2
|
export declare function bindingsOf(param: Param | undefined): readonly string[];
|
|
3
|
-
export declare function isValue(script: ClientScript): boolean;
|
|
4
3
|
export declare function capturesOf(script: ClientScript): readonly string[];
|
package/dist/bundle/params.js
CHANGED
|
@@ -3,15 +3,6 @@
|
|
|
3
3
|
export function bindingsOf(param) {
|
|
4
4
|
return param?.kind === "splice" ? param.bindings : [];
|
|
5
5
|
}
|
|
6
|
-
// Whether a script is one value for the bundle, made once at its top: a
|
|
7
|
-
// `once` script, a function and a class, as a module-level one is. A function
|
|
8
|
-
// or a class that reads a variable of the script around it, itself or through
|
|
9
|
-
// what it's handed, is made where it's read instead (see `valueOf`).
|
|
10
|
-
export function isValue(script) {
|
|
11
|
-
return (script.once === true ||
|
|
12
|
-
script.module.kind === "function" ||
|
|
13
|
-
script.module.kind === "class");
|
|
14
|
-
}
|
|
15
6
|
// The binding keys a script captures, in parameter order.
|
|
16
7
|
export function capturesOf(script) {
|
|
17
8
|
return script.module.params.flatMap((param) => param.kind === "capture" ? [param.key] : []);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"params.js","sourceRoot":"","sources":["../../src/bundle/params.ts"],"names":[],"mappings":"AAEA,4EAA4E;AAE5E,6DAA6D;AAC7D,MAAM,UAAU,UAAU,CAAC,KAAwB;IACjD,OAAO,KAAK,EAAE,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;AACxD,CAAC;AAED,
|
|
1
|
+
{"version":3,"file":"params.js","sourceRoot":"","sources":["../../src/bundle/params.ts"],"names":[],"mappings":"AAEA,4EAA4E;AAE5E,6DAA6D;AAC7D,MAAM,UAAU,UAAU,CAAC,KAAwB;IACjD,OAAO,KAAK,EAAE,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;AACxD,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,UAAU,CAAC,MAAoB;IAC7C,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAC5C,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAC5C,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backtickjs/bundler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Runs Backtick server components and bundles a screen per request: one JavaScript file for the client",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"backtick",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@backtickjs/core": "0.
|
|
42
|
+
"@backtickjs/core": "0.4.0",
|
|
43
43
|
"semver": "^7.8.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
|
|
11
11
|
import { BundlerError } from "../errors.js";
|
|
12
12
|
import { expandServerComponents } from "./expandServerComponents.js";
|
|
13
|
-
import { bindingsOf, capturesOf
|
|
13
|
+
import { bindingsOf, capturesOf } from "./params.js";
|
|
14
14
|
import { sourceName } from "./bindingKey.js";
|
|
15
15
|
import {
|
|
16
16
|
array,
|
|
@@ -31,8 +31,8 @@ import type { Modules } from "../modules.js";
|
|
|
31
31
|
*/
|
|
32
32
|
export interface BundleTree {
|
|
33
33
|
readonly modules: readonly (readonly [string, ScriptModule])[];
|
|
34
|
-
// The
|
|
35
|
-
//
|
|
34
|
+
// The values the bundle makes once, each under its label, in the order
|
|
35
|
+
// they're finished: after what they read.
|
|
36
36
|
readonly constants: readonly (readonly [string, string])[];
|
|
37
37
|
readonly root: string;
|
|
38
38
|
readonly names: Names;
|
|
@@ -177,24 +177,22 @@ export async function buildBundle(
|
|
|
177
177
|
return label;
|
|
178
178
|
};
|
|
179
179
|
|
|
180
|
-
// A
|
|
181
|
-
//
|
|
182
|
-
//
|
|
183
|
-
//
|
|
184
|
-
// two
|
|
180
|
+
// A script is one value, as a module-level `const` is: its code run at the
|
|
181
|
+
// top of the bundle, where nothing encloses it, and every read is that
|
|
182
|
+
// constant. One per script, not per code: two runs of a host function that
|
|
183
|
+
// each make a function are two functions, and two that each make a context
|
|
184
|
+
// two contexts, as in plain TypeScript.
|
|
185
185
|
//
|
|
186
|
-
// A
|
|
187
|
-
//
|
|
188
|
-
//
|
|
186
|
+
// A script that reads a variable of the scope it's read in, itself or
|
|
187
|
+
// through what it's handed, is made there instead, as one declared in a
|
|
188
|
+
// function is.
|
|
189
189
|
const values = new Map<ClientScript, string>();
|
|
190
190
|
const valueOf = (script: ClientScript, scope: Scope): string => {
|
|
191
191
|
let label = values.get(script);
|
|
192
192
|
if (label !== undefined) {
|
|
193
193
|
return label;
|
|
194
194
|
}
|
|
195
|
-
const at: Scope =
|
|
196
|
-
? rootScope()
|
|
197
|
-
: { bindings: scope.bindings, read: new Set() };
|
|
195
|
+
const at: Scope = { bindings: scope.bindings, read: new Set() };
|
|
198
196
|
const code = call(labelOf(scriptFor(script)), exprCallArgs(script, at));
|
|
199
197
|
const outside = [...at.read].filter((key) => scope.bindings.has(key));
|
|
200
198
|
if (outside.length > 0) {
|
|
@@ -214,13 +212,7 @@ export async function buildBundle(
|
|
|
214
212
|
// reached each script. Expansion has refused cycles, so it ends.
|
|
215
213
|
const render = (spliceable: unknown, scope: Scope = rootScope()): string => {
|
|
216
214
|
if (isClientScript(spliceable)) {
|
|
217
|
-
|
|
218
|
-
return valueOf(spliceable, scope);
|
|
219
|
-
}
|
|
220
|
-
return call(
|
|
221
|
-
labelOf(scriptFor(spliceable)),
|
|
222
|
-
exprCallArgs(spliceable, scope),
|
|
223
|
-
);
|
|
215
|
+
return valueOf(spliceable, scope);
|
|
224
216
|
}
|
|
225
217
|
if (isJsxElement(spliceable)) {
|
|
226
218
|
return renderJsx(spliceable);
|
|
@@ -307,9 +299,7 @@ export async function buildBundle(
|
|
|
307
299
|
sourceName(key) +
|
|
308
300
|
"` shadows it: the binding is still there, but no longer reachable by " +
|
|
309
301
|
"name, and naming it anyway would mean emitting what the source " +
|
|
310
|
-
"couldn't say.
|
|
311
|
-
"outside every script, so a fragment spliced into one can't reach " +
|
|
312
|
-
"its binding either.",
|
|
302
|
+
"couldn't say.",
|
|
313
303
|
);
|
|
314
304
|
};
|
|
315
305
|
|
|
@@ -3,9 +3,9 @@ import {
|
|
|
3
3
|
isClientImport,
|
|
4
4
|
isClientScript,
|
|
5
5
|
isJsxElement,
|
|
6
|
+
type JsxElement,
|
|
6
7
|
} from "@backtickjs/core";
|
|
7
8
|
import { BundlerError } from "../errors.js";
|
|
8
|
-
import { isValue } from "./params.js";
|
|
9
9
|
|
|
10
10
|
const CYCLE_ERROR =
|
|
11
11
|
"Can't splice a value that contains itself: a bundle writes each value " +
|
|
@@ -31,19 +31,19 @@ const contains = (ancestors: Ancestors | null, value: object): boolean => {
|
|
|
31
31
|
// each element of one replaced by what its component drew, expanded in turn.
|
|
32
32
|
// Siblings expand at once, so two components awaiting data wait together.
|
|
33
33
|
//
|
|
34
|
-
// A component runs
|
|
35
|
-
//
|
|
36
|
-
//
|
|
37
|
-
// server component comes back as
|
|
34
|
+
// A component runs once per element, as React's server renderer runs one: one
|
|
35
|
+
// element drawn in two places runs once, and two elements run twice. The
|
|
36
|
+
// component itself never leaves the host, and only the client code it bottoms
|
|
37
|
+
// out in reaches the bundle. A value holding no server component comes back as
|
|
38
|
+
// the same object.
|
|
38
39
|
//
|
|
39
|
-
// A
|
|
40
|
-
//
|
|
41
|
-
//
|
|
42
|
-
// each one's expansion for the call.
|
|
40
|
+
// A script is one value, so what one splices is expanded once, however many
|
|
41
|
+
// places read it. `shared` holds each element's and each script's expansion
|
|
42
|
+
// for the call.
|
|
43
43
|
export async function expandServerComponents(
|
|
44
44
|
spliceable: unknown,
|
|
45
45
|
ancestors: Ancestors | null = null,
|
|
46
|
-
|
|
46
|
+
shared = new Map<JsxElement | ClientScript, Promise<unknown>>(),
|
|
47
47
|
): Promise<unknown> {
|
|
48
48
|
if (typeof spliceable !== "object" || spliceable === null) {
|
|
49
49
|
return spliceable;
|
|
@@ -54,37 +54,43 @@ export async function expandServerComponents(
|
|
|
54
54
|
const inside: Ancestors = { value: spliceable, parent: ancestors };
|
|
55
55
|
const all = (entries: readonly unknown[]) =>
|
|
56
56
|
Promise.all(
|
|
57
|
-
entries.map((entry) => expandServerComponents(entry, inside,
|
|
57
|
+
entries.map((entry) => expandServerComponents(entry, inside, shared)),
|
|
58
58
|
);
|
|
59
59
|
|
|
60
|
+
// Each element and each script once, its expansion shared.
|
|
61
|
+
const once = (
|
|
62
|
+
key: JsxElement | ClientScript,
|
|
63
|
+
expand: () => Promise<unknown>,
|
|
64
|
+
): Promise<unknown> => {
|
|
65
|
+
let made = shared.get(key);
|
|
66
|
+
if (made === undefined) {
|
|
67
|
+
made = expand();
|
|
68
|
+
shared.set(key, made);
|
|
69
|
+
}
|
|
70
|
+
return made;
|
|
71
|
+
};
|
|
72
|
+
|
|
60
73
|
if (isJsxElement(spliceable)) {
|
|
61
74
|
const { type } = spliceable;
|
|
62
75
|
// A tag the client draws is left for rendering to refuse.
|
|
63
76
|
if (typeof type !== "function" || isClientImport(type)) {
|
|
64
77
|
return spliceable;
|
|
65
78
|
}
|
|
66
|
-
return
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
79
|
+
return once(spliceable, async () =>
|
|
80
|
+
expandServerComponents(
|
|
81
|
+
await type(spliceable.props as never),
|
|
82
|
+
inside,
|
|
83
|
+
shared,
|
|
84
|
+
),
|
|
70
85
|
);
|
|
71
86
|
}
|
|
72
87
|
if (isClientScript(spliceable)) {
|
|
73
|
-
|
|
88
|
+
return once(spliceable, async () => {
|
|
74
89
|
const args = await all(spliceable.args);
|
|
75
90
|
return args.every((arg, index) => arg === spliceable.args[index])
|
|
76
91
|
? spliceable
|
|
77
92
|
: { ...spliceable, args };
|
|
78
|
-
};
|
|
79
|
-
if (!isValue(spliceable)) {
|
|
80
|
-
return expanded();
|
|
81
|
-
}
|
|
82
|
-
let made = values.get(spliceable);
|
|
83
|
-
if (made === undefined) {
|
|
84
|
-
made = expanded();
|
|
85
|
-
values.set(spliceable, made);
|
|
86
|
-
}
|
|
87
|
-
return made;
|
|
93
|
+
});
|
|
88
94
|
}
|
|
89
95
|
if (Array.isArray(spliceable)) {
|
|
90
96
|
const elements = await all(spliceable);
|
package/src/bundle/params.ts
CHANGED
|
@@ -7,18 +7,6 @@ export function bindingsOf(param: Param | undefined): readonly string[] {
|
|
|
7
7
|
return param?.kind === "splice" ? param.bindings : [];
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
// Whether a script is one value for the bundle, made once at its top: a
|
|
11
|
-
// `once` script, a function and a class, as a module-level one is. A function
|
|
12
|
-
// or a class that reads a variable of the script around it, itself or through
|
|
13
|
-
// what it's handed, is made where it's read instead (see `valueOf`).
|
|
14
|
-
export function isValue(script: ClientScript): boolean {
|
|
15
|
-
return (
|
|
16
|
-
script.once === true ||
|
|
17
|
-
script.module.kind === "function" ||
|
|
18
|
-
script.module.kind === "class"
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
10
|
// The binding keys a script captures, in parameter order.
|
|
23
11
|
export function capturesOf(script: ClientScript): readonly string[] {
|
|
24
12
|
return script.module.params.flatMap((param) =>
|