runtime-compiler 3.0.3 → 3.0.5
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/index.d.ts +26 -23
- package/index.js +1 -1
- package/package.json +1 -1
- package/utils.d.ts +0 -10
- package/utils.js +1 -1
- package/call.d.ts +0 -25
- package/call.js +0 -1
package/index.d.ts
CHANGED
|
@@ -10,25 +10,40 @@ export type Identifier<T> = Value<T> & {
|
|
|
10
10
|
export type ExportedDependency<T> = number & {
|
|
11
11
|
"~type": T
|
|
12
12
|
};
|
|
13
|
+
export interface Scope {
|
|
14
|
+
body: string;
|
|
15
|
+
/**
|
|
16
|
+
* Next available id.
|
|
17
|
+
*/
|
|
18
|
+
id: number;
|
|
19
|
+
}
|
|
13
20
|
/**
|
|
14
|
-
*
|
|
21
|
+
* Declare a variable in the current scope.
|
|
15
22
|
*/
|
|
16
|
-
export declare const
|
|
17
|
-
interface InjectDependencyFn {
|
|
18
|
-
<T>(val: Expression<T>): Identifier<T>;
|
|
19
|
-
<T>(val: string): Identifier<T>;
|
|
20
|
-
}
|
|
23
|
+
export declare const declareLocal: (<T>(scope: Scope, expr: Expression<T>) => Identifier<T>) | ((scope: Scope, expr: string) => string);
|
|
21
24
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
25
|
+
* Export a local expression to a parent local variable
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* // Fork scope
|
|
29
|
+
* const childScope = {
|
|
30
|
+
* body: '',
|
|
31
|
+
* id: parentScope.id
|
|
32
|
+
* };
|
|
33
|
+
* // let d0;{let d1=1;d0=d1}
|
|
34
|
+
* const id = exportLocal(childScope, declareLocal(childScope, '1'), parentScope); // d0
|
|
35
|
+
*/
|
|
36
|
+
export declare const exportLocal: ((<T>(scope: Scope, expr: Expression<T>, parentScope: Scope) => Identifier<T>) | ((scope: Scope, expr: string, parentScope: Scope) => string));
|
|
37
|
+
/**
|
|
38
|
+
* External dependencies
|
|
24
39
|
*/
|
|
25
|
-
export declare const
|
|
40
|
+
export declare const $: any[];
|
|
26
41
|
/**
|
|
27
42
|
* Export a local dependency.
|
|
28
43
|
* Use in `default` and `build` mode.
|
|
29
44
|
* @param value
|
|
30
45
|
*/
|
|
31
|
-
export declare const exportDependency: <T>(value: Expression<T>) => ExportedDependency<T>;
|
|
46
|
+
export declare const exportDependency: <T>(scope: Scope, value: Expression<T>) => ExportedDependency<T>;
|
|
32
47
|
/**
|
|
33
48
|
* Mark a slot to export a dependency.
|
|
34
49
|
* Use in `hydrate` mode.
|
|
@@ -44,19 +59,7 @@ export declare const getDependency: <T>(idx: ExportedDependency<T>) => T;
|
|
|
44
59
|
*/
|
|
45
60
|
export declare const injectExternal: <T>(val: T) => Value<T>;
|
|
46
61
|
/**
|
|
47
|
-
* Evaluate to statements instead of a function.
|
|
48
|
-
* Use in `default` and `build` mode.
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* hydratedCode += `
|
|
52
|
-
* import { externals as $ } from 'runtime-compiler';
|
|
53
|
-
* ${evaluateToStatements()}
|
|
54
|
-
* `;
|
|
55
|
-
*/
|
|
56
|
-
export declare const evaluateToStatements: () => string;
|
|
57
|
-
/**
|
|
58
62
|
* Run evaluated code.
|
|
59
63
|
* Use in `default` mode.
|
|
60
64
|
*/
|
|
61
|
-
export declare const evaluate: () =>
|
|
62
|
-
export {};
|
|
65
|
+
export declare const evaluate: (statements: string) => void;
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export let
|
|
1
|
+
export let declareLocal=(e,a)=>(e.body+=`let d`+e.id+`=`+a+`;`,`d`+ e.id++);export let exportLocal=(e,a,o)=>{let s=`d`+ o.id++;o.body+=`let `+s+`;{`+e.body+s+`=`+a+`}`;return s};export let $=[];export let exportDependency=(e,a)=>(e.body+=`$[`+$.length+`]=`+a+`;`,$.push(null)-1);export let markExported=()=>$.push(null)-1;export let getDependency=e=>$[e];export let injectExternal=e=>`$[`+($.push(e)-1)+`]`;export let evaluate=e=>{globalThis.__rt_externals__=$;(0,eval)(`{let $=__rt_externals__;`+e+`}`)};
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"runtime-compiler","version":"3.0.
|
|
1
|
+
{"name":"runtime-compiler","version":"3.0.5","description":"Universal compiler system","keywords":[],"repository":{},"homepage":"","license":"MIT","type":"module","exports":{"./utils":"./utils.js","./config":"./config/index.js",".":"./index.js","./config/mode/hydrate":"./config/mode/hydrate.js","./config/mode/build":"./config/mode/build.js","./config/loader/hydrate":"./config/loader/hydrate.js","./config/loader/build":"./config/loader/build.js"}}
|
package/utils.d.ts
CHANGED
|
@@ -4,16 +4,6 @@ import { type Expression, type Value } from "./index.ts";
|
|
|
4
4
|
*/
|
|
5
5
|
export declare const noOp: () => string;
|
|
6
6
|
/**
|
|
7
|
-
* Inject a serializable constant.
|
|
8
|
-
* Use in `default` and `build` mode.
|
|
9
|
-
*/
|
|
10
|
-
export declare const injectConst: (val: any) => string;
|
|
11
|
-
/**
|
|
12
|
-
* Inject a serializable argument list.
|
|
13
|
-
* Use in `default` and `build` mode.
|
|
14
|
-
*/
|
|
15
|
-
export declare const injectArgsList: (list: any[]) => string;
|
|
16
|
-
/**
|
|
17
7
|
* Async function constructor
|
|
18
8
|
*/
|
|
19
9
|
export declare const AsyncFunction: typeof Function;
|
package/utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{injectExternal}from"./index.js";export let noOp=()=>``;export let AsyncFunction=(async()=>{}).constructor;export let derive=(r,i)=>injectExternal(i)+`(`+r.join()+`)`;export let deriveAsync=(r,i)=>`await `+injectExternal(i)+`(`+r.join()+`)`;
|
package/call.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
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
DELETED
|
@@ -1 +0,0 @@
|
|
|
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+`)`;
|