@backtickjs/core 0.4.0 → 0.5.1
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/ClientScript.d.ts +1 -0
- package/dist/ClientScript.js.map +1 -1
- package/dist/cjs.d.ts +5 -1
- package/dist/cjs.js +6 -2
- package/dist/cjs.js.map +1 -1
- package/package.json +1 -1
- package/src/ClientScript.ts +7 -3
- package/src/cjs.ts +6 -1
package/dist/ClientScript.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export interface ScriptModule {
|
|
|
13
13
|
readonly dependencies: readonly string[];
|
|
14
14
|
readonly params: readonly Param[];
|
|
15
15
|
readonly kind: "function" | "class" | "expression" | "block";
|
|
16
|
+
readonly scope: "module" | "function";
|
|
16
17
|
}
|
|
17
18
|
export interface ClientScript {
|
|
18
19
|
readonly "@backtickjs": "ClientScript";
|
package/dist/ClientScript.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClientScript.js","sourceRoot":"","sources":["../src/ClientScript.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ClientScript.js","sourceRoot":"","sources":["../src/ClientScript.ts"],"names":[],"mappings":"AA8CA,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,aAAa,IAAI,KAAK;QACtB,KAAK,CAAC,aAAa,CAAC,KAAK,cAAc,CACxC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,MAAM,CACpB,MAAoB,EACpB,IAA2B;IAE3B,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AACzD,CAAC"}
|
package/dist/cjs.d.ts
CHANGED
|
@@ -8,6 +8,10 @@ import type { ModuleMap } from "./modulesOf.js";
|
|
|
8
8
|
* entry an app imports is its format: a web page imports
|
|
9
9
|
* `@backtickjs/core/es`.
|
|
10
10
|
*
|
|
11
|
+
* Its values are kept in `values` by key, and so are those of the bundles it
|
|
12
|
+
* runs: one value per app, as a module is, however many bundles use it. A new
|
|
13
|
+
* `Map` by default, so a bundle run alone has its own.
|
|
14
|
+
*
|
|
11
15
|
* const screen = await execRoot(bundle, moduleMap);
|
|
12
16
|
*/
|
|
13
|
-
export declare function execRoot<T>(bundle: Bundle<T>, moduleMap: ModuleMap): Promise<Awaited<T>>;
|
|
17
|
+
export declare function execRoot<T>(bundle: Bundle<T>, moduleMap: ModuleMap, values?: Map<string, unknown>): Promise<Awaited<T>>;
|
package/dist/cjs.js
CHANGED
|
@@ -6,16 +6,20 @@
|
|
|
6
6
|
* entry an app imports is its format: a web page imports
|
|
7
7
|
* `@backtickjs/core/es`.
|
|
8
8
|
*
|
|
9
|
+
* Its values are kept in `values` by key, and so are those of the bundles it
|
|
10
|
+
* runs: one value per app, as a module is, however many bundles use it. A new
|
|
11
|
+
* `Map` by default, so a bundle run alone has its own.
|
|
12
|
+
*
|
|
9
13
|
* const screen = await execRoot(bundle, moduleMap);
|
|
10
14
|
*/
|
|
11
|
-
export async function execRoot(bundle, moduleMap) {
|
|
15
|
+
export async function execRoot(bundle, moduleMap, values = new Map()) {
|
|
12
16
|
const require = (specifier) => {
|
|
13
17
|
if (!Object.hasOwn(moduleMap, specifier)) {
|
|
14
18
|
throw new Error(`The bundle requires "${specifier}", which this app doesn't provide.`);
|
|
15
19
|
}
|
|
16
20
|
return moduleMap[specifier];
|
|
17
21
|
};
|
|
18
|
-
const module = { exports: {} };
|
|
22
|
+
const module = { exports: {}, values };
|
|
19
23
|
new Function("module", "exports", "require", bundle)(module, module.exports, require);
|
|
20
24
|
return module.exports;
|
|
21
25
|
}
|
package/dist/cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cjs.js","sourceRoot":"","sources":["../src/cjs.ts"],"names":[],"mappings":"AAGA
|
|
1
|
+
{"version":3,"file":"cjs.js","sourceRoot":"","sources":["../src/cjs.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,MAAiB,EACjB,SAAoB,EACpB,SAA+B,IAAI,GAAG,EAAE;IAExC,MAAM,OAAO,GAAG,CAAC,SAAiB,EAAW,EAAE;QAC7C,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,EAAE,CAAC;YACzC,MAAM,IAAI,KAAK,CACb,wBAAwB,SAAS,oCAAoC,CACtE,CAAC;QACJ,CAAC;QACD,OAAO,SAAS,CAAC,SAAS,CAAC,CAAC;IAC9B,CAAC,CAAC;IACF,MAAM,MAAM,GAAG,EAAE,OAAO,EAAE,EAAa,EAAE,MAAM,EAAE,CAAC;IAClD,IAAI,QAAQ,CAAC,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,CAClD,MAAM,EACN,MAAM,CAAC,OAAO,EACd,OAAO,CACR,CAAC;IACF,OAAO,MAAM,CAAC,OAAqB,CAAC;AACtC,CAAC"}
|
package/package.json
CHANGED
package/src/ClientScript.ts
CHANGED
|
@@ -23,10 +23,14 @@ export interface ScriptModule {
|
|
|
23
23
|
readonly dependencies: readonly string[];
|
|
24
24
|
// `params[i]` is the function's `$splice<i>` or `$capture<i>`
|
|
25
25
|
readonly params: readonly Param[];
|
|
26
|
-
// What the script is written as: a function, `(props) =>
|
|
27
|
-
//
|
|
28
|
-
// or an expression or a block, which a splice runs.
|
|
26
|
+
// What the script is written as: a function, `(props) => …`; a class,
|
|
27
|
+
// `class … {}`; an expression; or a block, which is the function it runs.
|
|
29
28
|
readonly kind: "function" | "class" | "expression" | "block";
|
|
29
|
+
// Where its `cs` is written in its host file: at the module's top level,
|
|
30
|
+
// run once, so its value is the app's, shared by every bundle of it, as a
|
|
31
|
+
// module-level `const` is; or in a function, run each call, so each value
|
|
32
|
+
// is its bundle's own.
|
|
33
|
+
readonly scope: "module" | "function";
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
// One run of a `cs`: its module, and the values that run passes it. The rest
|
package/src/cjs.ts
CHANGED
|
@@ -9,11 +9,16 @@ import type { ModuleMap } from "./modulesOf.js";
|
|
|
9
9
|
* entry an app imports is its format: a web page imports
|
|
10
10
|
* `@backtickjs/core/es`.
|
|
11
11
|
*
|
|
12
|
+
* Its values are kept in `values` by key, and so are those of the bundles it
|
|
13
|
+
* runs: one value per app, as a module is, however many bundles use it. A new
|
|
14
|
+
* `Map` by default, so a bundle run alone has its own.
|
|
15
|
+
*
|
|
12
16
|
* const screen = await execRoot(bundle, moduleMap);
|
|
13
17
|
*/
|
|
14
18
|
export async function execRoot<T>(
|
|
15
19
|
bundle: Bundle<T>,
|
|
16
20
|
moduleMap: ModuleMap,
|
|
21
|
+
values: Map<string, unknown> = new Map(),
|
|
17
22
|
): Promise<Awaited<T>> {
|
|
18
23
|
const require = (specifier: string): unknown => {
|
|
19
24
|
if (!Object.hasOwn(moduleMap, specifier)) {
|
|
@@ -23,7 +28,7 @@ export async function execRoot<T>(
|
|
|
23
28
|
}
|
|
24
29
|
return moduleMap[specifier];
|
|
25
30
|
};
|
|
26
|
-
const module = { exports: {} as unknown };
|
|
31
|
+
const module = { exports: {} as unknown, values };
|
|
27
32
|
new Function("module", "exports", "require", bundle)(
|
|
28
33
|
module,
|
|
29
34
|
module.exports,
|