runtime-compiler 1.0.6 → 1.0.8

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,2 +1,5 @@
1
1
  # `runtime-compiler`
2
- Universal compiler system.
2
+ A code generation system for JS.
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.
package/hydrate.js CHANGED
@@ -1 +1 @@
1
- import{compiledDependencies,externalDependencies}from"./index.js";export let hydrate=()=>{let n=[compiledDependencies].concat(externalDependencies);externalDependencies.length=0;return n};
1
+ import{clear,compiledDependencies,externalDependencies}from"./index.js";export let hydrate=()=>{let r=[compiledDependencies].concat(externalDependencies);clear();return r};
package/index.d.ts CHANGED
@@ -1,12 +1,22 @@
1
1
  export type CompiledDependency<T> = number & [T];
2
2
  /**
3
- * Inject a dependency.
3
+ * Inject a local dependency.
4
4
  */
5
- export declare const injectDependency: <T>(val: string) => CompiledDependency<T>;
5
+ export declare const injectDependency: (val: string) => string;
6
6
  /**
7
- * Mark a slot in `compiledDependencies` that will have a dependency.
7
+ * Wait for a dependency to resolve
8
+ * @param name
8
9
  */
9
- export declare const markDependency: <T>() => CompiledDependency<T>;
10
+ export declare const waitDependency: (name: string) => void;
11
+ /**
12
+ * Export a local dependency
13
+ * @param name
14
+ */
15
+ export declare const exportDependency: <T>(name: string) => CompiledDependency<T>;
16
+ /**
17
+ * Mark a slot in compiled dependencies
18
+ */
19
+ export declare const markExported: <T>() => CompiledDependency<T>;
10
20
  /**
11
21
  * Get the value of a dependency
12
22
  * @param idx
@@ -16,4 +26,16 @@ export declare const getDependency: <T>(idx: CompiledDependency<T>) => T;
16
26
  * Inject an external dependency
17
27
  */
18
28
  export declare const injectExternalDependency: (val: any) => string;
29
+ /**
30
+ * Clear compiler data
31
+ */
32
+ export declare const clear: () => void;
33
+ /**
34
+ * Get evaluate code
35
+ */
36
+ export declare const evaluateCode: () => string;
37
+ /**
38
+ * Get external dependency names
39
+ */
40
+ export declare const externalDependencyNames: () => string;
19
41
  export declare const AsyncFunction: typeof Function;
package/index.js CHANGED
@@ -1 +1 @@
1
- export let compiledDependencies=[];export let externalDependencies=[];export let localDeps=``;let localDepsCnt=0;export let injectDependency=e=>{localDeps+=e+`,`;return localDepsCnt++};export let markDependency=()=>localDepsCnt++;export let getDependency=c=>compiledDependencies[c];export let injectExternalDependency=e=>`_`+externalDependencies.push(e);export let AsyncFunction=(async()=>{}).constructor;
1
+ export let compiledDependencies=[];export let externalDependencies=[];export let localDeps=``;let localDepsCnt=0;export let injectDependency=e=>{localDeps=localDeps===``?`var __`+localDepsCnt+`=`+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=h=>compiledDependencies[h];export let injectExternalDependency=e=>`_`+externalDependencies.push(e);export let clear=()=>{externalDependencies.length=0;localDeps=``;localDepsCnt=0;exportedDeps=``;exportedDepsCnt=0};export let evaluateCode=()=>`{`+localDeps+(asyncDeps===``?`;_.push(`:`;[`+asyncDeps+`]=await Promise.all([`+asyncDeps+`]);_.push(`)+exportedDeps+`)}`;export let externalDependencyNames=()=>{let e=`_,`;for(let g=0;g<externalDependencies.length;g++)e+=`_`+(g+1)+`,`;return e};export let AsyncFunction=(async()=>{}).constructor;
package/jit.d.ts CHANGED
@@ -1,3 +1,3 @@
1
+ export declare const evaluateToString: () => string;
1
2
  export declare const evaluateSync: () => void;
2
3
  export declare const evaluate: () => Promise<void>;
3
- export declare const evaluateToString: () => string;
package/jit.js CHANGED
@@ -1 +1 @@
1
- import{AsyncFunction,compiledDependencies,externalDependencies,localDeps}from"./index.js";export let evaluateSync=()=>{let e=`_,`;for(let a=0;a<externalDependencies.length;a++)e+=`_`+(a+1)+`,`;Function(e,`_.push(`+localDeps+`)`)(compiledDependencies,...externalDependencies);externalDependencies.length=0};export let evaluate=async()=>{let o=`_,`;for(let e=0;e<externalDependencies.length;e++)o+=`_`+(e+1)+`,`;await AsyncFunction(o,`_.push(`+localDeps+`)`)(compiledDependencies,...externalDependencies);externalDependencies.length=0};export let evaluateToString=()=>{let e=`(_,`;for(let a=0;a<externalDependencies.length;a++)e+=`_`+(a+1)+`,`;return e+`)=>_.push(`+localDeps+`)`};
1
+ import{AsyncFunction,clear,compiledDependencies,evaluateCode,externalDependencies,externalDependencyNames}from"./index.js";export let evaluateToString=()=>`(`+externalDependencyNames()+`)=>`+evaluateCode();export let evaluateSync=()=>{Function(externalDependencyNames(),evaluateCode())(compiledDependencies,...externalDependencies);clear()};export let evaluate=async()=>{await AsyncFunction(externalDependencyNames(),evaluateCode())(compiledDependencies,...externalDependencies);clear()};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "runtime-compiler",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Universal compiler system",
5
5
  "keywords": [],
6
6
  "repository": {},
@@ -8,10 +8,10 @@
8
8
  "license": "MIT",
9
9
  "type": "module",
10
10
  "exports": {
11
+ ".": "./index.js",
11
12
  "./config": "./config.js",
13
+ "./hydrate": "./hydrate.js",
12
14
  "./hydrate-loader": "./hydrate-loader.js",
13
- "./jit": "./jit.js",
14
- ".": "./index.js",
15
- "./hydrate": "./hydrate.js"
15
+ "./jit": "./jit.js"
16
16
  }
17
17
  }