@backtickjs/bundler 0.1.4 → 0.1.6
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 +3 -2
- package/dist/bundle/buildBundle.d.ts +2 -2
- package/dist/bundle/buildBundle.js +34 -11
- package/dist/bundle/buildBundle.js.map +1 -1
- package/dist/bundle/expandJsxElement.d.ts +2 -2
- package/dist/bundle/expandJsxElement.js +1 -1
- package/dist/bundle/expandJsxElement.js.map +1 -1
- package/dist/bundler.d.ts +4 -4
- package/dist/bundler.js +1 -1
- package/dist/bundler.js.map +1 -1
- package/dist/print/code.d.ts +1 -2
- package/dist/print/code.js +4 -4
- package/dist/print/code.js.map +1 -1
- package/package.json +2 -2
- package/src/bundle/buildBundle.ts +39 -15
- package/src/bundle/expandJsxElement.ts +3 -3
- package/src/bundler.ts +8 -5
- package/src/print/code.ts +7 -6
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@ The packages the client provides, each at its exact version. The server decides
|
|
|
47
47
|
|
|
48
48
|
### What crosses into a script
|
|
49
49
|
|
|
50
|
-
Spliced values are written into the bundle as data
|
|
50
|
+
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.
|
|
51
51
|
|
|
52
52
|
### Formats
|
|
53
53
|
|
|
@@ -69,7 +69,8 @@ Spliced values are written into the bundle as data: strings, finite numbers, boo
|
|
|
69
69
|
- [`@backtickjs/core`](https://github.com/backtickjs/backtick/tree/main/packages/core): the `cs` tag
|
|
70
70
|
- [`@backtickjs/react-native-client`](https://github.com/backtickjs/backtick/tree/main/packages/react-native-client): runs a `cjs` bundle in a React Native app
|
|
71
71
|
- [`@backtickjs/react`](https://github.com/backtickjs/backtick/tree/main/packages/react), [`@backtickjs/react-native`](https://github.com/backtickjs/backtick/tree/main/packages/react-native), [`@backtickjs/solid-js`](https://github.com/backtickjs/backtick/tree/main/packages/solid-js): framework adapters
|
|
72
|
-
- [
|
|
72
|
+
- [How it works](https://backtickjs.com/docs/how-it-works)
|
|
73
|
+
- [Errors](https://backtickjs.com/docs/errors)
|
|
73
74
|
|
|
74
75
|
## License
|
|
75
76
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ClientModule
|
|
1
|
+
import { type ClientModule } from "@backtickjs/core";
|
|
2
2
|
import type { Names } from "../print/code.js";
|
|
3
3
|
/**
|
|
4
4
|
* A bundle as it is built, before it is printed: each script's module it
|
|
@@ -11,4 +11,4 @@ export interface BundleTree {
|
|
|
11
11
|
readonly root: string;
|
|
12
12
|
readonly names: Names;
|
|
13
13
|
}
|
|
14
|
-
export declare function buildBundle(value:
|
|
14
|
+
export declare function buildBundle(value: unknown, packageVersions: Readonly<Record<string, string>>): Promise<BundleTree>;
|
|
@@ -2,7 +2,7 @@ import { isClientImport, isClientScript, isJsxElement, } from "@backtickjs/core"
|
|
|
2
2
|
import { expandJsxElement } from "./expandJsxElement.js";
|
|
3
3
|
import { bindingsOf, capturesOf } from "./params.js";
|
|
4
4
|
import { sourceName } from "./bindingKey.js";
|
|
5
|
-
import { array, arrow, call, createNames, imported, literal, object,
|
|
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
|
|
7
7
|
// bundle introduces starts with `$`, which a script cannot bind, so none of
|
|
8
8
|
// those can meet a binding.
|
|
@@ -124,7 +124,28 @@ export async function buildBundle(value, packageVersions) {
|
|
|
124
124
|
// what to hand it; everything else is its literal form. Rendered in order,
|
|
125
125
|
// one value after the other, so the table follows the order rendering first
|
|
126
126
|
// reached each script.
|
|
127
|
+
// The objects rendering is inside of now. One it meets again contains
|
|
128
|
+
// itself, which written out would never end. A value used in two places
|
|
129
|
+
// isn't one: it's left before it's met again.
|
|
130
|
+
const path = new Set();
|
|
127
131
|
const render = async (value, scope = rootScope()) => {
|
|
132
|
+
if (typeof value !== "object" || value === null) {
|
|
133
|
+
return renderValue(value, scope);
|
|
134
|
+
}
|
|
135
|
+
if (path.has(value)) {
|
|
136
|
+
throw new Error("Can't splice a value that contains itself: a bundle writes each " +
|
|
137
|
+
"value out in full, so a cycle never ends. Break the cycle before " +
|
|
138
|
+
"splicing it.");
|
|
139
|
+
}
|
|
140
|
+
path.add(value);
|
|
141
|
+
try {
|
|
142
|
+
return await renderValue(value, scope);
|
|
143
|
+
}
|
|
144
|
+
finally {
|
|
145
|
+
path.delete(value);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
const renderValue = async (value, scope) => {
|
|
128
149
|
if (isClientScript(value)) {
|
|
129
150
|
const target = scriptFor(value);
|
|
130
151
|
if (target.module.kind !== "function") {
|
|
@@ -138,14 +159,10 @@ export async function buildBundle(value, packageVersions) {
|
|
|
138
159
|
if (isClientImport(value)) {
|
|
139
160
|
return imported(names, value);
|
|
140
161
|
}
|
|
141
|
-
if (value === null
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
if (value === undefined) {
|
|
146
|
-
return undefinedValue;
|
|
147
|
-
}
|
|
148
|
-
if (typeof value === "number" ||
|
|
162
|
+
if (value === null ||
|
|
163
|
+
value === undefined ||
|
|
164
|
+
typeof value === "number" ||
|
|
165
|
+
typeof value === "bigint" ||
|
|
149
166
|
typeof value === "string" ||
|
|
150
167
|
typeof value === "boolean") {
|
|
151
168
|
return literal(value);
|
|
@@ -166,8 +183,14 @@ export async function buildBundle(value, packageVersions) {
|
|
|
166
183
|
? "Can't splice a host function"
|
|
167
184
|
: `Can't splice the host function \`${name}\``) +
|
|
168
185
|
": it's host code, and only runs on the host. Write a client " +
|
|
169
|
-
"function as a script instead: cs`(n: number) =>
|
|
170
|
-
|
|
186
|
+
"function as a script instead: cs`(n: number) => ...`. If it's a " +
|
|
187
|
+
"server component, draw it with a tag in a braced splice: " +
|
|
188
|
+
`\`{\${<${/^[A-Z]/.test(name) ? name : "Name"} />}}\`.`);
|
|
189
|
+
}
|
|
190
|
+
if (typeof value !== "object") {
|
|
191
|
+
throw new Error("Can't splice a symbol: a bundle can't write one that is the same " +
|
|
192
|
+
"symbol on the client. Splice a string, and make the symbol from it " +
|
|
193
|
+
"in a script: cs`Symbol.for($key)`.");
|
|
171
194
|
}
|
|
172
195
|
// Only plain objects cross structurally. A class instance would land here
|
|
173
196
|
// and half-work — own fields would cross, getters and methods silently
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildBundle.js","sourceRoot":"","sources":["../../src/bundle/buildBundle.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,cAAc,EACd,cAAc,EACd,YAAY,
|
|
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,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,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;AAiB1B,6EAA6E;AAC7E,4EAA4E;AAC5E,4BAA4B;AAC5B,MAAM,QAAQ,GAAG,CAAC,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAUzD,MAAM,SAAS,GAAG,GAAU,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,GAAG,EAAE,EAAE,IAAI,EAAE,IAAI,GAAG,EAAE,EAAE,CAAC,CAAC;AAE1E,+DAA+D;AAC/D,EAAE;AACF,6EAA6E;AAC7E,4EAA4E;AAC5E,wEAAwE;AACxE,wEAAwE;AACxE,8EAA8E;AAC9E,WAAW;AACX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IAAI,CAAC,EAAE,CAAC;YACxD,OAAO,MAAM,CAAC,MAAM,gBAAgB,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;QAC1D,CAAC;QACD,sEAAsE;QACtE,yEAAyE;QACzE,eAAe;QACf,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CACb,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,KAAK,CACb,GAAG,GAAG,4DAA4D;YAChE,8BAA8B,CACjC,CAAC;IACJ,CAAC,CAAC;IAEF,8DAA8D;IAC9D,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,CAAC;IACjC,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,2 +1,2 @@
|
|
|
1
|
-
import type { JsxElement
|
|
2
|
-
export declare function expandJsxElement(jsx: JsxElement, component: (props: never) => unknown): Promise<
|
|
1
|
+
import type { JsxElement } from "@backtickjs/core";
|
|
2
|
+
export declare function expandJsxElement(jsx: JsxElement, component: (props: never) => unknown): Promise<unknown>;
|
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
// itself never leaves the host: a server component expands away here, and
|
|
4
4
|
// only the client component it bottoms out in reaches the bundle.
|
|
5
5
|
export async function expandJsxElement(jsx, component) {
|
|
6
|
-
return
|
|
6
|
+
return component(jsx.props);
|
|
7
7
|
}
|
|
8
8
|
//# sourceMappingURL=expandJsxElement.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expandJsxElement.js","sourceRoot":"","sources":["../../src/bundle/expandJsxElement.ts"],"names":[],"mappings":"AAEA,4EAA4E;AAC5E,4EAA4E;AAC5E,0EAA0E;AAC1E,kEAAkE;AAClE,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,GAAe,EACf,SAAoC;IAEpC,OAAO,
|
|
1
|
+
{"version":3,"file":"expandJsxElement.js","sourceRoot":"","sources":["../../src/bundle/expandJsxElement.ts"],"names":[],"mappings":"AAEA,4EAA4E;AAC5E,4EAA4E;AAC5E,0EAA0E;AAC1E,kEAAkE;AAClE,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,GAAe,EACf,SAAoC;IAEpC,OAAO,SAAS,CAAC,GAAG,CAAC,KAAc,CAAC,CAAC;AACvC,CAAC"}
|
package/dist/bundler.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Spliceable } from "@backtickjs/core";
|
|
2
|
-
export interface BuildOptions {
|
|
3
|
-
readonly input:
|
|
1
|
+
import type { Spliceable, SplicesAs } from "@backtickjs/core";
|
|
2
|
+
export interface BuildOptions<T = Spliceable> {
|
|
3
|
+
readonly input: T;
|
|
4
4
|
readonly packageVersions: Readonly<Record<string, string>>;
|
|
5
5
|
}
|
|
6
6
|
export interface OutputOptions {
|
|
@@ -28,5 +28,5 @@ export interface Bundle {
|
|
|
28
28
|
* give what comes back.
|
|
29
29
|
*/
|
|
30
30
|
export declare const bundler: {
|
|
31
|
-
build({ input, packageVersions }: BuildOptions): Promise<Bundle>;
|
|
31
|
+
build<T extends [T] extends [SplicesAs<T>] ? unknown : Spliceable>({ input, packageVersions, }: BuildOptions<T>): Promise<Bundle>;
|
|
32
32
|
};
|
package/dist/bundler.js
CHANGED
|
@@ -12,7 +12,7 @@ import { printBundle } from "./print/printBundle.js";
|
|
|
12
12
|
* give what comes back.
|
|
13
13
|
*/
|
|
14
14
|
export const bundler = {
|
|
15
|
-
async build({ input, packageVersions }) {
|
|
15
|
+
async build({ input, packageVersions, }) {
|
|
16
16
|
// Scripts come compiled for their framework when their host was built, so
|
|
17
17
|
// the bundle is only put together: nothing is compiled or parsed here.
|
|
18
18
|
const tree = await buildBundle(input, packageVersions);
|
package/dist/bundler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundler.js","sourceRoot":"","sources":["../src/bundler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAiCrD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,KAAK,CAAC,KAAK,
|
|
1
|
+
{"version":3,"file":"bundler.js","sourceRoot":"","sources":["../src/bundler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAiCrD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,KAAK,CAAC,KAAK,CAA8D,EACvE,KAAK,EACL,eAAe,GACC;QAChB,0EAA0E;QAC1E,uEAAuE;QACvE,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC;QACvD,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,GAAG,EAAE,IAAI,EAAE,CAAC;gBAC7B,CAAC;gBACD,IAAI,SAAS,KAAK,QAAQ,EAAE,CAAC;oBAC3B,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;gBACvB,CAAC;gBACD,MAAM,GAAG,GAAG,uCAAuC,kBAAkB,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC7E,OAAO,EAAE,IAAI,EAAE,GAAG,IAAI,0BAA0B,GAAG,EAAE,EAAE,GAAG,EAAE,CAAC;YAC/D,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
|
package/dist/print/code.d.ts
CHANGED
|
@@ -13,8 +13,7 @@ export interface Names {
|
|
|
13
13
|
}
|
|
14
14
|
export declare function createNames(packageVersions: Readonly<Record<string, string>>): Names;
|
|
15
15
|
export declare function string(value: string): string;
|
|
16
|
-
export declare function literal(value: string | number | boolean | null): string;
|
|
17
|
-
export declare const undefinedValue = "void 0";
|
|
16
|
+
export declare function literal(value: string | number | bigint | boolean | null | undefined): string;
|
|
18
17
|
export declare function call(callee: string, args: readonly string[]): string;
|
|
19
18
|
export declare function arrow(params: readonly string[], body: string): string;
|
|
20
19
|
export declare function array(elements: readonly string[]): string;
|
package/dist/print/code.js
CHANGED
|
@@ -17,14 +17,14 @@ export function literal(value) {
|
|
|
17
17
|
return string(value);
|
|
18
18
|
}
|
|
19
19
|
if (typeof value === "number") {
|
|
20
|
-
|
|
21
|
-
throw new Error(`${value} has no literal`);
|
|
22
|
-
}
|
|
20
|
+
// `String` writes NaN and the infinities by name, but -0 as "0".
|
|
23
21
|
return Object.is(value, -0) ? "-0" : String(value);
|
|
24
22
|
}
|
|
23
|
+
if (typeof value === "bigint") {
|
|
24
|
+
return `${value}n`;
|
|
25
|
+
}
|
|
25
26
|
return String(value);
|
|
26
27
|
}
|
|
27
|
-
export const undefinedValue = "void 0";
|
|
28
28
|
export function call(callee, args) {
|
|
29
29
|
return `${callee}(${args.join(", ")})`;
|
|
30
30
|
}
|
package/dist/print/code.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code.js","sourceRoot":"","sources":["../../src/print/code.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,6EAA6E;AAC7E,+EAA+E;AAC/E,iEAAiE;AAEjE,MAAM,UAAU,GAAG,4BAA4B,CAAC;AAWhD,MAAM,UAAU,WAAW,CACzB,eAAiD;IAEjD,OAAO,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE,EAAE,eAAe,EAAE,CAAC;AACjD,CAAC;AAED,2EAA2E;AAC3E,+EAA+E;AAC/E,qEAAqE;AACrE,MAAM,UAAU,MAAM,CAAC,KAAa;IAClC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAClC,kBAAkB,EAClB,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CACnE,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,OAAO,
|
|
1
|
+
{"version":3,"file":"code.js","sourceRoot":"","sources":["../../src/print/code.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,6EAA6E;AAC7E,+EAA+E;AAC/E,iEAAiE;AAEjE,MAAM,UAAU,GAAG,4BAA4B,CAAC;AAWhD,MAAM,UAAU,WAAW,CACzB,eAAiD;IAEjD,OAAO,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE,EAAE,eAAe,EAAE,CAAC;AACjD,CAAC;AAED,2EAA2E;AAC3E,+EAA+E;AAC/E,qEAAqE;AACrE,MAAM,UAAU,MAAM,CAAC,KAAa;IAClC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAClC,kBAAkB,EAClB,CAAC,IAAI,EAA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;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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backtickjs/bundler",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
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",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"semver": "^7.8.1",
|
|
43
|
-
"@backtickjs/core": "0.1.
|
|
43
|
+
"@backtickjs/core": "0.1.6"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/semver": "^7.8.0",
|
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
isClientScript,
|
|
6
6
|
isJsxElement,
|
|
7
7
|
type JsxElement,
|
|
8
|
-
type Spliceable,
|
|
9
8
|
} from "@backtickjs/core";
|
|
10
9
|
|
|
11
10
|
import { expandJsxElement } from "./expandJsxElement.js";
|
|
@@ -19,7 +18,6 @@ import {
|
|
|
19
18
|
imported,
|
|
20
19
|
literal,
|
|
21
20
|
object,
|
|
22
|
-
undefinedValue,
|
|
23
21
|
} from "../print/code.js";
|
|
24
22
|
import type { Names } from "../print/code.js";
|
|
25
23
|
|
|
@@ -70,7 +68,7 @@ const rootScope = (): Scope => ({ bindings: new Set(), read: new Set() });
|
|
|
70
68
|
// intermediate script that binds a same-looking variable has a different
|
|
71
69
|
// unique name, so there is nothing to disambiguate and nothing to rename.
|
|
72
70
|
export async function buildBundle(
|
|
73
|
-
value:
|
|
71
|
+
value: unknown,
|
|
74
72
|
packageVersions: Readonly<Record<string, string>>,
|
|
75
73
|
): Promise<BundleTree> {
|
|
76
74
|
const names = createNames(packageVersions);
|
|
@@ -184,10 +182,32 @@ export async function buildBundle(
|
|
|
184
182
|
// what to hand it; everything else is its literal form. Rendered in order,
|
|
185
183
|
// one value after the other, so the table follows the order rendering first
|
|
186
184
|
// reached each script.
|
|
185
|
+
// The objects rendering is inside of now. One it meets again contains
|
|
186
|
+
// itself, which written out would never end. A value used in two places
|
|
187
|
+
// isn't one: it's left before it's met again.
|
|
188
|
+
const path = new Set<object>();
|
|
187
189
|
const render = async (
|
|
188
|
-
value:
|
|
190
|
+
value: unknown,
|
|
189
191
|
scope: Scope = rootScope(),
|
|
190
192
|
): Promise<string> => {
|
|
193
|
+
if (typeof value !== "object" || value === null) {
|
|
194
|
+
return renderValue(value, scope);
|
|
195
|
+
}
|
|
196
|
+
if (path.has(value)) {
|
|
197
|
+
throw new Error(
|
|
198
|
+
"Can't splice a value that contains itself: a bundle writes each " +
|
|
199
|
+
"value out in full, so a cycle never ends. Break the cycle before " +
|
|
200
|
+
"splicing it.",
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
path.add(value);
|
|
204
|
+
try {
|
|
205
|
+
return await renderValue(value, scope);
|
|
206
|
+
} finally {
|
|
207
|
+
path.delete(value);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
const renderValue = async (value: unknown, scope: Scope): Promise<string> => {
|
|
191
211
|
if (isClientScript(value)) {
|
|
192
212
|
const target = scriptFor(value);
|
|
193
213
|
if (target.module.kind !== "function") {
|
|
@@ -207,15 +227,11 @@ export async function buildBundle(
|
|
|
207
227
|
if (isClientImport(value)) {
|
|
208
228
|
return imported(names, value);
|
|
209
229
|
}
|
|
210
|
-
if (value === null) {
|
|
211
|
-
return literal(null);
|
|
212
|
-
}
|
|
213
|
-
// Checked by name, since everything past here reads the value as an object.
|
|
214
|
-
if (value === undefined) {
|
|
215
|
-
return undefinedValue;
|
|
216
|
-
}
|
|
217
230
|
if (
|
|
231
|
+
value === null ||
|
|
232
|
+
value === undefined ||
|
|
218
233
|
typeof value === "number" ||
|
|
234
|
+
typeof value === "bigint" ||
|
|
219
235
|
typeof value === "string" ||
|
|
220
236
|
typeof value === "boolean"
|
|
221
237
|
) {
|
|
@@ -232,14 +248,22 @@ export async function buildBundle(
|
|
|
232
248
|
// code is written in a script, and reaches another as one.
|
|
233
249
|
// A server component among them, written as a tag: `<$Rule />`.
|
|
234
250
|
if (typeof value === "function") {
|
|
235
|
-
const { name } = value
|
|
251
|
+
const { name } = value;
|
|
236
252
|
throw new Error(
|
|
237
253
|
(name === ""
|
|
238
254
|
? "Can't splice a host function"
|
|
239
255
|
: `Can't splice the host function \`${name}\``) +
|
|
240
256
|
": it's host code, and only runs on the host. Write a client " +
|
|
241
|
-
"function as a script instead: cs`(n: number) =>
|
|
242
|
-
|
|
257
|
+
"function as a script instead: cs`(n: number) => ...`. If it's a " +
|
|
258
|
+
"server component, draw it with a tag in a braced splice: " +
|
|
259
|
+
`\`{\${<${/^[A-Z]/.test(name) ? name : "Name"} />}}\`.`,
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
if (typeof value !== "object") {
|
|
263
|
+
throw new Error(
|
|
264
|
+
"Can't splice a symbol: a bundle can't write one that is the same " +
|
|
265
|
+
"symbol on the client. Splice a string, and make the symbol from it " +
|
|
266
|
+
"in a script: cs`Symbol.for($key)`.",
|
|
243
267
|
);
|
|
244
268
|
}
|
|
245
269
|
// Only plain objects cross structurally. A class instance would land here
|
|
@@ -342,7 +366,7 @@ export async function buildBundle(
|
|
|
342
366
|
};
|
|
343
367
|
|
|
344
368
|
// Nothing encloses the root, so nothing it holds can capture.
|
|
345
|
-
const root = await render(value
|
|
369
|
+
const root = await render(value);
|
|
346
370
|
// In table order, which is the order rendering first reached each script.
|
|
347
371
|
const modules = [...numbers.keys()].map(
|
|
348
372
|
(script) => [labelOf(script), script.module] as const,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { JsxElement
|
|
1
|
+
import type { JsxElement } from "@backtickjs/core";
|
|
2
2
|
|
|
3
3
|
// Runs a host component and answers with what it drew, each time an element
|
|
4
4
|
// is drawn, as React renders an element each place it stands. The component
|
|
@@ -7,6 +7,6 @@ import type { JsxElement, Spliceable } from "@backtickjs/core";
|
|
|
7
7
|
export async function expandJsxElement(
|
|
8
8
|
jsx: JsxElement,
|
|
9
9
|
component: (props: never) => unknown,
|
|
10
|
-
): Promise<
|
|
11
|
-
return
|
|
10
|
+
): Promise<unknown> {
|
|
11
|
+
return component(jsx.props as never);
|
|
12
12
|
}
|
package/src/bundler.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { Spliceable } from "@backtickjs/core";
|
|
1
|
+
import type { Spliceable, SplicesAs } from "@backtickjs/core";
|
|
2
2
|
import { buildBundle } from "./bundle/buildBundle.js";
|
|
3
3
|
import { printBundle } from "./print/printBundle.js";
|
|
4
4
|
|
|
5
|
-
export interface BuildOptions {
|
|
6
|
-
// What to bundle.
|
|
7
|
-
readonly input:
|
|
5
|
+
export interface BuildOptions<T = Spliceable> {
|
|
6
|
+
// What to bundle: what a splice could carry, checked as a splice checks it.
|
|
7
|
+
readonly input: T;
|
|
8
8
|
// The packages the client provides, each at its exact version: left out of
|
|
9
9
|
// the bundle, which requires them. A script's import from any other, or
|
|
10
10
|
// needing a version it doesn't have, throws.
|
|
@@ -45,7 +45,10 @@ export interface Bundle {
|
|
|
45
45
|
* give what comes back.
|
|
46
46
|
*/
|
|
47
47
|
export const bundler = {
|
|
48
|
-
async build
|
|
48
|
+
async build<T extends [T] extends [SplicesAs<T>] ? unknown : Spliceable>({
|
|
49
|
+
input,
|
|
50
|
+
packageVersions,
|
|
51
|
+
}: BuildOptions<T>): Promise<Bundle> {
|
|
49
52
|
// Scripts come compiled for their framework when their host was built, so
|
|
50
53
|
// the bundle is only put together: nothing is compiled or parsed here.
|
|
51
54
|
const tree = await buildBundle(input, packageVersions);
|
package/src/print/code.ts
CHANGED
|
@@ -32,21 +32,22 @@ export function string(value: string): string {
|
|
|
32
32
|
);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export function literal(
|
|
35
|
+
export function literal(
|
|
36
|
+
value: string | number | bigint | boolean | null | undefined,
|
|
37
|
+
): string {
|
|
36
38
|
if (typeof value === "string") {
|
|
37
39
|
return string(value);
|
|
38
40
|
}
|
|
39
41
|
if (typeof value === "number") {
|
|
40
|
-
|
|
41
|
-
throw new Error(`${value} has no literal`);
|
|
42
|
-
}
|
|
42
|
+
// `String` writes NaN and the infinities by name, but -0 as "0".
|
|
43
43
|
return Object.is(value, -0) ? "-0" : String(value);
|
|
44
44
|
}
|
|
45
|
+
if (typeof value === "bigint") {
|
|
46
|
+
return `${value}n`;
|
|
47
|
+
}
|
|
45
48
|
return String(value);
|
|
46
49
|
}
|
|
47
50
|
|
|
48
|
-
export const undefinedValue = "void 0";
|
|
49
|
-
|
|
50
51
|
export function call(callee: string, args: readonly string[]): string {
|
|
51
52
|
return `${callee}(${args.join(", ")})`;
|
|
52
53
|
}
|