runtime-compiler 1.2.7 → 2.0.0

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 CHANGED
@@ -1,5 +1,7 @@
1
1
  # `runtime-compiler`
2
2
  A code generation system for JS.
3
3
 
4
- `runtime-compiler` combines all code generation process into one `Function` call.
5
- This makes it possible to bypass startup time code generation using ahead of time compilation while also speeds up runtime code generation.
4
+ ## Modes
5
+ - `default`: Build & run.
6
+ - `build`: Build only.
7
+ - `hydrate`: Run only.
@@ -0,0 +1,16 @@
1
+ /**
2
+ * False when in `default` and `build` mode, true in `hydrate` mode
3
+ */
4
+ export declare let isHydrating: boolean;
5
+ /**
6
+ * False when in `default` and `hydrate` mode, true in `build` mode
7
+ */
8
+ export declare let isOnlyBuilding: boolean;
9
+ /**
10
+ * @private
11
+ */
12
+ export declare const hydrating: () => void;
13
+ /**
14
+ * @private
15
+ */
16
+ export declare const building: () => void;
@@ -0,0 +1 @@
1
+ export let isHydrating=false;export let isOnlyBuilding=false;export let hydrating=()=>{isHydrating=true};export let building=()=>{isOnlyBuilding=true};
@@ -0,0 +1 @@
1
+ import{building}from"../index.js";building();
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ import{hydrating}from"../index.js";hydrating();
@@ -0,0 +1,2 @@
1
+ export declare const isHydrating: boolean;
2
+ export declare const isOnlyBuilding: boolean;
@@ -0,0 +1 @@
1
+ export let isHydrating=false;export let isOnlyBuilding=true;
@@ -0,0 +1,2 @@
1
+ export declare const isHydrating: boolean;
2
+ export declare const isOnlyBuilding: boolean;
@@ -0,0 +1 @@
1
+ export let isHydrating=true;export let isOnlyBuilding=false;
package/index.d.ts CHANGED
@@ -1,53 +1,77 @@
1
- export type CompiledDependency<T> = number & [T];
1
+ export type LocalDependency<T> = string & [T];
2
+ export type ExportedDependency<T> = number & [T];
2
3
  /**
3
4
  * Inject a local dependency.
5
+ * Use in `default` and `build` mode.
4
6
  */
5
- export declare const injectDependency: (val: string) => string;
7
+ export declare const injectDependency: <T>(val: string) => LocalDependency<T>;
6
8
  /**
7
- * Wait for a dependency to resolve
9
+ * Wait for a dependency to resolve.
10
+ * Use in `default` and `build` mode.
8
11
  * @param name
9
12
  */
10
13
  export declare const waitDependency: (name: string) => void;
11
14
  /**
12
- * Export a local dependency
15
+ * Export a local dependency.
16
+ * Use in `default` and `build` mode.
13
17
  * @param name
14
18
  */
15
- export declare const exportDependency: <T>(name: string) => CompiledDependency<T>;
19
+ export declare const exportDependency: <T>(name: LocalDependency<T>) => ExportedDependency<T>;
16
20
  /**
17
- * Mark a slot in compiled dependencies
21
+ * Mark a slot in compiled dependencies.
22
+ * Use in `hydrate` mode.
18
23
  */
19
- export declare const markExported: <T>() => CompiledDependency<T>;
24
+ export declare const markExported: <T>() => ExportedDependency<T>;
20
25
  /**
21
- * Get the value of a dependency
26
+ * Get the value of a dependency.
22
27
  * @param idx
23
28
  */
24
- export declare const getDependency: <T>(idx: CompiledDependency<T>) => T;
29
+ export declare const getDependency: <T>(idx: ExportedDependency<T>) => T;
25
30
  /**
26
- * Inject an external dependency
31
+ * Inject an external dependency.
27
32
  */
28
33
  export declare const injectExternalDependency: (val: any) => string;
29
34
  /**
30
- * Get external dependency names
35
+ * Get external dependency names.
36
+ * Use in `default` and `build` mode.
31
37
  */
32
38
  export declare const externalDependencyNames: () => string;
33
39
  /**
34
- * Clear compiler data
40
+ * Clear compiler data.
41
+ * Use in `default` and `build` mode.
35
42
  */
36
43
  export declare const clear: () => void;
37
44
  /**
38
- * Clear compiler data in hydration
45
+ * Clear compiler data.
46
+ * Use in `hydrate` mode.
39
47
  */
40
48
  export declare const clearHydration: () => void;
41
49
  /**
42
- * Noop function
43
- */
44
- export declare const noOp: () => string;
45
- /**
46
- * Lazily add the dependency when needed
50
+ * Lazily add the dependency when needed.
47
51
  */
48
52
  export declare const lazyDependency: <T>(inject: (v: T) => string, val: T) => () => string;
49
53
  /**
50
- * Get evaluate code
54
+ * Get evaluated code.
55
+ * Use in `default` and `build` mode.
51
56
  */
52
57
  export declare const evaluateCode: () => string;
58
+ /**
59
+ * Run hydration.
60
+ */
61
+ export declare const hydrate: () => any[];
62
+ /**
63
+ * Evaluate code to string.
64
+ * Use in `default` and `build` mode.
65
+ */
66
+ export declare const evaluateToString: () => string;
67
+ /**
68
+ * Run evaluated code synchronously.
69
+ * Use in `default` and `build` mode.
70
+ */
71
+ export declare const evaluateSync: () => void;
72
+ /**
73
+ * Run evaluated code asynchronously.
74
+ * Use in `default` and `build` mode.
75
+ */
76
+ export declare const evaluate: () => Promise<void>;
53
77
  export declare const AsyncFunction: typeof Function;
package/index.js CHANGED
@@ -1 +1 @@
1
- export let compiledDependencies=[];export let externalDependencies=[];export let cache={};export let localDeps=``;let localDepsCnt=0;export let injectDependency=e=>{localDeps+=`,$`+localDepsCnt+`=`+e;return`$`+ localDepsCnt++};export let asyncDeps=``;export let waitDependency=e=>{asyncDeps+=e+`,`};export let exportedDeps=``;let exportedDepsCnt=0;export let exportDependency=e=>{exportedDeps+=e+`,`;return exportedDepsCnt++};export let markExported=()=>exportedDepsCnt++;export let getDependency=v=>compiledDependencies[v];export let injectExternalDependency=e=>`_`+externalDependencies.push(e);export let externalDependencyNames=()=>{let e=`_,`;for(let y=0;y<externalDependencies.length;y++)e+=`_`+(y+1)+`,`;return e};export let clear=()=>{externalDependencies.length=0;cache={};localDeps=``;localDepsCnt=0;asyncDeps=``;exportedDeps=``};export let clearHydration=()=>{externalDependencies.length=0;cache={}};export let noOp=()=>``;export let lazyDependency=(e,v)=>{let b=Symbol();return()=>cache[b]??=e(v)};export let evaluateCode=()=>`{var $`+localDeps+(asyncDeps===``?`;_.push(`:`;[`+asyncDeps+`]=await Promise.all([`+asyncDeps+`]);_.push(`)+exportedDeps+`)}`;export let AsyncFunction=(async()=>{}).constructor;
1
+ export let compiledDependencies=[];export let externalDependencies=[];export let cache={};export let localDeps=``;let localDepsCnt=0;export let injectDependency=e=>{localDeps+=`,$`+localDepsCnt+`=`+e;return`$`+ localDepsCnt++};export let asyncDeps=``;export let waitDependency=e=>{asyncDeps+=e+`,`};export let exportedDeps=``;let exportedDepsCnt=0;export let exportDependency=e=>{exportedDeps+=e+`,`;return exportedDepsCnt++};export let markExported=()=>exportedDepsCnt++;export let getDependency=x=>compiledDependencies[x];export let injectExternalDependency=e=>`_`+externalDependencies.push(e);export let externalDependencyNames=()=>{let e=`_,`;for(let S=0;S<externalDependencies.length;S++)e+=`_`+(S+1)+`,`;return e};export let clear=()=>{externalDependencies.length=0;cache={};localDeps=``;localDepsCnt=0;asyncDeps=``;exportedDeps=``};export let clearHydration=()=>{externalDependencies.length=0;cache={}};export let lazyDependency=(e,x)=>{let C=Symbol();return()=>cache[C]??=e(x)};export let evaluateCode=()=>`{var $`+localDeps+(asyncDeps===``?`;_.push(`:`;[`+asyncDeps+`]=await Promise.all([`+asyncDeps+`]);_.push(`)+exportedDeps+`)}`;export let hydrate=()=>{let S=[compiledDependencies].concat(externalDependencies);clearHydration();return S};export let evaluateToString=()=>`(`+externalDependencyNames()+`)=>`+evaluateCode();export let evaluateSync=()=>{try{Function(externalDependencyNames(),evaluateCode())(compiledDependencies,...externalDependencies)}finally{clear()}};export let evaluate=async()=>AsyncFunction(externalDependencyNames(),evaluateCode())(compiledDependencies,...externalDependencies).finally(clear);export let AsyncFunction=(async()=>{}).constructor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "runtime-compiler",
3
- "version": "1.2.7",
3
+ "version": "2.0.0",
4
4
  "description": "Universal compiler system",
5
5
  "keywords": [],
6
6
  "repository": {},
@@ -8,11 +8,11 @@
8
8
  "license": "MIT",
9
9
  "type": "module",
10
10
  "exports": {
11
- "./hydrate-config": "./hydrate-config.js",
12
- "./config": "./config.js",
11
+ "./config": "./config/index.js",
13
12
  ".": "./index.js",
14
- "./hydrate-loader": "./hydrate-loader.js",
15
- "./hydrate": "./hydrate.js",
16
- "./jit": "./jit.js"
13
+ "./config/loader/hydrate": "./config/loader/hydrate.js",
14
+ "./config/loader/build": "./config/loader/build.js",
15
+ "./config/mode/build": "./config/mode/build.js",
16
+ "./config/mode/hydrate": "./config/mode/hydrate.js"
17
17
  }
18
18
  }
package/config.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export declare let isHydrating: boolean;
2
- /**
3
- * @private
4
- */
5
- export declare const hydrating: () => void;
package/config.js DELETED
@@ -1 +0,0 @@
1
- export let isHydrating=false;export let hydrating=()=>{isHydrating=true};
@@ -1 +0,0 @@
1
- export declare const isHydrating: boolean;
package/hydrate-config.js DELETED
@@ -1 +0,0 @@
1
- export let isHydrating=true;
package/hydrate-loader.js DELETED
@@ -1 +0,0 @@
1
- import{hydrating}from"./config.js";hydrating();
package/hydrate.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare const hydrate: () => any[];
package/hydrate.js DELETED
@@ -1 +0,0 @@
1
- import{clearHydration,compiledDependencies,externalDependencies}from"./index.js";export let hydrate=()=>{let r=[compiledDependencies].concat(externalDependencies);clearHydration();return r};
package/jit.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export declare const evaluateToString: () => string;
2
- export declare const evaluateSync: () => void;
3
- export declare const evaluate: () => Promise<void>;
package/jit.js DELETED
@@ -1 +0,0 @@
1
- import{AsyncFunction,clear,compiledDependencies,evaluateCode,externalDependencies,externalDependencyNames}from"./index.js";export let evaluateToString=()=>`(`+externalDependencyNames()+`)=>`+evaluateCode();export let evaluateSync=()=>{try{Function(externalDependencyNames(),evaluateCode())(compiledDependencies,...externalDependencies)}finally{clear()}};export let evaluate=async()=>AsyncFunction(externalDependencyNames(),evaluateCode())(compiledDependencies,...externalDependencies).finally(clear);