runtime-compiler 3.0.1 → 3.0.3
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 +25 -0
- package/call.js +1 -0
- package/index.d.ts +11 -17
- package/index.js +1 -1
- package/package.json +1 -1
- package/utils.d.ts +35 -0
- package/utils.js +1 -1
- package/derive.d.ts +0 -59
- package/derive.js +0 -1
package/call.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type Expression, type Value } from "./index.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Describe an injected call.
|
|
4
|
+
*/
|
|
5
|
+
export declare class InjectedCall<
|
|
6
|
+
const Args extends any[],
|
|
7
|
+
const R
|
|
8
|
+
> {
|
|
9
|
+
args: Expression<any>[];
|
|
10
|
+
fn: (...args: Args) => R;
|
|
11
|
+
constructor(args: Expression<any>[], fn: (...args: Args) => R);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
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.
|
|
24
|
+
*/
|
|
25
|
+
export declare const cacheCall: <R>(fn: (...args: any[]) => R, args: string) => Value<R>;
|
package/call.js
ADDED
|
@@ -0,0 +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
|
@@ -10,6 +10,10 @@ export type Identifier<T> = Value<T> & {
|
|
|
10
10
|
export type ExportedDependency<T> = number & {
|
|
11
11
|
"~type": T
|
|
12
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* External dependencies
|
|
15
|
+
*/
|
|
16
|
+
export declare const externals: any[];
|
|
13
17
|
interface InjectDependencyFn {
|
|
14
18
|
<T>(val: Expression<T>): Identifier<T>;
|
|
15
19
|
<T>(val: string): Identifier<T>;
|
|
@@ -42,27 +46,17 @@ export declare const injectExternal: <T>(val: T) => Value<T>;
|
|
|
42
46
|
/**
|
|
43
47
|
* Evaluate to statements instead of a function.
|
|
44
48
|
* Use in `default` and `build` mode.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* hydratedCode += `
|
|
52
|
+
* import { externals as $ } from 'runtime-compiler';
|
|
53
|
+
* ${evaluateToStatements()}
|
|
54
|
+
* `;
|
|
45
55
|
*/
|
|
46
56
|
export declare const evaluateToStatements: () => string;
|
|
47
57
|
/**
|
|
48
|
-
* Evaluate code to a function.
|
|
49
|
-
* Use in `build` mode.
|
|
50
|
-
*/
|
|
51
|
-
export declare const evaluateToFn: (extraCode: string) => Expression<(...args: any[]) => any>;
|
|
52
|
-
/**
|
|
53
58
|
* Run evaluated code.
|
|
54
59
|
* Use in `default` mode.
|
|
55
60
|
*/
|
|
56
|
-
export declare const evaluate: (
|
|
57
|
-
/**
|
|
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
|
-
* `;
|
|
66
|
-
*/
|
|
67
|
-
export declare const hydrate: <T>(compiledFn: (externalDependencies: any[]) => T) => T;
|
|
61
|
+
export declare const evaluate: () => any;
|
|
68
62
|
export {};
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
let externals=[];let localDeps=``;let localDepsCnt=0;let exportDeps=``;export let injectDependency=e=>{localDeps+=`,$`+localDepsCnt+`=`+e;return`$`+ localDepsCnt++};export let exportDependency=
|
|
1
|
+
export let externals=[];let localDeps=``;let localDepsCnt=0;let exportDeps=``;export let injectDependency=e=>{localDeps+=`,$`+localDepsCnt+`=`+e;return`$`+ localDepsCnt++};export let exportDependency=u=>(exportDeps+=`;$[`+externals.length+`]=`+u,externals.push(null)-1);export let markExported=()=>externals.push(null)-1;export let getDependency=u=>externals[u];export let injectExternal=u=>`$[`+(externals.push(u)-1)+`]`;export let evaluateToStatements=()=>localDeps.length===0?exportDeps+`;`:`{let `+localDeps.slice(1)+exportDeps+`}`;export let evaluate=()=>{globalThis.__runtime_compiler__=externals;(0,eval)(`{let $=__runtime_compiler__`+localDeps+exportDeps+`}`);delete globalThis.__runtime_compiler__};
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"runtime-compiler","version":"3.0.
|
|
1
|
+
{"name":"runtime-compiler","version":"3.0.3","description":"Universal compiler system","keywords":[],"repository":{},"homepage":"","license":"MIT","type":"module","exports":{".":"./index.js","./config/loader/hydrate":"./config/loader/hydrate.js","./config":"./config/index.js","./call":"./call.js","./config/loader/build":"./config/loader/build.js","./config/mode/build":"./config/mode/build.js","./utils":"./utils.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/derive.d.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { type Expression, type Value } from "./index.ts";
|
|
2
|
-
/**
|
|
3
|
-
* Derive a value from other expressions.
|
|
4
|
-
* Use in `default` and `build` mode.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* const newValue = derive(
|
|
8
|
-
* ['Math.random()' as Expression<number>],
|
|
9
|
-
* (rand) => rand * 10
|
|
10
|
-
* ); // '$[0](Math.random())'
|
|
11
|
-
*
|
|
12
|
-
* // In hydrate mode
|
|
13
|
-
* injectExternal((rand) => rand * 10);
|
|
14
|
-
*/
|
|
15
|
-
export declare const derive: <
|
|
16
|
-
const Expressions extends Expression<any>[],
|
|
17
|
-
R
|
|
18
|
-
>(values: Expressions, fn: (...args: { [K in keyof Expressions] : Expressions[K]["~type"] }) => R) => Value<R>;
|
|
19
|
-
/**
|
|
20
|
-
* Derive a value from other expressions.
|
|
21
|
-
* Use in `default` and `build` mode.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* const newValue = deriveAsync(
|
|
25
|
-
* ['await fetch("http://example.com")' as Expression<Response>],
|
|
26
|
-
* async (res) => await res.text()
|
|
27
|
-
* ); // 'await $[0](await fetch("http://example.com"))'
|
|
28
|
-
*
|
|
29
|
-
* // In hydrate mode
|
|
30
|
-
* injectExternal((rand) => rand * 10);
|
|
31
|
-
*/
|
|
32
|
-
export declare const deriveAsync: <
|
|
33
|
-
const Expressions extends Expression<any>[],
|
|
34
|
-
R
|
|
35
|
-
>(values: Expressions, fn: (...args: { [K in keyof Expressions] : Expressions[K]["~type"] }) => Promise<R>) => Expression<R>;
|
|
36
|
-
/**
|
|
37
|
-
* Describe an injected call.
|
|
38
|
-
*/
|
|
39
|
-
export declare class InjectedCall<
|
|
40
|
-
const Args extends any[],
|
|
41
|
-
const R
|
|
42
|
-
> {
|
|
43
|
-
args: Expression<any>[];
|
|
44
|
-
fn: (...args: Args) => R;
|
|
45
|
-
constructor(args: Expression<any>[], fn: (...args: Args) => R);
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* @param values
|
|
49
|
-
* @param fn
|
|
50
|
-
*/
|
|
51
|
-
export declare const inject: <
|
|
52
|
-
const Expressions extends Expression<any>[],
|
|
53
|
-
Args extends any[],
|
|
54
|
-
R
|
|
55
|
-
>(values: Expressions, fn: (...args: [...{ [K in keyof Expressions] : Expressions[K]["~type"] }, ...Args]) => R) => InjectedCall<Args, R>;
|
|
56
|
-
/**
|
|
57
|
-
* Inject the external function, cache the access to a local dependency and run with provided args.
|
|
58
|
-
*/
|
|
59
|
-
export declare const cacheCall: <R>(fn: (...args: any[]) => R, args: string) => Value<R>;
|
package/derive.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{injectDependency,injectExternal}from"./index.js";export let derive=(e,a)=>injectExternal(a)+`(`+e.join()+`)`;export let deriveAsync=(e,a)=>`await `+injectExternal(a)+`(`+e.join()+`)`;export class InjectedCall{args;fn;constructor(e,i){this.args=e;this.fn=i}}export let inject=(e,i)=>new InjectedCall(e,i);export let cacheCall=(a,o)=>injectDependency(injectExternal(a))+`(`+o+`)`;
|