@sheetxl/scripting 0.8.0-beta.1 → 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 -148
  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 +20 -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 -3
  33. package/types/src/type/Types.d.ts +45 -5
  34. package/browser/cjs/BJpcKKDPQlQbi5O5.cjs +0 -7
  35. package/browser/cjs/Bu4cZ8iSZ3rij-oV.cjs +0 -1
  36. package/browser/cjs/BvG8N7G_8CXIAlT-.cjs +0 -1
  37. package/browser/cjs/CY8w1D0xPdaNysFJ.cjs +0 -1
  38. package/browser/cjs/C_7w8EJZpHw8ueuq.cjs +0 -1
  39. package/browser/cjs/C_IEgjM-hSJCv6Gm.cjs +0 -1
  40. package/browser/cjs/CctaCN_w3o34V9AR.cjs +0 -1
  41. package/browser/cjs/DIf4GvYEqb4ayb6a.cjs +0 -1
  42. package/browser/cjs/DcNeWEf5ZqALrCr4.cjs +0 -1
  43. package/browser/cjs/_PKWNtAymIZGtvCb.cjs +0 -21
  44. package/browser/cjs/index.cjs +0 -1
  45. package/browser/esm/1kUe1fPM50LHqYNI.mjs +0 -15
  46. package/browser/esm/3YV545IwjRqG3c1v.mjs +0 -27
  47. package/browser/esm/CFj5DZ16U361ltLj.mjs +0 -8
  48. package/browser/esm/CSXzDPdxAeONd9Br.mjs +0 -152
  49. package/browser/esm/DCIZplzRAR9pzoyD.mjs +0 -12
  50. package/browser/esm/DL0Hj5P777IybKK1.mjs +0 -25
  51. package/browser/esm/Dn3tZ47l4kfqm82M.mjs +0 -434
  52. package/browser/esm/Im_056DAe1M8tSZK.mjs +0 -23
  53. package/browser/esm/bJcM1PsEX9VZuqnT.mjs +0 -87
  54. package/browser/esm/v5FtHwExzUecgxho.mjs +0 -112
  55. package/node/esm/CFj5DZ16U361ltLj.mjs +0 -8
  56. package/node/esm/CL56uy8tfvhJRKYS.mjs +0 -434
  57. package/node/esm/CZgThiQ_9yYAaYaW.mjs +0 -152
  58. package/node/esm/DDDZ5Wv9-gK2v6Qt.mjs +0 -23
  59. package/node/esm/DEIcuGll5aCjPisP.mjs +0 -27
  60. package/node/esm/DOv0wuhb-kNvUT7-.mjs +0 -12
  61. package/node/esm/NgoqymNyfjBf3Vbn.mjs +0 -17
  62. package/node/esm/P5z0UPrc8__6uFCR.mjs +0 -14
@@ -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,152 +1,87 @@
1
- /**
2
- * @license @sheetxl/scripting - Scripting - Scripting engine for Macros and formulas; includes TypeScript and EsBuild. - v0.8.0-beta.1
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
- UnknownCompat: "SXL3004",
42
- MissingSummary: "SXL9001",
43
- MissingParamDescription: "SXL9002",
44
- MissingReturns: "SXL9003"
45
- }), i = [
46
- {
47
- name: "summary",
48
- group: "sheetxl",
49
- description: "Short description shown in function tooltips and autocomplete."
50
- },
51
- {
52
- name: "param",
53
- group: "jsdoc",
54
- description: "Document a parameter. A string union type becomes a dropdown of allowed options.",
55
- snippet: "param ${1:name} ${2:description}"
56
- },
57
- {
58
- name: "returns",
59
- aliases: ["return"],
60
- group: "jsdoc",
61
- description: "Describe the return value."
62
- },
63
- {
64
- name: "category",
65
- group: "sheetxl",
66
- description: "Group the function under a category in the function list.",
67
- snippet: "category ${1:name}"
68
- },
69
- {
70
- name: "name",
71
- group: "sheetxl",
72
- description: "Override the displayed function name.",
73
- snippet: "name ${1:NAME}"
74
- },
75
- {
76
- name: "description",
77
- group: "sheetxl",
78
- description: "A longer description of the function."
79
- },
80
- {
81
- name: "deprecated",
82
- group: "sheetxl",
83
- standalone: !0,
84
- description: "Mark the function as deprecated (optionally with a reason)."
85
- },
86
- {
87
- name: "hidden",
88
- group: "sheetxl",
89
- standalone: !0,
90
- description: "Hide the function from the function list."
91
- },
92
- {
93
- name: "compat",
94
- group: "sheetxl",
95
- description: "Opt into a named engine compatibility behavior (`noReferenceLift`, `noMemberFilter`) or a family alias (`atp` = both).",
96
- snippet: "compat ${1:atp}"
97
- },
98
- {
99
- name: "example",
100
- group: "jsdoc",
101
- description: "Provide a usage example."
102
- },
103
- {
104
- name: "see",
105
- group: "jsdoc",
106
- description: "Reference a related function or link."
107
- }
108
- ], a = (() => {
109
- let e = /* @__PURE__ */ new Map();
110
- for (let t of i) if (e.set(t.name, t), t.aliases) for (let n of t.aliases) e.set(n, t);
111
- 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;
112
10
  })();
113
- function o(e) {
114
- return !0 === function(e) {
115
- if (!e) return;
116
- let t = (e.startsWith("@") ? e.slice(1) : e).toLowerCase();
117
- return a.get(t);
118
- }(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;
119
17
  }
120
- var s = n({ GLOBAL_CONTEXT_VARIABLE: () => c }), c = "__SHEETXL";
121
- async function l(e, t) {
122
- let { loadCompiledModule: n } = await import("./NgoqymNyfjBf3Vbn.mjs");
123
- 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;
124
22
  }
125
- var u = null, d = null, f = null, p = null;
126
- async function m() {
127
- return p ||= (async () => (await import("./P5z0UPrc8__6uFCR.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;
128
33
  }
129
- var h = Object.freeze({
130
- compile: async function(t) {
131
- if (!t?.source) return {
132
- module: null,
133
- diagnostics: []
134
- };
135
- if (d && e.deepEqual(d, t)) return u;
136
- let n = await (await async function() {
137
- if (f) return f;
138
- let { TypeScriptCompiler: e } = await import("./DEIcuGll5aCjPisP.mjs");
139
- return f = new e();
140
- }()).compileModule(t);
141
- return u = n, d = t, n;
142
- },
143
- lint: async function(e, t) {
144
- if (!e) return [];
145
- let [n, { lintScript: r }] = await Promise.all([m(), import("./CL56uy8tfvhJRKYS.mjs")]);
146
- return r(n, e, t);
147
- },
148
- cleanup: function() {
149
- f && (f.terminate(), f = null, u = null);
150
- }
151
- });
152
- 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.8.0-beta.1",
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.8.0-beta.1",
44
- "@sheetxl/utils": "^0.8.0-beta.1"
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,7 +31,27 @@ 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
  }
42
+ /**
43
+ * Walks an already-parsed/checked source file and applies SheetXL's semantic authoring rules.
44
+ *
45
+ * @param ts The TypeScript module (compiler API).
46
+ * @param sourceFile The script source file (must be created with `setParentNodes = true`).
47
+ * @param checker The type checker from the program containing `sourceFile`.
48
+ * @param options {@link AnalyzeOptions} — host facts the rules need.
49
+ *
50
+ * @remarks
51
+ * This is the single environment-agnostic engine. It does not emit, bundle, touch the DOM, or read
52
+ * the filesystem. {@link compileModule} calls it to build declarations and decide whether to emit;
53
+ * {@link lintScript} calls it to produce diagnostics for editors/CLIs.
54
+ */
35
55
  export declare function analyzeModule(ts: typeof import('typescript'), sourceFile: ts.SourceFile, checker: ts.TypeChecker, options?: AnalyzeOptions): Analysis;
36
56
  /**
37
57
  * Lints a script source string and returns positioned diagnostics.
@@ -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