@backtickjs/bundler 0.1.9 → 0.1.11

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/README.md CHANGED
@@ -10,7 +10,7 @@ npm install @backtickjs/bundler @backtickjs/core
10
10
 
11
11
  ## Usage
12
12
 
13
- For React Native, write CommonJS and serve it; the app fetches it and runs it with `evaluate` from `@backtickjs/react-native-client`:
13
+ For React Native, write CommonJS and serve it; the app fetches it and runs it with `execRoot` from `@backtickjs/core/cjs`:
14
14
 
15
15
  ```tsx
16
16
  import { bundler } from "@backtickjs/bundler";
@@ -23,8 +23,8 @@ const modules = {
23
23
  };
24
24
 
25
25
  // In a request handler:
26
- const bundle = await bundler.build({ input: <Home />, modules });
27
- const { code } = bundle.generate({ format: "cjs" });
26
+ const build = await bundler.build({ input: <Home />, modules });
27
+ const { code } = build.generate({ format: "cjs" });
28
28
  response.setHeader("content-type", "text/javascript");
29
29
  response.end(code);
30
30
  ```
@@ -38,7 +38,7 @@ import { createRoot } from "@backtickjs/react/client";
38
38
  import { Home } from "./Home.js";
39
39
 
40
40
  const element = <Home />;
41
- const bundle = await bundler.build({
41
+ const build = await bundler.build({
42
42
  input: cs`$createRoot(document.getElementById("app")!).render($element)`,
43
43
  modules: {
44
44
  react: "19.2.3",
@@ -46,7 +46,7 @@ const bundle = await bundler.build({
46
46
  "react-dom/client": "19.2.3",
47
47
  },
48
48
  });
49
- const { code } = bundle.generate({ format: "es", sourcemap: "inline" });
49
+ const { code } = build.generate({ format: "es", sourcemap: "inline" });
50
50
  ```
51
51
 
52
52
  ### `modules`
@@ -57,12 +57,12 @@ The modules the client provides, by specifier, each at the exact version of the
57
57
 
58
58
  ### What crosses into a script
59
59
 
60
- Spliced values are written into the bundle as data, never as code. What can't cross, `build` rejects before anything reaches the client; [Errors](https://backtickjs.com/docs/errors#from-the-bundler) has each message and its fix.
60
+ Spliced values are written into the bundle as data, never as code. What can't cross, `build` rejects before anything reaches the client; [Errors](https://backtickjs.com/docs/errors/#from-the-bundler) has each message and its fix.
61
61
 
62
62
  ### Formats
63
63
 
64
64
  - `"es"`: an ES module, for a web page. Packages are imported by specifier, which the page's import map resolves.
65
- - `"cjs"`: CommonJS, for a client that provides `require` itself, as a React Native app does through `evaluate`.
65
+ - `"cjs"`: CommonJS, for a client that provides `require` itself, as a React Native app does through `execRoot`.
66
66
 
67
67
  ### Source maps
68
68
 
@@ -70,17 +70,16 @@ Spliced values are written into the bundle as data, never as code. What can't cr
70
70
 
71
71
  ## API
72
72
 
73
- - `bundler.build({ input, modules })`: runs the server components in `input` and returns a `Bundle`. Async.
74
- - `Bundle.generate({ format, sourcemap })`: writes the bundle; returns `{ code, map }`, where `map` is `null` without a source map.
75
- - Types: `BuildOptions`, `OutputOptions`, `OutputChunk`, `Bundle`.
73
+ - `bundler.build({ input, modules })`: runs the server components in `input` and returns a `Build`. Async.
74
+ - `Build.generate({ format, sourcemap })`: writes the bundle; returns `{ code, map }`, where `code` is a `Bundle<T>` (from `@backtickjs/core`), typed by what `input` is on the client, and `map` is `null` without a source map.
75
+ - Types: `BuildOptions`, `OutputOptions`, `OutputChunk`, `Build`.
76
76
 
77
77
  ## Related
78
78
 
79
- - [`@backtickjs/core`](https://github.com/backtickjs/backtick/tree/main/packages/core): the `cs` tag
80
- - [`@backtickjs/react-native-client`](https://github.com/backtickjs/backtick/tree/main/packages/react-native-client): runs a `cjs` bundle in a React Native app
79
+ - [`@backtickjs/core`](https://github.com/backtickjs/backtick/tree/main/packages/core): the `cs` tag, and `execRoot`, which runs a bundle in the app
81
80
  - [`@backtickjs/react`](https://github.com/backtickjs/backtick/tree/main/adapters/react), [`@backtickjs/react-native`](https://github.com/backtickjs/backtick/tree/main/adapters/react-native), [`@backtickjs/solid-js`](https://github.com/backtickjs/backtick/tree/main/adapters/solid-js): framework adapters
82
- - [How it works](https://backtickjs.com/docs/how-it-works)
83
- - [Errors](https://backtickjs.com/docs/errors)
81
+ - [How it works](https://backtickjs.com/docs/how-it-works/)
82
+ - [Errors](https://backtickjs.com/docs/errors/)
84
83
 
85
84
  ## License
86
85
 
@@ -12,4 +12,4 @@ export interface BundleTree {
12
12
  readonly root: string;
13
13
  readonly names: Names;
14
14
  }
15
- export declare function buildBundle(value: unknown, provided: Modules): Promise<BundleTree>;
15
+ export declare function buildBundle(spliceable: unknown, provided: Modules): Promise<BundleTree>;
@@ -1,6 +1,6 @@
1
- import { isClientImport, isClientScript, isJsxElement, } from "@backtickjs/core";
1
+ import { isClientExec, isClientImport, isClientScript, isJsxElement, } from "@backtickjs/core";
2
2
  import { expandServerComponents } from "./expandServerComponents.js";
3
- import { bindingsOf, capturesOf } from "./params.js";
3
+ import { bindingsOf, capturesOf, isValue } from "./params.js";
4
4
  import { sourceName } from "./bindingKey.js";
5
5
  import { array, arrow, call, createNames, imported, literal, object, } from "../print/code.js";
6
6
  // Names a binding may not take: what strict code cannot bind. Every name the
@@ -25,7 +25,7 @@ const rootScope = () => ({ bindings: new Set(), read: new Set() });
25
25
  // name, a capture is threaded under that one name the whole way down — an
26
26
  // intermediate script that binds a same-looking variable has a different
27
27
  // unique name, so there is nothing to disambiguate and nothing to rename.
28
- export async function buildBundle(value, provided) {
28
+ export async function buildBundle(spliceable, provided) {
29
29
  const names = createNames(provided);
30
30
  // Each script's number, in the order rendering first reaches it. Two
31
31
  // scripts written at one source location are one declaration, so the first
@@ -86,21 +86,19 @@ export async function buildBundle(value, provided) {
86
86
  const passKeys = (target, hole) => bindingsOf(target.module.params[hole]);
87
87
  // A script's label: `$cs` and its number.
88
88
  const labelOf = (target) => `$cs${numbers.get(target)}`;
89
- // Every function the bundle writes is a closure: a function script, and the
90
- // thunk a splice is handed over as. One whose code reads nothing of the
89
+ // The thunk a splice is handed over as. One whose code reads nothing of the
91
90
  // scope it's written in, beyond its own parameters, is the same function
92
91
  // wherever it's written, so the bundle makes it once, as a constant, and
93
- // the same code anywhere else is that constant: a client component keeps
94
- // its identity across renders, and a value spliced at every level of a deep
95
- // composition is written once per level, not once per path. Making a
96
- // function runs nothing, so sharing one isn't observable; everything is
97
- // still rendered where it stands.
92
+ // the same code anywhere else is that constant: a value spliced at every
93
+ // level of a deep composition is written once per level, not once per path.
94
+ // A thunk is the bundle's own, never the script's, so sharing one isn't
95
+ // observable; everything is still rendered where it stands.
98
96
  const constants = [];
99
97
  const byCode = new Map();
100
- // `write` renders a closure's code in a scope that records what it reads:
101
- // a constant's label if it read nothing of `scope` beyond `own`, its
98
+ // `write` renders a thunk's code in a scope that records what it reads: a
99
+ // constant's label if it read nothing of `scope` beyond `own`, its
102
100
  // parameters, or else the code, written where it's used.
103
- const closure = (scope, own, write, name) => {
101
+ const thunk = (scope, own, write) => {
104
102
  const read = new Set();
105
103
  const code = write({
106
104
  bindings: new Set([...scope.bindings, ...own]),
@@ -113,27 +111,39 @@ export async function buildBundle(value, provided) {
113
111
  }
114
112
  let label = byCode.get(code);
115
113
  if (label === undefined) {
116
- label = `${name}${constants.length}`;
114
+ label = `$thunk${constants.length}`;
117
115
  byCode.set(code, label);
118
116
  constants.push([label, code]);
119
117
  }
120
118
  return label;
121
119
  };
122
- // A `once` script is one value: its code run at the top of the bundle,
123
- // where nothing encloses it, and every read is that constant. One per
124
- // script, which is one per call of `once`, not per code: two runs of a host
125
- // function that each make a context are two contexts, as two calls of
126
- // `createContext` are. Running code is observable, so unlike a function it
127
- // is never shared by code.
120
+ // A function, a class and a `once` script are each one value (see
121
+ // `isValue`): its code run at the top of the bundle, where nothing encloses
122
+ // it, and every read is that constant. One per script, not per code: two
123
+ // runs of a host function that each make a function are two functions, and
124
+ // two that each make a context two contexts, as in plain TypeScript.
125
+ //
126
+ // A function or a class that reads a variable of the scope it's read in,
127
+ // itself or through what it's handed, is made there instead, as one
128
+ // declared in a function is. A `once` script that does is refused.
128
129
  const values = new Map();
129
- const valueOf = (script) => {
130
+ const valueOf = (script, scope) => {
130
131
  let label = values.get(script);
131
- if (label === undefined) {
132
- const code = call(labelOf(scriptFor(script)), exprCallArgs(script, rootScope()));
133
- label = `$value${constants.length}`;
134
- values.set(script, label);
135
- constants.push([label, code]);
132
+ if (label !== undefined) {
133
+ return label;
136
134
  }
135
+ const at = script.once
136
+ ? rootScope()
137
+ : { bindings: scope.bindings, read: new Set() };
138
+ const code = call(labelOf(scriptFor(script)), exprCallArgs(script, at));
139
+ const outside = [...at.read].filter((key) => scope.bindings.has(key));
140
+ if (outside.length > 0) {
141
+ outside.forEach((key) => scope.read.add(key));
142
+ return code;
143
+ }
144
+ label = `$value${constants.length}`;
145
+ values.set(script, label);
146
+ constants.push([label, code]);
137
147
  return label;
138
148
  };
139
149
  // Writes a value as the code it becomes: composition as data, which is what
@@ -141,34 +151,34 @@ export async function buildBundle(value, provided) {
141
151
  // what to hand it; everything else is its literal form. Rendered in order,
142
152
  // one value after the other, so the table follows the order rendering first
143
153
  // reached each script. Expansion has refused cycles, so it ends.
144
- const render = (value, scope = rootScope()) => {
145
- if (isClientScript(value)) {
146
- if (value.once) {
147
- return valueOf(value);
154
+ const render = (spliceable, scope = rootScope()) => {
155
+ if (isClientScript(spliceable)) {
156
+ if (isValue(spliceable)) {
157
+ return valueOf(spliceable, scope);
148
158
  }
149
- const target = scriptFor(value);
150
- if (target.module.kind !== "function") {
151
- return call(labelOf(target), exprCallArgs(value, scope));
152
- }
153
- return closure(scope, [], (inner) => call(labelOf(target), exprCallArgs(value, inner)), "$function");
159
+ return call(labelOf(scriptFor(spliceable)), exprCallArgs(spliceable, scope));
160
+ }
161
+ if (isJsxElement(spliceable)) {
162
+ return renderJsx(spliceable);
154
163
  }
155
- if (isJsxElement(value)) {
156
- return renderJsx(value);
164
+ if (isClientImport(spliceable)) {
165
+ return imported(names, spliceable);
157
166
  }
158
- if (isClientImport(value)) {
159
- return imported(names, value);
167
+ if (isClientExec(spliceable)) {
168
+ names.exec = true;
169
+ return "$exec";
160
170
  }
161
- if (value === null ||
162
- value === undefined ||
163
- typeof value === "number" ||
164
- typeof value === "bigint" ||
165
- typeof value === "string" ||
166
- typeof value === "boolean") {
167
- return literal(value);
171
+ if (spliceable === null ||
172
+ spliceable === undefined ||
173
+ typeof spliceable === "number" ||
174
+ typeof spliceable === "bigint" ||
175
+ typeof spliceable === "string" ||
176
+ typeof spliceable === "boolean") {
177
+ return literal(spliceable);
168
178
  }
169
- if (Array.isArray(value)) {
179
+ if (Array.isArray(spliceable)) {
170
180
  const elements = [];
171
- for (const element of value) {
181
+ for (const element of spliceable) {
172
182
  elements.push(render(element, scope));
173
183
  }
174
184
  return array(elements);
@@ -176,8 +186,8 @@ export async function buildBundle(value, provided) {
176
186
  // A host function is host code, which never reaches the client: client
177
187
  // code is written in a script, and reaches another as one.
178
188
  // A server component among them, written as a tag: `<$Rule />`.
179
- if (typeof value === "function") {
180
- const { name } = value;
189
+ if (typeof spliceable === "function") {
190
+ const { name } = spliceable;
181
191
  throw new Error((name === ""
182
192
  ? "Can't splice a host function"
183
193
  : `Can't splice the host function \`${name}\``) +
@@ -186,7 +196,7 @@ export async function buildBundle(value, provided) {
186
196
  "server component, draw it with a tag in a braced splice: " +
187
197
  `\`{\${<${/^[A-Z]/.test(name) ? name : "Name"} />}}\`.`);
188
198
  }
189
- if (typeof value !== "object") {
199
+ if (typeof spliceable !== "object") {
190
200
  throw new Error("Can't splice a symbol: a bundle can't write one that is the same " +
191
201
  "symbol on the client. Splice a string, and make the symbol from it " +
192
202
  "in a script: cs`Symbol.for($key)`.");
@@ -196,14 +206,14 @@ export async function buildBundle(value, provided) {
196
206
  // vanish — so fail loudly instead. An object with behaviour is built by a
197
207
  // client function: `state` for what it holds, arrows for what may be done
198
208
  // to it.
199
- const prototype = Object.getPrototypeOf(value);
209
+ const prototype = Object.getPrototypeOf(spliceable);
200
210
  if (prototype !== Object.prototype && prototype !== null) {
201
- const name = value.constructor?.name ?? "an unknown class";
211
+ const name = spliceable.constructor?.name ?? "an unknown class";
202
212
  throw new Error(`Can't splice this \`${name}\` instance: only plain objects cross into ` +
203
213
  "a client script. Build one with a client function instead.");
204
214
  }
205
215
  const entries = [];
206
- for (const [key, entry] of Object.entries(value)) {
216
+ for (const [key, entry] of Object.entries(spliceable)) {
207
217
  entries.push([key, render(entry, scope)]);
208
218
  }
209
219
  return object(entries);
@@ -239,7 +249,7 @@ export async function buildBundle(value, provided) {
239
249
  // nested inside it.
240
250
  const passed = [...passKeys(target, index), ...capturesOf(target)];
241
251
  // A thunk taking them, the splice rendered inside it.
242
- parts.push(closure(scope, passed, (inner) => arrow(passed.map(displayName), render(arg, inner)), "$thunk"));
252
+ parts.push(thunk(scope, passed, (inner) => arrow(passed.map(displayName), render(arg, inner))));
243
253
  }
244
254
  for (const key of capturesOf(target)) {
245
255
  parts.push(capExpr(key, scope));
@@ -263,7 +273,7 @@ export async function buildBundle(value, provided) {
263
273
  };
264
274
  // Every server component first, so siblings run at once; then the drawing,
265
275
  // in order. Nothing encloses the root, so nothing it holds can capture.
266
- const root = render(await expandServerComponents(value));
276
+ const root = render(await expandServerComponents(spliceable));
267
277
  // In table order, which is the order rendering first reached each script.
268
278
  const modules = [...numbers.keys()].map((script) => [labelOf(script), script.module]);
269
279
  return { modules, constants, root, names };
@@ -1 +1 @@
1
- {"version":3,"file":"buildBundle.js","sourceRoot":"","sources":["../../src/bundle/buildBundle.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,cAAc,EACd,cAAc,EACd,YAAY,GAEb,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EACL,KAAK,EACL,KAAK,EACL,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,OAAO,EACP,MAAM,GACP,MAAM,kBAAkB,CAAC;AAkB1B,6EAA6E;AAC7E,4EAA4E;AAC5E,4BAA4B;AAC5B,MAAM,QAAQ,GAAG,CAAC,WAA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,CAAC,CAAC,MAAM,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC;QACrE,MAAM,IAAI,KAAK,CACb,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"}
@@ -3,5 +3,5 @@ interface Ancestors {
3
3
  readonly value: object;
4
4
  readonly parent: Ancestors | null;
5
5
  }
6
- export declare function expandServerComponents(value: unknown, ancestors?: Ancestors | null, values?: Map<ClientScript, Promise<unknown>>): Promise<unknown>;
6
+ export declare function expandServerComponents(spliceable: unknown, ancestors?: Ancestors | null, values?: Map<ClientScript, Promise<unknown>>): Promise<unknown>;
7
7
  export {};
@@ -1,4 +1,5 @@
1
1
  import { isClientImport, isClientScript, isJsxElement, } from "@backtickjs/core";
2
+ import { isValue } from "./params.js";
2
3
  const CYCLE_ERROR = "Can't splice a value that contains itself: a bundle writes each value " +
3
4
  "out in full, so a cycle never ends. Break the cycle before splicing it.";
4
5
  const contains = (ancestors, value) => {
@@ -18,58 +19,59 @@ const contains = (ancestors, value) => {
18
19
  // the client code it bottoms out in reaches the bundle. A value holding no
19
20
  // server component comes back as the same object.
20
21
  //
21
- // A `once` script is one value, so what it splices is expanded once, however
22
- // many places read it: a server component inside it runs once. `values` holds
22
+ // A function, a class and a `once` script are each one value (see `isValue`),
23
+ // so what one splices is expanded once, however many places read it: a server
24
+ // component inside it runs once. `values` holds
23
25
  // each one's expansion for the call.
24
- export async function expandServerComponents(value, ancestors = null, values = new Map()) {
25
- if (typeof value !== "object" || value === null) {
26
- return value;
26
+ export async function expandServerComponents(spliceable, ancestors = null, values = new Map()) {
27
+ if (typeof spliceable !== "object" || spliceable === null) {
28
+ return spliceable;
27
29
  }
28
- if (contains(ancestors, value)) {
30
+ if (contains(ancestors, spliceable)) {
29
31
  throw new Error(CYCLE_ERROR);
30
32
  }
31
- const inside = { value, parent: ancestors };
33
+ const inside = { value: spliceable, parent: ancestors };
32
34
  const all = (entries) => Promise.all(entries.map((entry) => expandServerComponents(entry, inside, values)));
33
- if (isJsxElement(value)) {
34
- const { type } = value;
35
+ if (isJsxElement(spliceable)) {
36
+ const { type } = spliceable;
35
37
  // A tag the client draws is left for rendering to refuse.
36
38
  if (typeof type !== "function" || isClientImport(type)) {
37
- return value;
39
+ return spliceable;
38
40
  }
39
- return expandServerComponents(await type(value.props), inside, values);
41
+ return expandServerComponents(await type(spliceable.props), inside, values);
40
42
  }
41
- if (isClientScript(value)) {
43
+ if (isClientScript(spliceable)) {
42
44
  const expanded = async () => {
43
- const args = await all(value.args);
44
- return args.every((arg, index) => arg === value.args[index])
45
- ? value
46
- : { ...value, args };
45
+ const args = await all(spliceable.args);
46
+ return args.every((arg, index) => arg === spliceable.args[index])
47
+ ? spliceable
48
+ : { ...spliceable, args };
47
49
  };
48
- if (!value.once) {
50
+ if (!isValue(spliceable)) {
49
51
  return expanded();
50
52
  }
51
- let made = values.get(value);
53
+ let made = values.get(spliceable);
52
54
  if (made === undefined) {
53
55
  made = expanded();
54
- values.set(value, made);
56
+ values.set(spliceable, made);
55
57
  }
56
58
  return made;
57
59
  }
58
- if (Array.isArray(value)) {
59
- const elements = await all(value);
60
- return elements.every((element, index) => element === value[index])
61
- ? value
60
+ if (Array.isArray(spliceable)) {
61
+ const elements = await all(spliceable);
62
+ return elements.every((element, index) => element === spliceable[index])
63
+ ? spliceable
62
64
  : elements;
63
65
  }
64
66
  // Only plain objects cross; rendering refuses anything else.
65
- const prototype = Object.getPrototypeOf(value);
67
+ const prototype = Object.getPrototypeOf(spliceable);
66
68
  if (prototype !== Object.prototype && prototype !== null) {
67
- return value;
69
+ return spliceable;
68
70
  }
69
- const entries = Object.entries(value);
71
+ const entries = Object.entries(spliceable);
70
72
  const expanded = await all(entries.map(([, entry]) => entry));
71
73
  if (expanded.every((entry, index) => entry === entries[index][1])) {
72
- return value;
74
+ return spliceable;
73
75
  }
74
76
  // Defined, not assigned, so a `__proto__` key stays a key.
75
77
  return Object.fromEntries(entries.map(([key], index) => [key, expanded[index]]));
@@ -1 +1 @@
1
- {"version":3,"file":"expandServerComponents.js","sourceRoot":"","sources":["../../src/bundle/expandServerComponents.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EACd,cAAc,EACd,YAAY,GACb,MAAM,kBAAkB,CAAC;AAE1B,MAAM,WAAW,GACf,wEAAwE;IACxE,yEAAyE,CAAC;AAS5E,MAAM,QAAQ,GAAG,CAAC,SAA2B,EAAE,KAAa,EAAW,EAAE;IACvE,KAAK,IAAI,EAAE,GAAG,SAAS,EAAE,EAAE,KAAK,IAAI,EAAE,EAAE,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC;QACrD,IAAI,EAAE,CAAC,KAAK,KAAK,KAAK,EAAE,CAAC;YACvB,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,8EAA8E;AAC9E,6EAA6E;AAC7E,0EAA0E;AAC1E,EAAE;AACF,+EAA+E;AAC/E,6EAA6E;AAC7E,2EAA2E;AAC3E,kDAAkD;AAClD,EAAE;AACF,6EAA6E;AAC7E,8EAA8E;AAC9E,qCAAqC;AACrC,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,KAAc,EACd,YAA8B,IAAI,EAClC,SAAS,IAAI,GAAG,EAAkC;IAElD,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,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CACtD,CAAC;AACJ,CAAC"}
@@ -1,3 +1,4 @@
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;
3
4
  export declare function capturesOf(script: ClientScript): readonly string[];
@@ -3,6 +3,15 @@
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
+ }
6
15
  // The binding keys a script captures, in parameter order.
7
16
  export function capturesOf(script) {
8
17
  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,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"}
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,wEAAwE;AACxE,8EAA8E;AAC9E,8EAA8E;AAC9E,qEAAqE;AACrE,MAAM,UAAU,OAAO,CAAC,MAAoB;IAC1C,OAAO,CACL,MAAM,CAAC,IAAI,KAAK,IAAI;QACpB,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,UAAU;QACjC,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,OAAO,CAC/B,CAAC;AACJ,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/dist/bundler.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Spliceable, SplicesAs } from "@backtickjs/core";
1
+ import type { Bundle, Spliceable, Spliced, SplicesAs } from "@backtickjs/core";
2
2
  import type { Modules } from "./modules.js";
3
3
  export interface BuildOptions<T = Spliceable> {
4
4
  readonly input: T;
@@ -8,26 +8,30 @@ export interface OutputOptions {
8
8
  readonly format: "es" | "cjs";
9
9
  readonly sourcemap?: false | "inline" | "hidden";
10
10
  }
11
- /** What `generate` writes: the code, and its map where one was asked for. */
12
- export interface OutputChunk {
13
- readonly code: string;
11
+ /**
12
+ * What `generate` writes: the bundle, which runs to a `T`, and its map where
13
+ * one was asked for.
14
+ */
15
+ export interface OutputChunk<T = unknown> {
16
+ readonly code: Bundle<T>;
14
17
  readonly map: string | null;
15
18
  }
16
- /** A built bundle, written out by `generate`. */
17
- export interface Bundle {
18
- generate(options: OutputOptions): OutputChunk;
19
+ /** What `build` makes of a value that is a `T` on the client, written out by
20
+ * `generate`. */
21
+ export interface Build<T = unknown> {
22
+ generate(options: OutputOptions): OutputChunk<T>;
19
23
  }
20
24
  /**
21
25
  * What runs your components and hands back what they drew, shaped as Rollup
22
26
  * is: a build, then output from it.
23
27
  *
24
- * const bundle = await bundler.build({ input: <Home />, modules });
25
- * const { code, map } = bundle.generate({ format: "es", sourcemap: "hidden" });
28
+ * const build = await bundler.build({ input: <Home />, modules });
29
+ * const { code, map } = build.generate({ format: "es", sourcemap: "hidden" });
26
30
  *
27
- * The module's default export is the value (CommonJS: `module.exports`). A
28
- * namespace rather than a bare function, so `bundle` stays a name a caller can
29
- * give what comes back.
31
+ * `code` is the bundle, a module whose default export is the value (CommonJS:
32
+ * `module.exports`). A namespace rather than a bare function, so `build`
33
+ * stays a name a caller can give what comes back.
30
34
  */
31
35
  export declare const bundler: {
32
- build<T extends [T] extends [SplicesAs<T>] ? unknown : Spliceable>({ input, modules, }: BuildOptions<T>): Promise<Bundle>;
36
+ build<T extends [T] extends [SplicesAs<T>] ? unknown : Spliceable>({ input, modules, }: BuildOptions<T>): Promise<Build<Spliced<T>>>;
33
37
  };
package/dist/bundler.js CHANGED
@@ -4,12 +4,12 @@ import { printBundle } from "./print/printBundle.js";
4
4
  * What runs your components and hands back what they drew, shaped as Rollup
5
5
  * is: a build, then output from it.
6
6
  *
7
- * const bundle = await bundler.build({ input: <Home />, modules });
8
- * const { code, map } = bundle.generate({ format: "es", sourcemap: "hidden" });
7
+ * const build = await bundler.build({ input: <Home />, modules });
8
+ * const { code, map } = build.generate({ format: "es", sourcemap: "hidden" });
9
9
  *
10
- * The module's default export is the value (CommonJS: `module.exports`). A
11
- * namespace rather than a bare function, so `bundle` stays a name a caller can
12
- * give what comes back.
10
+ * `code` is the bundle, a module whose default export is the value (CommonJS:
11
+ * `module.exports`). A namespace rather than a bare function, so `build`
12
+ * stays a name a caller can give what comes back.
13
13
  */
14
14
  export const bundler = {
15
15
  async build({ input, modules, }) {
@@ -18,7 +18,9 @@ export const bundler = {
18
18
  const tree = await buildBundle(input, modules);
19
19
  return {
20
20
  generate: ({ format, sourcemap = false }) => {
21
- const { code, map } = printBundle(tree, format);
21
+ const printed = printBundle(tree, format);
22
+ const code = printed.code;
23
+ const map = printed.map;
22
24
  if (sourcemap === false) {
23
25
  return { code, map: null };
24
26
  }
@@ -26,7 +28,10 @@ export const bundler = {
26
28
  return { code, map };
27
29
  }
28
30
  const url = `data:application/json;charset=utf-8,${encodeURIComponent(map)}`;
29
- return { code: `${code}\n//# sourceMappingURL=${url}`, map };
31
+ return {
32
+ code: `${code}\n//# sourceMappingURL=${url}`,
33
+ map,
34
+ };
30
35
  },
31
36
  };
32
37
  },
@@ -1 +1 @@
1
- {"version":3,"file":"bundler.js","sourceRoot":"","sources":["../src/bundler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAiCrD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,KAAK,CAAC,KAAK,CAA8D,EACvE,KAAK,EACL,OAAO,GACS;QAChB,0EAA0E;QAC1E,uEAAuE;QACvE,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC/C,OAAO;YACL,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,SAAS,GAAG,KAAK,EAAE,EAAE,EAAE;gBAC1C,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;gBAChD,IAAI,SAAS,KAAK,KAAK,EAAE,CAAC;oBACxB,OAAO,EAAE,IAAI,EAAE,GAA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;gBACD,MAAM,GAAG,GAAG,uCAAuC,kBAAkB,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC7E,OAAO;oBACL,IAAI,EAAE,GAAG,IAAI,0BAA0B,GAAG,EAAwB;oBAClE,GAAG;iBACJ,CAAC;YACJ,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { type Bundle, type BuildOptions, bundler, type OutputChunk, type OutputOptions, } from "./bundler.js";
1
+ export { type Build, type BuildOptions, bundler, type OutputChunk, type OutputOptions, } from "./bundler.js";
2
2
  export { type Modules, supports } from "./modules.js";
@@ -11,6 +11,7 @@ export interface Names {
11
11
  local: string;
12
12
  }>;
13
13
  readonly modules: Modules;
14
+ exec: boolean;
14
15
  }
15
16
  export declare function createNames(modules: Modules): Names;
16
17
  export declare function string(value: string): string;
@@ -4,7 +4,7 @@ import { supports } from "../modules.js";
4
4
  // for the framework's compiler. Everything is code, as a string.
5
5
  const IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
6
6
  export function createNames(modules) {
7
- return { imports: new Map(), modules };
7
+ return { imports: new Map(), modules, exec: false };
8
8
  }
9
9
  // A string, as a literal: `<` escaped, so no `</script>` or `<!--` appears
10
10
  // when the bundle is inlined in a page, and the line and paragraph separators,
@@ -1 +1 @@
1
- {"version":3,"file":"code.js","sourceRoot":"","sources":["../../src/print/code.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEvD,6EAA6E;AAC7E,+EAA+E;AAC/E,iEAAiE;AAEjE,MAAM,UAAU,GAAG,4BAA4B,CAAC;AAWhD,MAAM,UAAU,WAAW,CAAC,OAAgB;IAC1C,OAAO,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE,EAAE,OAAO,EAAE,CAAC;AACzC,CAAC;AAED,2EAA2E;AAC3E,+EAA+E;AAC/E,qEAAqE;AACrE,MAAM,UAAU,MAAM,CAA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,CAAC,IAAI,CAAC,GAAG,CAAC;AACpE,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,kBAAkB,CAChC,IAAY,EACZ,IAAY,EACZ,KAAa;IAEb,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC7D,OAAO,WAAW,QAAQ,KAAK,KAAK,gBAAgB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;AACvE,CAAC"}
@@ -11,6 +11,20 @@ const RUNTIME = `const $require = (id) => {
11
11
  }
12
12
  return $exports[id];
13
13
  };`;
14
+ // Another bundle, executed as this one is, to its value. As CommonJS, handed the
15
+ // `require` this bundle was: inside the module table, `require` is the
16
+ // table's own.
17
+ const EXEC_CJS = `const $exec = async (bundle) => {
18
+ const module = { exports: {} };
19
+ new Function("module", "exports", "require", bundle)(module, module.exports, require);
20
+ return module.exports;
21
+ };`;
22
+ // As an ES module, imported whole, the page's import map answering its
23
+ // imports as it answers this bundle's.
24
+ const EXEC_ES = `const $exec = async (bundle) => {
25
+ const module = await import("data:text/javascript," + encodeURIComponent(bundle));
26
+ return module.default;
27
+ };`;
14
28
  /**
15
29
  * A bundle tree as a module whose default export is the tree's root: the value
16
30
  * bundled, as its scripts wrote it.
@@ -36,6 +50,9 @@ export function printBundle(tree, format) {
36
50
  for (const { from, name, local } of names.imports.values()) {
37
51
  module.line(declaration(from, name, local));
38
52
  }
53
+ if (names.exec) {
54
+ module.line(format === "es" ? EXEC_ES : EXEC_CJS);
55
+ }
39
56
  // Each script a module table's entry, as webpack's and Metro's are: its body
40
57
  // under its id, run once by `$require`. The modules they require are the
41
58
  // client's, each imported whole, once.
@@ -1 +1 @@
1
- {"version":3,"file":"printBundle.js","sourceRoot":"","sources":["../../src/print/printBundle.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,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AG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC/B,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACrB,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;YAC/B,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAE,CAAC,MAAM,CAAC;QACjD,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC;QAC9B,CAAC;IACH,CAAC;IAED,IAAI,CAAC,IAAY;QACf,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC;IAC1B,CAAC;IAED,sEAAsE;IACtE,MAAM,CAAC,EAAE,IAAI,EAAE,GAAG,EAAgB;QAChC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;YAClB,MAAM,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE;YAClD,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAW;SAC/B,CAAC,CAAC;QACH,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC;IAED,8EAA8E;IAC9E,GAAG;QACD,OAAO,IAAI,CAAC,SAAS,CAAC;YACpB,OAAO,EAAE,CAAC;YACV,IAAI,EAAE,SAAS;YACf,QAAQ,EAAE,IAAI,CAAC,SAAS;SACzB,CAAC,CAAC;IACL,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backtickjs/bundler",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
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.1.9",
42
+ "@backtickjs/core": "^0.1.11",
43
43
  "semver": "^7.8.1"
44
44
  },
45
45
  "devDependencies": {
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  type ClientModule,
3
3
  type ClientScript,
4
+ isClientExec,
4
5
  isClientImport,
5
6
  isClientScript,
6
7
  isJsxElement,
@@ -8,7 +9,7 @@ import {
8
9
  } from "@backtickjs/core";
9
10
 
10
11
  import { expandServerComponents } from "./expandServerComponents.js";
11
- import { bindingsOf, capturesOf } from "./params.js";
12
+ import { bindingsOf, capturesOf, isValue } from "./params.js";
12
13
  import { sourceName } from "./bindingKey.js";
13
14
  import {
14
15
  array,
@@ -69,7 +70,7 @@ const rootScope = (): Scope => ({ bindings: new Set(), read: new Set() });
69
70
  // intermediate script that binds a same-looking variable has a different
70
71
  // unique name, so there is nothing to disambiguate and nothing to rename.
71
72
  export async function buildBundle(
72
- value: unknown,
73
+ spliceable: unknown,
73
74
  provided: Modules,
74
75
  ): Promise<BundleTree> {
75
76
  const names = createNames(provided);
@@ -137,25 +138,22 @@ export async function buildBundle(
137
138
  const labelOf = (target: ClientScript): string =>
138
139
  `$cs${numbers.get(target)!}`;
139
140
 
140
- // Every function the bundle writes is a closure: a function script, and the
141
- // thunk a splice is handed over as. One whose code reads nothing of the
141
+ // The thunk a splice is handed over as. One whose code reads nothing of the
142
142
  // scope it's written in, beyond its own parameters, is the same function
143
143
  // wherever it's written, so the bundle makes it once, as a constant, and
144
- // the same code anywhere else is that constant: a client component keeps
145
- // its identity across renders, and a value spliced at every level of a deep
146
- // composition is written once per level, not once per path. Making a
147
- // function runs nothing, so sharing one isn't observable; everything is
148
- // still rendered where it stands.
144
+ // the same code anywhere else is that constant: a value spliced at every
145
+ // level of a deep composition is written once per level, not once per path.
146
+ // A thunk is the bundle's own, never the script's, so sharing one isn't
147
+ // observable; everything is still rendered where it stands.
149
148
  const constants: (readonly [string, string])[] = [];
150
149
  const byCode = new Map<string, string>();
151
- // `write` renders a closure's code in a scope that records what it reads:
152
- // a constant's label if it read nothing of `scope` beyond `own`, its
150
+ // `write` renders a thunk's code in a scope that records what it reads: a
151
+ // constant's label if it read nothing of `scope` beyond `own`, its
153
152
  // parameters, or else the code, written where it's used.
154
- const closure = (
153
+ const thunk = (
155
154
  scope: Scope,
156
155
  own: readonly string[],
157
156
  write: (inner: Scope) => string,
158
- name: string,
159
157
  ): string => {
160
158
  const read = new Set<string>();
161
159
  const code = write({
@@ -171,31 +169,40 @@ export async function buildBundle(
171
169
  }
172
170
  let label = byCode.get(code);
173
171
  if (label === undefined) {
174
- label = `${name}${constants.length}`;
172
+ label = `$thunk${constants.length}`;
175
173
  byCode.set(code, label);
176
174
  constants.push([label, code]);
177
175
  }
178
176
  return label;
179
177
  };
180
178
 
181
- // A `once` script is one value: its code run at the top of the bundle,
182
- // where nothing encloses it, and every read is that constant. One per
183
- // script, which is one per call of `once`, not per code: two runs of a host
184
- // function that each make a context are two contexts, as two calls of
185
- // `createContext` are. Running code is observable, so unlike a function it
186
- // is never shared by code.
179
+ // A function, a class and a `once` script are each one value (see
180
+ // `isValue`): its code run at the top of the bundle, where nothing encloses
181
+ // it, and every read is that constant. One per script, not per code: two
182
+ // runs of a host function that each make a function are two functions, and
183
+ // two that each make a context two contexts, as in plain TypeScript.
184
+ //
185
+ // A function or a class that reads a variable of the scope it's read in,
186
+ // itself or through what it's handed, is made there instead, as one
187
+ // declared in a function is. A `once` script that does is refused.
187
188
  const values = new Map<ClientScript, string>();
188
- const valueOf = (script: ClientScript): string => {
189
+ const valueOf = (script: ClientScript, scope: Scope): string => {
189
190
  let label = values.get(script);
190
- if (label === undefined) {
191
- const code = call(
192
- labelOf(scriptFor(script)),
193
- exprCallArgs(script, rootScope()),
194
- );
195
- label = `$value${constants.length}`;
196
- values.set(script, label);
197
- constants.push([label, code]);
191
+ if (label !== undefined) {
192
+ return label;
193
+ }
194
+ const at: Scope = script.once
195
+ ? rootScope()
196
+ : { bindings: scope.bindings, read: new Set() };
197
+ const code = call(labelOf(scriptFor(script)), exprCallArgs(script, at));
198
+ const outside = [...at.read].filter((key) => scope.bindings.has(key));
199
+ if (outside.length > 0) {
200
+ outside.forEach((key) => scope.read.add(key));
201
+ return code;
198
202
  }
203
+ label = `$value${constants.length}`;
204
+ values.set(script, label);
205
+ constants.push([label, code]);
199
206
  return label;
200
207
  };
201
208
 
@@ -204,41 +211,39 @@ export async function buildBundle(
204
211
  // what to hand it; everything else is its literal form. Rendered in order,
205
212
  // one value after the other, so the table follows the order rendering first
206
213
  // reached each script. Expansion has refused cycles, so it ends.
207
- const render = (value: unknown, scope: Scope = rootScope()): string => {
208
- if (isClientScript(value)) {
209
- if (value.once) {
210
- return valueOf(value);
214
+ const render = (spliceable: unknown, scope: Scope = rootScope()): string => {
215
+ if (isClientScript(spliceable)) {
216
+ if (isValue(spliceable)) {
217
+ return valueOf(spliceable, scope);
211
218
  }
212
- const target = scriptFor(value);
213
- if (target.module.kind !== "function") {
214
- return call(labelOf(target), exprCallArgs(value, scope));
215
- }
216
- return closure(
217
- scope,
218
- [],
219
- (inner) => call(labelOf(target), exprCallArgs(value, inner)),
220
- "$function",
219
+ return call(
220
+ labelOf(scriptFor(spliceable)),
221
+ exprCallArgs(spliceable, scope),
221
222
  );
222
223
  }
223
- if (isJsxElement(value)) {
224
- return renderJsx(value);
224
+ if (isJsxElement(spliceable)) {
225
+ return renderJsx(spliceable);
226
+ }
227
+ if (isClientImport(spliceable)) {
228
+ return imported(names, spliceable);
225
229
  }
226
- if (isClientImport(value)) {
227
- return imported(names, value);
230
+ if (isClientExec(spliceable)) {
231
+ names.exec = true;
232
+ return "$exec";
228
233
  }
229
234
  if (
230
- value === null ||
231
- value === undefined ||
232
- typeof value === "number" ||
233
- typeof value === "bigint" ||
234
- typeof value === "string" ||
235
- typeof value === "boolean"
235
+ spliceable === null ||
236
+ spliceable === undefined ||
237
+ typeof spliceable === "number" ||
238
+ typeof spliceable === "bigint" ||
239
+ typeof spliceable === "string" ||
240
+ typeof spliceable === "boolean"
236
241
  ) {
237
- return literal(value);
242
+ return literal(spliceable);
238
243
  }
239
- if (Array.isArray(value)) {
244
+ if (Array.isArray(spliceable)) {
240
245
  const elements: string[] = [];
241
- for (const element of value) {
246
+ for (const element of spliceable) {
242
247
  elements.push(render(element, scope));
243
248
  }
244
249
  return array(elements);
@@ -246,8 +251,8 @@ export async function buildBundle(
246
251
  // A host function is host code, which never reaches the client: client
247
252
  // code is written in a script, and reaches another as one.
248
253
  // A server component among them, written as a tag: `<$Rule />`.
249
- if (typeof value === "function") {
250
- const { name } = value;
254
+ if (typeof spliceable === "function") {
255
+ const { name } = spliceable;
251
256
  throw new Error(
252
257
  (name === ""
253
258
  ? "Can't splice a host function"
@@ -258,7 +263,7 @@ export async function buildBundle(
258
263
  `\`{\${<${/^[A-Z]/.test(name) ? name : "Name"} />}}\`.`,
259
264
  );
260
265
  }
261
- if (typeof value !== "object") {
266
+ if (typeof spliceable !== "object") {
262
267
  throw new Error(
263
268
  "Can't splice a symbol: a bundle can't write one that is the same " +
264
269
  "symbol on the client. Splice a string, and make the symbol from it " +
@@ -270,16 +275,16 @@ export async function buildBundle(
270
275
  // vanish — so fail loudly instead. An object with behaviour is built by a
271
276
  // client function: `state` for what it holds, arrows for what may be done
272
277
  // to it.
273
- const prototype = Object.getPrototypeOf(value);
278
+ const prototype = Object.getPrototypeOf(spliceable);
274
279
  if (prototype !== Object.prototype && prototype !== null) {
275
- const name = value.constructor?.name ?? "an unknown class";
280
+ const name = spliceable.constructor?.name ?? "an unknown class";
276
281
  throw new Error(
277
282
  `Can't splice this \`${name}\` instance: only plain objects cross into ` +
278
283
  "a client script. Build one with a client function instead.",
279
284
  );
280
285
  }
281
286
  const entries: [string, string][] = [];
282
- for (const [key, entry] of Object.entries(value)) {
287
+ for (const [key, entry] of Object.entries(spliceable)) {
283
288
  entries.push([key, render(entry, scope)]);
284
289
  }
285
290
  return object(entries);
@@ -320,11 +325,8 @@ export async function buildBundle(
320
325
  const passed = [...passKeys(target, index), ...capturesOf(target)];
321
326
  // A thunk taking them, the splice rendered inside it.
322
327
  parts.push(
323
- closure(
324
- scope,
325
- passed,
326
- (inner) => arrow(passed.map(displayName), render(arg, inner)),
327
- "$thunk",
328
+ thunk(scope, passed, (inner) =>
329
+ arrow(passed.map(displayName), render(arg, inner)),
328
330
  ),
329
331
  );
330
332
  }
@@ -356,7 +358,7 @@ export async function buildBundle(
356
358
 
357
359
  // Every server component first, so siblings run at once; then the drawing,
358
360
  // in order. Nothing encloses the root, so nothing it holds can capture.
359
- const root = render(await expandServerComponents(value));
361
+ const root = render(await expandServerComponents(spliceable));
360
362
  // In table order, which is the order rendering first reached each script.
361
363
  const modules = [...numbers.keys()].map(
362
364
  (script) => [labelOf(script), script.module] as const,
@@ -4,6 +4,7 @@ import {
4
4
  isClientScript,
5
5
  isJsxElement,
6
6
  } from "@backtickjs/core";
7
+ import { isValue } from "./params.js";
7
8
 
8
9
  const CYCLE_ERROR =
9
10
  "Can't splice a value that contains itself: a bundle writes each value " +
@@ -34,70 +35,71 @@ const contains = (ancestors: Ancestors | null, value: object): boolean => {
34
35
  // the client code it bottoms out in reaches the bundle. A value holding no
35
36
  // server component comes back as the same object.
36
37
  //
37
- // A `once` script is one value, so what it splices is expanded once, however
38
- // many places read it: a server component inside it runs once. `values` holds
38
+ // A function, a class and a `once` script are each one value (see `isValue`),
39
+ // so what one splices is expanded once, however many places read it: a server
40
+ // component inside it runs once. `values` holds
39
41
  // each one's expansion for the call.
40
42
  export async function expandServerComponents(
41
- value: unknown,
43
+ spliceable: unknown,
42
44
  ancestors: Ancestors | null = null,
43
45
  values = new Map<ClientScript, Promise<unknown>>(),
44
46
  ): Promise<unknown> {
45
- if (typeof value !== "object" || value === null) {
46
- return value;
47
+ if (typeof spliceable !== "object" || spliceable === null) {
48
+ return spliceable;
47
49
  }
48
- if (contains(ancestors, value)) {
50
+ if (contains(ancestors, spliceable)) {
49
51
  throw new Error(CYCLE_ERROR);
50
52
  }
51
- const inside: Ancestors = { value, parent: ancestors };
53
+ const inside: Ancestors = { value: spliceable, parent: ancestors };
52
54
  const all = (entries: readonly unknown[]) =>
53
55
  Promise.all(
54
56
  entries.map((entry) => expandServerComponents(entry, inside, values)),
55
57
  );
56
58
 
57
- if (isJsxElement(value)) {
58
- const { type } = value;
59
+ if (isJsxElement(spliceable)) {
60
+ const { type } = spliceable;
59
61
  // A tag the client draws is left for rendering to refuse.
60
62
  if (typeof type !== "function" || isClientImport(type)) {
61
- return value;
63
+ return spliceable;
62
64
  }
63
65
  return expandServerComponents(
64
- await type(value.props as never),
66
+ await type(spliceable.props as never),
65
67
  inside,
66
68
  values,
67
69
  );
68
70
  }
69
- if (isClientScript(value)) {
71
+ if (isClientScript(spliceable)) {
70
72
  const expanded = async (): Promise<unknown> => {
71
- const args = await all(value.args);
72
- return args.every((arg, index) => arg === value.args[index])
73
- ? value
74
- : { ...value, args };
73
+ const args = await all(spliceable.args);
74
+ return args.every((arg, index) => arg === spliceable.args[index])
75
+ ? spliceable
76
+ : { ...spliceable, args };
75
77
  };
76
- if (!value.once) {
78
+ if (!isValue(spliceable)) {
77
79
  return expanded();
78
80
  }
79
- let made = values.get(value);
81
+ let made = values.get(spliceable);
80
82
  if (made === undefined) {
81
83
  made = expanded();
82
- values.set(value, made);
84
+ values.set(spliceable, made);
83
85
  }
84
86
  return made;
85
87
  }
86
- if (Array.isArray(value)) {
87
- const elements = await all(value);
88
- return elements.every((element, index) => element === value[index])
89
- ? value
88
+ if (Array.isArray(spliceable)) {
89
+ const elements = await all(spliceable);
90
+ return elements.every((element, index) => element === spliceable[index])
91
+ ? spliceable
90
92
  : elements;
91
93
  }
92
94
  // Only plain objects cross; rendering refuses anything else.
93
- const prototype = Object.getPrototypeOf(value);
95
+ const prototype = Object.getPrototypeOf(spliceable);
94
96
  if (prototype !== Object.prototype && prototype !== null) {
95
- return value;
97
+ return spliceable;
96
98
  }
97
- const entries = Object.entries(value);
99
+ const entries = Object.entries(spliceable);
98
100
  const expanded = await all(entries.map(([, entry]) => entry));
99
101
  if (expanded.every((entry, index) => entry === entries[index]![1])) {
100
- return value;
102
+ return spliceable;
101
103
  }
102
104
  // Defined, not assigned, so a `__proto__` key stays a key.
103
105
  return Object.fromEntries(
@@ -7,6 +7,18 @@ 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
+
10
22
  // The binding keys a script captures, in parameter order.
11
23
  export function capturesOf(script: ClientScript): readonly string[] {
12
24
  return script.module.params.flatMap((param) =>
package/src/bundler.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Spliceable, SplicesAs } from "@backtickjs/core";
1
+ import type { Bundle, Spliceable, Spliced, SplicesAs } from "@backtickjs/core";
2
2
  import { buildBundle } from "./bundle/buildBundle.js";
3
3
  import type { Modules } from "./modules.js";
4
4
  import { printBundle } from "./print/printBundle.js";
@@ -23,39 +23,45 @@ export interface OutputOptions {
23
23
  readonly sourcemap?: false | "inline" | "hidden";
24
24
  }
25
25
 
26
- /** What `generate` writes: the code, and its map where one was asked for. */
27
- export interface OutputChunk {
28
- readonly code: string;
26
+ /**
27
+ * What `generate` writes: the bundle, which runs to a `T`, and its map where
28
+ * one was asked for.
29
+ */
30
+ export interface OutputChunk<T = unknown> {
31
+ readonly code: Bundle<T>;
29
32
  readonly map: string | null;
30
33
  }
31
34
 
32
- /** A built bundle, written out by `generate`. */
33
- export interface Bundle {
34
- generate(options: OutputOptions): OutputChunk;
35
+ /** What `build` makes of a value that is a `T` on the client, written out by
36
+ * `generate`. */
37
+ export interface Build<T = unknown> {
38
+ generate(options: OutputOptions): OutputChunk<T>;
35
39
  }
36
40
 
37
41
  /**
38
42
  * What runs your components and hands back what they drew, shaped as Rollup
39
43
  * is: a build, then output from it.
40
44
  *
41
- * const bundle = await bundler.build({ input: <Home />, modules });
42
- * const { code, map } = bundle.generate({ format: "es", sourcemap: "hidden" });
45
+ * const build = await bundler.build({ input: <Home />, modules });
46
+ * const { code, map } = build.generate({ format: "es", sourcemap: "hidden" });
43
47
  *
44
- * The module's default export is the value (CommonJS: `module.exports`). A
45
- * namespace rather than a bare function, so `bundle` stays a name a caller can
46
- * give what comes back.
48
+ * `code` is the bundle, a module whose default export is the value (CommonJS:
49
+ * `module.exports`). A namespace rather than a bare function, so `build`
50
+ * stays a name a caller can give what comes back.
47
51
  */
48
52
  export const bundler = {
49
53
  async build<T extends [T] extends [SplicesAs<T>] ? unknown : Spliceable>({
50
54
  input,
51
55
  modules,
52
- }: BuildOptions<T>): Promise<Bundle> {
56
+ }: BuildOptions<T>): Promise<Build<Spliced<T>>> {
53
57
  // Scripts come compiled for their framework when their host was built, so
54
58
  // the bundle is only put together: nothing is compiled or parsed here.
55
59
  const tree = await buildBundle(input, modules);
56
60
  return {
57
61
  generate: ({ format, sourcemap = false }) => {
58
- const { code, map } = printBundle(tree, format);
62
+ const printed = printBundle(tree, format);
63
+ const code = printed.code as Bundle<Spliced<T>>;
64
+ const map = printed.map;
59
65
  if (sourcemap === false) {
60
66
  return { code, map: null };
61
67
  }
@@ -63,7 +69,10 @@ export const bundler = {
63
69
  return { code, map };
64
70
  }
65
71
  const url = `data:application/json;charset=utf-8,${encodeURIComponent(map)}`;
66
- return { code: `${code}\n//# sourceMappingURL=${url}`, map };
72
+ return {
73
+ code: `${code}\n//# sourceMappingURL=${url}` as Bundle<Spliced<T>>,
74
+ map,
75
+ };
67
76
  },
68
77
  };
69
78
  },
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export {
2
- type Bundle,
2
+ type Build,
3
3
  type BuildOptions,
4
4
  bundler,
5
5
  type OutputChunk,
package/src/print/code.ts CHANGED
@@ -14,10 +14,12 @@ const IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
14
14
  export interface Names {
15
15
  readonly imports: Map<string, { from: string; name: string; local: string }>;
16
16
  readonly modules: Modules;
17
+ // whether a script executes another bundle, which `$exec` does
18
+ exec: boolean;
17
19
  }
18
20
 
19
21
  export function createNames(modules: Modules): Names {
20
- return { imports: new Map(), modules };
22
+ return { imports: new Map(), modules, exec: false };
21
23
  }
22
24
 
23
25
  // A string, as a literal: `<` escaped, so no `</script>` or `<!--` appears
@@ -16,6 +16,22 @@ const RUNTIME = `const $require = (id) => {
16
16
  return $exports[id];
17
17
  };`;
18
18
 
19
+ // Another bundle, executed as this one is, to its value. As CommonJS, handed the
20
+ // `require` this bundle was: inside the module table, `require` is the
21
+ // table's own.
22
+ const EXEC_CJS = `const $exec = async (bundle) => {
23
+ const module = { exports: {} };
24
+ new Function("module", "exports", "require", bundle)(module, module.exports, require);
25
+ return module.exports;
26
+ };`;
27
+
28
+ // As an ES module, imported whole, the page's import map answering its
29
+ // imports as it answers this bundle's.
30
+ const EXEC_ES = `const $exec = async (bundle) => {
31
+ const module = await import("data:text/javascript," + encodeURIComponent(bundle));
32
+ return module.default;
33
+ };`;
34
+
19
35
  /**
20
36
  * A bundle tree as a module whose default export is the tree's root: the value
21
37
  * bundled, as its scripts wrote it.
@@ -44,6 +60,9 @@ export function printBundle(
44
60
  for (const { from, name, local } of names.imports.values()) {
45
61
  module.line(declaration(from, name, local));
46
62
  }
63
+ if (names.exec) {
64
+ module.line(format === "es" ? EXEC_ES : EXEC_CJS);
65
+ }
47
66
  // Each script a module table's entry, as webpack's and Metro's are: its body
48
67
  // under its id, run once by `$require`. The modules they require are the
49
68
  // client's, each imported whole, once.