runtime-compiler 4.0.2 → 4.0.3
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/build/index.js +1 -1
- package/build/rolldown.js +1 -1
- package/globals.d.ts +2 -2
- package/globals.js +1 -1
- package/package.json +1 -1
- package/utils.d.ts +8 -1
- package/utils.js +1 -1
- package/scope.d.ts +0 -13
- package/scope.js +0 -1
package/build/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Worker}from"node:worker_threads";let curRes,curRej;export const getPromiseResolvers=(res,rej)=>{curRes=res;curRej=rej};let workerOptions={eval:!0};export const runInWorker=code=>{let p=new Promise(getPromiseResolvers),worker=new Worker(`import"runtime-compiler/env/build";${code};\nimport{__rtcpl_ct__}from"runtime-compiler/globals";import{parentPort as __rtcpl_pp__}from"node:worker_threads";__rtcpl_pp__.postMessage(__rtcpl_ct__)`,workerOptions);worker.once("message",curRes);worker.once("error",curRej);return p};export const compile=async code=>{let str='import"runtime-compiler/env/aot";import{
|
|
1
|
+
import{Worker}from"node:worker_threads";let curRes,curRej;export const getPromiseResolvers=(res,rej)=>{curRes=res;curRej=rej};let workerOptions={eval:!0};export const runInWorker=code=>{let p=new Promise(getPromiseResolvers),worker=new Worker(`import"runtime-compiler/env/build";${code};\nimport{__rtcpl_ct__}from"runtime-compiler/globals";import{parentPort as __rtcpl_pp__}from"node:worker_threads";__rtcpl_pp__.postMessage(__rtcpl_ct__)`,workerOptions);worker.once("message",curRes);worker.once("error",curRej);return p};export const compile=async code=>{let str='import"runtime-compiler/env/aot";import{__rtcpl_aot_fns__}from"runtime-compiler/globals";__rtcpl_aot_fns__.push(';for(let codes=await runInWorker(code),i=codes.length-1;i>-1;i--)str+=`$=>{${codes[i]}},`;return str+");"+code};
|
package/build/rolldown.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{runInWorker}from"./index.js";let parseImportBindings=(code,start,end)=>{let startSpecs=code.indexOf("{",start),endSpecs=code.lastIndexOf("}",end);if(-1===start&&-1===end)throw new Error("Only named imports replacement is supported!");let bindings=[];for(let i=0,specifiers=code.slice(startSpecs+1,endSpecs-1).split(",");i<specifiers.length;i++){let specifier=specifiers[i].trim();if(""===specifier)continue;let parts=specifier.split(" as ",2);if(1===parts.length){let name=parts[0].trim();bindings.push({name,alias:name})}else bindings.push({name:parts[0].trim(),alias:parts[1].trim()})}return{bindings,start,end}};export default(()=>({name:"rolldown-plugin-runtime-compiler",resolveId:{filter:{id:/^runtime-compiler\/(?:env|globals)$/},handler:()=>!1},renderChunk:async(code,{imports})=>{let globalsImportIdx=imports.indexOf("runtime-compiler/globals");if(-1===globalsImportIdx)return null;imports.splice(globalsImportIdx);let envImportIdx=imports.indexOf("runtime-compiler/env"),envImport=null,globalsImport=null;-1===envImportIdx?envImport={bindings:[],start:0,end:0}:imports.splice(envImportIdx,1);for(let start=0,eol=code.indexOf("\n");eol>-1&&(null==envImport||null==globalsImport);eol=code.indexOf("\n",start=eol+1))code.startsWith("import",start)&&(code.endsWith('"runtime-compiler/env";',eol)?envImport=parseImportBindings(code,start,eol):code.endsWith('"runtime-compiler/globals";',eol)&&(globalsImport=parseImportBindings(code,start,eol)));let aotCode="
|
|
1
|
+
import{runInWorker}from"./index.js";let parseImportBindings=(code,start,end)=>{let startSpecs=code.indexOf("{",start),endSpecs=code.lastIndexOf("}",end);if(-1===start&&-1===end)throw new Error("Only named imports replacement is supported!");let bindings=[];for(let i=0,specifiers=code.slice(startSpecs+1,endSpecs-1).split(",");i<specifiers.length;i++){let specifier=specifiers[i].trim();if(""===specifier)continue;let parts=specifier.split(" as ",2);if(1===parts.length){let name=parts[0].trim();bindings.push({name,alias:name})}else bindings.push({name:parts[0].trim(),alias:parts[1].trim()})}return{bindings,start,end}};export default(()=>({name:"rolldown-plugin-runtime-compiler",resolveId:{filter:{id:/^runtime-compiler\/(?:env|globals)$/},handler:()=>!1},renderChunk:async(code,{imports})=>{let globalsImportIdx=imports.indexOf("runtime-compiler/globals");if(-1===globalsImportIdx)return null;imports.splice(globalsImportIdx);let envImportIdx=imports.indexOf("runtime-compiler/env"),envImport=null,globalsImport=null;-1===envImportIdx?envImport={bindings:[],start:0,end:0}:imports.splice(envImportIdx,1);for(let start=0,eol=code.indexOf("\n");eol>-1&&(null==envImport||null==globalsImport);eol=code.indexOf("\n",start=eol+1))code.startsWith("import",start)&&(code.endsWith('"runtime-compiler/env";',eol)?envImport=parseImportBindings(code,start,eol):code.endsWith('"runtime-compiler/globals";',eol)&&(globalsImport=parseImportBindings(code,start,eol)));let aotCode="const __rtcpl_r__=[],__rtcpl_aot_fns__=[";for(let codes=await runInWorker(code),i=codes.length-1;i>-1;i--)aotCode+=`$=>{${codes[i]}},`;aotCode+="]";for(let i=0,{bindings}=envImport;i<bindings.length;i++){let{name,alias}=bindings[i];aotCode+="IS_AOT"===name?`,${alias}=true`:"IS_BUILD"===name||"IS_JIT"===name?`,${alias}=false`:""}for(let i=0,{bindings}=globalsImport;i<bindings.length;i++){let{name,alias}=bindings[i];aotCode+="deref"===name?`,${alias}=i=>__rtcpl_r__[i]`:"evaluate"===name?`,${alias}=(_)=>__rtcpl_aot_fns__.pop()(__rtcpl_r__)`:"createRef"===name?`,${alias}=()=>__rtcpl_r__.push(undefined)-1`:"importRef"===name?`,${alias}=v=>__rtcpl_r__.push(v)-1`:""}aotCode+=";"+(envImport.start<globalsImport.start?code.slice(0,envImport.start)+code.slice(envImport.end,globalsImport.start)+code.slice(globalsImport.end):code.slice(0,globalsImport.start)+code.slice(globalsImport.end,envImport.start)+code.slice(envImport.end));return{code:aotCode}}}));
|
package/globals.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ export type Ref<T> = number & {
|
|
|
3
3
|
};
|
|
4
4
|
export declare const importRef: <T>(value: T) => Ref<T>;
|
|
5
5
|
export declare const createRef: <T>() => Ref<T>;
|
|
6
|
-
export declare let evaluate: <T>() => T;
|
|
7
|
-
export declare const
|
|
6
|
+
export declare let evaluate: <T>(content?: string | boolean | null | undefined) => T;
|
|
7
|
+
export declare const __rtcpl_aot_fns__: ((args: any[]) => any)[];
|
|
8
8
|
export declare const deref: <T>(id: Ref<T>) => T;
|
package/globals.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{IS_AOT,IS_BUILD}from"./env/index.js";
|
|
1
|
+
import{IS_AOT,IS_BUILD}from"./env/index.js";let __rtcpl_r__=[];export const importRef=value=>__rtcpl_r__.push(value)-1;export const createRef=()=>__rtcpl_r__.push(void 0)-1;export let __rtcpl_ct__=[];export let evaluate=IS_AOT?_=>__rtcpl_aot_fns__.pop()(__rtcpl_r__):IS_BUILD?content=>{if("string"==typeof content){__rtcpl_ct__.push(content);return(0,eval)(`$=>{${content}}`)(__rtcpl_r__)}__rtcpl_ct__.push("")}:content=>{if("string"==typeof content)return(0,eval)(`$=>{${content}}`)(__rtcpl_r__)};export const __rtcpl_aot_fns__=[];export const deref=id=>__rtcpl_r__[id];
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"runtime-compiler","version":"4.0.
|
|
1
|
+
{"name":"runtime-compiler","version":"4.0.3","description":"A code generation system.","keywords":[],"homepage":"","license":"MIT","repository":"","type":"module","exports":{"./*":"./*.js","./build":"./build/index.js","./env":"./env/index.js"}}
|
package/utils.d.ts
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type Expr<T> = string & {
|
|
2
|
+
"~": T;
|
|
3
|
+
};
|
|
4
|
+
export type Id<T> = Expr<T> & {
|
|
5
|
+
"~id": 0;
|
|
6
|
+
};
|
|
7
|
+
export declare const toExpr: <T>(str: string) => Expr<T>;
|
|
8
|
+
export declare const toId: <T>(str: string | Expr<T>) => Id<T>;
|
package/utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const toExpr=str=>str;export const toId=toExpr;
|
package/scope.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export type Scope = [start: string, end: string, nextId: number];
|
|
2
|
-
/**
|
|
3
|
-
* Get next available id in a scope.
|
|
4
|
-
*/
|
|
5
|
-
export declare const scopeNextId: (scope: Scope) => number;
|
|
6
|
-
/**
|
|
7
|
-
* Get scope content.
|
|
8
|
-
*/
|
|
9
|
-
export declare const scopeContent: (scope: Scope) => string;
|
|
10
|
-
/**
|
|
11
|
-
* Fork a new scope.
|
|
12
|
-
*/
|
|
13
|
-
export declare const scopeFork: <T extends Scope>(scope: T) => T;
|
package/scope.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const scopeNextId=scope=>scope[2]++;export const scopeContent=scope=>`{${scope[0]+scope[1]}}`;export const scopeFork=scope=>scope.slice();
|