runtime-compiler 3.0.0 → 3.0.2
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/call.d.ts +19 -17
- package/call.js +1 -1
- package/index.d.ts +29 -49
- package/index.js +1 -1
- package/package.json +1 -1
- package/utils.d.ts +35 -0
- package/utils.js +1 -1
- package/scope.d.ts +0 -4
- package/scope.js +0 -1
package/call.d.ts
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
import type
|
|
2
|
-
declare const sym: unique symbol;
|
|
3
|
-
type sym = typeof sym;
|
|
4
|
-
export interface InjectedCall<Deps extends Identifier<any>[]> {
|
|
5
|
-
[sym]: Deps;
|
|
6
|
-
}
|
|
1
|
+
import { type Expression, type Value } from "./index.ts";
|
|
7
2
|
/**
|
|
8
|
-
*
|
|
3
|
+
* Describe an injected call.
|
|
9
4
|
*/
|
|
10
|
-
export declare
|
|
11
|
-
const Deps extends Identifier<any>[],
|
|
5
|
+
export declare class InjectedCall<
|
|
12
6
|
const Args extends any[],
|
|
13
|
-
const
|
|
14
|
-
>
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
(
|
|
7
|
+
const R
|
|
8
|
+
> {
|
|
9
|
+
args: Expression<any>[];
|
|
10
|
+
fn: (...args: Args) => R;
|
|
11
|
+
constructor(args: Expression<any>[], fn: (...args: Args) => R);
|
|
18
12
|
}
|
|
19
13
|
/**
|
|
20
|
-
*
|
|
14
|
+
* @param values
|
|
15
|
+
* @param fn
|
|
16
|
+
*/
|
|
17
|
+
export declare const inject: <
|
|
18
|
+
const Expressions extends Expression<any>[],
|
|
19
|
+
Args extends any[],
|
|
20
|
+
R
|
|
21
|
+
>(values: Expressions, fn: (...args: [...{ [K in keyof Expressions] : Expressions[K]["~type"] }, ...Args]) => R) => InjectedCall<Args, R>;
|
|
22
|
+
/**
|
|
23
|
+
* Inject the external function, cache the access to a local dependency and run with provided args.
|
|
21
24
|
*/
|
|
22
|
-
export declare const
|
|
23
|
-
export {};
|
|
25
|
+
export declare const cacheCall: <R>(fn: (...args: any[]) => R, args: string) => Value<R>;
|
package/call.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{injectDependency,injectExternal}from"./index.js";export class InjectedCall{args;fn;constructor(e,n){this.args=e;this.fn=n}}export let inject=(e,n)=>new InjectedCall(e,n);export let cacheCall=(r,i)=>injectDependency(injectExternal(r))+`(`+i+`)`;
|
package/index.d.ts
CHANGED
|
@@ -1,26 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
[_01]: 0
|
|
1
|
+
export type Expression<T> = string & {
|
|
2
|
+
"~type": T
|
|
4
3
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
[_02]: 0
|
|
4
|
+
export type Value<T> = Expression<T> & {
|
|
5
|
+
"~value": 0
|
|
8
6
|
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
[_]: T
|
|
7
|
+
export type Identifier<T> = Value<T> & {
|
|
8
|
+
"~id": 0
|
|
12
9
|
};
|
|
13
|
-
declare const _11: unique symbol;
|
|
14
|
-
export type Identifier<T> = Expression<T> & {
|
|
15
|
-
[_11]: 0
|
|
16
|
-
};
|
|
17
|
-
declare const _20: unique symbol;
|
|
18
10
|
export type ExportedDependency<T> = number & {
|
|
19
|
-
|
|
11
|
+
"~type": T
|
|
20
12
|
};
|
|
21
|
-
export type InferExpression<T extends {
|
|
22
|
-
[_]: any
|
|
23
|
-
}> = T[typeof _];
|
|
24
13
|
interface InjectDependencyFn {
|
|
25
14
|
<T>(val: Expression<T>): Identifier<T>;
|
|
26
15
|
<T>(val: string): Identifier<T>;
|
|
@@ -33,56 +22,47 @@ export declare const injectDependency: InjectDependencyFn;
|
|
|
33
22
|
/**
|
|
34
23
|
* Export a local dependency.
|
|
35
24
|
* Use in `default` and `build` mode.
|
|
36
|
-
* @param
|
|
25
|
+
* @param value
|
|
37
26
|
*/
|
|
38
|
-
export declare const exportDependency: <T>(
|
|
27
|
+
export declare const exportDependency: <T>(value: Expression<T>) => ExportedDependency<T>;
|
|
39
28
|
/**
|
|
40
|
-
* Mark a slot
|
|
29
|
+
* Mark a slot to export a dependency.
|
|
41
30
|
* Use in `hydrate` mode.
|
|
42
31
|
*/
|
|
43
32
|
export declare const markExported: <T>() => ExportedDependency<T>;
|
|
44
33
|
/**
|
|
45
|
-
* Get the value of
|
|
34
|
+
* Get the value of an exported dependency.
|
|
46
35
|
* @param idx
|
|
47
36
|
*/
|
|
48
37
|
export declare const getDependency: <T>(idx: ExportedDependency<T>) => T;
|
|
49
38
|
/**
|
|
50
|
-
* Add extra code after dependency building
|
|
51
|
-
*/
|
|
52
|
-
export declare const addExtraCode: (str: string) => void;
|
|
53
|
-
/**
|
|
54
39
|
* Inject an external dependency.
|
|
55
40
|
*/
|
|
56
|
-
export declare const
|
|
41
|
+
export declare const injectExternal: <T>(val: T) => Value<T>;
|
|
57
42
|
/**
|
|
58
|
-
*
|
|
43
|
+
* Evaluate to statements instead of a function.
|
|
59
44
|
* Use in `default` and `build` mode.
|
|
60
45
|
*/
|
|
61
|
-
export declare const
|
|
62
|
-
/**
|
|
63
|
-
* Equivalent to calling `evaluate`/`evaluateSync` in `default` or `build` mode.
|
|
64
|
-
* Return the args that needs to be passed in.
|
|
65
|
-
* Use in `hydrate` mode.
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* (() => {
|
|
69
|
-
* // Built content
|
|
70
|
-
* })(finishHydration())
|
|
71
|
-
*/
|
|
72
|
-
export declare const hydrate: () => any[];
|
|
46
|
+
export declare const evaluateToStatements: () => string;
|
|
73
47
|
/**
|
|
74
|
-
*
|
|
75
|
-
* Use in `
|
|
48
|
+
* Evaluate code to a function.
|
|
49
|
+
* Use in `build` mode.
|
|
76
50
|
*/
|
|
77
|
-
export declare const
|
|
51
|
+
export declare const evaluateToFn: (extraCode: string) => Expression<(...args: any[]) => any>;
|
|
78
52
|
/**
|
|
79
|
-
*
|
|
80
|
-
* Use in `default`
|
|
53
|
+
* Run evaluated code.
|
|
54
|
+
* Use in `default` mode.
|
|
81
55
|
*/
|
|
82
|
-
export declare const
|
|
56
|
+
export declare const evaluate: (extraCode: string) => any;
|
|
83
57
|
/**
|
|
84
|
-
*
|
|
85
|
-
* Use in `
|
|
58
|
+
* Hydrate a built function.
|
|
59
|
+
* Use in `hydrate` mode.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* hydratedCode += `
|
|
63
|
+
* import { hydrate } from 'runtime-compiler';
|
|
64
|
+
* const compiled = hydrate(${evaluateToFn(app)});
|
|
65
|
+
* `;
|
|
86
66
|
*/
|
|
87
|
-
export declare const
|
|
67
|
+
export declare const hydrate: <T>(compiledFn: (externalDependencies: any[]) => T) => T;
|
|
88
68
|
export {};
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
let externals=[];let localDeps=``;let localDepsCnt=0;let exportDeps=``;export let injectDependency=e=>{localDeps+=`,$`+localDepsCnt+`=`+e;return`$`+ localDepsCnt++};export let exportDependency=d=>(exportDeps+=`;$[`+externals.length+`]=`+d,externals.push(null)-1);export let markExported=()=>externals.push(null)-1;export let getDependency=d=>externals[d];export let injectExternal=d=>`$[`+(externals.push(d)-1)+`]`;export let evaluateToStatements=()=>localDeps.length===0?exportDeps:`let `+localDeps.slice(1)+exportDeps;export let evaluateToFn=e=>`$=>{var _`+localDeps+exportDeps+e+`}`;export let evaluate=f=>Function(`$`,`var _`+localDeps+exportDeps+f)(externals);export let hydrate=d=>d(externals);
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"runtime-compiler","version":"3.0.
|
|
1
|
+
{"name":"runtime-compiler","version":"3.0.2","description":"Universal compiler system","keywords":[],"repository":{},"homepage":"","license":"MIT","type":"module","exports":{"./call":"./call.js","./config":"./config/index.js",".":"./index.js","./config/loader/hydrate":"./config/loader/hydrate.js","./utils":"./utils.js","./config/loader/build":"./config/loader/build.js","./config/mode/build":"./config/mode/build.js","./config/mode/hydrate":"./config/mode/hydrate.js"}}
|
package/utils.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type Expression, type Value } from "./index.ts";
|
|
1
2
|
/**
|
|
2
3
|
* Placeholder for `hydrate` mode.
|
|
3
4
|
*/
|
|
@@ -16,3 +17,37 @@ export declare const injectArgsList: (list: any[]) => string;
|
|
|
16
17
|
* Async function constructor
|
|
17
18
|
*/
|
|
18
19
|
export declare const AsyncFunction: typeof Function;
|
|
20
|
+
/**
|
|
21
|
+
* Derive a value from other expressions.
|
|
22
|
+
* Use in `default` and `build` mode.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* const newValue = derive(
|
|
26
|
+
* ['Math.random()' as Expression<number>],
|
|
27
|
+
* (rand) => rand * 10
|
|
28
|
+
* ); // '$[0](Math.random())'
|
|
29
|
+
*
|
|
30
|
+
* // In hydrate mode
|
|
31
|
+
* injectExternal((rand) => rand * 10);
|
|
32
|
+
*/
|
|
33
|
+
export declare const derive: <
|
|
34
|
+
const Expressions extends Expression<any>[],
|
|
35
|
+
R
|
|
36
|
+
>(values: Expressions, fn: (...args: { [K in keyof Expressions] : Expressions[K]["~type"] }) => R) => Value<R>;
|
|
37
|
+
/**
|
|
38
|
+
* Derive a value from other expressions.
|
|
39
|
+
* Use in `default` and `build` mode.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* const newValue = deriveAsync(
|
|
43
|
+
* ['await fetch("http://example.com")' as Expression<Response>],
|
|
44
|
+
* async (res) => await res.text()
|
|
45
|
+
* ); // 'await $[0](await fetch("http://example.com"))'
|
|
46
|
+
*
|
|
47
|
+
* // In hydrate mode
|
|
48
|
+
* injectExternal((rand) => rand * 10);
|
|
49
|
+
*/
|
|
50
|
+
export declare const deriveAsync: <
|
|
51
|
+
const Expressions extends Expression<any>[],
|
|
52
|
+
R
|
|
53
|
+
>(values: Expressions, fn: (...args: { [K in keyof Expressions] : Expressions[K]["~type"] }) => Promise<R>) => Expression<R>;
|
package/utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{injectDependency}from"./index.js";export let noOp=()=>``;export let injectConst=
|
|
1
|
+
import{injectDependency,injectExternal}from"./index.js";export let noOp=()=>``;export let injectConst=o=>injectDependency(JSON.stringify(o));export let injectArgsList=e=>e.length!==1?`...`+injectConst(e):injectConst(e[0]);export let AsyncFunction=(async()=>{}).constructor;export let derive=(e,s)=>injectExternal(s)+`(`+e.join()+`)`;export let deriveAsync=(e,s)=>`await `+injectExternal(s)+`(`+e.join()+`)`;
|
package/scope.d.ts
DELETED
package/scope.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export let init=()=>[0];export let nextId=e=>`l`+ e[0]++;export let idCount=e=>e[0];
|