@sheetxl/scripting 0.8.0-beta.11 → 0.8.0-beta.13
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/browser/esm/{_cUijEyyZifD_LZf.mjs → CNf-ETo-nO1YJpZd.mjs} +1 -1
- package/{node/esm/Cgbq_-KJhRYkRJw-.mjs → browser/esm/CUERvTrIURHqOWKm.mjs} +281 -282
- package/browser/esm/{BPtHkO7z1Di3YIjV.mjs → CwhaPB7R93eqixfq.mjs} +2 -2
- package/browser/esm/DfSFyaySrD6y1NJY.mjs +17 -0
- package/browser/esm/index.mjs +3 -3
- package/browser/esm/{CV6NN6Ju5xBT1o6B.mjs → tbtsT5bS-wwAAvcu.mjs} +1442 -1387
- package/node/esm/{C8P-wHdBmweFS0Ex.mjs → 2OiXgLd8VwO6IeDg.mjs} +1 -1
- package/node/esm/{ByvsA4Gi2N_jmjO4.mjs → BDIcVjo-h3KFdXXo.mjs} +1 -1
- package/node/esm/BLO91PRuOQIsW_Ow.mjs +580 -0
- package/node/esm/index.mjs +9 -9
- package/node/esm/{CLpM4kzEeZk_kWj4.mjs → oWHIRxwwLexnOwAn.mjs} +1 -1
- package/package.json +3 -3
- package/types/src/type/CompiledModule.d.ts +1 -1
- package/types/src/type/Diagnostic.d.ts +0 -2
- package/browser/esm/B73J41HhbJvswDz1.mjs +0 -17
- package/browser/esm/Cg2-n5X_c3X8uPPp.mjs +0 -581
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CommonUtils as
|
|
3
|
-
import { InteropScalarType as
|
|
4
|
-
var
|
|
1
|
+
import { n as Ee, r as i } from "./DfSFyaySrD6y1NJY.mjs";
|
|
2
|
+
import { CommonUtils as Ie } from "@sheetxl/utils";
|
|
3
|
+
import { InteropScalarType as ve, ScalarType as _, ValueKind as $e } from "@sheetxl/primitives";
|
|
4
|
+
var se = /* @__PURE__ */ new Map([["IReferenceRange", "p"], ["IRange", "r"]]), ie = new Set(Object.values($e).filter((r) => r !== $e.Omitted)), de = /* @__PURE__ */ new Map([["IWorkbook", "workbook"], ["IWorksheet", "sheet"], ["ICellRanges", "ranges"], ["ICellRange", "range"]]), Fe = Array.from(de.keys()), oe = (r, F) => {
|
|
5
5
|
Array.from(F.keys()).forEach(($) => {
|
|
6
6
|
const A = F.get($);
|
|
7
7
|
F.set(`${r}.${$}`, A);
|
|
8
8
|
});
|
|
9
|
-
},
|
|
9
|
+
}, De = /* @__PURE__ */ new Map([["Scalar", "*"], ["Lambda", "l"], ["FormulaError.Known", _.Error], ["Date", ve.Date], ["IRichData", ve.RichData]]), we = /* @__PURE__ */ new Map([["Repeating", "repeating"]]), Me = /* @__PURE__ */ new Set(["Flatten", "SheetXL.Flatten"]), Se = /* @__PURE__ */ new Set(["AcceptError"]), ke = /* @__PURE__ */ new Set(["Omittable"]), Ae = /* @__PURE__ */ new Set(["NoLift"]), Re = /* @__PURE__ */ new Set(["NoFilter"]), Ke = /* @__PURE__ */ new Set(["Lazy"]), le = /* @__PURE__ */ new Set(["ReportType"]), Ce = /^[a-zA-Z_-][a-zA-Z0-9_.-]*$/, Ue = /^([a-z]{1,3})([0-9]+)$/i, Pe = /^r[0-9]*c[0-9]*$/i, V = "SheetXL", q = (r) => {
|
|
10
10
|
const F = r.typeName.getText();
|
|
11
11
|
return F.startsWith(`${V}.`) ? F.slice(8) : F;
|
|
12
12
|
};
|
|
13
|
-
|
|
14
|
-
var
|
|
13
|
+
oe(V, se), oe(V, de), oe(V, we), Se.add(V + ".AcceptError"), ke.add(`${V}.Omittable`), Ae.add(`${V}.NoLift`), Re.add(`${V}.NoFilter`), Ke.add(`${V}.Lazy`), le.add(`${V}.ReportType`);
|
|
14
|
+
var ze = /* @__PURE__ */ new Map([["Volatile", () => ({ volatile: !0 })], [`${V}.Volatile`, () => ({ volatile: !0 })]]), be = "__scriptContext__", xe = "script", Oe = /* @__PURE__ */ new Set(["IScript.ScriptContext", `${V}.IScript.ScriptContext`, "ScriptContext"]), Te = (r, F) => {
|
|
15
15
|
const $ = F.literal;
|
|
16
16
|
if ($ === void 0) return;
|
|
17
17
|
const A = r.SyntaxKind;
|
|
@@ -51,372 +51,370 @@ var Pe = /* @__PURE__ */ new Map([["Promise", () => ({ async: !0 })], ["Observab
|
|
|
51
51
|
`).map((A) => A.trim()).filter(Boolean).join(" ")).filter(Boolean).join(`
|
|
52
52
|
`).trim();
|
|
53
53
|
};
|
|
54
|
-
function
|
|
54
|
+
function Ve(r, F, $, A) {
|
|
55
55
|
const B = A?.builtInNames?.length ? new Set(A.builtInNames.map((e) => e.toUpperCase())) : null, G = [], W = /* @__PURE__ */ new Map(), Q = [];
|
|
56
56
|
let X = null;
|
|
57
|
-
const U = (e, n,
|
|
58
|
-
const { start: u, length: y } = ((
|
|
59
|
-
if (!
|
|
57
|
+
const U = (e, n, o, l) => {
|
|
58
|
+
const { start: u, length: y } = ((T) => {
|
|
59
|
+
if (!T || typeof T.getStart != "function") return { start: 0, length: 0 };
|
|
60
60
|
try {
|
|
61
|
-
return { start:
|
|
61
|
+
return { start: T.getStart(), length: T.getWidth() };
|
|
62
62
|
} catch {
|
|
63
63
|
return { start: 0, length: 0 };
|
|
64
64
|
}
|
|
65
65
|
})(e);
|
|
66
|
-
Q.push({ start: u, length: y, severity:
|
|
67
|
-
},
|
|
68
|
-
U(e, n, "error",
|
|
69
|
-
}, N = (e) => e?.parent?.name?.escapedText
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
Q.push({ start: u, length: y, severity: o, code: n, message: l });
|
|
67
|
+
}, s = (e, n, o) => {
|
|
68
|
+
U(e, n, "error", o);
|
|
69
|
+
}, N = (e) => e?.parent?.name?.escapedText;
|
|
70
|
+
let Y = null;
|
|
71
|
+
const Z = (e, n, o, l, u = !1, y = !1, T = !1) => {
|
|
72
|
+
const x = { count: 0 }, p = M(e, n, o, l, x, u, y, T);
|
|
73
|
+
x.count >= 2 && (n.range || (n.range = "m", x.count -= 2), !l && x.count >= 1 && (x.count -= 1, x.count > 0 && s(e, i.ArrayDepth, `Arrays of more than 2 dimensions are not supported: '${N(e)}'.`))), x.count > 0 && (n.arrayDepth = x.count);
|
|
72
74
|
const h = n.enum;
|
|
73
|
-
return h && (
|
|
74
|
-
},
|
|
75
|
+
return h && (x.count > (T ? 1 : 0) || n.range) && !ge.has(n) && (n.valueOrRange || (s(e, i.EnumPosition, `A list cannot hold the enum '${h.id}': '${n.name ?? N(e)}'. Its members reach the body as they are, so nothing checks them against the enum. Take one value per argument ('...x: ${h.id}[]'), or type the list by its scalar ('${h.type}').`), delete n.enum)), p;
|
|
76
|
+
}, me = (e, n, o, l, u) => {
|
|
75
77
|
if (n !== "Lambda" && n !== `${V}.Lambda`) return !1;
|
|
76
78
|
const y = e.typeArguments;
|
|
77
|
-
let
|
|
78
|
-
if (y && y.length === 2) if (u && y[0].kind === r.SyntaxKind.TupleType && (
|
|
79
|
+
let T = "*";
|
|
80
|
+
if (y && y.length === 2) if (u && y[0].kind === r.SyntaxKind.TupleType && (o.lambdaArity = y[0].elements.length), y[1].kind === r.SyntaxKind.AnyKeyword) T = "raw";
|
|
79
81
|
else {
|
|
80
|
-
const
|
|
81
|
-
M(y[1],
|
|
82
|
+
const x = {};
|
|
83
|
+
M(y[1], x, l, !1, { count: 0 }), T = x.scalar ?? "*";
|
|
82
84
|
}
|
|
83
|
-
else if (y && y.length === 1 && y[0].kind !== r.SyntaxKind.TupleType && y[0].kind !== r.SyntaxKind.ArrayType) if (u && (
|
|
85
|
+
else if (y && y.length === 1 && y[0].kind !== r.SyntaxKind.TupleType && y[0].kind !== r.SyntaxKind.ArrayType) if (u && (o.lambdaArity = 2), y[0].kind === r.SyntaxKind.AnyKeyword) T = "raw";
|
|
84
86
|
else {
|
|
85
|
-
const
|
|
86
|
-
M(y[0],
|
|
87
|
+
const x = {};
|
|
88
|
+
M(y[0], x, l, !1, { count: 0 }), T = x.scalar ?? "*";
|
|
87
89
|
}
|
|
88
|
-
return
|
|
89
|
-
},
|
|
90
|
-
const n = e.getJsDocTags($).find((
|
|
91
|
-
if (n) return n.text?.map((
|
|
92
|
-
},
|
|
93
|
-
const
|
|
94
|
-
if (
|
|
95
|
-
if (u && u.flags & r.SymbolFlags.Alias) return void
|
|
90
|
+
return o.lambda = T, !0;
|
|
91
|
+
}, te = /* @__PURE__ */ new Map(), ue = /* @__PURE__ */ new Map(), ce = /* @__PURE__ */ new Map(), pe = /* @__PURE__ */ new Set(), ge = /* @__PURE__ */ new WeakSet(), ye = (e) => e !== void 0 && e.getSourceFile() === F, ne = (e, n = !1) => e.getJsDocTags($).find((l) => l.name === "name")?.text?.map((l) => l.text).join("").trim() || (n ? Ie.camelToPrettyCase(e.name) : e.name), fe = (e) => {
|
|
92
|
+
const n = e.getJsDocTags($).find((o) => o.name === "deprecated");
|
|
93
|
+
if (n) return n.text?.map((o) => o.text).join("").trim() || !0;
|
|
94
|
+
}, re = (e, n) => {
|
|
95
|
+
const o = r.isTypeReferenceNode(e) ? e.typeName : void 0, l = o ? $.getSymbolAtLocation(o) : void 0, u = l?.declarations?.length ? l : void 0;
|
|
96
|
+
if (o) {
|
|
97
|
+
if (u && u.flags & r.SymbolFlags.Alias) return void s(e, i.EnumNotLocal, `'${o.getText()}' is imported, so its declaration cannot be read: '${n}'. An enum must be declared in the module that uses it.`);
|
|
96
98
|
if (!(u && u.flags & r.SymbolFlags.Type)) {
|
|
97
|
-
const a =
|
|
98
|
-
return (u ? (u.flags & r.SymbolFlags.Variable) !== 0 : F.statements.some((
|
|
99
|
+
const a = o.getText();
|
|
100
|
+
return (u ? (u.flags & r.SymbolFlags.Variable) !== 0 : F.statements.some((m) => r.isVariableStatement(m) && m.declarationList.declarations.some((v) => r.isIdentifier(v.name) && v.name.text === a))) ? void s(e, i.EnumMissingAlias, `'${a}' is a value, not a type: '${n}'. Pair the object with a same-name type — 'type ${a} = typeof ${a}[keyof typeof ${a}];' — or declare it as 'enum ${a} { … }'.`) : null;
|
|
99
101
|
}
|
|
100
|
-
const t =
|
|
102
|
+
const t = te.get(u);
|
|
101
103
|
if (t !== void 0) return t;
|
|
102
|
-
if (
|
|
104
|
+
if (pe.has(u)) return;
|
|
103
105
|
}
|
|
104
106
|
const y = [];
|
|
105
|
-
let
|
|
107
|
+
let T = !1;
|
|
106
108
|
if (u && u.flags & r.SymbolFlags.Enum) {
|
|
107
|
-
if (!u.declarations?.some(
|
|
108
|
-
|
|
109
|
+
if (!u.declarations?.some(ye)) return void s(e, i.EnumNotLocal, `'${u.name}' is not declared in this module: '${n}'. An enum must be declared in the module that uses it.`);
|
|
110
|
+
T = !0;
|
|
109
111
|
let t = !1;
|
|
110
112
|
if (u.exports?.forEach((a) => {
|
|
111
|
-
const
|
|
112
|
-
if (!
|
|
113
|
-
const v = $.getConstantValue(
|
|
114
|
-
if (v === void 0) return
|
|
115
|
-
y.push([
|
|
116
|
-
}), t) return void
|
|
113
|
+
const m = a.valueDeclaration;
|
|
114
|
+
if (!m || !r.isEnumMember(m)) return;
|
|
115
|
+
const v = $.getConstantValue(m);
|
|
116
|
+
if (v === void 0) return s(m, i.EnumMemberNotConstant, `'${u.name}.${a.name}' is not a constant number or string. A formula passes the VALUE, so every member needs one that can be read at compile time.`), void (t = !0);
|
|
117
|
+
y.push([ne(a, !0), v, m, H(a.getDocumentationComment($)), fe(a)]);
|
|
118
|
+
}), t) return void pe.add(u);
|
|
117
119
|
} else {
|
|
118
|
-
const t = $.getTypeFromTypeNode(e), a = r.TypeFlags.Null | r.TypeFlags.Undefined | r.TypeFlags.Void,
|
|
119
|
-
for (const g of
|
|
120
|
-
if (!(g.flags & (r.TypeFlags.NumberLiteral | r.TypeFlags.StringLiteral))) return u &&
|
|
120
|
+
const t = $.getTypeFromTypeNode(e), a = r.TypeFlags.Null | r.TypeFlags.Undefined | r.TypeFlags.Void, m = (t.isUnion() ? t.types : [t]).filter((g) => !(g.flags & a)), v = [];
|
|
121
|
+
for (const g of m) {
|
|
122
|
+
if (!(g.flags & (r.TypeFlags.NumberLiteral | r.TypeFlags.StringLiteral))) return u && te.set(u, null), null;
|
|
121
123
|
v.push(g.value);
|
|
122
124
|
}
|
|
123
125
|
if (v.length === 0) return null;
|
|
124
|
-
const D = u?.declarations?.find((g) => r.isTypeAliasDeclaration(g)),
|
|
125
|
-
if (
|
|
126
|
-
const g =
|
|
127
|
-
const k = $.getTypeFromTypeNode(
|
|
126
|
+
const D = u?.declarations?.find((g) => r.isTypeAliasDeclaration(g)), E = r.isUnionTypeNode(e) ? e : D?.type;
|
|
127
|
+
if (E && r.isUnionTypeNode(E)) {
|
|
128
|
+
const g = E.types.map((d) => {
|
|
129
|
+
const k = $.getTypeFromTypeNode(d);
|
|
128
130
|
return k.isLiteral() ? k.value : void 0;
|
|
129
|
-
}), c = (
|
|
130
|
-
const k = g.indexOf(
|
|
131
|
+
}), c = (d) => {
|
|
132
|
+
const k = g.indexOf(d);
|
|
131
133
|
return k < 0 ? g.length : k;
|
|
132
134
|
};
|
|
133
|
-
v.sort((
|
|
135
|
+
v.sort((d, k) => c(d) - c(k));
|
|
134
136
|
}
|
|
135
137
|
const R = u && u.flags & r.SymbolFlags.Variable ? u.valueDeclaration : void 0, P = new Set(v);
|
|
136
|
-
if (u && R &&
|
|
137
|
-
const c = g.valueDeclaration,
|
|
138
|
-
if (!(
|
|
139
|
-
const k =
|
|
140
|
-
v.includes(k) && (
|
|
138
|
+
if (u && R && ye(R)) for (const g of $.getTypeOfSymbolAtLocation(u, R).getProperties()) {
|
|
139
|
+
const c = g.valueDeclaration, d = $.getTypeOfSymbolAtLocation(g, c ?? R);
|
|
140
|
+
if (!(d.flags & (r.TypeFlags.NumberLiteral | r.TypeFlags.StringLiteral))) continue;
|
|
141
|
+
const k = d.value;
|
|
142
|
+
v.includes(k) && (T = !0, P.delete(k), y.push([ne(g, !0), k, c, H(g.getDocumentationComment($)), fe(g)]));
|
|
141
143
|
}
|
|
142
144
|
for (const g of v) P.has(g) && y.push([String(g), g, void 0, null]);
|
|
143
145
|
}
|
|
144
146
|
if (y.length === 0) return null;
|
|
145
|
-
const
|
|
146
|
-
if (y.some(([, t]) => typeof t == "number" !==
|
|
147
|
-
const p = u ?
|
|
147
|
+
const x = typeof y[0][1] == "number";
|
|
148
|
+
if (y.some(([, t]) => typeof t == "number" !== x)) return void s(e, i.EnumMixed, `'${u?.name ?? e.getText()}' mixes number and string members: '${n}'. A parameter has one type, so an enum is all numbers or all strings.`);
|
|
149
|
+
const p = u ? ne(u) : y.map(([, t]) => String(t)).join("|"), h = u ? void 0 : ue.get(p);
|
|
148
150
|
if (h) return h;
|
|
149
|
-
if (
|
|
151
|
+
if (T) {
|
|
150
152
|
const t = /* @__PURE__ */ new Map();
|
|
151
|
-
for (const [a,
|
|
152
|
-
const
|
|
153
|
-
R !== void 0 ? U(v ?? e, i.EnumDuplicateValue, "warning", `'${p}.${
|
|
153
|
+
for (const [a, m, v, D] of y) {
|
|
154
|
+
const E = v?.name?.getText() ?? a, R = t.get(m);
|
|
155
|
+
R !== void 0 ? U(v ?? e, i.EnumDuplicateValue, "warning", `'${p}.${E}' has the same value as '${p}.${R}' (${JSON.stringify(m)}). A formula passes the value, so the two cannot be told apart.`) : t.set(m, E), D === "" && U(v ?? e, i.EnumMemberUndocumented, "warning", `'${p}.${E}' is missing a description. Add a doc comment above the member — it is what the argument dropdown shows.`);
|
|
154
156
|
}
|
|
155
157
|
}
|
|
156
|
-
const
|
|
157
|
-
u ?
|
|
158
|
+
const L = { id: p, type: x ? _.Number : _.String, members: y.map(([t, a, , , m]) => m ? [t, a, m] : [t, a]) };
|
|
159
|
+
u ? te.set(u, L) : ue.set(p, L);
|
|
158
160
|
const b = u ? H(u.getDocumentationComment($)) : "", f = {};
|
|
159
161
|
for (const [t, , , a] of y) a && (f[t] = { description: a });
|
|
160
162
|
if (b || Object.keys(f).length > 0) {
|
|
161
163
|
const t = {};
|
|
162
|
-
b && (t.summary = b), Object.keys(f).length > 0 && (t.members = f),
|
|
164
|
+
b && (t.summary = b), Object.keys(f).length > 0 && (t.members = f), ce.set(L, t);
|
|
163
165
|
}
|
|
164
|
-
return
|
|
165
|
-
}, M = (e, n,
|
|
166
|
+
return L;
|
|
167
|
+
}, M = (e, n, o, l, u, y = !1, T = !1, x = !1) => {
|
|
166
168
|
if (e) {
|
|
167
|
-
if (e.kind === r.SyntaxKind.ParenthesizedType) return M(e.type, n,
|
|
169
|
+
if (e.kind === r.SyntaxKind.ParenthesizedType) return M(e.type, n, o, l, u, y, T, x);
|
|
168
170
|
if (e.kind === r.SyntaxKind.UnionType) {
|
|
169
171
|
const p = (b) => b.kind === r.SyntaxKind.UndefinedKeyword || b.kind === r.SyntaxKind.VoidKeyword || b.kind === r.SyntaxKind.NullKeyword || b.kind === r.SyntaxKind.LiteralType && b.literal?.kind === r.SyntaxKind.NullKeyword, h = e.types.filter((b) => !p(b));
|
|
170
|
-
if (h.length === 1) return M(h[0], n,
|
|
171
|
-
const
|
|
172
|
-
if (
|
|
173
|
-
if (
|
|
172
|
+
if (h.length === 1) return M(h[0], n, o, l, u, y, T, x);
|
|
173
|
+
const L = re(e, n.name ?? N(e));
|
|
174
|
+
if (L === void 0) return;
|
|
175
|
+
if (L !== null) return n.scalar = L.type, void (l && (n.enum = L));
|
|
174
176
|
if (!l) return void (n.scalar = "*");
|
|
175
177
|
if (h.length === 2) {
|
|
176
178
|
const b = (t) => t.kind === r.SyntaxKind.TypeReference && r.isTypeReferenceNode(t) && q(t) === "Lambda", f = h.findIndex(b);
|
|
177
|
-
if (f >= 0 && !b(h[1 - f])) return M(h[1 - f], n,
|
|
179
|
+
if (f >= 0 && !b(h[1 - f])) return M(h[1 - f], n, o, l, u, y, T, x), void me(h[f], q(h[f]), n, o, l);
|
|
178
180
|
}
|
|
179
181
|
if (l && h.length === 2) {
|
|
180
182
|
const b = (t) => {
|
|
181
|
-
if (t.kind === r.SyntaxKind.TypeReference && !t.typeArguments?.length) return
|
|
183
|
+
if (t.kind === r.SyntaxKind.TypeReference && !t.typeArguments?.length) return se.get(q(t));
|
|
182
184
|
}, f = h.findIndex((t) => b(t) !== void 0);
|
|
183
185
|
if (f >= 0 && b(h[1 - f]) === void 0) {
|
|
184
186
|
const t = {}, a = u.count;
|
|
185
|
-
if (M(h[1 - f], t,
|
|
187
|
+
if (M(h[1 - f], t, o, l, u, y, !1), t.scalar && !t.range && t.lambda == null && u.count === a) {
|
|
186
188
|
n.range = b(h[f]), n.scalar = t.scalar, n.valueOrRange = !0;
|
|
187
|
-
const
|
|
188
|
-
return void (
|
|
189
|
+
const m = t.enum;
|
|
190
|
+
return void (m && (n.enum = m));
|
|
189
191
|
}
|
|
190
192
|
}
|
|
191
193
|
}
|
|
192
194
|
if (l && h.length === 2) {
|
|
193
195
|
const b = (t) => t.kind === r.SyntaxKind.TypeReference && !t.typeArguments?.length && q(t) === "Scalar", f = h.findIndex(b);
|
|
194
196
|
if (f >= 0 && !b(h[1 - f])) {
|
|
195
|
-
const t =
|
|
197
|
+
const t = re(h[1 - f], n.name ?? N(e));
|
|
196
198
|
if (t === void 0) return;
|
|
197
199
|
if (t !== null) return n.scalar = "*", void (n.enum = t);
|
|
198
200
|
}
|
|
199
201
|
}
|
|
200
|
-
return void
|
|
202
|
+
return void s(e, i.InvalidParamType, `Union parameter types are not supported: '${N(e)}'. Use a single type, optionally with '| null' or '| undefined', 'T | Lambda<…>' for a value-or-lambda slot, 'IRange | Scalar' for a value-or-range slot, or 'E | Scalar' for an uncoerced slot whose values an enum documents.`);
|
|
201
203
|
}
|
|
202
204
|
if (e.kind === r.SyntaxKind.NumberKeyword) n.scalar = _.Number;
|
|
203
205
|
else if (e.kind === r.SyntaxKind.StringKeyword) n.scalar = _.String;
|
|
204
206
|
else if (e.kind === r.SyntaxKind.BooleanKeyword) n.scalar = _.Boolean;
|
|
205
207
|
else if (e.kind === r.SyntaxKind.UndefinedKeyword || e.kind === r.SyntaxKind.NullKeyword || e.kind === r.SyntaxKind.VoidKeyword) {
|
|
206
|
-
if (l) return void
|
|
208
|
+
if (l) return void s(e, i.UndefinedInput, `'undefined' is not a valid type for input: '${N(e)}'.`);
|
|
207
209
|
n.scalar = _.Null;
|
|
208
210
|
} else if (e.kind === r.SyntaxKind.BigIntKeyword) n.scalar = _.Number;
|
|
209
211
|
else if (e.kind === r.SyntaxKind.AnyKeyword) l && (n.range = "*");
|
|
210
212
|
else if (e.kind === r.SyntaxKind.ArrayType) {
|
|
211
213
|
const p = e.elementType;
|
|
212
|
-
if (!p) return void
|
|
213
|
-
if (l &&
|
|
214
|
-
const h = n,
|
|
214
|
+
if (!p) return void s(e, i.UntypedArray, `'Array' must be typed: '${N(e)}'.`);
|
|
215
|
+
if (l && T) {
|
|
216
|
+
const h = n, L = h.name ?? N(e) ?? "parameter", b = h.acceptError;
|
|
215
217
|
delete h.acceptError;
|
|
216
|
-
const f = { name:
|
|
217
|
-
return Z(p, f,
|
|
218
|
+
const f = { name: L };
|
|
219
|
+
return Z(p, f, o, !0), b && !f.acceptError && (f.acceptError = !0), void (h.repeating = [f]);
|
|
218
220
|
}
|
|
219
|
-
u.count++, M(p, n,
|
|
221
|
+
u.count++, M(p, n, o, l, u);
|
|
220
222
|
} else if (e.kind !== r.SyntaxKind.TupleType) if (e.kind === r.SyntaxKind.TypeReference) {
|
|
221
223
|
const p = q(e);
|
|
222
|
-
if (
|
|
224
|
+
if (Se.has(p)) {
|
|
223
225
|
const t = N(e);
|
|
224
|
-
if (!l) return void
|
|
226
|
+
if (!l) return void s(e, i.InvalidReturnType, `'${p}' is not a valid return type: '${t}'. It describes how an ARGUMENT is received.`);
|
|
225
227
|
const a = n;
|
|
226
|
-
if (a.acceptError) return void
|
|
227
|
-
const
|
|
228
|
-
return
|
|
228
|
+
if (a.acceptError) return void s(e, i.InvalidParamType, `'${t}' declares 'AcceptError' more than once.`);
|
|
229
|
+
const m = e.typeArguments;
|
|
230
|
+
return m && m.length === 1 ? (a.acceptError = !0, M(m[0], n, o, l, u, y, T, x)) : void s(e, i.GenericArity, `'${p}' must be typed with exactly 1 type: '${t}'.`);
|
|
229
231
|
}
|
|
230
|
-
if (
|
|
232
|
+
if (le.has(p)) {
|
|
231
233
|
const t = n.name ?? N(e);
|
|
232
|
-
if (!l) return void
|
|
234
|
+
if (!l) return void s(e, i.InvalidReturnType, `'ReportType' is not a valid return type: '${t}'. It describes how an ARGUMENT is received.`);
|
|
233
235
|
const a = e.typeArguments;
|
|
234
|
-
return a && a.length === 1 ? (n.reportType = !0, M(a[0], n,
|
|
236
|
+
return a && a.length === 1 ? (n.reportType = !0, M(a[0], n, o, l, u, y, T, x)) : void s(e, i.GenericArity, `'${p}' must be typed with exactly 1 type: '${t}'.`);
|
|
235
237
|
}
|
|
236
|
-
if (
|
|
238
|
+
if (Ae.has(p)) {
|
|
237
239
|
const t = n.name ?? N(e);
|
|
238
|
-
if (!l) return void
|
|
240
|
+
if (!l) return void s(e, i.InvalidReturnType, `'NoLift' is not a valid return type: '${t}'. It describes how an ARGUMENT is received.`);
|
|
239
241
|
const a = e.typeArguments;
|
|
240
|
-
if (!a || a.length !== 1) return void
|
|
241
|
-
const
|
|
242
|
-
|
|
242
|
+
if (!a || a.length !== 1) return void s(e, i.GenericArity, `'${p}' must be typed with exactly 1 type: '${t}'.`);
|
|
243
|
+
const m = n;
|
|
244
|
+
m.noLift = !0;
|
|
243
245
|
const v = u.count;
|
|
244
|
-
return M(a[0], n,
|
|
246
|
+
return M(a[0], n, o, l, u, y, T, x), void ((m.range || m.lambda != null || m.repeating || u.count !== v) && s(e, i.InvalidParamType, `'${t}': 'NoLift' applies to a SCALAR parameter only - a range, list, repeating or lambda slot never lifts.`));
|
|
245
247
|
}
|
|
246
|
-
if (
|
|
248
|
+
if (Re.has(p)) {
|
|
247
249
|
const t = n.name ?? N(e);
|
|
248
|
-
if (!l) return void
|
|
250
|
+
if (!l) return void s(e, i.InvalidReturnType, `'NoFilter' is not a valid return type: '${t}'. It describes how an ARGUMENT is received.`);
|
|
249
251
|
const a = e.typeArguments;
|
|
250
|
-
if (!a || a.length !== 1) return void
|
|
251
|
-
const
|
|
252
|
-
|
|
252
|
+
if (!a || a.length !== 1) return void s(e, i.GenericArity, `'${p}' must be typed with exactly 1 type: '${t}'.`);
|
|
253
|
+
const m = n;
|
|
254
|
+
m.noFilter = !0;
|
|
253
255
|
const v = u.count;
|
|
254
|
-
if (M(a[0], n,
|
|
255
|
-
const D =
|
|
256
|
+
if (M(a[0], n, o, l, u, y, T, x), m.range || m.lambda != null || u.count !== v) return void s(e, i.InvalidParamType, `'${t}': 'NoFilter' applies to a SCALAR slot only - a range, list or lambda slot has no members to coerce.`);
|
|
257
|
+
const D = m.repeating;
|
|
256
258
|
if (D) {
|
|
257
|
-
if (delete
|
|
259
|
+
if (delete m.noFilter, D.length !== 1) return void s(e, i.InvalidParamType, `'${t}': 'NoFilter' over a repeating group applies to a period-1 group only - write it on the slot that takes the members.`);
|
|
258
260
|
D[0].noFilter = !0;
|
|
259
|
-
} else
|
|
261
|
+
} else T && s(e, i.InvalidParamType, `'${t}': 'NoFilter' applies to a REPEATING slot only - a single scalar argument has no members to coerce.`);
|
|
260
262
|
return;
|
|
261
263
|
}
|
|
262
|
-
if (
|
|
264
|
+
if (ke.has(p)) {
|
|
263
265
|
const t = n.name ?? N(e);
|
|
264
|
-
if (!l) return void
|
|
266
|
+
if (!l) return void s(e, i.InvalidReturnType, `'Omittable' is not a valid return type: '${t}'. It describes how an ARGUMENT is received.`);
|
|
265
267
|
const a = e.typeArguments;
|
|
266
|
-
if (!a || a.length < 1 || a.length > 2) return void
|
|
267
|
-
const
|
|
268
|
-
if (
|
|
269
|
-
const
|
|
270
|
-
if (
|
|
271
|
-
|
|
268
|
+
if (!a || a.length < 1 || a.length > 2) return void s(e, i.GenericArity, `'${p}' must be typed with 1 or 2 types: '${t}'.`);
|
|
269
|
+
const m = n;
|
|
270
|
+
if (m.omittable = !0, a.length === 2) {
|
|
271
|
+
const E = Te(r, a[1]);
|
|
272
|
+
if (E === void 0) return void s(e, i.InvalidParamType, `'${t}' declares '${p}' with a second type that is not a literal value. Use a number, string, boolean or null - the engine substitutes it for an omitted argument.`);
|
|
273
|
+
m.omittedValue = E;
|
|
272
274
|
}
|
|
273
|
-
const v = M(a[0], n,
|
|
274
|
-
return
|
|
275
|
+
const v = M(a[0], n, o, l, u, y, T, x), D = m.omittedValue;
|
|
276
|
+
return m.enum && D != null && !m.enum.members.some(([, E]) => E === D) && s(a[1], i.EnumOmittedValue, `'${t}': ${JSON.stringify(D)} is not a member of '${m.enum.id}'. An omitted argument must mean a member (${m.enum.members.map(([, E]) => JSON.stringify(E)).join(", ")}) or null.`), v;
|
|
275
277
|
}
|
|
276
|
-
if (
|
|
278
|
+
if (Ke.has(p)) {
|
|
277
279
|
const t = n.name ?? N(e);
|
|
278
|
-
if (!l) return void
|
|
280
|
+
if (!l) return void s(e, i.InvalidReturnType, `'Lazy' is not a valid return type: '${t}'. It describes how an ARGUMENT is received.`);
|
|
279
281
|
const a = n;
|
|
280
|
-
if (a.lazy) return void
|
|
281
|
-
const
|
|
282
|
-
if (!
|
|
283
|
-
if (a.lazy = !0,
|
|
284
|
-
const v = Te(r,
|
|
285
|
-
if (v === void 0) return void
|
|
282
|
+
if (a.lazy) return void s(e, i.InvalidParamType, `'${t}' declares 'Lazy' more than once.`);
|
|
283
|
+
const m = e.typeArguments;
|
|
284
|
+
if (!m || m.length < 1 || m.length > 2) return void s(e, i.GenericArity, `'${p}' must be typed with 1 or 2 types: '${t}'.`);
|
|
285
|
+
if (a.lazy = !0, m.length === 2) {
|
|
286
|
+
const v = Te(r, m[1]);
|
|
287
|
+
if (v === void 0) return void s(e, i.InvalidParamType, `'${t}' declares '${p}' with a second type that is not a literal value. Use a number, string, boolean or null - the engine substitutes it for an absent argument.`);
|
|
286
288
|
a.optional = !0, a.defaultValue = v;
|
|
287
289
|
}
|
|
288
|
-
return M(
|
|
290
|
+
return M(m[0], n, o, l, u, y, T, x), void (a.enum ? (s(e, i.EnumPosition, `'${t}': 'Lazy' cannot hold the enum '${a.enum.id}'. The argument may never be evaluated, so there is no point at which it could be checked against the members.`), delete a.enum) : a.lambda != null ? s(e, i.InvalidParamType, `'${t}': 'Lazy' cannot be combined with a Lambda parameter - a callable slot is already the body's to call, or not.`) : a.repeating && s(e, i.InvalidParamType, `'${t}': 'Lazy' applies to a VALUE, not to a repeating group - mark the group's slots instead.`));
|
|
289
291
|
}
|
|
290
|
-
if (
|
|
292
|
+
if (Me.has(p)) {
|
|
291
293
|
const t = n.name ?? N(e);
|
|
292
|
-
if (!l) return void
|
|
294
|
+
if (!l) return void s(e, i.InvalidReturnType, `'Flatten' is not a valid return type: '${t}'. It describes how an ARGUMENT is received.`);
|
|
293
295
|
const a = e.typeArguments;
|
|
294
|
-
return a && a.length === 1 ? (u.count++, M(a[0], n,
|
|
296
|
+
return a && a.length === 1 ? (u.count++, M(a[0], n, o, l, u, y)) : void s(e, i.GenericArity, `'${p}' must be typed with exactly 1 type: '${t}'.`);
|
|
295
297
|
}
|
|
296
|
-
if (
|
|
298
|
+
if (we.get(p) === "repeating") {
|
|
297
299
|
const t = n.name ?? N(e);
|
|
298
|
-
if (!l) return void
|
|
299
|
-
if (u.count !== 0) return void
|
|
300
|
-
const a = n,
|
|
301
|
-
if (!
|
|
300
|
+
if (!l) return void s(e, i.RepeatingPosition, `'Repeating' is not a valid return type: '${t}'.`);
|
|
301
|
+
if (u.count !== 0) return void s(e, i.RepeatingPosition, `'Repeating' cannot be nested inside another type: '${t}'.`);
|
|
302
|
+
const a = n, m = e.typeArguments;
|
|
303
|
+
if (!m || m.length < 1 || m.length > 2) return void s(e, i.GenericArity, `'${p}' must be typed with 1 type, optionally followed by a maximum argument count: '${t}'.`);
|
|
302
304
|
let v;
|
|
303
|
-
if (
|
|
304
|
-
const R =
|
|
305
|
-
if (!Number.isInteger(g) || g < 1 || g > 255) return void
|
|
306
|
-
v = g,
|
|
305
|
+
if (m.length === 2) {
|
|
306
|
+
const R = m[1], P = R.kind === r.SyntaxKind.LiteralType ? R.literal : null, g = P && P.kind === r.SyntaxKind.NumericLiteral ? Number(P.text) : NaN;
|
|
307
|
+
if (!Number.isInteger(g) || g < 1 || g > 255) return void s(R, i.RepeatingMax, `'${t}': '${p}'’s maximum must be a whole number between 1 and 255.`);
|
|
308
|
+
v = g, o.maxArguments = g;
|
|
307
309
|
}
|
|
308
|
-
if (
|
|
310
|
+
if (x) return v === void 0 ? void s(e, i.RepeatingPosition, `'${t}' is a rest parameter and a repeating group. A group already repeats — drop the '...', or give the group a maximum ('Repeating<T, 254>') if the ceiling is all you meant.`) : M(m[0], n, o, l, u, y, T);
|
|
309
311
|
const D = a.acceptError;
|
|
310
312
|
delete a.acceptError;
|
|
311
|
-
const
|
|
312
|
-
const
|
|
313
|
+
const E = ((R, P, g, c) => {
|
|
314
|
+
const d = (C, K, S) => {
|
|
313
315
|
const w = { name: C };
|
|
314
316
|
return Z(K, w, g, !0), S && (w.optional = !0), c && !w.acceptError && (w.acceptError = !0), w;
|
|
315
317
|
};
|
|
316
|
-
if (R.kind !== r.SyntaxKind.TupleType) return [
|
|
318
|
+
if (R.kind !== r.SyntaxKind.TupleType) return [d(P, R, !1)];
|
|
317
319
|
const k = R.elements;
|
|
318
|
-
if (k.length < 2) return
|
|
320
|
+
if (k.length < 2) return s(R, i.RepeatingSlots, `'${P}': a repeating group of period ${k.length} must be spelled 'Repeating<T>' without the tuple.`), null;
|
|
319
321
|
const j = [];
|
|
320
322
|
for (let C = 0; C < k.length; C++) {
|
|
321
323
|
const K = k[C];
|
|
322
|
-
if (K.kind !== r.SyntaxKind.NamedTupleMember) return
|
|
324
|
+
if (K.kind !== r.SyntaxKind.NamedTupleMember) return s(K, i.RepeatingSlots, `'${P}': every slot of a repeating group must be labelled, e.g. 'Repeating<[criteriaRange: IRange, criteria: Scalar]>'.`), null;
|
|
323
325
|
const S = !!K.questionToken;
|
|
324
|
-
if (S && C !== k.length - 1) return
|
|
325
|
-
j.push(
|
|
326
|
+
if (S && C !== k.length - 1) return s(K, i.RepeatingOptional, `'${P}': only the LAST slot of a repeating group may be optional (slot '${K.name?.getText?.()}' is not).`), null;
|
|
327
|
+
j.push(d(K.name?.getText?.() ?? `${C}`, K.type, S));
|
|
326
328
|
}
|
|
327
329
|
return j;
|
|
328
|
-
})(
|
|
329
|
-
return void (
|
|
330
|
+
})(m[0], t ?? "parameter", o, D);
|
|
331
|
+
return void (E && (a.repeating = E));
|
|
330
332
|
}
|
|
331
|
-
const h =
|
|
332
|
-
let
|
|
333
|
-
h && (n.range = h,
|
|
334
|
-
const b =
|
|
335
|
-
if (b && (n.scalar = b), b !== void 0 && (
|
|
333
|
+
const h = se.get(p);
|
|
334
|
+
let L = !1;
|
|
335
|
+
h && (n.range = h, L = !0);
|
|
336
|
+
const b = De.get(p);
|
|
337
|
+
if (b && (n.scalar = b), b !== void 0 && (L = !0), me(e, p, n, o, l)) return;
|
|
336
338
|
if (l) {
|
|
337
|
-
if (p === "Volatile" || p === `${V}.Volatile`) return void
|
|
338
|
-
if (
|
|
339
|
-
const t =
|
|
339
|
+
if (p === "Volatile" || p === `${V}.Volatile`) return void s(e, i.InvalidParamType, `'Volatile' is not a valid parameter type: '${N(e)}'. It describes the function's RESULT, so it belongs on the return type.`);
|
|
340
|
+
if (Oe.has(p)) return be;
|
|
341
|
+
const t = de.get(p);
|
|
340
342
|
if (t) return t;
|
|
341
|
-
} else
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
let d = 0;
|
|
346
|
-
if (a.async && d++, a.stream && d++, d > 1) return void o(e, i.MultipleModifiers, `'${p}' cannot have multiple modifiers: '${N(e)}'.`);
|
|
347
|
-
E = !0;
|
|
348
|
-
}
|
|
343
|
+
} else if (p === "Promise") Y = e, L = !0;
|
|
344
|
+
else {
|
|
345
|
+
const t = ze.get(p);
|
|
346
|
+
t && (Object.assign(n, t()), L = !0);
|
|
349
347
|
}
|
|
350
|
-
if (!
|
|
351
|
-
const t =
|
|
348
|
+
if (!L) {
|
|
349
|
+
const t = re(e, n.name ?? N(e));
|
|
352
350
|
if (t === void 0) return;
|
|
353
351
|
if (t !== null) return n.scalar = t.type, void (l && (n.enum = t));
|
|
354
352
|
}
|
|
355
|
-
if (!
|
|
356
|
-
const t = "number, string, boolean, Scalar, Lambda, Date, FormulaError.Known, IRichData, IRange, IReferenceRange (and arrays of these; optionally wrapped in AcceptError<T>, or grouped with Repeating<T>)", a = "number, string, boolean, Scalar, Date, FormulaError.Known, IRichData, IRange,
|
|
357
|
-
let
|
|
358
|
-
return
|
|
353
|
+
if (!L) {
|
|
354
|
+
const t = "number, string, boolean, Scalar, Lambda, Date, FormulaError.Known, IRichData, IRange, IReferenceRange (and arrays of these; optionally wrapped in AcceptError<T>, or grouped with Repeating<T>)", a = "number, string, boolean, Scalar, Date, FormulaError.Known, IRichData, IRange, Volatile<T> (and arrays of these)";
|
|
355
|
+
let m;
|
|
356
|
+
return m = l ? y ? `'${p}' is not a valid first parameter: '${N(e)}'. The first parameter is EITHER a macro target (making this a macro) OR a calculation input (making this a calculation function). Allowed: ${Fe.join(", ")} (macro target); ${t} (calculation input).` : `'${p}' is not a valid parameter type: '${N(e)}'. Allowed: ${t}.` : `'${p}' is not a valid return type: '${N(e)}'. Allowed: ${a}.`, void s(e, l ? i.InvalidParamType : i.InvalidReturnType, m);
|
|
359
357
|
}
|
|
360
358
|
const f = e.typeArguments;
|
|
361
359
|
if (f) {
|
|
362
|
-
if (f.length !== 1) return void
|
|
363
|
-
const t = f[0], a = l && r.isTypeReferenceNode(t) &&
|
|
364
|
-
a &&
|
|
360
|
+
if (f.length !== 1) return void s(e, i.GenericArity, `'${p}' must be typed with exactly 1 type: '${N(e)}'.`);
|
|
361
|
+
const t = f[0], a = l && r.isTypeReferenceNode(t) && le.has(q(t)), m = n.reportType;
|
|
362
|
+
a && ge.add(n), Z(t, n, o, l), a && m === void 0 && delete n.reportType;
|
|
365
363
|
const v = n.enum;
|
|
366
|
-
v && !a && (
|
|
364
|
+
v && !a && (s(f[0], i.EnumPosition, `'${p}' cannot hold the enum '${v.id}': '${N(e)}'. The members of a range reach the body as they are, so nothing checks them against the enum. Take the enum as a value, or type the range by its scalar ('${p}<${v.type}>').`), delete n.enum);
|
|
367
365
|
}
|
|
368
|
-
} else e.kind === r.SyntaxKind.FunctionType && ((p, h,
|
|
369
|
-
if (!b) return void
|
|
366
|
+
} else e.kind === r.SyntaxKind.FunctionType && ((p, h, L, b) => {
|
|
367
|
+
if (!b) return void s(p, i.FunctionReturn, `Function type is not a valid return type: '${N(p)}'. Declare a 'Lambda' return instead.`);
|
|
370
368
|
const f = p.type, t = {};
|
|
371
369
|
let a = "*";
|
|
372
|
-
f && (f.kind === r.SyntaxKind.AnyKeyword ? a = "raw" : (M(f, t,
|
|
373
|
-
const
|
|
374
|
-
|
|
375
|
-
})(e, n,
|
|
376
|
-
} else
|
|
370
|
+
f && (f.kind === r.SyntaxKind.AnyKeyword ? a = "raw" : (M(f, t, L, !1, { count: 0 }), a = t.scalar ?? "*"));
|
|
371
|
+
const m = p.parameters;
|
|
372
|
+
m && !m.some((v) => v.dotDotDotToken) && (h.lambdaArity = m.length), h.lambda = a;
|
|
373
|
+
})(e, n, o, l);
|
|
374
|
+
} else s(e, i.MissingType, `Type is not defined for '${n?.name ?? "return"}'.`);
|
|
377
375
|
};
|
|
378
376
|
try {
|
|
379
377
|
r.forEachChild(F, (e) => {
|
|
380
378
|
if (((n) => (r.getCombinedModifierFlags(n) & r.ModifierFlags.Export) !== 0)(e) && r.isFunctionDeclaration(e)) {
|
|
381
379
|
const n = e?.name?.getText();
|
|
382
|
-
if (!e.body) return void
|
|
383
|
-
if (!n) return void
|
|
384
|
-
const
|
|
380
|
+
if (!e.body) return void s(e, i.NoBody, `'${n}': function has no body.`);
|
|
381
|
+
if (!n) return void s(e, i.Anonymous, "Anonymous exported functions are not allowed.");
|
|
382
|
+
const o = {}, l = { parameters: {} };
|
|
385
383
|
try {
|
|
386
|
-
|
|
384
|
+
o.name = n;
|
|
387
385
|
const u = $.getSymbolAtLocation(e.name), y = H(u?.getDocumentationComment($));
|
|
388
386
|
y && (l.summary = y);
|
|
389
|
-
const x = {};
|
|
390
|
-
Z(e.type, x, s, !1), s.returnType = x;
|
|
391
387
|
const T = {};
|
|
392
|
-
|
|
393
|
-
const
|
|
394
|
-
|
|
388
|
+
Y = null, Z(e.type, T, o, !1), o.returnType = T;
|
|
389
|
+
const x = {};
|
|
390
|
+
((g) => (r.getCombinedModifierFlags(g) & r.ModifierFlags.Default) !== 0)(e) && (x.default = !0, X = n), o.parameters = [];
|
|
391
|
+
const p = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), L = /* @__PURE__ */ new Set();
|
|
392
|
+
let b = null, f = null, t = null, a = 0, m = !1, v = 0;
|
|
395
393
|
for (let g = 0; g < e.parameters.length; g++) {
|
|
396
|
-
const c = e.parameters[g],
|
|
397
|
-
|
|
398
|
-
const k =
|
|
399
|
-
if (A?.lenient && g === 0 && !c.type &&
|
|
400
|
-
|
|
394
|
+
const c = e.parameters[g], d = {};
|
|
395
|
+
d.name = c.name?.getText();
|
|
396
|
+
const k = o.parameters.length === 0;
|
|
397
|
+
if (A?.lenient && g === 0 && !c.type && x.default) {
|
|
398
|
+
o.context = xe;
|
|
401
399
|
continue;
|
|
402
400
|
}
|
|
403
|
-
const j = Z(c.type,
|
|
404
|
-
if (j ===
|
|
405
|
-
g === 0 &&
|
|
401
|
+
const j = Z(c.type, d, o, !0, k, !c.dotDotDotToken, !!c.dotDotDotToken);
|
|
402
|
+
if (j === be) {
|
|
403
|
+
g === 0 && o.context === void 0 && (o.context = xe);
|
|
406
404
|
continue;
|
|
407
405
|
}
|
|
408
406
|
if (j) {
|
|
409
|
-
if (
|
|
410
|
-
|
|
407
|
+
if (o.parameters.length !== 0) return void s(c, i.ContextNotFirst, `'${o.name}' contexts must be the first parameter: '${d.name}'.`);
|
|
408
|
+
o.context = j;
|
|
411
409
|
continue;
|
|
412
410
|
}
|
|
413
|
-
if (
|
|
414
|
-
if (b !== null) return void
|
|
415
|
-
b =
|
|
416
|
-
} else if (b !== null) return void
|
|
417
|
-
const C =
|
|
411
|
+
if (d.lambda !== void 0) {
|
|
412
|
+
if (b !== null) return void s(c, i.MultipleLambda, `'${o.name}' has more than one Lambda parameter ('${b}' and '${d.name}'). Only one Lambda parameter is allowed.`);
|
|
413
|
+
b = d.name;
|
|
414
|
+
} else if (b !== null) return void s(c, i.LambdaNotLast, `'${o.name}' Lambda parameter ('${b}') must be the last parameter, but '${d.name}' follows it.`);
|
|
415
|
+
const C = d.optional === !0 || c.initializer !== void 0 && c.initializer !== null || c.questionToken !== void 0 && c.questionToken !== null;
|
|
418
416
|
let K;
|
|
419
|
-
if (C && (
|
|
417
|
+
if (C && (d.optional = !0, c.initializer)) try {
|
|
420
418
|
if (c.initializer.kind === r.SyntaxKind.StringLiteral) K = c.initializer.text;
|
|
421
419
|
else if (c.initializer.kind === r.SyntaxKind.NumericLiteral) K = parseFloat(c.initializer.text);
|
|
422
420
|
else if (c.initializer.kind === r.SyntaxKind.TrueKeyword || c.initializer.kind === r.SyntaxKind.FalseKeyword) K = c.initializer.kind === r.SyntaxKind.TrueKeyword;
|
|
@@ -427,56 +425,56 @@ function Oe(r, F, $, A) {
|
|
|
427
425
|
O.flags & (r.TypeFlags.NumberLiteral | r.TypeFlags.StringLiteral) && (K = O.value);
|
|
428
426
|
}
|
|
429
427
|
} catch (O) {
|
|
430
|
-
console.warn(`Couldn't extract default value for parameter '${
|
|
428
|
+
console.warn(`Couldn't extract default value for parameter '${d.name}'`, O);
|
|
431
429
|
}
|
|
432
|
-
c.dotDotDotToken && (
|
|
433
|
-
const S =
|
|
430
|
+
c.dotDotDotToken && (d.rest = !0);
|
|
431
|
+
const S = d.repeating;
|
|
434
432
|
if (S) {
|
|
435
|
-
if (
|
|
436
|
-
if (C && S.length === 1) return void
|
|
437
|
-
if (f !== null) return void
|
|
438
|
-
if (t !== null) return void
|
|
439
|
-
f =
|
|
433
|
+
if (d.rest) return void s(c, i.RepeatingPosition, `'${o.name}' parameter '${d.name}' is both a rest parameter and a repeating group. A group already repeats — drop the '...'.`);
|
|
434
|
+
if (C && S.length === 1) return void s(c, i.RepeatingOptional, `'${o.name}' parameter '${d.name}' cannot be an optional repeating group. Use '...${d.name}: T[]' for zero-or-more, or drop the '?' for one-or-more.`);
|
|
435
|
+
if (f !== null) return void s(c, i.MultipleRepeating, `'${o.name}' has more than one repeating group ('${f}' and '${d.name}'). Only one is allowed — two would make the argument count ambiguous.`);
|
|
436
|
+
if (t !== null) return void s(c, i.RepeatingOptional, `'${o.name}' parameter '${t}' is optional and precedes the repeating group '${d.name}'. Every parameter outside a group must be required.`);
|
|
437
|
+
f = d.name, a = S.length, m = S[S.length - 1].optional === !0;
|
|
440
438
|
} else {
|
|
441
|
-
if (f !== null &&
|
|
439
|
+
if (f !== null && d.rest) return void s(c, i.RepeatingOptional, `'${o.name}' parameter '${d.name}' is a rest parameter and follows the repeating group '${f}'. Two variadic tails would make the argument count ambiguous.`);
|
|
442
440
|
if (f !== null && C) {
|
|
443
|
-
if (v >= a - 1) return void
|
|
444
|
-
if (
|
|
441
|
+
if (v >= a - 1) return void s(c, i.RepeatingOptional, a === 1 ? `'${o.name}' parameter '${d.name}' is optional and follows the period-1 repeating group '${f}'. One more argument is indistinguishable from one more repetition — make it required, or give the group a period.` : `'${o.name}' has ${v + 1} optional parameters after the repeating group '${f}', which has period ${a}. At most ${a - 1} may be optional, or the argument count no longer decides the parse.`);
|
|
442
|
+
if (m) return void s(c, i.RepeatingOptional, `'${o.name}' parameter '${d.name}' is optional and follows '${f}', whose own last slot is already optional. Both omissions reach the same argument count — drop one.`);
|
|
445
443
|
v++;
|
|
446
444
|
}
|
|
447
445
|
}
|
|
448
|
-
C && !S && (t =
|
|
449
|
-
const w = (
|
|
450
|
-
if (w > I) return void
|
|
451
|
-
|
|
446
|
+
C && !S && (t = d.name);
|
|
447
|
+
const w = (d.range ? 2 : 0) + (d.arrayDepth ?? 0), ee = d.range === "r" || d.range === "p" || d.range === "*", I = d.rest || ee ? 3 : 2;
|
|
448
|
+
if (w > I) return void s(c, i.ArrayDepth, `'${o.name}' parameter '${d.name}' has an array depth of ${w}; the maximum is ${I}${d.rest ? " for a rest parameter" : " (use a rest parameter for one more level, or an IRange)"}.`);
|
|
449
|
+
o.parameters.push(d);
|
|
452
450
|
const z = { description: "" };
|
|
453
|
-
l.parameters[
|
|
454
|
-
const
|
|
455
|
-
z.description = H(
|
|
456
|
-
for (const O of [
|
|
457
|
-
const J = O.enum ?
|
|
451
|
+
l.parameters[d.name] = z;
|
|
452
|
+
const ae = $.getSymbolAtLocation(c.name);
|
|
453
|
+
z.description = H(ae?.getDocumentationComment($)), K !== void 0 && (d.defaultValue = K);
|
|
454
|
+
for (const O of [d, ...d.repeating ?? []]) {
|
|
455
|
+
const J = O.enum ? ce.get(O.enum) : void 0;
|
|
458
456
|
J && ((l.enums ??= {})[O.enum.id] = J);
|
|
459
457
|
}
|
|
460
|
-
if (p.set(
|
|
461
|
-
|
|
458
|
+
if (p.set(d.name, d), h.set(d.name, c), S && S.length > 1) {
|
|
459
|
+
L.add(d.name);
|
|
462
460
|
for (const O of S) {
|
|
463
|
-
const J = `${
|
|
461
|
+
const J = `${d.name}.${O.name}`;
|
|
464
462
|
l.parameters[J] = { description: "" }, p.set(J, O), h.set(J, c);
|
|
465
463
|
}
|
|
466
464
|
}
|
|
467
465
|
}
|
|
468
|
-
const D =
|
|
466
|
+
const D = o.maxArguments;
|
|
469
467
|
if (D !== void 0) {
|
|
470
|
-
const g =
|
|
471
|
-
if (!g.some((
|
|
468
|
+
const g = o.parameters ?? [];
|
|
469
|
+
if (!g.some((d) => d.rest === !0 || d.repeating !== void 0)) return void s(e, i.RepeatingMax, `'${o.name}' declares a maximum of ${D} arguments but takes a fixed ${g.length}. A maximum only means something on a variadic tail.`);
|
|
472
470
|
let c = 0;
|
|
473
|
-
for (const
|
|
474
|
-
if (D < c) return void
|
|
471
|
+
for (const d of g) d.rest !== !0 && d.optional !== !0 && (c += d.repeating ? d.repeating.length : 1);
|
|
472
|
+
if (D < c) return void s(e, i.RepeatingMax, `'${o.name}' declares a maximum of ${D} arguments but requires ${c}.`);
|
|
475
473
|
}
|
|
476
474
|
if (e.jsDoc && e.jsDoc.length > 0) {
|
|
477
475
|
const g = e.jsDoc, c = g.length;
|
|
478
|
-
for (let
|
|
479
|
-
const k = g[
|
|
476
|
+
for (let d = 0; d < c; d++) {
|
|
477
|
+
const k = g[d]?.tags;
|
|
480
478
|
if (!k) continue;
|
|
481
479
|
const j = k.length;
|
|
482
480
|
for (let C = 0; C < j; C++) {
|
|
@@ -485,19 +483,19 @@ function Oe(r, F, $, A) {
|
|
|
485
483
|
if (!S) continue;
|
|
486
484
|
S = S.toLowerCase();
|
|
487
485
|
let w = K.comment;
|
|
488
|
-
const
|
|
489
|
-
if (typeof w == "string" ||
|
|
486
|
+
const ee = Ee(S);
|
|
487
|
+
if (typeof w == "string" || ee) {
|
|
490
488
|
if (typeof w == "string" && (w = w.replace(/\r\n?/g, `
|
|
491
|
-
`).trim()),
|
|
489
|
+
`).trim()), ee || !w || (w = w.split(`
|
|
492
490
|
`)[0].trim(), w && w.length !== 0)) {
|
|
493
491
|
if (w && typeof w == "string") {
|
|
494
492
|
const I = /\{@link(code|plain)?\s+([^}|]+)(?:\s*\|\s*([^}]+))?\}/g;
|
|
495
|
-
let z,
|
|
493
|
+
let z, ae = w, O = [];
|
|
496
494
|
for (; (z = I.exec(w)) !== null; ) {
|
|
497
|
-
const [J,
|
|
498
|
-
|
|
495
|
+
const [J, je, Ne, he] = z, Le = [Ne.trim()];
|
|
496
|
+
he && Le.push(he.trim());
|
|
499
497
|
}
|
|
500
|
-
w =
|
|
498
|
+
w = ae, O.length > 0 && S === "see" && (l.links || (l.links = []), l.links.push(...O));
|
|
501
499
|
}
|
|
502
500
|
if (S === "name") {
|
|
503
501
|
const I = w;
|
|
@@ -506,76 +504,77 @@ function Oe(r, F, $, A) {
|
|
|
506
504
|
if (S === "param") {
|
|
507
505
|
const I = K.name?.getText?.() ?? K.name?.text;
|
|
508
506
|
if (!p.get(I)) {
|
|
509
|
-
|
|
507
|
+
s(K, i.UnknownParam, `Parameter '${I}' not found in function '${n}'.`);
|
|
510
508
|
continue;
|
|
511
509
|
}
|
|
512
510
|
const z = l.parameters?.[I];
|
|
513
511
|
z && !z.description && typeof w == "string" && w && (z.description = w);
|
|
514
|
-
} else if (S === "returns" || S === "return")
|
|
512
|
+
} else if (S === "returns" || S === "return") o.returnType.description = w;
|
|
515
513
|
else if (S === "returnkind") {
|
|
516
514
|
const I = (w ?? "").trim().toLowerCase();
|
|
517
|
-
|
|
515
|
+
ie.has(I) ? o.returnType.kind = I : s(K, i.UnknownReturnKind, `'@returnKind ${I}' is not a known value kind. Known: ${[...ie].map((z) => `'${z}'`).join(", ")}.`);
|
|
518
516
|
} else if (S === "category") l.category = w;
|
|
519
517
|
else if (S === "deprecated" || S === "hidden") {
|
|
520
518
|
let I = !0;
|
|
521
519
|
const z = w?.toLowerCase();
|
|
522
|
-
z === "false" ? I = !1 : z !== "true" && (I = w), I !== !1 && (l.deprecated = I ?? !0,
|
|
520
|
+
z === "false" ? I = !1 : z !== "true" && (I = w), I !== !1 && (l.deprecated = I ?? !0, o.hidden = !0);
|
|
523
521
|
}
|
|
524
522
|
}
|
|
525
523
|
}
|
|
526
|
-
} else S === "returnkind" &&
|
|
524
|
+
} else S === "returnkind" && s(K, i.UnknownReturnKind, `'@returnKind' needs a value kind. Known: ${[...ie].map((I) => `'${I}'`).join(", ")}.`);
|
|
527
525
|
}
|
|
528
526
|
}
|
|
529
527
|
}
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
528
|
+
if (!o.context && Y) return void s(Y, i.InvalidReturnType, `'${n}': Promise<T> is not a valid return type for a calculation function. Return the value the cell shows now, and call FormulaContext.defer(executor, payload) to deliver the result later.`);
|
|
529
|
+
Object.keys(o.returnType).length === 0 && delete o.returnType, Object.keys(x).length > 0 && (o.behavior = x), l.summary || U(e.name ?? e, i.MissingSummary, "warning", `'${n}': missing a description. Add a JSDoc comment above the function.`);
|
|
530
|
+
const E = !o.context, R = E && l.name || n;
|
|
531
|
+
if (E && !Ce.test(R)) {
|
|
533
532
|
const g = l.name ? `'@name ${l.name}'` : `'${R}'`;
|
|
534
|
-
return void
|
|
533
|
+
return void s(e.name ?? e, i.InvalidName, `'${n}': ${g} cannot be called from a formula. A function name starts with a letter or '_', and continues with letters, digits, '_' or '.'.` + (l.name ? "" : " Add an '@name' tag to register it under another name."));
|
|
535
534
|
}
|
|
536
|
-
if (
|
|
537
|
-
if (
|
|
538
|
-
const c =
|
|
535
|
+
if (E && !A?.isBuiltIn && ((g) => {
|
|
536
|
+
if (Pe.test(g)) return !0;
|
|
537
|
+
const c = Ue.exec(g);
|
|
539
538
|
if (!c) return !1;
|
|
540
|
-
let
|
|
541
|
-
for (const j of c[1].toUpperCase())
|
|
539
|
+
let d = 0;
|
|
540
|
+
for (const j of c[1].toUpperCase()) d = 26 * d + (j.charCodeAt(0) - 64);
|
|
542
541
|
const k = Number(c[2]);
|
|
543
|
-
return
|
|
542
|
+
return d <= 16384 && k >= 1 && k <= 1048576;
|
|
544
543
|
})(R)) {
|
|
545
544
|
const g = l.name ? `'@name ${l.name}'` : `'${R}'`;
|
|
546
|
-
return void
|
|
545
|
+
return void s(e.name ?? e, i.InvalidName, `'${n}': ${g} cannot be called from a formula. It reads as a cell address.` + (l.name ? "" : " Add an '@name' tag to register it under another name."));
|
|
547
546
|
}
|
|
548
547
|
const P = W.get(R.toUpperCase());
|
|
549
|
-
if (P !== void 0) return void
|
|
550
|
-
if (W.set(R.toUpperCase(), n),
|
|
551
|
-
if (
|
|
548
|
+
if (P !== void 0) return void s(e.name ?? e, i.DuplicateName, `'${n}': '${R}' is already the name of '${P}' in this module.`);
|
|
549
|
+
if (W.set(R.toUpperCase(), n), E && B?.has(R.toUpperCase())) return void s(e.name ?? e, i.BuiltInName, `'${R}' is a built-in function. Choose a different name - a calculation function cannot replace a built-in.`);
|
|
550
|
+
if (E) {
|
|
552
551
|
const g = l.parameters ?? {};
|
|
553
|
-
for (const [c,
|
|
552
|
+
for (const [c, d] of Object.entries(g)) if (!L.has(c) && !d.description) {
|
|
554
553
|
const k = h.get(c);
|
|
555
554
|
U(k, i.MissingParamDescription, "warning", `'${n}': parameter '${c}' is missing a description. Add an '@param ${c}' tag.`);
|
|
556
555
|
}
|
|
557
556
|
}
|
|
558
|
-
G.push([
|
|
557
|
+
G.push([o, l]);
|
|
559
558
|
} catch (u) {
|
|
560
|
-
|
|
559
|
+
s(e, i.ParseError, `'${n}': ${u.message}`);
|
|
561
560
|
}
|
|
562
561
|
}
|
|
563
562
|
});
|
|
564
563
|
} catch (e) {
|
|
565
|
-
|
|
564
|
+
s(void 0, i.ParseError, `Unable to analyze module: ${e?.message ?? e}`);
|
|
566
565
|
}
|
|
567
566
|
return { functions: G, autoRun: X, diagnostics: Q };
|
|
568
567
|
}
|
|
569
|
-
function
|
|
568
|
+
function Je(r, F, $) {
|
|
570
569
|
const A = "script.ts", B = "lib.d.ts", G = { [A]: F ?? "", [B]: "" }, W = r.createProgram([A], { allowJs: !0, noResolve: !0, noLib: !0, isolatedModules: !0, module: 99, target: r.ScriptTarget.ES2020 }, { getSourceFile: (U) => {
|
|
571
|
-
const
|
|
572
|
-
if (
|
|
570
|
+
const s = G[U];
|
|
571
|
+
if (s !== void 0) return r.createSourceFile(U, s, r.ScriptTarget.Latest, !0);
|
|
573
572
|
}, fileExists: (U) => G[U] !== void 0, readFile: (U) => G[U], writeFile: () => {
|
|
574
573
|
}, getCurrentDirectory: () => "./", getCanonicalFileName: (U) => U, useCaseSensitiveFileNames: () => !0, getDefaultLibFileName: () => B, getNewLine: () => `
|
|
575
574
|
` }), Q = W.getTypeChecker(), X = W.getSourceFile(A);
|
|
576
|
-
return X ?
|
|
575
|
+
return X ? Ve(r, X, Q, $).diagnostics : [];
|
|
577
576
|
}
|
|
578
577
|
export {
|
|
579
|
-
|
|
580
|
-
|
|
578
|
+
Ve as analyzeModule,
|
|
579
|
+
Je as lintScript
|
|
581
580
|
};
|