runtime-compiler 2.0.4 → 2.0.7

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 CHANGED
@@ -1,8 +1,12 @@
1
- import type { LocalDependency } from "./index.ts";
1
+ import type { InferDependency, LocalDependency } from "./index.ts";
2
2
  /**
3
3
  * Inject dependency to an fn for later compilation
4
4
  */
5
- export declare const inject: (deps: LocalDependency<any>[], fn: any) => any;
5
+ export declare const inject: <
6
+ const Deps extends LocalDependency<any>[],
7
+ const Args extends any[],
8
+ const Ret
9
+ >(deps: Deps, fn: (...args: [...{ [K in keyof Deps] : InferDependency<Deps[K]> }, ...Args]) => Ret) => ((...args: Args) => Ret);
6
10
  /**
7
11
  * Get fn injected dependency list
8
12
  */
package/index.d.ts CHANGED
@@ -5,18 +5,15 @@ export type LocalDependency<T> = string & {
5
5
  export type ExportedDependency<T> = number & {
6
6
  [_]: T
7
7
  };
8
+ export type InferDependency<T extends {
9
+ [_]: any
10
+ }> = T[typeof _];
8
11
  /**
9
12
  * Inject a local dependency.
10
13
  * Use in `default` and `build` mode.
11
14
  */
12
15
  export declare const injectDependency: <T>(val: string) => LocalDependency<T>;
13
16
  /**
14
- * Wait for a dependency to resolve.
15
- * Use in `default` and `build` mode.
16
- * @param name
17
- */
18
- export declare const waitDependency: (name: string) => void;
19
- /**
20
17
  * Export a local dependency.
21
18
  * Use in `default` and `build` mode.
22
19
  * @param name
@@ -33,6 +30,14 @@ export declare const markExported: <T>() => ExportedDependency<T>;
33
30
  */
34
31
  export declare const getDependency: <T>(idx: ExportedDependency<T>) => T;
35
32
  /**
33
+ * Add extra code after dependency building
34
+ */
35
+ export declare let extraCode: string;
36
+ /**
37
+ * Add extra code after dependency building
38
+ */
39
+ export declare const addExtraCode: (str: string) => void;
40
+ /**
36
41
  * Inject an external dependency.
37
42
  */
38
43
  export declare const injectExternalDependency: (val: any) => string;
@@ -47,10 +52,10 @@ export declare const externalDependencyNames: () => string;
47
52
  */
48
53
  export declare const clear: () => void;
49
54
  /**
50
- * Clear compiler data.
55
+ * Equivalent to calling `evaluate`/`evaluateSync` in `default` or `build` mode.
51
56
  * Use in `hydrate` mode.
52
57
  */
53
- export declare const clearHydration: () => void;
58
+ export declare const finishHydration: () => void;
54
59
  /**
55
60
  * Lazily add the dependency when needed.
56
61
  */
@@ -61,10 +66,6 @@ export declare const lazyDependency: <T>(inject: (v: T) => string, val: T) => ((
61
66
  */
62
67
  export declare const evaluateCode: () => string;
63
68
  /**
64
- * Run hydration.
65
- */
66
- export declare const hydrate: () => any[];
67
- /**
68
69
  * Evaluate code to string.
69
70
  * Use in `default` and `build` mode.
70
71
  */
package/index.js CHANGED
@@ -1 +1 @@
1
- import{AsyncFunction}from"./utils.js";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=e=>compiledDependencies[e];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,S)=>{let C=Symbol();return()=>cache[C]??=e(S)};export let evaluateCode=()=>`{var $`+localDeps+(asyncDeps===``?`;_.push(`:`;[`+asyncDeps+`]=await Promise.all([`+asyncDeps+`]);_.push(`)+exportedDeps+`)}`;export let hydrate=()=>{let e=[compiledDependencies].concat(externalDependencies);clearHydration();return e};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);
1
+ import{AsyncFunction}from"./utils.js";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 exportedDeps=``;let exportedDepsCnt=0;export let exportDependency=e=>{exportedDeps+=e+`,`;return exportedDepsCnt++};export let markExported=()=>exportedDepsCnt++;export let getDependency=e=>compiledDependencies[e];export let extraCode=``;export let addExtraCode=e=>{extraCode+=e};export let injectExternalDependency=e=>`_`+externalDependencies.push(e);export let externalDependencyNames=()=>{let e=`_,`;for(let x=0;x<externalDependencies.length;x++)e+=`_`+(x+1)+`,`;return e};export let clear=()=>{externalDependencies.length=0;cache={};localDeps=``;localDepsCnt=0;exportedDeps=``;extraCode=``};export let finishHydration=()=>{externalDependencies.length=0;cache={}};export let lazyDependency=(e,x)=>{let S=Symbol();return()=>cache[S]??=e(x)};export let evaluateCode=()=>`{var $`+localDeps+`;_.push(`+exportedDeps+`);`+extraCode+`}`;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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "runtime-compiler",
3
- "version": "2.0.4",
3
+ "version": "2.0.7",
4
4
  "description": "Universal compiler system",
5
5
  "keywords": [],
6
6
  "repository": {},
@@ -8,13 +8,13 @@
8
8
  "license": "MIT",
9
9
  "type": "module",
10
10
  "exports": {
11
- "./utils": "./utils.js",
12
- ".": "./index.js",
13
11
  "./call": "./call.js",
14
- "./config/mode/hydrate": "./config/mode/hydrate.js",
12
+ "./config": "./config/index.js",
13
+ "./config/mode/build": "./config/mode/build.js",
15
14
  "./config/loader/hydrate": "./config/loader/hydrate.js",
15
+ ".": "./index.js",
16
+ "./utils": "./utils.js",
16
17
  "./config/loader/build": "./config/loader/build.js",
17
- "./config": "./config/index.js",
18
- "./config/mode/build": "./config/mode/build.js"
18
+ "./config/mode/hydrate": "./config/mode/hydrate.js"
19
19
  }
20
20
  }