@code0-tech/triangulum 0.2.0 → 0.3.0
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/LICENSE +1 -1
- package/dist/extraction/getTypeFromValue.d.ts +1 -1
- package/dist/extraction/getTypeVariant.d.ts +3 -2
- package/dist/extraction/getTypesFromNode.d.ts +1 -1
- package/dist/extraction/getValueFromType.d.ts +1 -1
- package/dist/suggestion/getNodeSuggestions.d.ts +1 -1
- package/dist/suggestion/getReferenceSuggestions.d.ts +1 -1
- package/dist/suggestion/getValueSuggestions.d.ts +2 -2
- package/dist/triangulum.cjs.js +35 -32
- package/dist/triangulum.es.js +337 -332
- package/dist/utils.d.ts +3 -3
- package/dist/validation/getFlowValidation.d.ts +1 -1
- package/dist/validation/getNodeValidation.d.ts +1 -1
- package/dist/validation/getValueValidation.d.ts +1 -1
- package/package.json +1 -1
package/dist/triangulum.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import y, { flattenDiagnosticMessageText as Z } from "typescript";
|
|
2
2
|
function A() {
|
|
3
3
|
return A = Object.assign ? Object.assign.bind() : function(e) {
|
|
4
4
|
for (var t = 1; t < arguments.length; t++) {
|
|
@@ -18,36 +18,36 @@ var X = typeof process < "u", ee = W && typeof localStorage.getItem == "function
|
|
|
18
18
|
};
|
|
19
19
|
function te(e, t, n, r, o) {
|
|
20
20
|
r === void 0 && (r = {});
|
|
21
|
-
var
|
|
22
|
-
if (
|
|
21
|
+
var s = A({}, G(n), r), c = re(e, t, s, n, o), a = c.languageServiceHost, u = c.updateFile, p = c.deleteFile, l = n.createLanguageService(a), h = l.getCompilerOptionsDiagnostics();
|
|
22
|
+
if (h.length) {
|
|
23
23
|
var i = Y(e, r, n);
|
|
24
|
-
throw new Error(n.formatDiagnostics(
|
|
24
|
+
throw new Error(n.formatDiagnostics(h, i.compilerHost));
|
|
25
25
|
}
|
|
26
26
|
return {
|
|
27
27
|
// @ts-ignore
|
|
28
28
|
name: "vfs",
|
|
29
29
|
sys: e,
|
|
30
|
-
languageService:
|
|
31
|
-
getSourceFile: function(
|
|
32
|
-
var
|
|
33
|
-
return (
|
|
30
|
+
languageService: l,
|
|
31
|
+
getSourceFile: function(v) {
|
|
32
|
+
var d;
|
|
33
|
+
return (d = l.getProgram()) == null ? void 0 : d.getSourceFile(v);
|
|
34
34
|
},
|
|
35
|
-
createFile: function(
|
|
36
|
-
u(n.createSourceFile(
|
|
35
|
+
createFile: function(v, d) {
|
|
36
|
+
u(n.createSourceFile(v, d, s.target, !1));
|
|
37
37
|
},
|
|
38
|
-
updateFile: function(
|
|
39
|
-
var
|
|
40
|
-
if (!
|
|
41
|
-
throw new Error("Did not find a source file for " +
|
|
42
|
-
var S =
|
|
43
|
-
span:
|
|
44
|
-
newLength:
|
|
38
|
+
updateFile: function(v, d, T) {
|
|
39
|
+
var g = l.getProgram().getSourceFile(v);
|
|
40
|
+
if (!g)
|
|
41
|
+
throw new Error("Did not find a source file for " + v);
|
|
42
|
+
var S = g.text, m = T ?? n.createTextSpan(0, S.length), $ = S.slice(0, m.start) + d + S.slice(m.start + m.length), F = n.updateSourceFile(g, $, {
|
|
43
|
+
span: m,
|
|
44
|
+
newLength: d.length
|
|
45
45
|
});
|
|
46
|
-
u(
|
|
46
|
+
u(F);
|
|
47
47
|
},
|
|
48
|
-
deleteFile: function(
|
|
49
|
-
var
|
|
50
|
-
|
|
48
|
+
deleteFile: function(v) {
|
|
49
|
+
var d = l.getProgram().getSourceFile(v);
|
|
50
|
+
d && p(d);
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
53
|
}
|
|
@@ -58,8 +58,8 @@ function w(e, t) {
|
|
|
58
58
|
return function() {
|
|
59
59
|
for (var n = arguments.length, r = new Array(n), o = 0; o < n; o++)
|
|
60
60
|
r[o] = arguments[o];
|
|
61
|
-
var
|
|
62
|
-
return J.apply(void 0, ["> " + e].concat(r)), J("< " +
|
|
61
|
+
var s = t.apply(void 0, r), c = typeof s == "string" ? s.slice(0, 80) + "..." : s;
|
|
62
|
+
return J.apply(void 0, ["> " + e].concat(r)), J("< " + c), s;
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
65
|
var G = function(t) {
|
|
@@ -133,7 +133,7 @@ function ne(e) {
|
|
|
133
133
|
function Y(e, t, n) {
|
|
134
134
|
var r = /* @__PURE__ */ new Map(), o = function(a) {
|
|
135
135
|
return r.set(a.fileName, a), a;
|
|
136
|
-
},
|
|
136
|
+
}, s = {
|
|
137
137
|
compilerHost: A({}, e, {
|
|
138
138
|
getCanonicalFileName: function(a) {
|
|
139
139
|
return a;
|
|
@@ -147,8 +147,8 @@ function Y(e, t, n) {
|
|
|
147
147
|
return e.newLine;
|
|
148
148
|
},
|
|
149
149
|
getSourceFile: function(a, u) {
|
|
150
|
-
var
|
|
151
|
-
return r.get(a) || o(n.createSourceFile(a, e.readFile(a), (
|
|
150
|
+
var p;
|
|
151
|
+
return r.get(a) || o(n.createSourceFile(a, e.readFile(a), (p = u ?? t.target) != null ? p : G(n).target, !1));
|
|
152
152
|
},
|
|
153
153
|
useCaseSensitiveFileNames: function() {
|
|
154
154
|
return e.useCaseSensitiveFileNames;
|
|
@@ -163,12 +163,12 @@ function Y(e, t, n) {
|
|
|
163
163
|
return r.delete(a.fileName), e.deleteFile(a.fileName), u;
|
|
164
164
|
}
|
|
165
165
|
};
|
|
166
|
-
return
|
|
166
|
+
return s;
|
|
167
167
|
}
|
|
168
168
|
function re(e, t, n, r, o) {
|
|
169
|
-
var
|
|
169
|
+
var s = [].concat(t), c = Y(e, n, r), a = c.compilerHost, u = c.updateFile, p = c.deleteFile, l = /* @__PURE__ */ new Map(), h = 0, i = A({}, a, {
|
|
170
170
|
getProjectVersion: function() {
|
|
171
|
-
return
|
|
171
|
+
return h.toString();
|
|
172
172
|
},
|
|
173
173
|
getCompilationSettings: function() {
|
|
174
174
|
return n;
|
|
@@ -185,29 +185,29 @@ function re(e, t, n, r, o) {
|
|
|
185
185
|
// is used in bisecting for changes, it needs to guard against being busted in that
|
|
186
186
|
// couple-week period, so we defensively make a slice here.
|
|
187
187
|
getScriptFileNames: function() {
|
|
188
|
-
return
|
|
188
|
+
return s.slice();
|
|
189
189
|
},
|
|
190
|
-
getScriptSnapshot: function(
|
|
191
|
-
var T = e.readFile(
|
|
190
|
+
getScriptSnapshot: function(d) {
|
|
191
|
+
var T = e.readFile(d);
|
|
192
192
|
if (T && typeof T == "string")
|
|
193
193
|
return r.ScriptSnapshot.fromString(T);
|
|
194
194
|
},
|
|
195
|
-
getScriptVersion: function(
|
|
196
|
-
return
|
|
195
|
+
getScriptVersion: function(d) {
|
|
196
|
+
return l.get(d) || "0";
|
|
197
197
|
},
|
|
198
198
|
writeFile: e.writeFile
|
|
199
|
-
}),
|
|
199
|
+
}), f = {
|
|
200
200
|
languageServiceHost: i,
|
|
201
|
-
updateFile: function(
|
|
202
|
-
|
|
201
|
+
updateFile: function(d) {
|
|
202
|
+
h++, l.set(d.fileName, h.toString()), s.includes(d.fileName) || s.push(d.fileName), u(d);
|
|
203
203
|
},
|
|
204
|
-
deleteFile: function(
|
|
205
|
-
|
|
206
|
-
var T =
|
|
207
|
-
T !== -1 &&
|
|
204
|
+
deleteFile: function(d) {
|
|
205
|
+
h++, l.set(d.fileName, h.toString());
|
|
206
|
+
var T = s.indexOf(d.fileName);
|
|
207
|
+
T !== -1 && s.splice(T, 1), p(d);
|
|
208
208
|
}
|
|
209
209
|
};
|
|
210
|
-
return
|
|
210
|
+
return f;
|
|
211
211
|
}
|
|
212
212
|
const ie = `
|
|
213
213
|
interface Array<T> {
|
|
@@ -229,17 +229,17 @@ function I(e, t) {
|
|
|
229
229
|
const n = /* @__PURE__ */ new Map();
|
|
230
230
|
n.set(e, t), n.set("lib.codezero.d.ts", ie);
|
|
231
231
|
const r = ne(n);
|
|
232
|
-
return te(r, [e, "lib.codezero.d.ts"],
|
|
232
|
+
return te(r, [e, "lib.codezero.d.ts"], y, oe);
|
|
233
233
|
}
|
|
234
234
|
const oe = {
|
|
235
|
-
target:
|
|
235
|
+
target: y.ScriptTarget.Latest,
|
|
236
236
|
lib: ["lib.codezero.d.ts"],
|
|
237
237
|
noEmit: !0,
|
|
238
238
|
strictNullChecks: !0
|
|
239
239
|
};
|
|
240
|
-
function
|
|
241
|
-
const t = Array.from(new Set(e
|
|
242
|
-
`), n = e
|
|
240
|
+
function V(e) {
|
|
241
|
+
const t = Array.from(new Set(e?.flatMap((r) => r.genericKeys || []))).map((r) => `type ${r} = any;`).join(`
|
|
242
|
+
`), n = e?.map(
|
|
243
243
|
(r) => `type ${r.identifier}${r.genericKeys ? `<${r.genericKeys.join(",")}>` : ""} = ${r.type};`
|
|
244
244
|
).join(`
|
|
245
245
|
`);
|
|
@@ -255,7 +255,7 @@ function ae(e, t) {
|
|
|
255
255
|
return typeof n;
|
|
256
256
|
}
|
|
257
257
|
function B(e, t) {
|
|
258
|
-
const n = e
|
|
258
|
+
const n = e?.nodes;
|
|
259
259
|
if (n)
|
|
260
260
|
return Array.isArray(n) ? n.find((r) => r.id === t) : n.nodes?.find((r) => r.id === t);
|
|
261
261
|
}
|
|
@@ -263,35 +263,35 @@ function q(e, t, n) {
|
|
|
263
263
|
const r = e?.value;
|
|
264
264
|
if (!r) return "undefined";
|
|
265
265
|
if (r.__typename === "ReferenceValue") {
|
|
266
|
-
const o = r,
|
|
267
|
-
if (!
|
|
268
|
-
let
|
|
266
|
+
const o = r, s = B(t, o.nodeFunctionId);
|
|
267
|
+
if (!s) return "undefined";
|
|
268
|
+
let c = n?.(t, s).returnType;
|
|
269
269
|
if (o.referencePath && o.referencePath.length > 0) {
|
|
270
270
|
let a;
|
|
271
|
-
const u =
|
|
271
|
+
const u = s.parameters?.nodes;
|
|
272
272
|
if (u && u.length > 0) {
|
|
273
|
-
const
|
|
274
|
-
|
|
273
|
+
const p = u[0];
|
|
274
|
+
p?.value?.__typename === "LiteralValue" && (a = p.value.value);
|
|
275
275
|
}
|
|
276
|
-
|
|
276
|
+
c = ae(a, o.referencePath);
|
|
277
277
|
}
|
|
278
|
-
return `({} as ${
|
|
278
|
+
return `({} as ${c})`;
|
|
279
279
|
}
|
|
280
280
|
if (r.__typename === "NodeFunctionIdWrapper") {
|
|
281
|
-
const o = r.id,
|
|
282
|
-
if (!
|
|
283
|
-
const
|
|
284
|
-
if (
|
|
285
|
-
return
|
|
286
|
-
const
|
|
287
|
-
return
|
|
288
|
-
}, a = s
|
|
289
|
-
return a ? `(() => ({} as ${n(t, a)
|
|
281
|
+
const o = r.id, s = B(t, o);
|
|
282
|
+
if (!s) return "(() => undefined)";
|
|
283
|
+
const c = (p) => {
|
|
284
|
+
if (p.functionDefinition?.identifier === "std::control::return")
|
|
285
|
+
return p;
|
|
286
|
+
const l = p.nextNodeId ? B(t, p.nextNodeId) : void 0;
|
|
287
|
+
return l ? c(l) : void 0;
|
|
288
|
+
}, a = c(s);
|
|
289
|
+
return a ? `(() => ({} as ${n?.(t, a)?.returnType}))` : "(() => undefined)";
|
|
290
290
|
}
|
|
291
291
|
return r.__typename === "LiteralValue" ? JSON.stringify(r.value) : "undefined";
|
|
292
292
|
}
|
|
293
293
|
const H = (e, t) => {
|
|
294
|
-
const n = e
|
|
294
|
+
const n = e?.nodes?.nodes;
|
|
295
295
|
if (n)
|
|
296
296
|
return n.find(
|
|
297
297
|
(r) => r?.parameters?.nodes?.some(
|
|
@@ -299,131 +299,131 @@ const H = (e, t) => {
|
|
|
299
299
|
)
|
|
300
300
|
);
|
|
301
301
|
}, Q = (e, t, n, r = /* @__PURE__ */ new Set()) => {
|
|
302
|
-
const o = t
|
|
302
|
+
const o = t?.id;
|
|
303
303
|
if (!o || r.has(o)) return !1;
|
|
304
304
|
r.add(o);
|
|
305
|
-
const
|
|
306
|
-
const u = e
|
|
307
|
-
return u ? u.id === n ? !0 :
|
|
305
|
+
const s = (a) => {
|
|
306
|
+
const u = e?.nodes?.nodes?.find((p) => p?.nextNodeId === a);
|
|
307
|
+
return u ? u.id === n ? !0 : s(u.id) : !1;
|
|
308
308
|
};
|
|
309
|
-
if (
|
|
310
|
-
const
|
|
311
|
-
return
|
|
309
|
+
if (s(o)) return !0;
|
|
310
|
+
const c = H(e, o);
|
|
311
|
+
return c ? c.id === n ? !0 : Q(e, c, n, r) : !1;
|
|
312
312
|
}, se = (e, t, n) => {
|
|
313
|
-
if (!n
|
|
313
|
+
if (!n?.nodeFunctionId)
|
|
314
314
|
return { isValid: !0 };
|
|
315
315
|
if (n.parameterIndex !== void 0 && n.inputIndex !== void 0) {
|
|
316
|
-
if (t
|
|
317
|
-
let r = H(e, t
|
|
316
|
+
if (t?.id === n.nodeFunctionId) return { isValid: !0 };
|
|
317
|
+
let r = H(e, t?.id);
|
|
318
318
|
for (; r; ) {
|
|
319
319
|
if (r.id === n.nodeFunctionId) return { isValid: !0 };
|
|
320
320
|
r = H(e, r.id);
|
|
321
321
|
}
|
|
322
322
|
return {
|
|
323
323
|
isValid: !1,
|
|
324
|
-
error: `Invalid input reference: Node ${t
|
|
324
|
+
error: `Invalid input reference: Node ${t?.id} is not in the scope of Node ${n.nodeFunctionId}.`
|
|
325
325
|
};
|
|
326
326
|
}
|
|
327
327
|
return Q(e, t, n.nodeFunctionId) ? { isValid: !0 } : {
|
|
328
328
|
isValid: !1,
|
|
329
329
|
error: `Node ${n.nodeFunctionId} has not been executed yet or is not visible in this scope.`
|
|
330
330
|
};
|
|
331
|
-
},
|
|
332
|
-
const n = `const tempValue = ${JSON.stringify(e?.value) ?? "any"};`, r = "index.ts", o = I(r, n),
|
|
331
|
+
}, fe = (e) => {
|
|
332
|
+
const n = `const tempValue = ${JSON.stringify(e?.value) ?? "any"};`, r = "index.ts", o = I(r, n), s = o.getSourceFile(r), a = o.languageService.getProgram().getTypeChecker();
|
|
333
333
|
let u = "any";
|
|
334
|
-
const
|
|
335
|
-
if (
|
|
336
|
-
const
|
|
334
|
+
const p = (l) => {
|
|
335
|
+
if (y.isVariableDeclaration(l) && l.name.getText() === "tempValue") {
|
|
336
|
+
const h = a.getTypeAtLocation(l);
|
|
337
337
|
u = a.typeToString(
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
338
|
+
h,
|
|
339
|
+
l,
|
|
340
|
+
y.TypeFormatFlags.NoTruncation | y.TypeFormatFlags.UseFullyQualifiedType
|
|
341
341
|
);
|
|
342
342
|
}
|
|
343
|
-
|
|
343
|
+
y.forEachChild(l, p);
|
|
344
344
|
};
|
|
345
|
-
return
|
|
345
|
+
return p(s), u;
|
|
346
346
|
};
|
|
347
|
-
var ce = /* @__PURE__ */ ((e) => (e[e.PRIMITIVE = 0] = "PRIMITIVE", e[e.TYPE = 1] = "TYPE", e[e.ARRAY = 2] = "ARRAY", e[e.OBJECT = 3] = "OBJECT", e))(ce || {});
|
|
348
|
-
const
|
|
347
|
+
var ce = /* @__PURE__ */ ((e) => (e[e.PRIMITIVE = 0] = "PRIMITIVE", e[e.TYPE = 1] = "TYPE", e[e.ARRAY = 2] = "ARRAY", e[e.OBJECT = 3] = "OBJECT", e[e.NODE = 4] = "NODE", e))(ce || {});
|
|
348
|
+
const de = (e, t) => {
|
|
349
349
|
const r = `
|
|
350
|
-
${
|
|
350
|
+
${V(t)}
|
|
351
351
|
type TargetType = ${e};
|
|
352
352
|
const val: TargetType = {} as any;
|
|
353
|
-
`, o = "index.ts",
|
|
354
|
-
let
|
|
355
|
-
const
|
|
356
|
-
if (
|
|
357
|
-
const i = u.getTypeAtLocation(
|
|
358
|
-
u.isArrayType(i) ?
|
|
353
|
+
`, o = "index.ts", s = I(o, r), c = s.getSourceFile(o), u = s.languageService.getProgram().getTypeChecker();
|
|
354
|
+
let p = 1;
|
|
355
|
+
const l = (h) => {
|
|
356
|
+
if (y.isVariableDeclaration(h) && h.name.getText() === "val") {
|
|
357
|
+
const i = u.getTypeAtLocation(h);
|
|
358
|
+
i.getCallSignatures().length > 0 ? p = 4 : u.isArrayType(i) ? p = 2 : i.isStringLiteral() || i.isNumberLiteral() || (i.getFlags() & (y.TypeFlags.String | y.TypeFlags.Number | y.TypeFlags.Boolean | y.TypeFlags.EnumLiteral | y.TypeFlags.BigInt | y.TypeFlags.ESSymbol)) !== 0 ? p = 0 : (i.isClassOrInterface() || (i.getFlags() & y.TypeFlags.Object) !== 0) && i.getProperties().length > 0 ? p = 3 : p = 1;
|
|
359
359
|
}
|
|
360
|
-
|
|
360
|
+
y.forEachChild(h, l);
|
|
361
361
|
};
|
|
362
|
-
return
|
|
362
|
+
return l(c), p;
|
|
363
363
|
}, ge = (e, t) => {
|
|
364
364
|
const n = `
|
|
365
|
-
${
|
|
365
|
+
${V(t)}
|
|
366
366
|
type Target = ${e};
|
|
367
|
-
`, r = "index.ts", o = I(r, n),
|
|
368
|
-
(i) =>
|
|
367
|
+
`, r = "index.ts", o = I(r, n), s = o.getSourceFile(r), a = o.languageService.getProgram().getTypeChecker(), u = s.statements.find(
|
|
368
|
+
(i) => y.isTypeAliasDeclaration(i) && i.name.text === "Target"
|
|
369
369
|
);
|
|
370
370
|
if (!u)
|
|
371
371
|
return { __typename: "LiteralValue", value: null };
|
|
372
|
-
const
|
|
373
|
-
if (
|
|
374
|
-
|
|
375
|
-
const
|
|
372
|
+
const p = a.getTypeAtLocation(u.type), l = (i, f, v = /* @__PURE__ */ new Set()) => {
|
|
373
|
+
if (v.has(i)) return null;
|
|
374
|
+
v.add(i);
|
|
375
|
+
const d = i.getFlags();
|
|
376
376
|
if (i.isUnion()) {
|
|
377
|
-
if (
|
|
378
|
-
const S = a.getTypeFromTypeNode(
|
|
379
|
-
return
|
|
377
|
+
if (f.type, y.isTypeAliasDeclaration(f) && f.type && y.isUnionTypeNode(f.type)) {
|
|
378
|
+
const S = a.getTypeFromTypeNode(f.type.types[0]);
|
|
379
|
+
return l(S, f, v);
|
|
380
380
|
}
|
|
381
381
|
const T = i.types.filter((S) => {
|
|
382
|
-
const
|
|
383
|
-
return !(
|
|
384
|
-
}),
|
|
385
|
-
return g
|
|
382
|
+
const m = S.getFlags();
|
|
383
|
+
return !(m & y.TypeFlags.Undefined) && !(m & y.TypeFlags.Null);
|
|
384
|
+
}), g = T.length > 0 ? T[0] : i.types[0];
|
|
385
|
+
return l(g, f, v);
|
|
386
386
|
}
|
|
387
|
-
if (
|
|
388
|
-
if (
|
|
389
|
-
if (
|
|
390
|
-
if (
|
|
391
|
-
if (
|
|
392
|
-
if (
|
|
387
|
+
if (d & y.TypeFlags.StringLiteral) return i.value;
|
|
388
|
+
if (d & y.TypeFlags.String) return "sample";
|
|
389
|
+
if (d & y.TypeFlags.NumberLiteral) return i.value;
|
|
390
|
+
if (d & y.TypeFlags.Number) return 1;
|
|
391
|
+
if (d & y.TypeFlags.BooleanLiteral) return i.intrinsicName === "true";
|
|
392
|
+
if (d & y.TypeFlags.Boolean) return !1;
|
|
393
393
|
if (a.isArrayType(i)) {
|
|
394
|
-
const
|
|
395
|
-
return [g
|
|
394
|
+
const g = i.typeArguments?.[0] || a.getAnyType();
|
|
395
|
+
return [l(g, f, v)];
|
|
396
396
|
}
|
|
397
|
-
if (i.isClassOrInterface() ||
|
|
397
|
+
if (i.isClassOrInterface() || d & y.TypeFlags.Object || i.getProperties().length > 0) {
|
|
398
398
|
const T = {};
|
|
399
399
|
return i.getProperties().forEach((S) => {
|
|
400
|
-
const
|
|
401
|
-
|
|
400
|
+
const m = a.getTypeOfSymbolAtLocation(S, f);
|
|
401
|
+
m && (T[S.getName()] = l(m, f, v));
|
|
402
402
|
}), T;
|
|
403
403
|
}
|
|
404
404
|
return null;
|
|
405
405
|
};
|
|
406
406
|
return {
|
|
407
|
-
value:
|
|
407
|
+
value: l(p, u)
|
|
408
408
|
};
|
|
409
409
|
}, z = (e, t, n, r) => {
|
|
410
|
-
const
|
|
411
|
-
if (!
|
|
410
|
+
const s = new Map(n?.map((F) => [F.identifier, F])).get(t?.functionDefinition?.identifier);
|
|
411
|
+
if (!s)
|
|
412
412
|
return {
|
|
413
413
|
isValid: !1,
|
|
414
414
|
returnType: "any",
|
|
415
|
-
diagnostics: [{ message: `Function ${t
|
|
415
|
+
diagnostics: [{ message: `Function ${t?.id} not found`, nodeId: t?.id, code: 404, severity: "error" }]
|
|
416
416
|
};
|
|
417
|
-
const
|
|
418
|
-
for (const
|
|
419
|
-
const N =
|
|
417
|
+
const c = t?.parameters?.nodes || [], a = [];
|
|
418
|
+
for (const F of c) {
|
|
419
|
+
const N = F.value;
|
|
420
420
|
if (N?.__typename === "ReferenceValue") {
|
|
421
|
-
const
|
|
422
|
-
|
|
423
|
-
message:
|
|
421
|
+
const x = se(e, t, N);
|
|
422
|
+
x.isValid || a.push({
|
|
423
|
+
message: x.error || "Scope error",
|
|
424
424
|
code: 403,
|
|
425
|
-
nodeId: t
|
|
426
|
-
parameterIndex:
|
|
425
|
+
nodeId: t?.id,
|
|
426
|
+
parameterIndex: c.indexOf(F),
|
|
427
427
|
severity: "error"
|
|
428
428
|
});
|
|
429
429
|
}
|
|
@@ -434,240 +434,242 @@ const fe = (e, t) => {
|
|
|
434
434
|
returnType: "any",
|
|
435
435
|
diagnostics: a
|
|
436
436
|
};
|
|
437
|
-
const u =
|
|
438
|
-
(
|
|
437
|
+
const u = c.map((F) => q(F, e, (N, x) => z(N, x, n, r))), p = u.map(
|
|
438
|
+
(F) => F === "undefined" ? "({} as any)" : F
|
|
439
439
|
).join(", ");
|
|
440
|
-
let
|
|
441
|
-
const
|
|
442
|
-
${
|
|
443
|
-
declare function testFunc${
|
|
444
|
-
const result = testFunc(${
|
|
445
|
-
`, i = "index.ts",
|
|
440
|
+
let l = s.signature;
|
|
441
|
+
const h = `
|
|
442
|
+
${V(r)}
|
|
443
|
+
declare function testFunc${l};
|
|
444
|
+
const result = testFunc(${p});
|
|
445
|
+
`, i = "index.ts", f = I(i, h), v = f.getSourceFile(i), d = f.languageService.getProgram(), T = d.getTypeChecker(), g = d.getSemanticDiagnostics(v);
|
|
446
446
|
let S = "any";
|
|
447
|
-
const
|
|
448
|
-
if (
|
|
449
|
-
const N = T.getTypeAtLocation(
|
|
447
|
+
const m = (F) => {
|
|
448
|
+
if (y.isVariableDeclaration(F) && F.name.getText() === "result") {
|
|
449
|
+
const N = T.getTypeAtLocation(F);
|
|
450
450
|
S = T.typeToString(
|
|
451
451
|
N,
|
|
452
|
-
|
|
453
|
-
|
|
452
|
+
F,
|
|
453
|
+
y.TypeFormatFlags.NoTruncation | y.TypeFormatFlags.UseFullyQualifiedType
|
|
454
454
|
);
|
|
455
455
|
}
|
|
456
|
-
|
|
456
|
+
y.forEachChild(F, m);
|
|
457
457
|
};
|
|
458
|
-
|
|
459
|
-
const
|
|
460
|
-
const N =
|
|
461
|
-
`),
|
|
458
|
+
m(v);
|
|
459
|
+
const $ = g.map((F) => {
|
|
460
|
+
const N = y.flattenDiagnosticMessageText(F.messageText, `
|
|
461
|
+
`), x = /\b([TRKV])\b/.test(N), C = N.includes("not assignable to parameter of type") && (N.includes("'{}'") || N.includes("undefined")) || N.includes("not assignable to type 'undefined'") || N.includes("not assignable to type 'void'") || N.includes("may be a mistake because neither type sufficiently overlaps");
|
|
462
462
|
return {
|
|
463
463
|
message: N,
|
|
464
|
-
code:
|
|
465
|
-
nodeId: t
|
|
464
|
+
code: F.code,
|
|
465
|
+
nodeId: t?.id,
|
|
466
466
|
parameterIndex: (() => {
|
|
467
|
-
if (
|
|
468
|
-
const P =
|
|
469
|
-
const b =
|
|
470
|
-
return
|
|
467
|
+
if (F.start !== void 0) {
|
|
468
|
+
const P = c.findIndex((M, L) => {
|
|
469
|
+
const b = h.indexOf(u[L]);
|
|
470
|
+
return F.start >= b && F.start < b + u[L].length;
|
|
471
471
|
});
|
|
472
472
|
if (P !== -1) return P;
|
|
473
473
|
}
|
|
474
474
|
})(),
|
|
475
|
-
severity:
|
|
475
|
+
severity: x || C ? "warning" : "error"
|
|
476
476
|
};
|
|
477
477
|
});
|
|
478
478
|
return {
|
|
479
|
-
isValid:
|
|
479
|
+
isValid: !$.some((F) => F.severity === "error"),
|
|
480
480
|
returnType: S,
|
|
481
|
-
diagnostics:
|
|
481
|
+
diagnostics: $
|
|
482
482
|
};
|
|
483
483
|
}, pe = (e, t, n) => {
|
|
484
|
-
const o = new Map(t
|
|
484
|
+
const o = new Map(t?.map((m) => [m.identifier, m])).get(e?.functionDefinition?.identifier);
|
|
485
485
|
if (!o)
|
|
486
486
|
return {
|
|
487
487
|
parameters: [],
|
|
488
488
|
returnType: "any"
|
|
489
489
|
};
|
|
490
|
-
const
|
|
490
|
+
const s = {
|
|
491
491
|
id: "gid://sagittarius/Flow/0",
|
|
492
492
|
nodes: { __typename: "NodeFunctionConnection", nodes: [e] }
|
|
493
|
-
}, u = (e
|
|
494
|
-
${
|
|
495
|
-
declare function testFunc${
|
|
493
|
+
}, u = (e?.parameters?.nodes || []).map((m) => q(m, s, ($, F) => z($, F, t, n))).map((m) => m === "undefined" ? "({} as any)" : m).join(", "), p = o.signature, l = `
|
|
494
|
+
${V(n)}
|
|
495
|
+
declare function testFunc${p};
|
|
496
496
|
const result = testFunc(${u});
|
|
497
|
-
`,
|
|
498
|
-
let T = "any",
|
|
499
|
-
const S = (
|
|
500
|
-
if (
|
|
501
|
-
const
|
|
502
|
-
if (T =
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
),
|
|
507
|
-
const
|
|
508
|
-
N && (
|
|
509
|
-
const C =
|
|
510
|
-
return
|
|
497
|
+
`, h = "index.ts", i = I(h, l), f = i.getSourceFile(h), d = i.languageService.getProgram().getTypeChecker();
|
|
498
|
+
let T = "any", g = [];
|
|
499
|
+
const S = (m) => {
|
|
500
|
+
if (y.isVariableDeclaration(m) && m.name.getText() === "result") {
|
|
501
|
+
const $ = d.getTypeAtLocation(m);
|
|
502
|
+
if (T = d.typeToString(
|
|
503
|
+
$,
|
|
504
|
+
m,
|
|
505
|
+
y.TypeFormatFlags.NoTruncation
|
|
506
|
+
), y.isCallExpression(m.initializer)) {
|
|
507
|
+
const F = m.initializer, N = d.getResolvedSignature(F);
|
|
508
|
+
N && (g = N.getParameters().map((x) => {
|
|
509
|
+
const C = d.getTypeOfSymbolAtLocation(x, F);
|
|
510
|
+
return d.typeToString(
|
|
511
511
|
C,
|
|
512
|
-
|
|
513
|
-
|
|
512
|
+
F,
|
|
513
|
+
y.TypeFormatFlags.NoTruncation
|
|
514
514
|
);
|
|
515
515
|
}));
|
|
516
516
|
}
|
|
517
517
|
}
|
|
518
|
-
|
|
518
|
+
y.forEachChild(m, S);
|
|
519
519
|
};
|
|
520
|
-
return S(
|
|
521
|
-
parameters:
|
|
520
|
+
return S(f), {
|
|
521
|
+
parameters: g,
|
|
522
522
|
returnType: T
|
|
523
523
|
};
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
if (
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
${E(n)}
|
|
524
|
+
}, me = (e, t, n) => {
|
|
525
|
+
let r = t;
|
|
526
|
+
if (e && t) {
|
|
527
|
+
let o = function(i) {
|
|
528
|
+
const f = i.match(/<([^>]+)>/);
|
|
529
|
+
return f ? f[1].split(",").map((v) => v.trim()).filter(Boolean).length : 0;
|
|
530
|
+
};
|
|
531
|
+
const s = `
|
|
532
|
+
${V(n)}
|
|
534
533
|
type TargetType = ${e};
|
|
535
|
-
${t
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
534
|
+
${t?.map((i, f) => `
|
|
535
|
+
declare function Fu${f}${i.signature};
|
|
536
|
+
type F${f} = ReturnType<typeof Fu${f}${o(i.signature) > 0 ? `<${Array(o(i.signature)).fill("any").join(", ")}>` : ""}>;
|
|
537
|
+
`).join(`
|
|
539
538
|
`)}
|
|
540
|
-
${t
|
|
539
|
+
${t?.map((i, f) => `const check${f}: TargetType = {} as F${f};`).join(`
|
|
541
540
|
`)}
|
|
542
|
-
`,
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
`).findIndex((
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
|
|
541
|
+
`, c = "index.ts", a = I(c, s), u = a.getSourceFile(c), l = a.languageService.getProgram().getSemanticDiagnostics(), h = /* @__PURE__ */ new Set();
|
|
542
|
+
l.forEach((i) => {
|
|
543
|
+
i.file === u && i.start !== void 0 && h.add(u.getLineAndCharacterOfPosition(i.start).line);
|
|
544
|
+
}), r = t.filter((i, f) => {
|
|
545
|
+
const v = `const check${f}: TargetType = {} as F${f};`, T = s.split(`
|
|
546
|
+
`).findIndex((g) => g.includes(v));
|
|
547
|
+
return T !== -1 && !h.has(T);
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
return r?.map((o) => ({
|
|
551
|
+
__typename: "NodeFunction",
|
|
552
|
+
id: "gid://sagittarius/NodeFunction/1",
|
|
553
|
+
functionDefinition: {
|
|
554
|
+
__typename: "FunctionDefinition",
|
|
555
|
+
id: o.identifier,
|
|
556
|
+
identifier: o.identifier
|
|
557
|
+
},
|
|
558
|
+
parameters: {
|
|
559
|
+
__typename: "NodeParameterConnection",
|
|
560
|
+
nodes: (o.parameterDefinitions?.nodes || []).map((s) => ({
|
|
561
|
+
__typename: "NodeParameter",
|
|
562
|
+
parameterDefinition: {
|
|
563
|
+
__typename: "ParameterDefinition",
|
|
564
|
+
id: s?.identifier,
|
|
565
|
+
identifier: s?.identifier
|
|
566
|
+
},
|
|
567
|
+
value: null
|
|
568
|
+
}))
|
|
569
|
+
}
|
|
570
|
+
})).filter((o) => o !== null) ?? [];
|
|
571
|
+
}, ye = (e, t, n = "any", r, o) => {
|
|
572
|
+
if (!e) return [];
|
|
573
|
+
if (!t) return [];
|
|
574
|
+
const s = [], c = e?.nodes?.nodes || [], a = c.find((i) => i?.id === t);
|
|
573
575
|
if (!a) return [];
|
|
574
|
-
const u =
|
|
576
|
+
const u = V(o), p = (i, f) => {
|
|
575
577
|
if (!n || n === "any" || i === "any") return !0;
|
|
576
|
-
const
|
|
578
|
+
const v = "index.ts", d = `
|
|
577
579
|
${u}
|
|
578
580
|
const val: ${i} = {} as any;
|
|
579
|
-
const test: ${n} = val${
|
|
580
|
-
`, T = I(
|
|
581
|
-
return !T.languageService.getProgram().getSemanticDiagnostics(
|
|
582
|
-
},
|
|
583
|
-
const
|
|
581
|
+
const test: ${n} = val${f ? `.${f}` : ""};
|
|
582
|
+
`, T = I(v, d), g = T.getSourceFile(v);
|
|
583
|
+
return !T.languageService.getProgram().getSemanticDiagnostics(g).some(($) => $.category === y.DiagnosticCategory.Error);
|
|
584
|
+
}, l = (i, f) => {
|
|
585
|
+
const v = [], d = "index.ts", T = `
|
|
584
586
|
${u}
|
|
585
587
|
const val: ${i} = {} as any;
|
|
586
|
-
`,
|
|
587
|
-
|
|
588
|
-
const
|
|
588
|
+
`, g = I(d, T), S = g.getSourceFile(d), m = g.languageService.getProgram(), $ = m.getTypeChecker();
|
|
589
|
+
p(i) && v.push({ ...f, referencePath: [] });
|
|
590
|
+
const F = (x, C = []) => {
|
|
589
591
|
if (C.length > 3) return;
|
|
590
|
-
const P =
|
|
592
|
+
const P = x.getProperties();
|
|
591
593
|
for (const M of P) {
|
|
592
594
|
const L = M.getName();
|
|
593
595
|
let b;
|
|
594
|
-
if (
|
|
595
|
-
const _ =
|
|
596
|
-
_ && (b =
|
|
596
|
+
if ($.getPropertyOfType) {
|
|
597
|
+
const _ = $.getPropertyOfType(x, L);
|
|
598
|
+
_ && (b = $.getTypeOfSymbolAtLocation(_, S));
|
|
597
599
|
} else {
|
|
598
|
-
const _ =
|
|
599
|
-
_ && (b =
|
|
600
|
+
const _ = x.getProperty(L);
|
|
601
|
+
_ && (b = $.getTypeOfSymbolAtLocation(_, S));
|
|
600
602
|
}
|
|
601
603
|
if (!b) continue;
|
|
602
|
-
const D = [...C, L],
|
|
603
|
-
|
|
604
|
-
...
|
|
604
|
+
const D = [...C, L], E = D.join(".");
|
|
605
|
+
p(i, E) && v.push({
|
|
606
|
+
...f,
|
|
605
607
|
referencePath: D.map((_) => ({
|
|
606
608
|
__typename: "ReferencePath",
|
|
607
609
|
path: _
|
|
608
610
|
}))
|
|
609
|
-
}),
|
|
611
|
+
}), F(b, D);
|
|
610
612
|
}
|
|
611
613
|
};
|
|
612
|
-
if (
|
|
613
|
-
let
|
|
614
|
+
if (m.getSemanticDiagnostics(S).length === 0) {
|
|
615
|
+
let x;
|
|
614
616
|
const C = (P) => {
|
|
615
|
-
|
|
617
|
+
y.isVariableDeclaration(P) && P.name.getText() === "val" && (x = $.getTypeAtLocation(P)), y.forEachChild(P, C);
|
|
616
618
|
};
|
|
617
|
-
C(S),
|
|
619
|
+
C(S), x && F(x);
|
|
618
620
|
}
|
|
619
|
-
return
|
|
621
|
+
return v;
|
|
620
622
|
};
|
|
621
623
|
if (e.inputType) {
|
|
622
624
|
const i = e.inputType || "any";
|
|
623
|
-
|
|
625
|
+
s.push(...l(i, {}));
|
|
624
626
|
}
|
|
625
|
-
|
|
627
|
+
c.forEach((i) => {
|
|
626
628
|
if (!(!i || i.id === t) && ue(e, i, a)) {
|
|
627
|
-
const
|
|
628
|
-
|
|
629
|
+
const f = z(e, i, r, o);
|
|
630
|
+
s.push(...l(f.returnType, {
|
|
629
631
|
__typename: "ReferenceValue",
|
|
630
632
|
nodeFunctionId: i.id,
|
|
631
633
|
referencePath: []
|
|
632
634
|
}));
|
|
633
635
|
}
|
|
634
636
|
});
|
|
635
|
-
let
|
|
636
|
-
for (;
|
|
637
|
-
if (r
|
|
638
|
-
const
|
|
639
|
-
const
|
|
640
|
-
if (
|
|
641
|
-
const T =
|
|
637
|
+
let h = O(e, t);
|
|
638
|
+
for (; h; ) {
|
|
639
|
+
if (r?.find((f) => f.identifier === h.functionDefinition?.identifier)) {
|
|
640
|
+
const f = h.parameters?.nodes?.findIndex((v) => {
|
|
641
|
+
const d = v?.value;
|
|
642
|
+
if (d?.__typename === "NodeFunctionIdWrapper") {
|
|
643
|
+
const T = d;
|
|
642
644
|
return T.id === t || U(e, T.id || void 0, t);
|
|
643
645
|
}
|
|
644
646
|
return !1;
|
|
645
647
|
});
|
|
646
|
-
|
|
648
|
+
f !== void 0 && f !== -1 && s.push(...l("any", {
|
|
647
649
|
__typename: "ReferenceValue",
|
|
648
|
-
nodeFunctionId:
|
|
649
|
-
parameterIndex:
|
|
650
|
+
nodeFunctionId: h.id,
|
|
651
|
+
parameterIndex: f,
|
|
650
652
|
inputIndex: 0,
|
|
651
653
|
referencePath: []
|
|
652
654
|
}));
|
|
653
655
|
}
|
|
654
|
-
|
|
656
|
+
h = O(e, h.id);
|
|
655
657
|
}
|
|
656
|
-
return
|
|
658
|
+
return s;
|
|
657
659
|
};
|
|
658
660
|
function ue(e, t, n) {
|
|
659
661
|
const r = e.nodes?.nodes || [];
|
|
660
662
|
let o = t.nextNodeId;
|
|
661
|
-
const
|
|
663
|
+
const s = /* @__PURE__ */ new Set();
|
|
662
664
|
for (; o; ) {
|
|
663
665
|
if (o === n.id) return !0;
|
|
664
|
-
if (
|
|
665
|
-
|
|
666
|
+
if (s.has(o)) break;
|
|
667
|
+
s.add(o), o = r.find((u) => u?.id === o)?.nextNodeId;
|
|
666
668
|
}
|
|
667
|
-
let
|
|
668
|
-
for (;
|
|
669
|
-
if (
|
|
670
|
-
|
|
669
|
+
let c = O(e, n.id);
|
|
670
|
+
for (; c; ) {
|
|
671
|
+
if (c.id === t.id) return !0;
|
|
672
|
+
c = O(e, c.id);
|
|
671
673
|
}
|
|
672
674
|
return !1;
|
|
673
675
|
}
|
|
@@ -681,96 +683,99 @@ function O(e, t) {
|
|
|
681
683
|
function U(e, t, n) {
|
|
682
684
|
if (!t) return !1;
|
|
683
685
|
if (t === n) return !0;
|
|
684
|
-
const o = (e.nodes?.nodes || []).find((
|
|
685
|
-
return o ? o.nextNodeId && U(e, o.nextNodeId || void 0, n) ? !0 : !!o.parameters?.nodes?.some((
|
|
686
|
-
const a =
|
|
686
|
+
const o = (e.nodes?.nodes || []).find((c) => c?.id === t);
|
|
687
|
+
return o ? o.nextNodeId && U(e, o.nextNodeId || void 0, n) ? !0 : !!o.parameters?.nodes?.some((c) => {
|
|
688
|
+
const a = c?.value;
|
|
687
689
|
return a?.__typename === "NodeFunctionIdWrapper" ? U(e, a.id || void 0, n) : !1;
|
|
688
690
|
}) : !1;
|
|
689
691
|
}
|
|
690
|
-
const ve = (e) => {
|
|
692
|
+
const ve = (e, t) => {
|
|
691
693
|
if (!e) return [];
|
|
692
|
-
const
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
694
|
+
const n = `
|
|
695
|
+
${V(t)}
|
|
696
|
+
type T = ${e}; const val: T = {} as any;
|
|
697
|
+
`, r = "index.ts", o = I(r, n), s = o.getSourceFile(r), a = o.languageService.getProgram().getTypeChecker(), u = s.statements.find(y.isTypeAliasDeclaration);
|
|
698
|
+
if (!u) return [];
|
|
699
|
+
const p = a.getTypeAtLocation(u), l = (i) => i.isUnion() ? i.types.flatMap(l) : i.isStringLiteral() ? [i.value] : i.isNumberLiteral() ? [i.value.toString()] : i.intrinsicName === "true" ? ["true"] : i.intrinsicName === "false" ? ["false"] : [];
|
|
700
|
+
return Array.from(new Set(l(p))).map((i) => ({
|
|
696
701
|
__typename: "LiteralValue",
|
|
697
|
-
value:
|
|
702
|
+
value: i
|
|
698
703
|
}));
|
|
699
704
|
}, k = (e) => e.replace(/[^a-zA-Z0-9]/g, "_"), Fe = (e, t, n) => {
|
|
700
|
-
const r = /* @__PURE__ */ new Set(), o = e
|
|
701
|
-
if (r.has(
|
|
702
|
-
const
|
|
703
|
-
if (!
|
|
704
|
-
r.add(
|
|
705
|
-
const
|
|
706
|
-
if (
|
|
705
|
+
const r = /* @__PURE__ */ new Set(), o = e?.nodes?.nodes || [], s = new Map(t?.map((g) => [g.identifier, g])), c = (g, S = "") => {
|
|
706
|
+
if (r.has(g)) return "";
|
|
707
|
+
const m = o.find((L) => L?.id === g);
|
|
708
|
+
if (!m || !m.functionDefinition) return "";
|
|
709
|
+
r.add(g);
|
|
710
|
+
const $ = s.get(m.functionDefinition?.identifier);
|
|
711
|
+
if (!$) return `${S}// Error: Function ${m.functionDefinition.identifier} not found
|
|
707
712
|
`;
|
|
708
|
-
const N = (
|
|
713
|
+
const N = (m.parameters?.nodes || []).map((L, b) => {
|
|
709
714
|
const D = L.value;
|
|
710
715
|
if (!D) return "undefined";
|
|
711
716
|
if (D.__typename === "ReferenceValue") {
|
|
712
|
-
const
|
|
713
|
-
if (!
|
|
714
|
-
let _ =
|
|
715
|
-
return
|
|
717
|
+
const E = D;
|
|
718
|
+
if (!E.nodeFunctionId) return "undefined";
|
|
719
|
+
let _ = E.parameterIndex !== void 0 ? `/* @pos ${g} ${b} */ p_${k(E.nodeFunctionId)}_${E.parameterIndex}` : `/* @pos ${g} ${b} */ node_${k(E.nodeFunctionId)}`;
|
|
720
|
+
return E.referencePath?.forEach((j) => {
|
|
716
721
|
_ += `?.${j.path}`;
|
|
717
722
|
}), _;
|
|
718
723
|
}
|
|
719
724
|
if (D.__typename === "LiteralValue")
|
|
720
|
-
return `/* @pos ${
|
|
725
|
+
return `/* @pos ${g} ${b} */ ${JSON.stringify(D.value)}`;
|
|
721
726
|
if (D.__typename === "NodeFunctionIdWrapper") {
|
|
722
|
-
const
|
|
723
|
-
return `/* @pos ${
|
|
727
|
+
const E = D, _ = `p_${k(m.id)}_${b}`, j = c(E.id, S + " ");
|
|
728
|
+
return `/* @pos ${g} ${b} */ (${_}) => {
|
|
724
729
|
${j}${S}}`;
|
|
725
730
|
}
|
|
726
731
|
return "undefined";
|
|
727
|
-
}).join(", "),
|
|
728
|
-
let M = `${S}const ${
|
|
732
|
+
}).join(", "), x = `node_${k(m.id)}`, C = `fn_${$.identifier?.replace(/::/g, "_")}`, P = N.includes("undefined");
|
|
733
|
+
let M = `${S}const ${x} = ${C}(${N})${P ? " as any" : ""} ;
|
|
729
734
|
`;
|
|
730
|
-
return
|
|
731
|
-
}, a =
|
|
732
|
-
`),
|
|
733
|
-
`),
|
|
735
|
+
return m.nextNodeId && (M += c(m.nextNodeId, S)), M;
|
|
736
|
+
}, a = V(n), u = t?.map((g) => `declare function fn_${g.identifier?.replace(/::/g, "_")}${g.signature}`).join(`
|
|
737
|
+
`), p = o.map((g) => g?.id ? c(g.id) : "").filter((g) => g !== "").join(`
|
|
738
|
+
`), l = `${a}
|
|
734
739
|
${u}
|
|
735
740
|
|
|
736
741
|
// --- Flow ---
|
|
737
|
-
${
|
|
738
|
-
const S = Z(
|
|
742
|
+
${p}`, h = "index.ts", i = I(h, l), f = i.getSourceFile(h), T = i.languageService.getProgram().getSemanticDiagnostics(f).map((g) => {
|
|
743
|
+
const S = Z(g.messageText, `
|
|
739
744
|
`);
|
|
740
745
|
if (S.includes("Argument of type 'undefined'") || S.includes("not assignable to type 'undefined'")) return null;
|
|
741
|
-
let
|
|
742
|
-
if (
|
|
743
|
-
const C =
|
|
744
|
-
C && (
|
|
746
|
+
let $, F;
|
|
747
|
+
if (g.start !== void 0) {
|
|
748
|
+
const C = f.getFullText().substring(0, g.start).match(/\/\* @pos ([^ ]+) (\d+) \*\/\s*$/);
|
|
749
|
+
C && ($ = C[1], F = parseInt(C[2], 10));
|
|
745
750
|
}
|
|
746
751
|
return {
|
|
747
752
|
message: S,
|
|
748
|
-
code:
|
|
753
|
+
code: g.code,
|
|
749
754
|
severity: "error",
|
|
750
|
-
nodeId:
|
|
751
|
-
parameterIndex:
|
|
755
|
+
nodeId: $,
|
|
756
|
+
parameterIndex: F
|
|
752
757
|
};
|
|
753
|
-
}).filter((
|
|
758
|
+
}).filter((g) => g !== null);
|
|
754
759
|
return {
|
|
755
|
-
isValid: !T.some((
|
|
760
|
+
isValid: !T.some((g) => g?.severity === "error"),
|
|
756
761
|
returnType: "void",
|
|
757
762
|
diagnostics: T
|
|
758
763
|
};
|
|
759
764
|
}, he = (e, t, n) => {
|
|
760
|
-
const r = JSON.stringify(t
|
|
761
|
-
${
|
|
765
|
+
const r = JSON.stringify(t?.value), o = `
|
|
766
|
+
${V(n)}
|
|
762
767
|
const testValue: ${e} = ${r};
|
|
763
|
-
`,
|
|
764
|
-
const
|
|
765
|
-
`),
|
|
768
|
+
`, s = "index.ts", u = I(s, o).languageService.getSemanticDiagnostics(s).map((p) => {
|
|
769
|
+
const l = y.flattenDiagnosticMessageText(p.messageText, `
|
|
770
|
+
`), h = /\b([TRKV])\b/.test(l), i = l.includes("not assignable to parameter of type") && (l.includes("'{}'") || l.includes("undefined")) || l.includes("not assignable to type 'undefined'") || l.includes("not assignable to type 'void'") || l.includes("may be a mistake because neither type sufficiently overlaps");
|
|
766
771
|
return {
|
|
767
|
-
message:
|
|
768
|
-
code:
|
|
769
|
-
severity:
|
|
772
|
+
message: l,
|
|
773
|
+
code: p.code,
|
|
774
|
+
severity: h || i ? "warning" : "error"
|
|
770
775
|
};
|
|
771
776
|
});
|
|
772
777
|
return {
|
|
773
|
-
isValid: !u.some((
|
|
778
|
+
isValid: !u.some((p) => p.severity === "error"),
|
|
774
779
|
returnType: "void",
|
|
775
780
|
diagnostics: u
|
|
776
781
|
};
|
|
@@ -781,8 +786,8 @@ export {
|
|
|
781
786
|
me as getNodeSuggestions,
|
|
782
787
|
z as getNodeValidation,
|
|
783
788
|
ye as getReferenceSuggestions,
|
|
784
|
-
|
|
785
|
-
|
|
789
|
+
fe as getTypeFromValue,
|
|
790
|
+
de as getTypeVariant,
|
|
786
791
|
pe as getTypesFromNode,
|
|
787
792
|
ge as getValueFromType,
|
|
788
793
|
ve as getValueSuggestions,
|