runtime-compiler 2.0.0 → 2.0.2

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
@@ -5,3 +5,13 @@ A code generation system for JS.
5
5
  - `default`: Build & run.
6
6
  - `build`: Build only.
7
7
  - `hydrate`: Run only.
8
+
9
+ ```ts
10
+ import { isHydrating, onlyBuild } from 'runtime-compiler/config';
11
+
12
+ // Whether the process is in `hydrate` mode
13
+ isHydrating;
14
+
15
+ // Whether the process is in `build` mode
16
+ onlyBuild;
17
+ ```
package/call.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import type { LocalDependency } from "./index.ts";
2
+ export type InferArgs<T extends LocalDependency<any>[]> = T extends [LocalDependency<infer First>, ...infer Rest extends LocalDependency<any>[]] ? [First, ...InferArgs<Rest>] : [];
3
+ /**
4
+ * Inject dependency to an fn for later compilation
5
+ */
6
+ export declare const inject: <
7
+ const Deps extends LocalDependency<any>[],
8
+ Args extends any[],
9
+ Ret
10
+ >(deps: Deps, fn: (...args: [...InferArgs<Deps>, ...Args]) => Ret) => (...args: Args) => Ret;
11
+ /**
12
+ * Get fn injected dependency list
13
+ */
14
+ export declare const getDeps: (fn: (...args: any[]) => any) => LocalDependency<any[]> | undefined;
package/call.js ADDED
@@ -0,0 +1 @@
1
+ let sym=Symbol();export let inject=(t,n)=>{n[sym]=t;return n};export let getDeps=t=>t[sym];
package/config/index.d.ts CHANGED
@@ -5,12 +5,4 @@ export declare let isHydrating: boolean;
5
5
  /**
6
6
  * False when in `default` and `hydrate` mode, true in `build` mode
7
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;
8
+ export declare let onlyBuild: boolean;
package/config/index.js CHANGED
@@ -1 +1 @@
1
- export let isHydrating=false;export let isOnlyBuilding=false;export let hydrating=()=>{isHydrating=true};export let building=()=>{isOnlyBuilding=true};
1
+ export let isHydrating=false;export let onlyBuild=false;export let hydrating=()=>{isHydrating=true};export let building=()=>{onlyBuild=true};
@@ -1,2 +1,2 @@
1
1
  export declare const isHydrating: boolean;
2
- export declare const isOnlyBuilding: boolean;
2
+ export declare const onlyBuild: boolean;
@@ -1 +1 @@
1
- export let isHydrating=false;export let isOnlyBuilding=true;
1
+ export let isHydrating=false;export let onlyBuild=true;
@@ -1,2 +1,2 @@
1
1
  export declare const isHydrating: boolean;
2
- export declare const isOnlyBuilding: boolean;
2
+ export declare const onlyBuild: boolean;
@@ -1 +1 @@
1
- export let isHydrating=true;export let isOnlyBuilding=false;
1
+ export let isHydrating=true;export let onlyBuild=false;
package/index.d.ts CHANGED
@@ -1,5 +1,10 @@
1
- export type LocalDependency<T> = string & [T];
2
- export type ExportedDependency<T> = number & [T];
1
+ declare const _: unique symbol;
2
+ export type LocalDependency<T> = string & {
3
+ [_]: T
4
+ };
5
+ export type ExportedDependency<T> = number & {
6
+ [_]: T
7
+ };
3
8
  /**
4
9
  * Inject a local dependency.
5
10
  * Use in `default` and `build` mode.
@@ -49,7 +54,7 @@ export declare const clearHydration: () => void;
49
54
  /**
50
55
  * Lazily add the dependency when needed.
51
56
  */
52
- export declare const lazyDependency: <T>(inject: (v: T) => string, val: T) => () => string;
57
+ export declare const lazyDependency: <T>(inject: (v: T) => string, val: T) => (() => string);
53
58
  /**
54
59
  * Get evaluated code.
55
60
  * Use in `default` and `build` mode.
@@ -74,4 +79,4 @@ export declare const evaluateSync: () => void;
74
79
  * Use in `default` and `build` mode.
75
80
  */
76
81
  export declare const evaluate: () => Promise<void>;
77
- export declare const AsyncFunction: typeof Function;
82
+ export {};
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=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;
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "runtime-compiler",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Universal compiler system",
5
5
  "keywords": [],
6
6
  "repository": {},
@@ -8,11 +8,13 @@
8
8
  "license": "MIT",
9
9
  "type": "module",
10
10
  "exports": {
11
- "./config": "./config/index.js",
12
- ".": "./index.js",
11
+ "./utils": "./utils.js",
13
12
  "./config/loader/hydrate": "./config/loader/hydrate.js",
13
+ ".": "./index.js",
14
+ "./call": "./call.js",
15
+ "./config/mode/hydrate": "./config/mode/hydrate.js",
16
+ "./config": "./config/index.js",
14
17
  "./config/loader/build": "./config/loader/build.js",
15
- "./config/mode/build": "./config/mode/build.js",
16
- "./config/mode/hydrate": "./config/mode/hydrate.js"
18
+ "./config/mode/build": "./config/mode/build.js"
17
19
  }
18
20
  }
package/utils.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Placeholder for `hydrate` mode.
3
+ */
4
+ export declare const noOp: () => string;
5
+ /**
6
+ * Inject a constant.
7
+ * Use in `default` and `build` mode.
8
+ */
9
+ export declare const injectConst: (val: any) => string;
10
+ /**
11
+ * Inject an argument list.
12
+ * Use in `default` and `build` mode.
13
+ */
14
+ export declare const injectArgsList: (list: any[]) => string;
15
+ /**
16
+ * Async function constructor
17
+ */
18
+ export declare const AsyncFunction: typeof Function;
package/utils.js ADDED
@@ -0,0 +1 @@
1
+ import{injectDependency}from"./index.js";export let noOp=()=>``;export let injectConst=i=>injectDependency(JSON.stringify(i));export let injectArgsList=e=>e.length!==1?`...`+injectConst(e):injectConst(e[0]);export let AsyncFunction=(async()=>{}).constructor;