@sheetxl/scripting 0.7.28-beta.4 → 0.8.0-beta.10

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.
Files changed (62) hide show
  1. package/README.md +4 -4
  2. package/browser/esm/21ztp96onxWNyfBZ.mjs +581 -0
  3. package/browser/esm/4VkvY2rXOd49uHcQ.mjs +4 -0
  4. package/browser/esm/B73J41HhbJvswDz1.mjs +17 -0
  5. package/browser/esm/B_2CC0NvNtPBw_ad.mjs +22 -0
  6. package/browser/esm/BvzmZuTo8xvOBJ6a.mjs +3627 -0
  7. package/browser/esm/BxiAkxNyUQseLNBv.mjs +10 -0
  8. package/browser/esm/D9jTpNifykCuQkTL.mjs +18 -0
  9. package/browser/esm/Ly2yqBRuG8dssY2w.mjs +162 -0
  10. package/browser/esm/NpFv8YNKRgVPGXOq.mjs +9 -0
  11. package/browser/esm/index.mjs +71 -41
  12. package/browser/esm/qjsNvVXUFvwuddu9.mjs +23 -0
  13. package/node/esm/4VkvY2rXOd49uHcQ.mjs +4 -0
  14. package/node/esm/B74CcyWYGHJL1E2s.mjs +581 -0
  15. package/node/esm/ClxOMp6IdEZdW4Qd.mjs +8 -0
  16. package/node/esm/D0CDObJV23Rxk8-r.mjs +15 -0
  17. package/node/esm/Dhbf7vOdddc7aiOT.mjs +23 -0
  18. package/node/esm/Dl6HzBX-qBm0gCfJ.mjs +20 -0
  19. package/node/esm/DoQf-VD0li_RugX4.mjs +161 -0
  20. package/node/esm/index.mjs +83 -141
  21. package/node/esm/og3Pk2ReS3UiORbF.mjs +21 -0
  22. package/package.json +6 -7
  23. package/types/src/compiler/Bundler.d.ts +1 -1
  24. package/types/src/compiler/insertRunGuard.d.ts +11 -0
  25. package/types/src/lib/typescript/typescript.browser.d.ts +6 -0
  26. package/types/src/lib/typescript/typescript.node.d.ts +11 -0
  27. package/types/src/linter/Linter.d.ts +7 -0
  28. package/types/src/runtime/RunGuard.d.ts +31 -0
  29. package/types/src/runtime/index.d.ts +1 -0
  30. package/types/src/type/CompileOptions.d.ts +50 -0
  31. package/types/src/type/CompiledModule.d.ts +36 -6
  32. package/types/src/type/Diagnostic.d.ts +25 -1
  33. package/types/src/type/Types.d.ts +44 -3
  34. package/browser/cjs/1_xhnTjP6m5oj6za.cjs +0 -21
  35. package/browser/cjs/B_2b6uA3WKl7970Q.cjs +0 -1
  36. package/browser/cjs/Bu4cZ8iSZ3rij-oV.cjs +0 -1
  37. package/browser/cjs/BvG8N7G_8CXIAlT-.cjs +0 -1
  38. package/browser/cjs/BwpBc8k-Fp1SAn7l.cjs +0 -1
  39. package/browser/cjs/C_7w8EJZpHw8ueuq.cjs +0 -1
  40. package/browser/cjs/C_IEgjM-hSJCv6Gm.cjs +0 -1
  41. package/browser/cjs/CctaCN_w3o34V9AR.cjs +0 -1
  42. package/browser/cjs/DSEShe7kGtxvljOr.cjs +0 -1
  43. package/browser/cjs/index.cjs +0 -1
  44. package/browser/cjs/qWYyYsBboXc9p0Lw.cjs +0 -7
  45. package/browser/esm/80oYnILw-_ixsNjP.mjs +0 -15
  46. package/browser/esm/BIKWt7VvnYQGipn8.mjs +0 -87
  47. package/browser/esm/BvzriDVNz7rvv-CN.mjs +0 -12
  48. package/browser/esm/BzbjwP47XqWR_dLy.mjs +0 -421
  49. package/browser/esm/CDBoNa-_uINySbpK.mjs +0 -152
  50. package/browser/esm/CUE7cb3UPOJM-3kD.mjs +0 -25
  51. package/browser/esm/DQW5CKiti4COASaz.mjs +0 -23
  52. package/browser/esm/NC0vOHwL24BJSQ_l.mjs +0 -27
  53. package/browser/esm/boW6I_VE4ZlDrs3P.mjs +0 -8
  54. package/browser/esm/iMHa0nIFHsIvws4V.mjs +0 -105
  55. package/node/esm/BHErJ0QgPjNC4lWi.mjs +0 -152
  56. package/node/esm/BOT12k_HrUajuNNO.mjs +0 -12
  57. package/node/esm/CUJYmJq64kAxqquM.mjs +0 -421
  58. package/node/esm/Dyqi5Bjd6JfFkMrp.mjs +0 -17
  59. package/node/esm/GDpQxq3gDBro-Loq.mjs +0 -27
  60. package/node/esm/VR8Qx9rC5rrXqlNV.mjs +0 -23
  61. package/node/esm/bmKxP3gmEczTpaFo.mjs +0 -14
  62. package/node/esm/boW6I_VE4ZlDrs3P.mjs +0 -8
@@ -0,0 +1,20 @@
1
+ var o = class {
2
+ constructor(e) {
3
+ this._onExecute = e;
4
+ }
5
+ execute(e) {
6
+ return this._onExecute(e);
7
+ }
8
+ start() {
9
+ return Promise.resolve();
10
+ }
11
+ terminate() {
12
+ }
13
+ };
14
+ async function a() {
15
+ const { compileModule: e } = await import("./DoQf-VD0li_RugX4.mjs"), t = new o((r) => e(r));
16
+ return await t.start(), t;
17
+ }
18
+ export {
19
+ a as createCompilerWorker
20
+ };
@@ -0,0 +1,161 @@
1
+ import { DiagnosticCode as U, t as x } from "./index.mjs";
2
+ import { analyzeModule as V } from "./B74CcyWYGHJL1E2s.mjs";
3
+ import { t as I } from "./4VkvY2rXOd49uHcQ.mjs";
4
+ import { CommonUtils as X } from "@sheetxl/utils";
5
+ var g = null, w = null, q = { compilerOptions: { target: "esnext" } };
6
+ async function H(t, m, p = "/script.js", u = x, n = !1) {
7
+ try {
8
+ const d = await (async function() {
9
+ if (g) return g;
10
+ if (w) {
11
+ if (await w, !g) throw new Error("ESBuild initialization promise resolved, but instance is not available.");
12
+ return g;
13
+ }
14
+ let i, o;
15
+ w = new Promise((r, l) => {
16
+ i = r, o = l;
17
+ });
18
+ try {
19
+ const { initialize: r } = await import("./ClxOMp6IdEZdW4Qd.mjs");
20
+ return g = await r(), i(), g;
21
+ } catch (r) {
22
+ throw console.error("Failed to import or initialize esbuild:", r), w = null, o(r), r;
23
+ }
24
+ })(), c = "@sheetxl/primitives", s = `
25
+ export const FormulaContext = globalThis.${u}?.FormulaContext;
26
+ export const ScalarType = globalThis.${u}?.ScalarType;
27
+ export const Observable = globalThis.${u}?.Observable;
28
+ export const IRange = globalThis.${u}?.IRange;
29
+ export const FormulaError = globalThis.${u}?.FormulaError;
30
+ // Add more exports as needed
31
+ `, a = await d.build({ entryPoints: [p], bundle: !0, write: !1, format: "esm", plugins: [{ name: "sheetxl-esbuild-in-memory", setup(i) {
32
+ const o = "sheetxl-" + (/* @__PURE__ */ new Date()).getTime();
33
+ i.onResolve({ filter: new RegExp(`^(${p.replace("/", "\\/")}|${c})$`) }, (r) => ({ path: r.path, namespace: o })), i.onResolve({ filter: /.*/ }, (r) => {
34
+ if (r.namespace !== o) return console.warn(`esbuild: Treating import "${r.path}" as external.`), { path: r.path, external: !0 };
35
+ }), i.onLoad({ filter: /.*/, namespace: o }, (r) => {
36
+ let l;
37
+ if (r.path === p) l = m;
38
+ else {
39
+ if (r.path !== c) return { errors: [{ text: `Cannot load unknown path in ${o}: ${r.path}` }] };
40
+ l = s;
41
+ }
42
+ return { contents: l, loader: "ts" };
43
+ });
44
+ } }], sourcemap: "inline", tsconfigRaw: q, minify: n, platform: "neutral" });
45
+ if (a.outputFiles && a.outputFiles.length > 0) return a.outputFiles[0].text;
46
+ throw a.errors && a.errors.length > 0 ? new Error(`esbuild bundling failed: ${a.errors.map((i) => i.text).join(`
47
+ `)}`) : new Error("esbuild did not produce an output file.");
48
+ } catch (d) {
49
+ throw console.error("esbuild bundling process failed:", d), d;
50
+ }
51
+ }
52
+ function Y(t, m, p) {
53
+ return (u) => {
54
+ const n = u.factory, d = () => n.createExpressionStatement(n.createCallChain(n.createPropertyAccessExpression(n.createIdentifier(x), "checkRun"), n.createToken(t.SyntaxKind.QuestionDotToken), void 0, [n.createStringLiteral(m), n.createNumericLiteral(p)])), c = (a) => {
55
+ const i = a.statements;
56
+ let o = 0;
57
+ for (; o < i.length && t.isExpressionStatement(i[o]) && t.isStringLiteral(i[o].expression); ) o++;
58
+ return n.updateBlock(a, [...i.slice(0, o), d(), ...i.slice(o)]);
59
+ }, s = (a) => {
60
+ if (((i) => t.isForStatement(i) || t.isForInStatement(i) || t.isForOfStatement(i) || t.isWhileStatement(i) || t.isDoStatement(i))(a)) {
61
+ const i = a.statement;
62
+ return t.visitEachChild(a, (o) => {
63
+ const r = s(o);
64
+ return o === i ? (l = r, t.isBlock(l) ? c(l) : n.createBlock([d(), l], !0)) : r;
65
+ var l;
66
+ }, u);
67
+ }
68
+ if (t.isFunctionLike(a) && a.body) {
69
+ const i = a.body;
70
+ return t.visitEachChild(a, (o) => {
71
+ const r = s(o);
72
+ return o === i ? (l = r, t.isBlock(l) ? c(l) : n.createBlock([d(), n.createReturnStatement(l)], !0)) : r;
73
+ var l;
74
+ }, u);
75
+ }
76
+ return t.visitEachChild(a, s, u);
77
+ };
78
+ return (a) => t.visitNode(a, s);
79
+ };
80
+ }
81
+ var Z = async () => `
82
+ interface FirstTest {
83
+ isTrue?: boolean;
84
+ }
85
+ `, v = null, L = "sheetxl.d.ts", N = "sheetxl-modules.d.ts", _ = ["lib.webworker.d.ts", "lib.es2020.d.ts", "lib.esnext.asynciterable.d.ts"], O = /* @__PURE__ */ new Map(), D = null, R = null;
86
+ async function ee() {
87
+ return R || (R = import("./og3Pk2ReS3UiORbF.mjs").then(async (t) => {
88
+ const m = await j();
89
+ return t.readLibFile(m, "lib.es5.d.ts") !== void 0 ? t.readLibFile : null;
90
+ })), R;
91
+ }
92
+ async function j() {
93
+ if (v) return v;
94
+ try {
95
+ const t = await (await import("./og3Pk2ReS3UiORbF.mjs")).initialize();
96
+ if (!t) throw new Error("TypeScript could not be loaded. Check your connection and try again.");
97
+ return t;
98
+ } catch (t) {
99
+ throw v = null, t;
100
+ } finally {
101
+ v = null;
102
+ }
103
+ }
104
+ async function se(t) {
105
+ const m = t?.source ?? null;
106
+ if (!m) return { module: null, diagnostics: [] };
107
+ const p = (t.disableBundle || t.declarationsOnly) ?? !1, [u, n, d] = await Promise.all([Z(), j(), t.ambientTypes ? ee() : null]), c = d ? t.ambientTypes ?? null : null;
108
+ let s = "";
109
+ const a = { allowJs: !0, declaration: !1, sourceMap: !1, inlineSourceMap: !1, inlineSources: !1, isolatedModules: !0, preserveConstEnums: !1, module: 99, noResolve: !0, emitDeclarationOnly: !1, target: n.ScriptTarget.ES2020, ...c ? { lib: _, skipLibCheck: !0, strict: !0 } : {} }, i = "script", o = `${i}.ts`, r = "lib.d.ts", l = "global.d.ts", f = { [o]: m, [r]: `
110
+ /**
111
+ * Represents the completion of an asynchronous operation
112
+ */
113
+ interface Promise<T> {
114
+ /**
115
+ * Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
116
+ * resolved value cannot be modified from the callback.
117
+ * @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
118
+ * @returns A Promise for the completion of the callback.
119
+ */
120
+ finally(onfinally?: (() => void) | undefined | null): Promise<T>;
121
+ }
122
+ `, [l]: u, ...c ? { [L]: c, [N]: `declare module '@sheetxl/primitives' { export = SheetXL; }
123
+ ` } : {} }, S = (e) => f[e] ?? (d && e.startsWith("lib.") ? d(n, e) : void 0), z = { getSourceFile: (e, $, te, ne) => {
124
+ if (e === L) return D?.text !== c && (D = { text: c, file: n.createSourceFile(e, c, n.ScriptTarget.Latest, !1) }), D.file;
125
+ if (f[e] === void 0) {
126
+ let y = O.get(e);
127
+ if (!y) {
128
+ const B = S(e);
129
+ if (B === void 0) return;
130
+ y = n.createSourceFile(e, B, n.ScriptTarget.Latest, !1), O.set(e, y);
131
+ }
132
+ return y;
133
+ }
134
+ return n.createSourceFile(e, f[e], n.ScriptTarget.Latest, !0);
135
+ }, fileExists: (e) => S(e) !== void 0, readFile: S, writeFile: (e, $) => {
136
+ f[e] = $;
137
+ }, getCurrentDirectory: () => "./", getCanonicalFileName: (e) => e, useCaseSensitiveFileNames: () => !0, getDefaultLibFileName: (e) => r, getNewLine: () => `
138
+ ` }, h = n.createProgram([o, l, ...c ? [L, N] : []], a, z), A = h.getTypeChecker(), T = h.getSourceFile(o), F = t.runGuard;
139
+ h.emit(void 0, void 0, void 0, void 0, F ? { before: [Y(n, F.key, F.timeoutMs)] } : void 0), s = f[`${i}.js`] ?? "";
140
+ const M = (e) => ({ start: e.start ?? 0, length: e.length ?? 0, severity: e.category === n.DiagnosticCategory.Warning ? "warning" : "error", code: `TS${e.code}`, message: n.flattenDiagnosticMessageText(e.messageText, `
141
+ `) }), W = h.getSyntacticDiagnostics(T).map(M), G = c ? h.getSemanticDiagnostics(T).filter((e) => e.category === n.DiagnosticCategory.Error || e.category === n.DiagnosticCategory.Warning).map(M) : [], k = V(n, T, A, { builtInNames: t.builtInNames, isBuiltIn: t.isBuiltIn, lenient: t.lenient });
142
+ let b = [...W, ...G, ...k.diagnostics];
143
+ t.lenient && (b = b.filter((e) => e.code !== U.MissingType));
144
+ const J = k.functions, P = k.autoRun, K = b.some((e) => e.severity === "error"), Q = `${X.uuidV4()}-script`;
145
+ let C = null;
146
+ if (K) s = "";
147
+ else {
148
+ try {
149
+ p || (s = await H(0, s, i, void 0, t.minify ?? !1));
150
+ } catch {
151
+ console.warn("Error bundling script");
152
+ }
153
+ const e = s.indexOf(I);
154
+ e > -1 && (C = s.substring(e + I.length + 1, s.length), s = s.substring(0, e), s = s.replaceAll("globalThis." + x, x));
155
+ }
156
+ const E = { functions: J, commitId: Q, source: m, language: "typescript", compiled: s };
157
+ return C && (E.sourceMap = C), P && (E.autoRun = P), { module: E, diagnostics: b };
158
+ }
159
+ export {
160
+ se as compileModule
161
+ };
@@ -1,145 +1,87 @@
1
- /**
2
- * @license @sheetxl/scripting - Scripting - Scripting engine for Macros and formulas; includes TypeScript and EsBuild. - v0.7.28-beta.4
3
- *
4
- * (C) 2026-present SheetXL Inc. & Michael T. Ford
5
- * License: The license can be found at https://www.sheetxl.com/license.
6
- */
7
- import { CommonUtils as e } from "@sheetxl/utils";
8
- var t = Object.defineProperty, n = (e, n) => {
9
- let r = {};
10
- for (var i in e) t(r, i, {
11
- get: e[i],
12
- enumerable: !0
13
- });
14
- return n || t(r, Symbol.toStringTag, { value: "Module" }), r;
15
- }, r = Object.freeze({
16
- NoBody: "SXL1001",
17
- Anonymous: "SXL1002",
18
- ParseError: "SXL1003",
19
- InvalidParamType: "SXL2001",
20
- InvalidReturnType: "SXL2002",
21
- UndefinedInput: "SXL2003",
22
- MissingType: "SXL2004",
23
- UntypedArray: "SXL2005",
24
- GenericArity: "SXL2006",
25
- MultipleModifiers: "SXL2007",
26
- ContextNotFirst: "SXL2010",
27
- MultipleLambda: "SXL2020",
28
- LambdaNotLast: "SXL2021",
29
- LambdaScalarMismatch: "SXL2022",
30
- LambdaReturn: "SXL2023",
31
- FunctionReturn: "SXL2024",
32
- LambdaArity: "SXL2025",
33
- ArrayDepth: "SXL2030",
34
- RepeatingPosition: "SXL2040",
35
- MultipleRepeating: "SXL2041",
36
- RepeatingSlots: "SXL2042",
37
- RepeatingOptional: "SXL2043",
38
- NoExports: "SXL3001",
39
- UnknownParam: "SXL3002",
40
- BuiltInName: "SXL3003",
41
- MissingSummary: "SXL9001",
42
- MissingParamDescription: "SXL9002",
43
- MissingReturns: "SXL9003"
44
- }), i = [
45
- {
46
- name: "summary",
47
- group: "sheetxl",
48
- description: "Short description shown in function tooltips and autocomplete."
49
- },
50
- {
51
- name: "param",
52
- group: "jsdoc",
53
- description: "Document a parameter. A string union type becomes a dropdown of allowed options.",
54
- snippet: "param ${1:name} ${2:description}"
55
- },
56
- {
57
- name: "returns",
58
- aliases: ["return"],
59
- group: "jsdoc",
60
- description: "Describe the return value."
61
- },
62
- {
63
- name: "category",
64
- group: "sheetxl",
65
- description: "Group the function under a category in the function list.",
66
- snippet: "category ${1:name}"
67
- },
68
- {
69
- name: "name",
70
- group: "sheetxl",
71
- description: "Override the displayed function name.",
72
- snippet: "name ${1:NAME}"
73
- },
74
- {
75
- name: "description",
76
- group: "sheetxl",
77
- description: "A longer description of the function."
78
- },
79
- {
80
- name: "deprecated",
81
- group: "sheetxl",
82
- standalone: !0,
83
- description: "Mark the function as deprecated (optionally with a reason)."
84
- },
85
- {
86
- name: "hidden",
87
- group: "sheetxl",
88
- standalone: !0,
89
- description: "Hide the function from the function list."
90
- },
91
- {
92
- name: "example",
93
- group: "jsdoc",
94
- description: "Provide a usage example."
95
- },
96
- {
97
- name: "see",
98
- group: "jsdoc",
99
- description: "Reference a related function or link."
100
- }
101
- ], a = (() => {
102
- let e = /* @__PURE__ */ new Map();
103
- for (let t of i) if (e.set(t.name, t), t.aliases) for (let n of t.aliases) e.set(n, t);
104
- return e;
1
+ import { CommonUtils as f } from "@sheetxl/utils";
2
+ var c = Object.defineProperty, p = (e, n) => {
3
+ let t = {};
4
+ for (var i in e) c(t, i, { get: e[i], enumerable: !0 });
5
+ return n || c(t, Symbol.toStringTag, { value: "Module" }), t;
6
+ }, x = Object.freeze({ NoBody: "SXL1001", Anonymous: "SXL1002", ParseError: "SXL1003", InvalidParamType: "SXL2001", InvalidReturnType: "SXL2002", UndefinedInput: "SXL2003", MissingType: "SXL2004", UntypedArray: "SXL2005", GenericArity: "SXL2006", MultipleModifiers: "SXL2007", ContextNotFirst: "SXL2010", MultipleLambda: "SXL2020", LambdaNotLast: "SXL2021", LambdaScalarMismatch: "SXL2022", LambdaReturn: "SXL2023", FunctionReturn: "SXL2024", LambdaArity: "SXL2025", ArrayDepth: "SXL2030", RepeatingPosition: "SXL2040", MultipleRepeating: "SXL2041", RepeatingSlots: "SXL2042", RepeatingOptional: "SXL2043", RepeatingMax: "SXL2044", EnumMixed: "SXL2050", EnumMemberNotConstant: "SXL2051", EnumNotLocal: "SXL2052", EnumMissingAlias: "SXL2053", EnumPosition: "SXL2054", EnumOmittedValue: "SXL2055", NoExports: "SXL3001", UnknownParam: "SXL3002", BuiltInName: "SXL3003", UnknownReturnKind: "SXL3005", InvalidName: "SXL3006", DuplicateName: "SXL3007", MissingSummary: "SXL9001", MissingParamDescription: "SXL9002", MissingReturns: "SXL9003", EnumDuplicateValue: "SXL9004", EnumMemberUndocumented: "SXL9005" }), L = [{ name: "param", group: "jsdoc", description: "Document a parameter. A string union type becomes a dropdown of allowed options.", snippet: "param ${1:name} ${2:description}" }, { name: "returns", aliases: ["return"], group: "jsdoc", description: "Describe the return value." }, { name: "category", group: "sheetxl", description: "Group the function under a category in the function list.", snippet: "category ${1:name}" }, { name: "name", group: "sheetxl", description: "A name an identifier cannot spell: the name formulas call a function by (MY.FUNC), or an enum member's label.", snippet: "name ${1:NAME}" }, { name: "description", group: "sheetxl", description: "A longer description of the function." }, { name: "deprecated", group: "sheetxl", standalone: !0, description: "Mark the function as deprecated (optionally with a reason)." }, { name: "hidden", group: "sheetxl", standalone: !0, description: "Hide the function from the function list." }, { name: "returnkind", group: "sheetxl", description: "Declare the value kind of the return (a ValueKind word, e.g. `number`, `array`, `reference`) where the type spelling cannot say it (a union return collapses to any).", snippet: "returnKind ${1:number}" }, { name: "example", group: "jsdoc", description: "Provide a usage example." }, { name: "see", group: "jsdoc", description: "Reference a related function or link." }], S = (() => {
7
+ const e = /* @__PURE__ */ new Map();
8
+ for (const n of L) if (e.set(n.name, n), n.aliases) for (const t of n.aliases) e.set(t, n);
9
+ return e;
105
10
  })();
106
- function o(e) {
107
- return !0 === function(e) {
108
- if (!e) return;
109
- let t = (e.startsWith("@") ? e.slice(1) : e).toLowerCase();
110
- return a.get(t);
111
- }(e)?.standalone;
11
+ function v(e) {
12
+ return (function(n) {
13
+ if (!n) return;
14
+ const t = (n.startsWith("@") ? n.slice(1) : n).toLowerCase();
15
+ return S.get(t);
16
+ })(e)?.standalone === !0;
112
17
  }
113
- var s = n({ GLOBAL_CONTEXT_VARIABLE: () => c }), c = "__SHEETXL";
114
- async function l(e, t) {
115
- let { loadCompiledModule: n } = await import("./Dyqi5Bjd6JfFkMrp.mjs");
116
- return n(e, t);
18
+ var N = p({ GLOBAL_CONTEXT_VARIABLE: () => X }), X = "__SHEETXL", A = p({ RUN_INTERRUPTED: () => l, abort: () => w, check: () => h, isInterrupted: () => b, release: () => M }), a = /* @__PURE__ */ new Map(), g = 256, y = 16, l = "RunInterrupted";
19
+ function d(e) {
20
+ const n = new Error(e);
21
+ return n.name = l, n;
117
22
  }
118
- var u = null, d = null, f = null, p = null;
119
- async function m() {
120
- return p ||= (async () => (await import("./bmKxP3gmEczTpaFo.mjs")).initialize())(), p;
23
+ function m(e) {
24
+ let n = a.get(e);
25
+ if (!n) {
26
+ if (a.size >= g) {
27
+ const t = a.keys().next().value;
28
+ t !== void 0 && a.delete(t);
29
+ }
30
+ n = { started: Date.now(), calls: 0, stopped: null }, a.set(e, n);
31
+ }
32
+ return n;
121
33
  }
122
- var h = Object.freeze({
123
- compile: async function(t) {
124
- if (!t?.source) return {
125
- module: null,
126
- diagnostics: []
127
- };
128
- if (d && e.deepEqual(d, t)) return u;
129
- let n = await (await async function() {
130
- if (f) return f;
131
- let { TypeScriptCompiler: e } = await import("./GDpQxq3gDBro-Loq.mjs");
132
- return f = new e();
133
- }()).compileModule(t);
134
- return u = n, d = t, n;
135
- },
136
- lint: async function(e, t) {
137
- if (!e) return [];
138
- let [n, { lintScript: r }] = await Promise.all([m(), import("./CUJYmJq64kAxqquM.mjs")]);
139
- return r(n, e, t);
140
- },
141
- cleanup: function() {
142
- f && (f.terminate(), f = null, u = null);
143
- }
144
- });
145
- export { s as Constants, r as DiagnosticCode, i as DocTags, h as ScriptCompiler, l as loadCompiledModule, o as n, c as t };
34
+ function h(e, n) {
35
+ const t = m(e);
36
+ if (t.stopped) throw t.stopped;
37
+ if (++t.calls % y === 0 && Date.now() - t.started > n) throw t.stopped = d(`Run stopped: it exceeded the ${Math.round(n / 1e3)} s time limit.`), t.stopped;
38
+ }
39
+ function w(e, n = "Run cancelled.") {
40
+ m(e).stopped = d(n);
41
+ }
42
+ function M(e) {
43
+ a.delete(e);
44
+ }
45
+ function b(e) {
46
+ return e?.name === l;
47
+ }
48
+ async function C(e, n) {
49
+ const { loadCompiledModule: t } = await import("./D0CDObJV23Rxk8-r.mjs");
50
+ return t(e, n);
51
+ }
52
+ var s = null, u = null, r = null, o = null;
53
+ async function E() {
54
+ return o || (o = (async () => {
55
+ const e = await (await import("./og3Pk2ReS3UiORbF.mjs")).initialize();
56
+ if (!e) throw new Error("TypeScript could not be loaded. Check your connection and try again.");
57
+ return e;
58
+ })()).catch(() => {
59
+ o = null;
60
+ }), o;
61
+ }
62
+ var D = Object.freeze({ compile: async function(e) {
63
+ if (!e?.source) return { module: null, diagnostics: [] };
64
+ if (u && f.deepEqual(u, e)) return s;
65
+ const n = await (await (async function() {
66
+ if (r) return r;
67
+ const { TypeScriptCompiler: t } = await import("./Dhbf7vOdddc7aiOT.mjs");
68
+ return r = new t();
69
+ })()).compileModule(e);
70
+ return s = n, u = e, n;
71
+ }, lint: async function(e, n) {
72
+ if (!e) return [];
73
+ const [t, { lintScript: i }] = await Promise.all([E(), import("./B74CcyWYGHJL1E2s.mjs")]);
74
+ return i(t, e, n);
75
+ }, cleanup: function() {
76
+ r && (r.terminate(), r = null, s = null);
77
+ } });
78
+ export {
79
+ N as Constants,
80
+ x as DiagnosticCode,
81
+ L as DocTags,
82
+ A as RunGuard,
83
+ D as ScriptCompiler,
84
+ C as loadCompiledModule,
85
+ v as n,
86
+ X as t
87
+ };
@@ -0,0 +1,21 @@
1
+ import { readFileSync as e } from "node:fs";
2
+ import { dirname as o, join as a } from "node:path";
3
+ async function l() {
4
+ try {
5
+ return await import("typescript");
6
+ } catch (r) {
7
+ throw console.error("Error initializing Node TypeScript module:", r), r;
8
+ }
9
+ }
10
+ function s(r, t) {
11
+ const i = o(r.getDefaultLibFilePath({}));
12
+ try {
13
+ return e(a(i, t), "utf8");
14
+ } catch {
15
+ return;
16
+ }
17
+ }
18
+ export {
19
+ l as initialize,
20
+ s as readLibFile
21
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sheetxl/scripting",
3
3
  "description": "Scripting - Scripting engine for Macros and formulas; includes TypeScript and EsBuild.",
4
- "version": "0.7.28-beta.4",
4
+ "version": "0.8.0-beta.10",
5
5
  "license": "SEE LICENSE IN <LICENSE>",
6
6
  "type": "module",
7
7
  "exports": {
@@ -9,13 +9,12 @@
9
9
  "types": "./types/index.d.ts",
10
10
  "browser": "./browser/esm/index.mjs",
11
11
  "node": "./node/esm/index.mjs",
12
- "import": "./browser/esm/index.mjs",
13
- "require": "./browser/cjs/index.cjs"
12
+ "default": "./browser/esm/index.mjs"
14
13
  }
15
14
  },
16
15
  "types": "./types/index.d.ts",
17
16
  "module": "./browser/esm/index.mjs",
18
- "main": "./browser/cjs/index.cjs",
17
+ "main": "./browser/esm/index.mjs",
19
18
  "sideEffects": false,
20
19
  "engines": {
21
20
  "node": ">=22"
@@ -40,8 +39,8 @@
40
39
  "scripting"
41
40
  ],
42
41
  "dependencies": {
43
- "@sheetxl/primitives": "^0.7.28-beta.4",
44
- "@sheetxl/utils": "^0.7.28-beta.4"
42
+ "@sheetxl/primitives": "^0.8.0-beta.10",
43
+ "@sheetxl/utils": "^0.8.0-beta.10"
45
44
  },
46
45
  "peerDependencies": {
47
46
  "esbuild-wasm": ">=0.25.7",
@@ -49,6 +48,6 @@
49
48
  "vite": "^8.0.0"
50
49
  },
51
50
  "devDependencies": {
52
- "@types/node": "^26.1.2"
51
+ "@types/node": "^26.6.4"
53
52
  }
54
53
  }
@@ -3,5 +3,5 @@
3
3
  * resolving '@sheetxl/primitives' to a framework-controlled implementation.
4
4
  * Other imports are treated as external.
5
5
  */
6
- export declare function bundleScript(ts: typeof import('typescript'), codeAsString: string, entryPointId?: string, globalVariable?: string): Promise<string>;
6
+ export declare function bundleScript(ts: typeof import('typescript'), codeAsString: string, entryPointId?: string, globalVariable?: string, minify?: boolean): Promise<string>;
7
7
  //# sourceMappingURL=Bundler.d.ts.map
@@ -0,0 +1,11 @@
1
+ import { default as ts } from 'typescript';
2
+ /**
3
+ * An emit transformer that puts `__SHEETXL.checkRun?.(key, timeoutMs)` at the top of every loop body
4
+ * and every function body, so a runaway run can be stopped from inside (see `RunGuard`).
5
+ *
6
+ * @remarks
7
+ * Loops are what run away; function bodies cover recursion. An arrow's expression body becomes a
8
+ * block that checks and returns. A directive prologue (`'use strict'`) stays first.
9
+ */
10
+ export declare function createRunGuardTransformer(ts: typeof import('typescript'), key: string, timeoutMs: number): ts.TransformerFactory<ts.SourceFile>;
11
+ //# sourceMappingURL=insertRunGuard.d.ts.map
@@ -1,4 +1,10 @@
1
1
  type TypeScriptModule = typeof import('typescript');
2
2
  export declare function initialize(): Promise<TypeScriptModule>;
3
+ /**
4
+ * The browser has no copy of TypeScript's library declarations, so a type-checking compile cannot
5
+ * run here; the editor's own language worker covers semantic checking interactively. Always
6
+ * `undefined` — see the node half for the contract.
7
+ */
8
+ export declare function readLibFile(_ts: TypeScriptModule, _fileName: string): string | undefined;
3
9
  export {};
4
10
  //# sourceMappingURL=typescript.browser.d.ts.map
@@ -1,4 +1,15 @@
1
1
  type TypeScriptModule = typeof import('typescript');
2
2
  export declare function initialize(): Promise<TypeScriptModule>;
3
+ /**
4
+ * Reads one of TypeScript's own library declaration files (`lib.es2020.d.ts`, ...) from the
5
+ * installed package, or `undefined` when there is no such file.
6
+ *
7
+ * @remarks
8
+ * Synchronous because a compiler host's `readFile` is. Under Node the libs sit beside the module
9
+ * on disk, so a type-checking compile can resolve `lib` references the way `tsc` does; the browser
10
+ * half of this conditional export has no such directory and answers `undefined`, which is how the
11
+ * compiler learns that semantic checking is unavailable there.
12
+ */
13
+ export declare function readLibFile(ts: TypeScriptModule, fileName: string): string | undefined;
3
14
  export {};
4
15
  //# sourceMappingURL=typescript.node.d.ts.map
@@ -31,6 +31,13 @@ export interface AnalyzeOptions {
31
31
  * case-insensitively.
32
32
  */
33
33
  builtInNames?: readonly string[];
34
+ /** Whether the source is the built-in library - see `CompileOptions.isBuiltIn`. */
35
+ isBuiltIn?: boolean;
36
+ /**
37
+ * Code that runs once - see `CompileOptions.lenient`. The default export IS the entry, so its
38
+ * first parameter, left untyped, is the script context (`export default function main(ctx)`).
39
+ */
40
+ lenient?: boolean;
34
41
  }
35
42
  /**
36
43
  * Walks an already-parsed/checked source file and applies SheetXL's semantic authoring rules.
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Stops a runaway run from inside its own code.
3
+ *
4
+ * @remarks
5
+ * A script runs on the host's thread, so nothing outside it can interrupt a synchronous loop. A
6
+ * compile that asks for a guard (`CompileOptions.runGuard`) inserts `check(key, timeoutMs)` at the
7
+ * top of every loop body and function body; the check throws once the run has been going longer
8
+ * than `timeoutMs`, or once {@link abort} has been called for its key.
9
+ *
10
+ * The key and the limit are compiled into the module, so any host that executes it enforces the
11
+ * limit — the MCP server in-process, the VS Code webview for an attended session — and concurrent
12
+ * runs never read each other's state. The clock starts at the first check, which is the entry
13
+ * function's own.
14
+ *
15
+ * Not covered: a single engine call that never returns, with no user loop around it.
16
+ */
17
+ /** `error.name` of what a stopped run throws. */
18
+ export declare const RUN_INTERRUPTED = "RunInterrupted";
19
+ /**
20
+ * The compiled-in check. Throws when the run keyed `key` has exceeded `timeoutMs` or was aborted.
21
+ */
22
+ export declare function check(key: string, timeoutMs: number): void;
23
+ /**
24
+ * Stops the run keyed `key` at its next check — including a run that has not reached its first one.
25
+ */
26
+ export declare function abort(key: string, reason?: string): void;
27
+ /** Forgets a finished run. */
28
+ export declare function release(key: string): void;
29
+ /** True when `error` is what {@link check} throws. */
30
+ export declare function isInterrupted(error: unknown): boolean;
31
+ //# sourceMappingURL=RunGuard.d.ts.map
@@ -1,2 +1,3 @@
1
1
  export * as Constants from './Constants';
2
+ export * as RunGuard from './RunGuard';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -15,6 +15,14 @@ export interface CompileOptions {
15
15
  * This is useful for validation
16
16
  */
17
17
  disableBundle?: boolean;
18
+ /**
19
+ * If true, the bundle is minified. For a module that is stored (a workbook's scripts, a `.sxlm`).
20
+ *
21
+ * @remarks
22
+ * Off by default: code that is only run keeps its own names, so a runtime error reads as the
23
+ * author wrote it (`wb.getSheet is not a function`, not `a.getSheet`).
24
+ */
25
+ minify?: boolean;
18
26
  /**
19
27
  * If true, this will not include the source map in the compiled module.
20
28
  */
@@ -38,6 +46,48 @@ export interface CompileOptions {
38
46
  * without a position. Compared case-insensitively.
39
47
  */
40
48
  builtInNames?: readonly string[];
49
+ /**
50
+ * Whether the source IS the built-in library rather than a script written against it.
51
+ *
52
+ * @remarks
53
+ * A built-in name is resolved before a formula reads it any other way, so it may take a name
54
+ * that is refused to a user function - `LOG10`, which also reads as a cell address.
55
+ */
56
+ isBuiltIn?: boolean;
57
+ /**
58
+ * The ambient declarations the script is written against — the shipped `scripting.d.ts`.
59
+ *
60
+ * @remarks
61
+ * Supplied, the compile type-checks the script against that surface and reports what TypeScript
62
+ * finds: a member the receiver does not have (with TypeScript's own "did you mean"), a wrong
63
+ * argument, an unknown name. Omitted, the compile reports syntax and authoring rules only. The
64
+ * check also needs TypeScript's own libs, which only Node has on disk; a browser compile ignores
65
+ * this option and leaves semantic checking to the editor's language worker.
66
+ */
67
+ ambientTypes?: string;
68
+ /**
69
+ * Compile in a stop check, for a host running agent-written code on its own thread.
70
+ *
71
+ * @remarks
72
+ * Every loop body and function body calls `RunGuard.check(key, timeoutMs)`, which throws once the
73
+ * run has gone on longer than `timeoutMs` or `RunGuard.abort(key)` was called. `key` identifies
74
+ * this compile's run, so give each run its own. Omitted, the module carries no checks.
75
+ */
76
+ runGuard?: {
77
+ key: string;
78
+ timeoutMs: number;
79
+ };
80
+ /**
81
+ * Check the source as code that runs once, not as code kept to be run again.
82
+ *
83
+ * @remarks
84
+ * For an ad hoc run (`sheetxl -e`, the MCP `run` tool). Annotations are not required: a default
85
+ * export's untyped first parameter is the script context, and a missing type is not reported.
86
+ *
87
+ * A run is not type-checked before it executes - leave {@link ambientTypes} out. The types are
88
+ * there to explain a run that went wrong, which is `diagnoseRun` in `@sheetxl/runner`.
89
+ */
90
+ lenient?: boolean;
41
91
  }
42
92
  /**
43
93
  * The result of a compile operation: the compiled artifact plus this compile's positioned