@code0-tech/triangulum 0.4.0 → 0.5.1
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/dist/triangulum.cjs.js +17 -17
- package/dist/triangulum.es.js +117 -116
- package/package.json +1 -1
package/dist/triangulum.cjs.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("typescript");function R(){return R=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var i=arguments[n];for(var r in i)({}).hasOwnProperty.call(i,r)&&(t[r]=i[r])}return t},R.apply(null,arguments)}var Y=!1;try{Y=typeof localStorage<"u"}catch{}var X=typeof process<"u",ee=Y&&typeof localStorage.getItem=="function"&&localStorage.getItem("DEBUG")||X&&process.env.DEBUG,J=ee?console.log:function(t){return""};function te(t,n,i,r,g){r===void 0&&(r={});var l=R({},q(i),r),p=re(t,n,l,i,g),u=p.languageServiceHost,c=p.updateFile,
|
|
2
|
-
`,useCaseSensitiveFileNames:!0,write:function(){return I("write")},writeFile:function(i,r){t.set(i,r)},deleteFile:function(i){t.delete(i)}}}function G(t,n,i){var r=new Map,g=function(u){return r.set(u.fileName,u),u},l={compilerHost:R({},t,{getCanonicalFileName:function(u){return u},getDefaultLibFileName:function(){return"/"+i.getDefaultLibFileName(n)},getNewLine:function(){return t.newLine},getSourceFile:function(u,c){var
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("typescript");function R(){return R=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var i=arguments[n];for(var r in i)({}).hasOwnProperty.call(i,r)&&(t[r]=i[r])}return t},R.apply(null,arguments)}var Y=!1;try{Y=typeof localStorage<"u"}catch{}var X=typeof process<"u",ee=Y&&typeof localStorage.getItem=="function"&&localStorage.getItem("DEBUG")||X&&process.env.DEBUG,J=ee?console.log:function(t){return""};function te(t,n,i,r,g){r===void 0&&(r={});var l=R({},q(i),r),p=re(t,n,l,i,g),u=p.languageServiceHost,c=p.updateFile,d=p.deleteFile,a=i.createLanguageService(u),F=a.getCompilerOptionsDiagnostics();if(F.length){var s=G(t,r,i);throw new Error(i.formatDiagnostics(F,s.compilerHost))}return{name:"vfs",sys:t,languageService:a,getSourceFile:function(e){var o;return(o=a.getProgram())==null?void 0:o.getSourceFile(e)},createFile:function(e,o){c(i.createSourceFile(e,o,l.target,!1))},updateFile:function(e,o,m){var T=a.getProgram().getSourceFile(e);if(!T)throw new Error("Did not find a source file for "+e);var v=T.text,S=m??i.createTextSpan(0,v.length),C=v.slice(0,S.start)+o+v.slice(S.start+S.length),w=i.updateSourceFile(T,C,{span:S,newLength:o.length});c(w)},deleteFile:function(e){var o=a.getProgram().getSourceFile(e);o&&d(o)}}}function I(t){throw new Error("Method '"+t+"' is not implemented.")}function k(t,n){return function(){for(var i=arguments.length,r=new Array(i),g=0;g<i;g++)r[g]=arguments[g];var l=n.apply(void 0,r),p=typeof l=="string"?l.slice(0,80)+"...":l;return J.apply(void 0,["> "+t].concat(r)),J("< "+p),l}}var q=function(n){return R({},n.getDefaultCompilerOptions(),{jsx:n.JsxEmit.React,strict:!0,esModuleInterop:!0,module:n.ModuleKind.ESNext,suppressOutputPathCheck:!0,skipLibCheck:!0,skipDefaultLibCheck:!0},n.versionMajorMinor&&Number(n.versionMajorMinor.split(".")[0])>=6?{ignoreDeprecations:"6.0"}:{moduleResolution:n.ModuleResolutionKind.NodeJs})},K=function(n){return n.replace("/","/lib.").toLowerCase()};function ne(t){return{args:[],createDirectory:function(){return I("createDirectory")},directoryExists:k("directoryExists",function(n){return Array.from(t.keys()).some(function(i){return i.startsWith(n)})}),exit:function(){return I("exit")},fileExists:k("fileExists",function(n){return t.has(n)||t.has(K(n))}),getCurrentDirectory:function(){return"/"},getDirectories:function(){return[]},getExecutingFilePath:function(){return I("getExecutingFilePath")},readDirectory:k("readDirectory",function(n){return n==="/"?Array.from(t.keys()):[]}),readFile:k("readFile",function(n){var i;return(i=t.get(n))!=null?i:t.get(K(n))}),resolvePath:function(i){return i},newLine:`
|
|
2
|
+
`,useCaseSensitiveFileNames:!0,write:function(){return I("write")},writeFile:function(i,r){t.set(i,r)},deleteFile:function(i){t.delete(i)}}}function G(t,n,i){var r=new Map,g=function(u){return r.set(u.fileName,u),u},l={compilerHost:R({},t,{getCanonicalFileName:function(u){return u},getDefaultLibFileName:function(){return"/"+i.getDefaultLibFileName(n)},getNewLine:function(){return t.newLine},getSourceFile:function(u,c){var d;return r.get(u)||g(i.createSourceFile(u,t.readFile(u),(d=c??n.target)!=null?d:q(i).target,!1))},useCaseSensitiveFileNames:function(){return t.useCaseSensitiveFileNames}}),updateFile:function(u){var c=r.has(u.fileName);return t.writeFile(u.fileName,u.text),r.set(u.fileName,u),c},deleteFile:function(u){var c=r.has(u.fileName);return r.delete(u.fileName),t.deleteFile(u.fileName),c}};return l}function re(t,n,i,r,g){var l=[].concat(n),p=G(t,i,r),u=p.compilerHost,c=p.updateFile,d=p.deleteFile,a=new Map,F=0,s=R({},u,{getProjectVersion:function(){return F.toString()},getCompilationSettings:function(){return i},getCustomTransformers:function(){return g},getScriptFileNames:function(){return l.slice()},getScriptSnapshot:function(o){var m=t.readFile(o);if(m&&typeof m=="string")return r.ScriptSnapshot.fromString(m)},getScriptVersion:function(o){return a.get(o)||"0"},writeFile:t.writeFile}),y={languageServiceHost:s,updateFile:function(o){F++,a.set(o.fileName,F.toString()),l.includes(o.fileName)||l.push(o.fileName),c(o)},deleteFile:function(o){F++,a.set(o.fileName,F.toString());var m=l.indexOf(o.fileName);m!==-1&&l.splice(m,1),d(o)}};return y}const Q=(t,n,i)=>{if(!t)return{parameters:[],returnType:"any"};const r=t.id||"temp_node_id",g={...t,id:r,parameters:{...t.parameters,nodes:t.parameters?.nodes?.map(e=>e?.value?e:{...e,value:null})||[]}},l=r+"_params",p={...g,id:l,parameters:{...g.parameters,nodes:g.parameters.nodes.map(e=>e.value?.__typename==="LiteralValue"&&e.value.value!==null&&typeof e.value.value!="object"?{...e,value:null}:e)}},c=oe({nodes:{__typename:"NodeFunctionConnection",nodes:[g,p]}},n,i),d=L(r),a=L(l),F=c.parameters.get(d)||[],s=c.parameters.get(a)||[];return{parameters:F.map((e,o)=>{const m=s[o];return m&&m!=="any"&&m!=="unknown"?m:e}),returnType:c.nodes.get(d)||"any"}};var j=(t=>(t[t.PRIMITIVE=0]="PRIMITIVE",t[t.TYPE=1]="TYPE",t[t.ARRAY=2]="ARRAY",t[t.OBJECT=3]="OBJECT",t[t.NODE=4]="NODE",t))(j||{});const U=(t,n)=>{const r=`
|
|
3
3
|
${O(n)}
|
|
4
4
|
type TargetType = ${t};
|
|
5
5
|
const val: TargetType = {} as any;
|
|
6
|
-
`,g="index.ts",l=A(g,r),p=l.getSourceFile(g),c=l.languageService.getProgram().getTypeChecker();let
|
|
6
|
+
`,g="index.ts",l=A(g,r),p=l.getSourceFile(g),c=l.languageService.getProgram().getTypeChecker();let d=1;const a=F=>{if(f.isVariableDeclaration(F)&&F.name.getText()==="val"){const s=c.getTypeAtLocation(F);s.getCallSignatures().length>0?d=4:c.isArrayType(s)?d=2:s.isStringLiteral()||s.isNumberLiteral()||(s.getFlags()&(f.TypeFlags.String|f.TypeFlags.Number|f.TypeFlags.Boolean|f.TypeFlags.EnumLiteral|f.TypeFlags.BigInt|f.TypeFlags.ESSymbol))!==0?d=0:s.isClassOrInterface()||(s.getFlags()&f.TypeFlags.Object)!==0?d=3:d=1}f.forEachChild(F,a)};return a(p),d},ie=`
|
|
7
7
|
interface Array<T> {
|
|
8
8
|
[n: number]: T;
|
|
9
9
|
length: number;
|
|
@@ -22,20 +22,20 @@
|
|
|
22
22
|
`;function A(t,n){const i=new Map;i.set(t,n),i.set("lib.codezero.d.ts",ie);const r=ne(i);return te(r,[t,"lib.codezero.d.ts"],f,ae)}const ae={target:f.ScriptTarget.Latest,lib:["lib.codezero.d.ts"],noEmit:!0,strictNullChecks:!0};function O(t){const n=Array.from(new Set(t?.flatMap(r=>r.genericKeys||[]))).map(r=>`type ${r} = any;`).join(`
|
|
23
23
|
`),i=t?.map(r=>`type ${r.identifier}${(r.genericKeys?.length??0)>0?`<${r.genericKeys?.join(",")}>`:""} = ${r.type};`).join(`
|
|
24
24
|
`);return`${n}
|
|
25
|
-
${i}`}const
|
|
26
|
-
`;let v={parameters:[]};r||(v=Q(
|
|
27
|
-
${V}${o}}`}else{const D=v.parameters[h];if(D?U(D,i)===j.NODE:!1){const M=`p_${
|
|
28
|
-
${H}${o}}`}else{const M=u(_.id,e,h);return`/* @pos ${e} ${h} */ ${M}`}}}return r?`/* @pos ${e} ${h} */ {}`:`/* @pos ${e} ${h} */ undefined`}).join(", "),w=`node_${
|
|
29
|
-
`;return
|
|
25
|
+
${i}`}const L=t=>t.replace(/[^a-zA-Z0-9]/g,"_");function z(t,n,i,r=!1){const g=t?.nodes?.nodes||[],l=new Map(n?.map(e=>[e.identifier,e])),p=new Set,u=(e,o,m)=>{const T=g.find(P=>P?.id===e);if(!T||!T.functionDefinition?.identifier)return"undefined";const S=(T.parameters?.nodes||[]).map((P,x)=>{const E=P.value;if(!E)return r?`/* @pos ${e} ${x} */ {}`:`/* @pos ${e} ${x} */ undefined`;if(E.__typename==="ReferenceValue"){const $=E;if(!$.nodeFunctionId)return`/* @pos ${e} ${x} */ undefined`;let N=$.inputIndex!==void 0?`p_${L($.nodeFunctionId)}_${$.parameterIndex}[${$.inputIndex}]`:`node_${L($.nodeFunctionId)}`;return $.referencePath?.forEach(h=>{N+=`?.${h.path}`}),`/* @pos ${e} ${x} */ ${N}`}return E.__typename==="LiteralValue"?`/* @pos ${e} ${x} */ ${JSON.stringify(E.value)}`:E.__typename==="NodeFunctionIdWrapper"?u(E.id,e,x):r?`/* @pos ${e} ${x} */ ({} as any)`:`/* @pos ${e} ${x} */ undefined`}).join(", "),w=`${`fn_${T.functionDefinition.identifier.replace(/::/g,"_")}`}(${S})`;return o!==void 0&&m!==void 0?`${w}`:w},c=(e,o="")=>{if(p.has(e))return"";const m=g.find(N=>N?.id===e);if(!m||!m.functionDefinition)return"";if(p.add(e),!l.get(m.functionDefinition.identifier))return`${o}// Error: Function ${m.functionDefinition.identifier} not found
|
|
26
|
+
`;let v={parameters:[]};r||(v=Q(m,n,i));const C=(m.parameters?.nodes||[]).map((N,h)=>{const b=N.value;if(!b)return r?`/* @pos ${e} ${h} */ {}`:`/* @pos ${e} ${h} */ undefined`;if(b.__typename==="ReferenceValue"){const _=b;if(!_.nodeFunctionId)return`/* @pos ${e} ${h} */ undefined`;let D=_.inputIndex!==void 0?`p_${L(_.nodeFunctionId)}_${_.parameterIndex}[${_.inputIndex}]`:`node_${L(_.nodeFunctionId)}`;return _.referencePath?.forEach(V=>{D+=`?.${V.path}`}),`/* @pos ${e} ${h} */ ${D}`}if(b.__typename==="LiteralValue")return`/* @pos ${e} ${h} */ ${JSON.stringify(b.value)}`;if(b.__typename==="NodeFunctionIdWrapper"){const _=b;if(r){const D=`p_${L(e)}_${h}`,V=c(_.id,o+" ");return`/* @pos ${e} ${h} */ (...${D}) => {
|
|
27
|
+
${V}${o}}`}else{const D=v.parameters[h];if(D?U(D,i)===j.NODE:!1){const M=`p_${L(e)}_${h}`,H=c(_.id,o+" ");return`/* @pos ${e} ${h} */ (...${M}) => {
|
|
28
|
+
${H}${o}}`}else{const M=u(_.id,e,h);return`/* @pos ${e} ${h} */ ${M}`}}}return r?`/* @pos ${e} ${h} */ {}`:`/* @pos ${e} ${h} */ undefined`}).join(", "),w=`node_${L(m.id)}`,P=`fn_${m?.functionDefinition?.identifier?.replace(/::/g,"_")}`,x=C.includes("undefined"),E=m.functionDefinition.identifier==="std::control::return";let $=`${o}${E?"return ":`const ${w} = `}${P}(${C}) ;
|
|
29
|
+
`;return m.nextNodeId&&($+=c(m.nextNodeId,o)),$},d=O(i),a=n?.map(e=>`declare function fn_${e.identifier?.replace(/::/g,"_")}${e.signature}`).join(`
|
|
30
30
|
`),F=new Set(g.map(e=>e?.nextNodeId).filter(e=>!!e)),s=new Set;g.forEach(e=>e?.parameters?.nodes?.forEach(o=>{o?.value?.__typename==="NodeFunctionIdWrapper"&&o.value.id&&s.add(o.value.id)}));const y=g.filter(e=>e?.id&&!F.has(e.id)&&!s.has(e.id)).map(e=>c(e.id)).join(`
|
|
31
|
-
`);return`${
|
|
31
|
+
`);return`${d}
|
|
32
32
|
${a}
|
|
33
33
|
|
|
34
34
|
// --- Flow ---
|
|
35
|
-
${y}`}function oe(t,n,i){const r=z(t,n,i,!0),g="index.ts",l=A(g,r),p=l.getSourceFile(g),c=l.languageService.getProgram().getTypeChecker(),
|
|
35
|
+
${y}`}function oe(t,n,i){const r=z(t,n,i,!0),g="index.ts",l=A(g,r),p=l.getSourceFile(g),c=l.languageService.getProgram().getTypeChecker(),d=new Map,a=new Map,F=new Map;(t?.nodes?.nodes||[]).forEach(e=>{e?.id&&F.set(L(e.id),e)});const y=e=>{if(f.isVariableDeclaration(e)&&e.name.getText().startsWith("node_")){const o=e.name.getText().replace("node_",""),m=c.getTypeAtLocation(e);if(d.set(o,c.typeToString(m,e,f.TypeFormatFlags.NoTruncation)),e.initializer&&f.isCallExpression(e.initializer)){const T=c.getResolvedSignature(e.initializer);if(T){const v=T.getParameters().map(S=>{const C=c.getTypeOfSymbolAtLocation(S,e.initializer);return c.typeToString(C,e.initializer,f.TypeFormatFlags.NoTruncation)});a.set(o,v)}}}if(f.isReturnStatement(e)&&e.expression&&f.isCallExpression(e.expression)){const o=e.expression;c.getResolvedSignature(o)}f.forEachChild(e,y)};return y(p),{nodes:d,parameters:a}}const se=t=>{const i=`const tempValue = ${JSON.stringify(t?.value)??"any"};`,r="index.ts",g=A(r,i),l=g.getSourceFile(r),u=g.languageService.getProgram().getTypeChecker();let c="any";const d=a=>{if(f.isVariableDeclaration(a)&&a.name.getText()==="tempValue"){const F=u.getTypeAtLocation(a);c=u.typeToString(F,a,f.TypeFormatFlags.NoTruncation|f.TypeFormatFlags.UseFullyQualifiedType)}f.forEachChild(a,d)};return d(l),c},ce=(t,n)=>{const i=`
|
|
36
36
|
${O(n)}
|
|
37
37
|
type Target = ${t};
|
|
38
|
-
`,r="index.ts",g=A(r,i),l=g.getSourceFile(r),u=g.languageService.getProgram().getTypeChecker(),c=l.statements.find(s=>f.isTypeAliasDeclaration(s)&&s.name.text==="Target");if(!c)return{__typename:"LiteralValue",value:null};const
|
|
38
|
+
`,r="index.ts",g=A(r,i),l=g.getSourceFile(r),u=g.languageService.getProgram().getTypeChecker(),c=l.statements.find(s=>f.isTypeAliasDeclaration(s)&&s.name.text==="Target");if(!c)return{__typename:"LiteralValue",value:null};const d=u.getTypeAtLocation(c.type),a=(s,y,e=new Set)=>{if(e.has(s))return null;e.add(s);const o=s.getFlags();if(s.isUnion()){if(y.type,f.isTypeAliasDeclaration(y)&&y.type&&f.isUnionTypeNode(y.type)){const v=u.getTypeFromTypeNode(y.type.types[0]);return a(v,y,e)}const m=s.types.filter(v=>{const S=v.getFlags();return!(S&f.TypeFlags.Undefined)&&!(S&f.TypeFlags.Null)}),T=m.length>0?m[0]:s.types[0];return a(T,y,e)}if(o&f.TypeFlags.StringLiteral)return s.value;if(o&f.TypeFlags.String)return"";if(o&f.TypeFlags.NumberLiteral)return s.value;if(o&f.TypeFlags.Number)return 0;if(o&f.TypeFlags.BooleanLiteral)return s.intrinsicName==="true";if(o&f.TypeFlags.Boolean)return!1;if(u.isArrayType(s)){const T=s.typeArguments?.[0]||u.getAnyType();return a(T,y,e)==="null"?[a(T,y,e)]:[]}if(s.isClassOrInterface()||o&f.TypeFlags.Object||s.getProperties().length>0){const m={};return s.getProperties().forEach(v=>{const S=u.getTypeOfSymbolAtLocation(v,y);S&&(m[v.getName()]=a(S,y,e))}),m}return null};return{__typename:"LiteralValue",value:a(d,c)}},le=(t,n,i)=>{let r=n;const g=t?U(t,i):null;if(t&&n&&g!==j.NODE){let l=function(y){const e=y.trim().match(/^<([^>]+)>/);return e?e[1].split(",").map(o=>o.trim()).filter(Boolean).length:0};const p=`
|
|
39
39
|
${O(i)}
|
|
40
40
|
type TargetType = ${t};
|
|
41
41
|
${n?.map((y,e)=>`
|
|
@@ -45,13 +45,13 @@ ${y}`}function oe(t,n,i){const r=z(t,n,i,!0),g="index.ts",l=A(g,r),p=l.getSource
|
|
|
45
45
|
`)}
|
|
46
46
|
${n?.map((y,e)=>`const check${e}: TargetType = {} as F${e};`).join(`
|
|
47
47
|
`)}
|
|
48
|
-
`,u="index.ts",c=A(u,p),
|
|
49
|
-
`).findIndex(v=>v.includes(o));return T!==-1&&!s.has(T)})}return r?.map(l=>({__typename:"NodeFunction",id:"gid://sagittarius/NodeFunction/1",functionDefinition:{__typename:"FunctionDefinition",id:l.id,identifier:l.identifier},parameters:{__typename:"NodeParameterConnection",nodes:(l.parameterDefinitions?.nodes||[]).map(p=>({__typename:"NodeParameter",parameterDefinition:{__typename:"ParameterDefinition",id:p?.id,identifier:p?.identifier},value:null}))}})).filter(l=>l!==null)??[]},ue=(t,n,i,r,g)=>{const l=z(t,r,g,!0),p="index.ts",u=A(p,l),c=u.getSourceFile(p),a=u.languageService.getProgram().getTypeChecker(),F=c.getFullText(),s=`/* @pos ${n} ${i} */`,e=F.indexOf(s)+s.length;function o($,N){let h=$;return f.forEachChild($,b=>{b.getStart(c,!0)<=N&&b.getEnd()>=N&&(h=o(b,N))}),h}const T=o(c,e);let v;if(f.isCallExpression(T)&&(v=T),!v)return[];const S=a.getResolvedSignature(v);if(!S)return[];const C=S.getParameters(),w=C[i]||C[C.length-1],
|
|
48
|
+
`,u="index.ts",c=A(u,p),d=c.getSourceFile(u),F=c.languageService.getProgram().getSemanticDiagnostics(),s=new Set;F.forEach(y=>{y.file===d&&y.start!==void 0&&s.add(d.getLineAndCharacterOfPosition(y.start).line)}),r=n.filter((y,e)=>{const o=`const check${e}: TargetType = {} as F${e};`,T=p.split(`
|
|
49
|
+
`).findIndex(v=>v.includes(o));return T!==-1&&!s.has(T)})}return r?.map(l=>({__typename:"NodeFunction",id:"gid://sagittarius/NodeFunction/1",functionDefinition:{__typename:"FunctionDefinition",id:l.id,identifier:l.identifier},parameters:{__typename:"NodeParameterConnection",nodes:(l.parameterDefinitions?.nodes||[]).map(p=>({__typename:"NodeParameter",parameterDefinition:{__typename:"ParameterDefinition",id:p?.id,identifier:p?.identifier},value:null}))}})).filter(l=>l!==null)??[]},ue=(t,n,i,r,g)=>{const l=z(t,r,g,!0),p="index.ts",u=A(p,l),c=u.getSourceFile(p),a=u.languageService.getProgram().getTypeChecker(),F=c.getFullText(),s=`/* @pos ${n} ${i} */`,e=F.indexOf(s)+s.length;function o($,N){let h=$;return f.forEachChild($,b=>{b.getStart(c,!0)<=N&&b.getEnd()>=N&&(h=o(b,N))}),h}const T=o(c,e);let v;if(f.isCallExpression(T)&&(v=T),!v)return[];const S=a.getResolvedSignature(v);if(!S)return[];const C=S.getParameters(),w=C[i]||C[C.length-1],P=a.getTypeOfSymbolAtLocation(w,T),x=a.getSymbolsInScope(T,f.SymbolFlags.Variable),E=[];return x.forEach($=>{const N=$.getName();if(!N.startsWith("node_")&&!N.startsWith("p_"))return;const h=$.valueDeclaration||$.declarations?.[0];if(!h||h.getEnd()>=e)return;const b=a.getTypeOfSymbolAtLocation($,T);if(N.startsWith("node_")){if((b.flags&f.TypeFlags.Void)===0&&a.isTypeAssignableTo(b,P)){const _=N.replace("node_","").replace(/___/g,"://").replace(/__/g,"/").replace(/_/g,"/");E.push({__typename:"ReferenceValue",nodeFunctionId:_})}}else if(N.startsWith("p_")){const _=N.replace("p_",""),D=_.lastIndexOf("_"),V=_.substring(0,D),M=parseInt(_.substring(D+1),10),H=V.replace("p_","").replace(/___/g,"://").replace(/__/g,"/").replace(/_/g,"/");if(a.isTupleType(b)){const B=b;a.getTypeArguments(B).forEach((Z,W)=>{a.isTypeAssignableTo(Z,P)&&E.push({__typename:"ReferenceValue",nodeFunctionId:H,parameterIndex:isNaN(M)?0:M,inputIndex:W,inputTypeIdentifier:B.target.labeledElementDeclarations?.[W].name.getText()})})}}}),E},ge=(t,n)=>{if(!t)return[];const i=`
|
|
50
50
|
${O(n)}
|
|
51
51
|
type VALUE = ${t}; const val: VALUE = {} as any;
|
|
52
|
-
`,r="index.ts",g=A(r,i),l=g.getSourceFile(r),u=g.languageService.getProgram().getTypeChecker(),c=l.statements.find(s=>f.isTypeAliasDeclaration(s)&&s.name.text==="VALUE");if(!c||!f.isTypeAliasDeclaration(c))return[];const
|
|
53
|
-
`);let s,y;if(a.start!==void 0){const e=p.getFullText(),o=Math.max(0,a.start-300),
|
|
52
|
+
`,r="index.ts",g=A(r,i),l=g.getSourceFile(r),u=g.languageService.getProgram().getTypeChecker(),c=l.statements.find(s=>f.isTypeAliasDeclaration(s)&&s.name.text==="VALUE");if(!c||!f.isTypeAliasDeclaration(c))return[];const d=u.getTypeAtLocation(c),a=s=>s.isUnion()?s.types.flatMap(a):s.isStringLiteral()?[s.value]:s.isNumberLiteral()?[s.value.toString()]:s.intrinsicName==="true"?["true"]:s.intrinsicName==="false"?["false"]:[];return Array.from(new Set(a(d))).map(s=>({__typename:"LiteralValue",value:s}))},pe=(t,n,i)=>{const r=z(t,n,i),g="index.ts",l=A(g,r),p=l.getSourceFile(g),d=l.languageService.getProgram().getSemanticDiagnostics(p).map(a=>{const F=f.flattenDiagnosticMessageText(a.messageText,`
|
|
53
|
+
`);let s,y;if(a.start!==void 0){const e=p.getFullText(),o=Math.max(0,a.start-300),m=Math.min(e.length,a.start),T=e.substring(o,m),v=/\/\* @pos ([^ ]+) (\d+) \*\//g;let S,C=null,w=-1;for(;(S=v.exec(T))!==null;){const x=o+S.index+S[0].length;x<=a.start&&x>w&&(w=x,C=S)}C&&(s=C[1],y=parseInt(C[2],10))}return{message:F,code:a.code,severity:"error",nodeId:s,parameterIndex:y}}).filter(a=>a!==null);return{isValid:!d.some(a=>a?.severity==="error"),returnType:"void",diagnostics:d}},fe=(t,n,i)=>{const r=JSON.stringify(n?.value),g=`
|
|
54
54
|
${O(i)}
|
|
55
55
|
const testValue: ${t} = ${r};
|
|
56
|
-
`,l="index.ts",c=A(l,g).languageService.getSemanticDiagnostics(l).map(
|
|
57
|
-
`),F=a.includes("not assignable to parameter of type")&&(a.includes("'{}'")||a.includes("undefined"))||a.includes("not assignable to type 'undefined'")||a.includes("not assignable to type 'void'")||a.includes("may be a mistake because neither type sufficiently overlaps");return{message:a,code:
|
|
56
|
+
`,l="index.ts",c=A(l,g).languageService.getSemanticDiagnostics(l).map(d=>{const a=f.flattenDiagnosticMessageText(d.messageText,`
|
|
57
|
+
`),F=a.includes("not assignable to parameter of type")&&(a.includes("'{}'")||a.includes("undefined"))||a.includes("not assignable to type 'undefined'")||a.includes("not assignable to type 'void'")||a.includes("may be a mistake because neither type sufficiently overlaps");return{message:a,code:d.code,severity:F?"warning":"error"}});return{isValid:!c.some(d=>d.severity==="error"),returnType:"void",diagnostics:c}};exports.DataTypeVariant=j;exports.getFlowValidation=pe;exports.getNodeSuggestions=le;exports.getReferenceSuggestions=ue;exports.getTypeFromValue=se;exports.getTypeVariant=U;exports.getTypesFromNode=Q;exports.getValueFromType=ce;exports.getValueSuggestions=ge;exports.getValueValidation=fe;
|
package/dist/triangulum.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import m, { flattenDiagnosticMessageText as Z } from "typescript";
|
|
2
2
|
function R() {
|
|
3
3
|
return R = Object.assign ? Object.assign.bind() : function(t) {
|
|
4
4
|
for (var n = 1; n < arguments.length; n++) {
|
|
@@ -18,7 +18,7 @@ var X = typeof process < "u", ee = K && typeof localStorage.getItem == "function
|
|
|
18
18
|
};
|
|
19
19
|
function te(t, n, i, r, g) {
|
|
20
20
|
r === void 0 && (r = {});
|
|
21
|
-
var l = R({}, Y(i), r), p = re(t, n, l, i, g), u = p.languageServiceHost, c = p.updateFile,
|
|
21
|
+
var l = R({}, Y(i), r), p = re(t, n, l, i, g), u = p.languageServiceHost, c = p.updateFile, d = p.deleteFile, a = i.createLanguageService(u), F = a.getCompilerOptionsDiagnostics();
|
|
22
22
|
if (F.length) {
|
|
23
23
|
var s = G(t, r, i);
|
|
24
24
|
throw new Error(i.formatDiagnostics(F, s.compilerHost));
|
|
@@ -35,11 +35,11 @@ function te(t, n, i, r, g) {
|
|
|
35
35
|
createFile: function(e, o) {
|
|
36
36
|
c(i.createSourceFile(e, o, l.target, !1));
|
|
37
37
|
},
|
|
38
|
-
updateFile: function(e, o,
|
|
38
|
+
updateFile: function(e, o, f) {
|
|
39
39
|
var v = a.getProgram().getSourceFile(e);
|
|
40
40
|
if (!v)
|
|
41
41
|
throw new Error("Did not find a source file for " + e);
|
|
42
|
-
var T = v.text, S =
|
|
42
|
+
var T = v.text, S = f ?? i.createTextSpan(0, T.length), C = T.slice(0, S.start) + o + T.slice(S.start + S.length), w = i.updateSourceFile(v, C, {
|
|
43
43
|
span: S,
|
|
44
44
|
newLength: o.length
|
|
45
45
|
});
|
|
@@ -47,7 +47,7 @@ function te(t, n, i, r, g) {
|
|
|
47
47
|
},
|
|
48
48
|
deleteFile: function(e) {
|
|
49
49
|
var o = a.getProgram().getSourceFile(e);
|
|
50
|
-
o &&
|
|
50
|
+
o && d(o);
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
53
|
}
|
|
@@ -147,8 +147,8 @@ function G(t, n, i) {
|
|
|
147
147
|
return t.newLine;
|
|
148
148
|
},
|
|
149
149
|
getSourceFile: function(u, c) {
|
|
150
|
-
var
|
|
151
|
-
return r.get(u) || g(i.createSourceFile(u, t.readFile(u), (
|
|
150
|
+
var d;
|
|
151
|
+
return r.get(u) || g(i.createSourceFile(u, t.readFile(u), (d = c ?? n.target) != null ? d : Y(i).target, !1));
|
|
152
152
|
},
|
|
153
153
|
useCaseSensitiveFileNames: function() {
|
|
154
154
|
return t.useCaseSensitiveFileNames;
|
|
@@ -166,7 +166,7 @@ function G(t, n, i) {
|
|
|
166
166
|
return l;
|
|
167
167
|
}
|
|
168
168
|
function re(t, n, i, r, g) {
|
|
169
|
-
var l = [].concat(n), p = G(t, i, r), u = p.compilerHost, c = p.updateFile,
|
|
169
|
+
var l = [].concat(n), p = G(t, i, r), u = p.compilerHost, c = p.updateFile, d = p.deleteFile, a = /* @__PURE__ */ new Map(), F = 0, s = R({}, u, {
|
|
170
170
|
getProjectVersion: function() {
|
|
171
171
|
return F.toString();
|
|
172
172
|
},
|
|
@@ -188,9 +188,9 @@ function re(t, n, i, r, g) {
|
|
|
188
188
|
return l.slice();
|
|
189
189
|
},
|
|
190
190
|
getScriptSnapshot: function(o) {
|
|
191
|
-
var
|
|
192
|
-
if (
|
|
193
|
-
return r.ScriptSnapshot.fromString(
|
|
191
|
+
var f = t.readFile(o);
|
|
192
|
+
if (f && typeof f == "string")
|
|
193
|
+
return r.ScriptSnapshot.fromString(f);
|
|
194
194
|
},
|
|
195
195
|
getScriptVersion: function(o) {
|
|
196
196
|
return a.get(o) || "0";
|
|
@@ -203,8 +203,8 @@ function re(t, n, i, r, g) {
|
|
|
203
203
|
},
|
|
204
204
|
deleteFile: function(o) {
|
|
205
205
|
F++, a.set(o.fileName, F.toString());
|
|
206
|
-
var
|
|
207
|
-
|
|
206
|
+
var f = l.indexOf(o.fileName);
|
|
207
|
+
f !== -1 && l.splice(f, 1), d(o);
|
|
208
208
|
}
|
|
209
209
|
};
|
|
210
210
|
return y;
|
|
@@ -227,13 +227,13 @@ const ie = (t, n, i) => {
|
|
|
227
227
|
}
|
|
228
228
|
}, c = se({
|
|
229
229
|
nodes: { __typename: "NodeFunctionConnection", nodes: [g, p] }
|
|
230
|
-
}, n, i),
|
|
230
|
+
}, n, i), d = L(r), a = L(l), F = c.parameters.get(d) || [], s = c.parameters.get(a) || [];
|
|
231
231
|
return {
|
|
232
232
|
parameters: F.map((e, o) => {
|
|
233
|
-
const
|
|
234
|
-
return
|
|
233
|
+
const f = s[o];
|
|
234
|
+
return f && f !== "any" && f !== "unknown" ? f : e;
|
|
235
235
|
}),
|
|
236
|
-
returnType: c.nodes.get(
|
|
236
|
+
returnType: c.nodes.get(d) || "any"
|
|
237
237
|
};
|
|
238
238
|
};
|
|
239
239
|
var H = /* @__PURE__ */ ((t) => (t[t.PRIMITIVE = 0] = "PRIMITIVE", t[t.TYPE = 1] = "TYPE", t[t.ARRAY = 2] = "ARRAY", t[t.OBJECT = 3] = "OBJECT", t[t.NODE = 4] = "NODE", t))(H || {});
|
|
@@ -242,16 +242,16 @@ const q = (t, n) => {
|
|
|
242
242
|
${O(n)}
|
|
243
243
|
type TargetType = ${t};
|
|
244
244
|
const val: TargetType = {} as any;
|
|
245
|
-
`, g = "index.ts", l =
|
|
246
|
-
let
|
|
245
|
+
`, g = "index.ts", l = P(g, r), p = l.getSourceFile(g), c = l.languageService.getProgram().getTypeChecker();
|
|
246
|
+
let d = 1;
|
|
247
247
|
const a = (F) => {
|
|
248
|
-
if (
|
|
248
|
+
if (m.isVariableDeclaration(F) && F.name.getText() === "val") {
|
|
249
249
|
const s = c.getTypeAtLocation(F);
|
|
250
|
-
s.getCallSignatures().length > 0 ?
|
|
250
|
+
s.getCallSignatures().length > 0 ? d = 4 : c.isArrayType(s) ? d = 2 : s.isStringLiteral() || s.isNumberLiteral() || (s.getFlags() & (m.TypeFlags.String | m.TypeFlags.Number | m.TypeFlags.Boolean | m.TypeFlags.EnumLiteral | m.TypeFlags.BigInt | m.TypeFlags.ESSymbol)) !== 0 ? d = 0 : s.isClassOrInterface() || (s.getFlags() & m.TypeFlags.Object) !== 0 ? d = 3 : d = 1;
|
|
251
251
|
}
|
|
252
|
-
|
|
252
|
+
m.forEachChild(F, a);
|
|
253
253
|
};
|
|
254
|
-
return a(p),
|
|
254
|
+
return a(p), d;
|
|
255
255
|
}, ae = `
|
|
256
256
|
interface Array<T> {
|
|
257
257
|
[n: number]: T;
|
|
@@ -269,14 +269,14 @@ const q = (t, n) => {
|
|
|
269
269
|
type Record<K extends keyof any, T> = { [P in K]: T; };
|
|
270
270
|
type ReturnType<T extends (...args: any) => any> = T extends (...args: any) => infer R ? R : any;
|
|
271
271
|
`;
|
|
272
|
-
function
|
|
272
|
+
function P(t, n) {
|
|
273
273
|
const i = /* @__PURE__ */ new Map();
|
|
274
274
|
i.set(t, n), i.set("lib.codezero.d.ts", ae);
|
|
275
275
|
const r = ne(i);
|
|
276
|
-
return te(r, [t, "lib.codezero.d.ts"],
|
|
276
|
+
return te(r, [t, "lib.codezero.d.ts"], m, oe);
|
|
277
277
|
}
|
|
278
278
|
const oe = {
|
|
279
|
-
target:
|
|
279
|
+
target: m.ScriptTarget.Latest,
|
|
280
280
|
lib: ["lib.codezero.d.ts"],
|
|
281
281
|
noEmit: !0,
|
|
282
282
|
strictNullChecks: !0
|
|
@@ -292,166 +292,167 @@ ${i}`;
|
|
|
292
292
|
}
|
|
293
293
|
const L = (t) => t.replace(/[^a-zA-Z0-9]/g, "_");
|
|
294
294
|
function U(t, n, i, r = !1) {
|
|
295
|
-
const g = t?.nodes?.nodes || [], l = new Map(n?.map((e) => [e.identifier, e])), p = /* @__PURE__ */ new Set(), u = (e, o,
|
|
296
|
-
const v = g.find((
|
|
295
|
+
const g = t?.nodes?.nodes || [], l = new Map(n?.map((e) => [e.identifier, e])), p = /* @__PURE__ */ new Set(), u = (e, o, f) => {
|
|
296
|
+
const v = g.find((A) => A?.id === e);
|
|
297
297
|
if (!v || !v.functionDefinition?.identifier) return "undefined";
|
|
298
|
-
const S = (v.parameters?.nodes || []).map((
|
|
299
|
-
const E =
|
|
298
|
+
const S = (v.parameters?.nodes || []).map((A, x) => {
|
|
299
|
+
const E = A.value;
|
|
300
300
|
if (!E) return r ? `/* @pos ${e} ${x} */ {}` : `/* @pos ${e} ${x} */ undefined`;
|
|
301
301
|
if (E.__typename === "ReferenceValue") {
|
|
302
302
|
const $ = E;
|
|
303
303
|
if (!$.nodeFunctionId) return `/* @pos ${e} ${x} */ undefined`;
|
|
304
|
-
let
|
|
304
|
+
let _ = $.inputIndex !== void 0 ? `p_${L($.nodeFunctionId)}_${$.parameterIndex}[${$.inputIndex}]` : `node_${L($.nodeFunctionId)}`;
|
|
305
305
|
return $.referencePath?.forEach((h) => {
|
|
306
|
-
|
|
307
|
-
}), `/* @pos ${e} ${x} */ ${
|
|
306
|
+
_ += `?.${h.path}`;
|
|
307
|
+
}), `/* @pos ${e} ${x} */ ${_}`;
|
|
308
308
|
}
|
|
309
309
|
return E.__typename === "LiteralValue" ? `/* @pos ${e} ${x} */ ${JSON.stringify(E.value)}` : E.__typename === "NodeFunctionIdWrapper" ? u(E.id, e, x) : r ? `/* @pos ${e} ${x} */ ({} as any)` : `/* @pos ${e} ${x} */ undefined`;
|
|
310
310
|
}).join(", "), w = `${`fn_${v.functionDefinition.identifier.replace(/::/g, "_")}`}(${S})`;
|
|
311
|
-
return o !== void 0 &&
|
|
311
|
+
return o !== void 0 && f !== void 0 ? `${w}` : w;
|
|
312
312
|
}, c = (e, o = "") => {
|
|
313
313
|
if (p.has(e)) return "";
|
|
314
|
-
const
|
|
315
|
-
if (!
|
|
316
|
-
if (p.add(e), !l.get(
|
|
314
|
+
const f = g.find((_) => _?.id === e);
|
|
315
|
+
if (!f || !f.functionDefinition) return "";
|
|
316
|
+
if (p.add(e), !l.get(f.functionDefinition.identifier)) return `${o}// Error: Function ${f.functionDefinition.identifier} not found
|
|
317
317
|
`;
|
|
318
318
|
let T = { parameters: [] };
|
|
319
|
-
r || (T = ie(
|
|
320
|
-
const C = (
|
|
321
|
-
const b =
|
|
319
|
+
r || (T = ie(f, n, i));
|
|
320
|
+
const C = (f.parameters?.nodes || []).map((_, h) => {
|
|
321
|
+
const b = _.value;
|
|
322
322
|
if (!b) return r ? `/* @pos ${e} ${h} */ {}` : `/* @pos ${e} ${h} */ undefined`;
|
|
323
323
|
if (b.__typename === "ReferenceValue") {
|
|
324
|
-
const
|
|
325
|
-
if (!
|
|
326
|
-
let D =
|
|
327
|
-
return
|
|
324
|
+
const N = b;
|
|
325
|
+
if (!N.nodeFunctionId) return `/* @pos ${e} ${h} */ undefined`;
|
|
326
|
+
let D = N.inputIndex !== void 0 ? `p_${L(N.nodeFunctionId)}_${N.parameterIndex}[${N.inputIndex}]` : `node_${L(N.nodeFunctionId)}`;
|
|
327
|
+
return N.referencePath?.forEach((V) => {
|
|
328
328
|
D += `?.${V.path}`;
|
|
329
329
|
}), `/* @pos ${e} ${h} */ ${D}`;
|
|
330
330
|
}
|
|
331
331
|
if (b.__typename === "LiteralValue") return `/* @pos ${e} ${h} */ ${JSON.stringify(b.value)}`;
|
|
332
332
|
if (b.__typename === "NodeFunctionIdWrapper") {
|
|
333
|
-
const
|
|
333
|
+
const N = b;
|
|
334
334
|
if (r) {
|
|
335
|
-
const D = `p_${L(e)}_${h}`, V = c(
|
|
335
|
+
const D = `p_${L(e)}_${h}`, V = c(N.id, o + " ");
|
|
336
336
|
return `/* @pos ${e} ${h} */ (...${D}) => {
|
|
337
337
|
${V}${o}}`;
|
|
338
338
|
} else {
|
|
339
339
|
const D = T.parameters[h];
|
|
340
340
|
if (D ? q(D, i) === H.NODE : !1) {
|
|
341
|
-
const M = `p_${L(e)}_${h}`, j = c(
|
|
341
|
+
const M = `p_${L(e)}_${h}`, j = c(N.id, o + " ");
|
|
342
342
|
return `/* @pos ${e} ${h} */ (...${M}) => {
|
|
343
343
|
${j}${o}}`;
|
|
344
344
|
} else {
|
|
345
|
-
const M = u(
|
|
345
|
+
const M = u(N.id, e, h);
|
|
346
346
|
return `/* @pos ${e} ${h} */ ${M}`;
|
|
347
347
|
}
|
|
348
348
|
}
|
|
349
349
|
}
|
|
350
350
|
return r ? `/* @pos ${e} ${h} */ {}` : `/* @pos ${e} ${h} */ undefined`;
|
|
351
|
-
}).join(", "), w = `node_${L(
|
|
352
|
-
let $ = `${o}${E ? "return " : `const ${w} = `}${
|
|
351
|
+
}).join(", "), w = `node_${L(f.id)}`, A = `fn_${f?.functionDefinition?.identifier?.replace(/::/g, "_")}`, x = C.includes("undefined"), E = f.functionDefinition.identifier === "std::control::return";
|
|
352
|
+
let $ = `${o}${E ? "return " : `const ${w} = `}${A}(${C}) ;
|
|
353
353
|
`;
|
|
354
|
-
return
|
|
355
|
-
},
|
|
354
|
+
return f.nextNodeId && ($ += c(f.nextNodeId, o)), $;
|
|
355
|
+
}, d = O(i), a = n?.map((e) => `declare function fn_${e.identifier?.replace(/::/g, "_")}${e.signature}`).join(`
|
|
356
356
|
`), F = new Set(g.map((e) => e?.nextNodeId).filter((e) => !!e)), s = /* @__PURE__ */ new Set();
|
|
357
357
|
g.forEach((e) => e?.parameters?.nodes?.forEach((o) => {
|
|
358
358
|
o?.value?.__typename === "NodeFunctionIdWrapper" && o.value.id && s.add(o.value.id);
|
|
359
359
|
}));
|
|
360
360
|
const y = g.filter((e) => e?.id && !F.has(e.id) && !s.has(e.id)).map((e) => c(e.id)).join(`
|
|
361
361
|
`);
|
|
362
|
-
return `${
|
|
362
|
+
return `${d}
|
|
363
363
|
${a}
|
|
364
364
|
|
|
365
365
|
// --- Flow ---
|
|
366
366
|
${y}`;
|
|
367
367
|
}
|
|
368
368
|
function se(t, n, i) {
|
|
369
|
-
const r = U(t, n, i, !0), g = "index.ts", l =
|
|
369
|
+
const r = U(t, n, i, !0), g = "index.ts", l = P(g, r), p = l.getSourceFile(g), c = l.languageService.getProgram().getTypeChecker(), d = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), F = /* @__PURE__ */ new Map();
|
|
370
370
|
(t?.nodes?.nodes || []).forEach((e) => {
|
|
371
371
|
e?.id && F.set(L(e.id), e);
|
|
372
372
|
});
|
|
373
373
|
const y = (e) => {
|
|
374
|
-
if (
|
|
375
|
-
const o = e.name.getText().replace("node_", ""),
|
|
376
|
-
if (
|
|
374
|
+
if (m.isVariableDeclaration(e) && e.name.getText().startsWith("node_")) {
|
|
375
|
+
const o = e.name.getText().replace("node_", ""), f = c.getTypeAtLocation(e);
|
|
376
|
+
if (d.set(o, c.typeToString(f, e, m.TypeFormatFlags.NoTruncation)), e.initializer && m.isCallExpression(e.initializer)) {
|
|
377
377
|
const v = c.getResolvedSignature(e.initializer);
|
|
378
378
|
if (v) {
|
|
379
379
|
const T = v.getParameters().map((S) => {
|
|
380
380
|
const C = c.getTypeOfSymbolAtLocation(S, e.initializer);
|
|
381
|
-
return c.typeToString(C, e.initializer,
|
|
381
|
+
return c.typeToString(C, e.initializer, m.TypeFormatFlags.NoTruncation);
|
|
382
382
|
});
|
|
383
383
|
a.set(o, T);
|
|
384
384
|
}
|
|
385
385
|
}
|
|
386
386
|
}
|
|
387
|
-
if (
|
|
387
|
+
if (m.isReturnStatement(e) && e.expression && m.isCallExpression(e.expression)) {
|
|
388
388
|
const o = e.expression;
|
|
389
389
|
c.getResolvedSignature(o);
|
|
390
390
|
}
|
|
391
|
-
|
|
391
|
+
m.forEachChild(e, y);
|
|
392
392
|
};
|
|
393
|
-
return y(p), { nodes:
|
|
393
|
+
return y(p), { nodes: d, parameters: a };
|
|
394
394
|
}
|
|
395
395
|
const ue = (t) => {
|
|
396
|
-
const i = `const tempValue = ${JSON.stringify(t?.value) ?? "any"};`, r = "index.ts", g =
|
|
396
|
+
const i = `const tempValue = ${JSON.stringify(t?.value) ?? "any"};`, r = "index.ts", g = P(r, i), l = g.getSourceFile(r), u = g.languageService.getProgram().getTypeChecker();
|
|
397
397
|
let c = "any";
|
|
398
|
-
const
|
|
399
|
-
if (
|
|
398
|
+
const d = (a) => {
|
|
399
|
+
if (m.isVariableDeclaration(a) && a.name.getText() === "tempValue") {
|
|
400
400
|
const F = u.getTypeAtLocation(a);
|
|
401
401
|
c = u.typeToString(
|
|
402
402
|
F,
|
|
403
403
|
a,
|
|
404
|
-
|
|
404
|
+
m.TypeFormatFlags.NoTruncation | m.TypeFormatFlags.UseFullyQualifiedType
|
|
405
405
|
);
|
|
406
406
|
}
|
|
407
|
-
|
|
407
|
+
m.forEachChild(a, d);
|
|
408
408
|
};
|
|
409
|
-
return
|
|
409
|
+
return d(l), c;
|
|
410
410
|
}, ge = (t, n) => {
|
|
411
411
|
const i = `
|
|
412
412
|
${O(n)}
|
|
413
413
|
type Target = ${t};
|
|
414
|
-
`, r = "index.ts", g =
|
|
415
|
-
(s) =>
|
|
414
|
+
`, r = "index.ts", g = P(r, i), l = g.getSourceFile(r), u = g.languageService.getProgram().getTypeChecker(), c = l.statements.find(
|
|
415
|
+
(s) => m.isTypeAliasDeclaration(s) && s.name.text === "Target"
|
|
416
416
|
);
|
|
417
417
|
if (!c)
|
|
418
418
|
return { __typename: "LiteralValue", value: null };
|
|
419
|
-
const
|
|
419
|
+
const d = u.getTypeAtLocation(c.type), a = (s, y, e = /* @__PURE__ */ new Set()) => {
|
|
420
420
|
if (e.has(s)) return null;
|
|
421
421
|
e.add(s);
|
|
422
422
|
const o = s.getFlags();
|
|
423
423
|
if (s.isUnion()) {
|
|
424
|
-
if (y.type,
|
|
424
|
+
if (y.type, m.isTypeAliasDeclaration(y) && y.type && m.isUnionTypeNode(y.type)) {
|
|
425
425
|
const T = u.getTypeFromTypeNode(y.type.types[0]);
|
|
426
426
|
return a(T, y, e);
|
|
427
427
|
}
|
|
428
|
-
const
|
|
428
|
+
const f = s.types.filter((T) => {
|
|
429
429
|
const S = T.getFlags();
|
|
430
|
-
return !(S &
|
|
431
|
-
}), v =
|
|
430
|
+
return !(S & m.TypeFlags.Undefined) && !(S & m.TypeFlags.Null);
|
|
431
|
+
}), v = f.length > 0 ? f[0] : s.types[0];
|
|
432
432
|
return a(v, y, e);
|
|
433
433
|
}
|
|
434
|
-
if (o &
|
|
435
|
-
if (o &
|
|
436
|
-
if (o &
|
|
437
|
-
if (o &
|
|
438
|
-
if (o &
|
|
439
|
-
if (o &
|
|
434
|
+
if (o & m.TypeFlags.StringLiteral) return s.value;
|
|
435
|
+
if (o & m.TypeFlags.String) return "";
|
|
436
|
+
if (o & m.TypeFlags.NumberLiteral) return s.value;
|
|
437
|
+
if (o & m.TypeFlags.Number) return 0;
|
|
438
|
+
if (o & m.TypeFlags.BooleanLiteral) return s.intrinsicName === "true";
|
|
439
|
+
if (o & m.TypeFlags.Boolean) return !1;
|
|
440
440
|
if (u.isArrayType(s)) {
|
|
441
441
|
const v = s.typeArguments?.[0] || u.getAnyType();
|
|
442
|
-
return [a(v, y, e)];
|
|
442
|
+
return a(v, y, e) === "null" ? [a(v, y, e)] : [];
|
|
443
443
|
}
|
|
444
|
-
if (s.isClassOrInterface() || o &
|
|
445
|
-
const
|
|
444
|
+
if (s.isClassOrInterface() || o & m.TypeFlags.Object || s.getProperties().length > 0) {
|
|
445
|
+
const f = {};
|
|
446
446
|
return s.getProperties().forEach((T) => {
|
|
447
447
|
const S = u.getTypeOfSymbolAtLocation(T, y);
|
|
448
|
-
S && (
|
|
449
|
-
}),
|
|
448
|
+
S && (f[T.getName()] = a(S, y, e));
|
|
449
|
+
}), f;
|
|
450
450
|
}
|
|
451
451
|
return null;
|
|
452
452
|
};
|
|
453
453
|
return {
|
|
454
|
-
|
|
454
|
+
__typename: "LiteralValue",
|
|
455
|
+
value: a(d, c)
|
|
455
456
|
};
|
|
456
457
|
}, pe = (t, n, i) => {
|
|
457
458
|
let r = n;
|
|
@@ -471,9 +472,9 @@ const ue = (t) => {
|
|
|
471
472
|
`)}
|
|
472
473
|
${n?.map((y, e) => `const check${e}: TargetType = {} as F${e};`).join(`
|
|
473
474
|
`)}
|
|
474
|
-
`, u = "index.ts", c =
|
|
475
|
+
`, u = "index.ts", c = P(u, p), d = c.getSourceFile(u), F = c.languageService.getProgram().getSemanticDiagnostics(), s = /* @__PURE__ */ new Set();
|
|
475
476
|
F.forEach((y) => {
|
|
476
|
-
y.file ===
|
|
477
|
+
y.file === d && y.start !== void 0 && s.add(d.getLineAndCharacterOfPosition(y.start).line);
|
|
477
478
|
}), r = n.filter((y, e) => {
|
|
478
479
|
const o = `const check${e}: TargetType = {} as F${e};`, v = p.split(`
|
|
479
480
|
`).findIndex((T) => T.includes(o));
|
|
@@ -502,42 +503,42 @@ const ue = (t) => {
|
|
|
502
503
|
}
|
|
503
504
|
})).filter((l) => l !== null) ?? [];
|
|
504
505
|
}, fe = (t, n, i, r, g) => {
|
|
505
|
-
const l = U(t, r, g, !0), p = "index.ts", u =
|
|
506
|
-
function o($,
|
|
506
|
+
const l = U(t, r, g, !0), p = "index.ts", u = P(p, l), c = u.getSourceFile(p), a = u.languageService.getProgram().getTypeChecker(), F = c.getFullText(), s = `/* @pos ${n} ${i} */`, e = F.indexOf(s) + s.length;
|
|
507
|
+
function o($, _) {
|
|
507
508
|
let h = $;
|
|
508
|
-
return
|
|
509
|
-
b.getStart(c, !0) <=
|
|
509
|
+
return m.forEachChild($, (b) => {
|
|
510
|
+
b.getStart(c, !0) <= _ && b.getEnd() >= _ && (h = o(b, _));
|
|
510
511
|
}), h;
|
|
511
512
|
}
|
|
512
513
|
const v = o(c, e);
|
|
513
514
|
let T;
|
|
514
|
-
if (
|
|
515
|
+
if (m.isCallExpression(v) && (T = v), !T)
|
|
515
516
|
return [];
|
|
516
517
|
const S = a.getResolvedSignature(T);
|
|
517
518
|
if (!S) return [];
|
|
518
|
-
const C = S.getParameters(), w = C[i] || C[C.length - 1],
|
|
519
|
+
const C = S.getParameters(), w = C[i] || C[C.length - 1], A = a.getTypeOfSymbolAtLocation(w, v), x = a.getSymbolsInScope(v, m.SymbolFlags.Variable), E = [];
|
|
519
520
|
return x.forEach(($) => {
|
|
520
|
-
const
|
|
521
|
-
if (!
|
|
521
|
+
const _ = $.getName();
|
|
522
|
+
if (!_.startsWith("node_") && !_.startsWith("p_")) return;
|
|
522
523
|
const h = $.valueDeclaration || $.declarations?.[0];
|
|
523
524
|
if (!h || h.getEnd() >= e)
|
|
524
525
|
return;
|
|
525
526
|
const b = a.getTypeOfSymbolAtLocation($, v);
|
|
526
|
-
if (
|
|
527
|
-
if ((b.flags &
|
|
528
|
-
const
|
|
527
|
+
if (_.startsWith("node_")) {
|
|
528
|
+
if ((b.flags & m.TypeFlags.Void) === 0 && a.isTypeAssignableTo(b, A)) {
|
|
529
|
+
const N = _.replace("node_", "").replace(/___/g, "://").replace(/__/g, "/").replace(/_/g, "/");
|
|
529
530
|
E.push({
|
|
530
531
|
__typename: "ReferenceValue",
|
|
531
|
-
nodeFunctionId:
|
|
532
|
+
nodeFunctionId: N
|
|
532
533
|
// Bei node_ keine Indizes laut Vorgabe
|
|
533
534
|
});
|
|
534
535
|
}
|
|
535
|
-
} else if (
|
|
536
|
-
const
|
|
536
|
+
} else if (_.startsWith("p_")) {
|
|
537
|
+
const N = _.replace("p_", ""), D = N.lastIndexOf("_"), V = N.substring(0, D), M = parseInt(N.substring(D + 1), 10), j = V.replace("p_", "").replace(/___/g, "://").replace(/__/g, "/").replace(/_/g, "/");
|
|
537
538
|
if (a.isTupleType(b)) {
|
|
538
539
|
const z = b;
|
|
539
540
|
a.getTypeArguments(z).forEach((Q, B) => {
|
|
540
|
-
a.isTypeAssignableTo(Q,
|
|
541
|
+
a.isTypeAssignableTo(Q, A) && E.push({
|
|
541
542
|
__typename: "ReferenceValue",
|
|
542
543
|
nodeFunctionId: j,
|
|
543
544
|
parameterIndex: isNaN(M) ? 0 : M,
|
|
@@ -554,22 +555,22 @@ const ue = (t) => {
|
|
|
554
555
|
const i = `
|
|
555
556
|
${O(n)}
|
|
556
557
|
type VALUE = ${t}; const val: VALUE = {} as any;
|
|
557
|
-
`, r = "index.ts", g =
|
|
558
|
-
(s) =>
|
|
558
|
+
`, r = "index.ts", g = P(r, i), l = g.getSourceFile(r), u = g.languageService.getProgram().getTypeChecker(), c = l.statements.find(
|
|
559
|
+
(s) => m.isTypeAliasDeclaration(s) && s.name.text === "VALUE"
|
|
559
560
|
);
|
|
560
|
-
if (!c || !
|
|
561
|
-
const
|
|
562
|
-
return Array.from(new Set(a(
|
|
561
|
+
if (!c || !m.isTypeAliasDeclaration(c)) return [];
|
|
562
|
+
const d = u.getTypeAtLocation(c), a = (s) => s.isUnion() ? s.types.flatMap(a) : s.isStringLiteral() ? [s.value] : s.isNumberLiteral() ? [s.value.toString()] : s.intrinsicName === "true" ? ["true"] : s.intrinsicName === "false" ? ["false"] : [];
|
|
563
|
+
return Array.from(new Set(a(d))).map((s) => ({
|
|
563
564
|
__typename: "LiteralValue",
|
|
564
565
|
value: s
|
|
565
566
|
}));
|
|
566
567
|
}, de = (t, n, i) => {
|
|
567
|
-
const r = U(t, n, i), g = "index.ts", l =
|
|
568
|
+
const r = U(t, n, i), g = "index.ts", l = P(g, r), p = l.getSourceFile(g), d = l.languageService.getProgram().getSemanticDiagnostics(p).map((a) => {
|
|
568
569
|
const F = Z(a.messageText, `
|
|
569
570
|
`);
|
|
570
571
|
let s, y;
|
|
571
572
|
if (a.start !== void 0) {
|
|
572
|
-
const e = p.getFullText(), o = Math.max(0, a.start - 300),
|
|
573
|
+
const e = p.getFullText(), o = Math.max(0, a.start - 300), f = Math.min(e.length, a.start), v = e.substring(o, f), T = /\/\* @pos ([^ ]+) (\d+) \*\//g;
|
|
573
574
|
let S, C = null, w = -1;
|
|
574
575
|
for (; (S = T.exec(v)) !== null; ) {
|
|
575
576
|
const x = o + S.index + S[0].length;
|
|
@@ -586,25 +587,25 @@ const ue = (t) => {
|
|
|
586
587
|
};
|
|
587
588
|
}).filter((a) => a !== null);
|
|
588
589
|
return {
|
|
589
|
-
isValid: !
|
|
590
|
+
isValid: !d.some((a) => a?.severity === "error"),
|
|
590
591
|
returnType: "void",
|
|
591
|
-
diagnostics:
|
|
592
|
+
diagnostics: d
|
|
592
593
|
};
|
|
593
594
|
}, ye = (t, n, i) => {
|
|
594
595
|
const r = JSON.stringify(n?.value), g = `
|
|
595
596
|
${O(i)}
|
|
596
597
|
const testValue: ${t} = ${r};
|
|
597
|
-
`, l = "index.ts", c =
|
|
598
|
-
const a =
|
|
598
|
+
`, l = "index.ts", c = P(l, g).languageService.getSemanticDiagnostics(l).map((d) => {
|
|
599
|
+
const a = m.flattenDiagnosticMessageText(d.messageText, `
|
|
599
600
|
`), F = a.includes("not assignable to parameter of type") && (a.includes("'{}'") || a.includes("undefined")) || a.includes("not assignable to type 'undefined'") || a.includes("not assignable to type 'void'") || a.includes("may be a mistake because neither type sufficiently overlaps");
|
|
600
601
|
return {
|
|
601
602
|
message: a,
|
|
602
|
-
code:
|
|
603
|
+
code: d.code,
|
|
603
604
|
severity: F ? "warning" : "error"
|
|
604
605
|
};
|
|
605
606
|
});
|
|
606
607
|
return {
|
|
607
|
-
isValid: !c.some((
|
|
608
|
+
isValid: !c.some((d) => d.severity === "error"),
|
|
608
609
|
returnType: "void",
|
|
609
610
|
diagnostics: c
|
|
610
611
|
};
|