@sheetxl/scripting 0.8.0-beta.5 → 0.8.0-beta.7

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.
@@ -4,7 +4,7 @@ var t = class {
4
4
  }
5
5
  async getWorkerWrapper() {
6
6
  if (this.workerWrapper) return this.workerWrapper;
7
- const { createCompilerWorker: r } = await import("./DyZ4_kNN_urjQyjU.mjs");
7
+ const { createCompilerWorker: r } = await import("./ChXuG8IaqC3qeOH3.mjs");
8
8
  return this.workerWrapper = await r(), this.workerWrapper;
9
9
  }
10
10
  async compileModule(r) {
@@ -50,7 +50,7 @@ var k = Object.freeze({ compile: async function(t) {
50
50
  if (l && f.deepEqual(l, t)) return a;
51
51
  const n = await (await (async function() {
52
52
  if (o) return o;
53
- const { TypeScriptCompiler: e } = await import("./DaQ0EpmIY8CRghRW.mjs");
53
+ const { TypeScriptCompiler: e } = await import("./DJmAxtGDsADOLRhd.mjs");
54
54
  return o = new e();
55
55
  })()).compileModule(t);
56
56
  return a = n, l = t, n;
@@ -0,0 +1,161 @@
1
+ import { DiagnosticCode as U, t as x } from "./index.mjs";
2
+ import { analyzeModule as V } from "./byRhqE863Yd8YyB5.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
+ };
@@ -12,7 +12,7 @@ var o = class {
12
12
  }
13
13
  };
14
14
  async function a() {
15
- const { compileModule: e } = await import("./BRuHQvNZfkRtcqXr.mjs"), t = new o((r) => e(r));
15
+ const { compileModule: e } = await import("./Bj3F3BUcrLYUg3Dv.mjs"), t = new o((r) => e(r));
16
16
  return await t.start(), t;
17
17
  }
18
18
  export {
@@ -4,7 +4,7 @@ var t = class {
4
4
  }
5
5
  async getWorkerWrapper() {
6
6
  if (this.workerWrapper) return this.workerWrapper;
7
- const { createCompilerWorker: r } = await import("./DiwsulR7CwM-KFcK.mjs");
7
+ const { createCompilerWorker: r } = await import("./DlnqsBJLAzuuPNOx.mjs");
8
8
  return this.workerWrapper = await r(), this.workerWrapper;
9
9
  }
10
10
  async compileModule(r) {
@@ -64,7 +64,7 @@ var D = Object.freeze({ compile: async function(e) {
64
64
  if (u && f.deepEqual(u, e)) return s;
65
65
  const n = await (await (async function() {
66
66
  if (r) return r;
67
- const { TypeScriptCompiler: t } = await import("./CZo429AzOkBwGTWk.mjs");
67
+ const { TypeScriptCompiler: t } = await import("./Dp_cerCAQ8jL3dyP.mjs");
68
68
  return r = new t();
69
69
  })()).compileModule(e);
70
70
  return s = n, u = e, n;
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.5",
4
+ "version": "0.8.0-beta.7",
5
5
  "license": "SEE LICENSE IN <LICENSE>",
6
6
  "type": "module",
7
7
  "exports": {
@@ -40,8 +40,8 @@
40
40
  "scripting"
41
41
  ],
42
42
  "dependencies": {
43
- "@sheetxl/primitives": "^0.8.0-beta.5",
44
- "@sheetxl/utils": "^0.8.0-beta.5"
43
+ "@sheetxl/primitives": "^0.8.0-beta.7",
44
+ "@sheetxl/utils": "^0.8.0-beta.7"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "esbuild-wasm": ">=0.25.7",
@@ -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
@@ -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
  */
@@ -73,16 +81,11 @@ export interface CompileOptions {
73
81
  * Check the source as code that runs once, not as code kept to be run again.
74
82
  *
75
83
  * @remarks
76
- * For an agent's ad hoc run. Only a finding that would fail at run time stops the run; the rest
77
- * are reported as warnings:
78
- *
79
- * - Annotations are not required: an untyped parameter is `any` (no `noImplicitAny`), and a
80
- * missing type on an entry is not reported.
81
- * - A member the receiver does not have, read where a missing member is expected - `r.getFormat?.()`,
82
- * `r.getFormulas ? … : …`, `typeof r.x` - is a probe, and a warning: it reads `undefined`.
83
- * - A condition on a function that is never called (TS2774) is a warning.
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.
84
86
  *
85
- * Only meaningful with {@link ambientTypes}; without them there is no semantic check to relax.
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`.
86
89
  */
87
90
  lenient?: boolean;
88
91
  }
@@ -1,29 +0,0 @@
1
- const k=require("./C83wXnFq94exmYt9.cjs"),U=require("./Bn3oEXST6uP5oPU2.cjs"),Q=require("./ZKJrH74dcPwEAgmF.cjs"),N=require("./DLi7EA_dfez5uwwY.cjs");let J=require("@sheetxl/utils");var g=null,v=null,H={compilerOptions:{target:"esnext"}};async function Y(t,d,u="/script.js",c=k.GLOBAL_CONTEXT_VARIABLE){try{const e=await(async function(){if(g)return g;if(v){if(await v,!g)throw new Error("ESBuild initialization promise resolved, but instance is not available.");return g}let r,s;v=new Promise((i,f)=>{r=i,s=f});try{const{initialize:i}=await Promise.resolve().then(()=>require("./DcxyEv9XIOa5qfCm.cjs"));return g=await i(),r(),g}catch(i){throw console.error("Failed to import or initialize esbuild:",i),v=null,s(i),i}})(),a="@sheetxl/primitives",l=`
2
- export const FormulaContext = globalThis.${c}?.FormulaContext;
3
- export const ScalarType = globalThis.${c}?.ScalarType;
4
- export const Observable = globalThis.${c}?.Observable;
5
- export const IRange = globalThis.${c}?.IRange;
6
- export const FormulaError = globalThis.${c}?.FormulaError;
7
- // Add more exports as needed
8
- `,o=await e.build({entryPoints:[u],bundle:!0,write:!1,format:"esm",plugins:[{name:"sheetxl-esbuild-in-memory",setup(r){const s="sheetxl-"+new Date().getTime();r.onResolve({filter:new RegExp(`^(${u.replace("/","\\/")}|${a})$`)},i=>({path:i.path,namespace:s})),r.onResolve({filter:/.*/},i=>{if(i.namespace!==s)return console.warn(`esbuild: Treating import "${i.path}" as external.`),{path:i.path,external:!0}}),r.onLoad({filter:/.*/,namespace:s},i=>{let f;if(i.path===u)f=d;else{if(i.path!==a)return{errors:[{text:`Cannot load unknown path in ${s}: ${i.path}`}]};f=l}return{contents:f,loader:"ts"}})}}],sourcemap:"inline",tsconfigRaw:H,minify:!0,platform:"neutral"});if(o.outputFiles&&o.outputFiles.length>0)return o.outputFiles[0].text;throw o.errors&&o.errors.length>0?new Error(`esbuild bundling failed: ${o.errors.map(r=>r.text).join(`
9
- `)}`):new Error("esbuild did not produce an output file.")}catch(e){throw console.error("esbuild bundling process failed:",e),e}}function Z(t,d,u){return c=>{const e=c.factory,a=()=>e.createExpressionStatement(e.createCallChain(e.createPropertyAccessExpression(e.createIdentifier(k.GLOBAL_CONTEXT_VARIABLE),"checkRun"),e.createToken(t.SyntaxKind.QuestionDotToken),void 0,[e.createStringLiteral(d),e.createNumericLiteral(u)])),l=r=>{const s=r.statements;let i=0;for(;i<s.length&&t.isExpressionStatement(s[i])&&t.isStringLiteral(s[i].expression);)i++;return e.updateBlock(r,[...s.slice(0,i),a(),...s.slice(i)])},o=r=>{if((s=>t.isForStatement(s)||t.isForInStatement(s)||t.isForOfStatement(s)||t.isWhileStatement(s)||t.isDoStatement(s))(r)){const s=r.statement;return t.visitEachChild(r,i=>{const f=o(i);return i===s?(m=f,t.isBlock(m)?l(m):e.createBlock([a(),m],!0)):f;var m},c)}if(t.isFunctionLike(r)&&r.body){const s=r.body;return t.visitEachChild(r,i=>{const f=o(i);return i===s?(m=f,t.isBlock(m)?l(m):e.createBlock([a(),e.createReturnStatement(m)],!0)):f;var m},c)}return t.visitEachChild(r,o,c)};return r=>t.visitNode(r,o)}}var ee=new Set(["TS2339","TS2551"]);function te(t,d,u){let c=null;const e=a=>{u<a.getStart(d)||u>=a.end||(a.getStart(d)===u&&(c=a),t.forEachChild(a,e))};return t.forEachChild(d,e),c}function ne(t,d){const u=d.parent;if(!u||!t.isPropertyAccessExpression(u)||u.name!==d)return!1;let c=u,e=u.parent;for(;e&&(t.isParenthesizedExpression(e)||t.isNonNullExpression(e));)c=e,e=e.parent;if(!e)return!1;if((t.isCallExpression(e)||t.isPropertyAccessExpression(e)||t.isElementAccessExpression(e))&&e.expression===c)return!!e.questionDotToken;if(t.isTypeOfExpression(e))return!0;if(t.isPrefixUnaryExpression(e))return e.operator===t.SyntaxKind.ExclamationToken;if(t.isConditionalExpression(e))return e.condition===c;if(t.isIfStatement(e)||t.isWhileStatement(e)||t.isDoStatement(e))return e.expression===c;if(t.isBinaryExpression(e)){const a=e.operatorToken.kind,l=t.SyntaxKind;if(a===l.AmpersandAmpersandToken||a===l.BarBarToken||a===l.QuestionQuestionToken)return e.left===c;if(a===l.EqualsEqualsEqualsToken||a===l.ExclamationEqualsEqualsToken||a===l.EqualsEqualsToken||a===l.ExclamationEqualsToken)return((o,r)=>r.kind===o.SyntaxKind.NullKeyword||o.isIdentifier(r)&&r.text==="undefined")(t,e.left===c?e.right:e.left)}return!1}var ie=async()=>`
10
- interface FirstTest {
11
- isTrue?: boolean;
12
- }
13
- `,w=null,R="sheetxl.d.ts",$="sheetxl-modules.d.ts",re=["lib.webworker.d.ts","lib.es2020.d.ts","lib.esnext.asynciterable.d.ts"],M=new Map,B=null,P=null;async function oe(){return P||(P=Promise.resolve().then(()=>require("./D5np5QScDyDDD_WJ.cjs")).then(async t=>{const d=await _();return t.readLibFile(d,"lib.es5.d.ts")!==void 0?t.readLibFile:null})),P}async function _(){if(w)return w;try{const t=await(await Promise.resolve().then(()=>require("./D5np5QScDyDDD_WJ.cjs"))).initialize();if(!t)throw new Error("TypeScript could not be loaded. Check your connection and try again.");return t}catch(t){throw w=null,t}finally{w=null}}exports.compileModule=async function(t){const d=t?.source??null;if(!d)return{module:null,diagnostics:[]};const u=(t.disableBundle||t.declarationsOnly)??!1,[c,e,a]=await Promise.all([ie(),_(),t.ambientTypes?oe():null]),l=a?t.ambientTypes??null:null;let o="";const r={allowJs:!0,declaration:!1,sourceMap:!1,inlineSourceMap:!1,inlineSources:!1,isolatedModules:!0,preserveConstEnums:!1,module:99,noResolve:!0,emitDeclarationOnly:!1,target:e.ScriptTarget.ES2020,...l?{lib:re,skipLibCheck:!0,strict:!0}:{},...l&&t.lenient?{noImplicitAny:!1}:{}},s="script",i=`${s}.ts`,f="lib.d.ts",m="global.d.ts",y={[i]:d,[f]:`
14
- /**
15
- * Represents the completion of an asynchronous operation
16
- */
17
- interface Promise<T> {
18
- /**
19
- * Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
20
- * resolved value cannot be modified from the callback.
21
- * @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
22
- * @returns A Promise for the completion of the callback.
23
- */
24
- finally(onfinally?: (() => void) | undefined | null): Promise<T>;
25
- }
26
- `,[m]:c,...l?{[R]:l,[$]:`declare module '@sheetxl/primitives' { export = SheetXL; }
27
- `}:{}},C=n=>y[n]??(a&&n.startsWith("lib.")?a(e,n):void 0),z={getSourceFile:(n,b,D,h)=>{if(n===R)return B?.text!==l&&(B={text:l,file:e.createSourceFile(n,l,e.ScriptTarget.Latest,!1)}),B.file;if(y[n]===void 0){let p=M.get(n);if(!p){const x=C(n);if(x===void 0)return;p=e.createSourceFile(n,x,e.ScriptTarget.Latest,!1),M.set(n,p)}return p}return e.createSourceFile(n,y[n],e.ScriptTarget.Latest,!0)},fileExists:n=>C(n)!==void 0,readFile:C,writeFile:(n,b)=>{y[n]=b},getCurrentDirectory:()=>"./",getCanonicalFileName:n=>n,useCaseSensitiveFileNames:()=>!0,getDefaultLibFileName:n=>f,getNewLine:()=>`
28
- `},E=e.createProgram([i,m,...l?[R,$]:[]],r,z),j=E.getTypeChecker(),T=E.getSourceFile(i),F=t.runGuard;E.emit(void 0,void 0,void 0,void 0,F?{before:[Z(e,F.key,F.timeoutMs)]}:void 0),o=y[`${s}.js`]??"";const O=n=>({start:n.start??0,length:n.length??0,severity:n.category===e.DiagnosticCategory.Warning?"warning":"error",code:`TS${n.code}`,message:e.flattenDiagnosticMessageText(n.messageText,`
29
- `)}),G=E.getSyntacticDiagnostics(T).map(O),K=l?E.getSemanticDiagnostics(T).filter(n=>n.category===e.DiagnosticCategory.Error||n.category===e.DiagnosticCategory.Warning).map(O):[],L=Q.analyzeModule(e,T,j,{builtInNames:t.builtInNames,isBuiltIn:t.isBuiltIn,lenient:!!l&&t.lenient});let S=[...G,...K,...L.diagnostics];l&&t.lenient&&(S=(function(n,b,D){const h=[];for(const p of D)if(p.code!==U.DiagnosticCode.MissingType)if(p.severity!=="error")h.push(p);else if(p.code==="TS2774")h.push({...p,severity:"warning"});else if(ee.has(p.code)){const x=te(n,b,p.start);h.push(x&&ne(n,x)?{...p,severity:"warning",message:`${p.message} Read as a probe, it is undefined.`}:p)}else h.push(p);return h})(e,T,S));const V=L.functions,q=L.autoRun,W=S.some(n=>n.severity==="error"),X=`${J.CommonUtils.uuidV4()}-script`;let A=null;if(W)o="";else{try{u||(o=await Y(0,o,s))}catch{console.warn("Error bundling script")}const n=o.indexOf(N.SOURCEMAP_IDENTIFIER);n>-1&&(A=o.substring(n+N.SOURCEMAP_IDENTIFIER.length+1,o.length),o=o.substring(0,n),o=o.replaceAll("globalThis."+k.GLOBAL_CONTEXT_VARIABLE,k.GLOBAL_CONTEXT_VARIABLE))}const I={functions:V,commitId:X,source:d,language:"typescript",compiled:o};return A&&(I.sourceMap=A),q&&(I.autoRun=q),{module:I,diagnostics:S}};
@@ -1,197 +0,0 @@
1
- import { n as k } from "./BxiAkxNyUQseLNBv.mjs";
2
- import { r as V } from "./B73J41HhbJvswDz1.mjs";
3
- import { analyzeModule as X } from "./BXhWTnlrRShaRGS5.mjs";
4
- import { t as M } from "./4VkvY2rXOd49uHcQ.mjs";
5
- import { CommonUtils as H } from "@sheetxl/utils";
6
- var g = null, E = null, Y = { compilerOptions: { target: "esnext" } };
7
- async function Z(t, d, u = "/script.js", c = k) {
8
- try {
9
- const e = await (async function() {
10
- if (g) return g;
11
- if (E) {
12
- if (await E, !g) throw new Error("ESBuild initialization promise resolved, but instance is not available.");
13
- return g;
14
- }
15
- let r, s;
16
- E = new Promise((i, m) => {
17
- r = i, s = m;
18
- });
19
- try {
20
- const { initialize: i } = await import("./D9jTpNifykCuQkTL.mjs");
21
- return g = await i(), r(), g;
22
- } catch (i) {
23
- throw console.error("Failed to import or initialize esbuild:", i), E = null, s(i), i;
24
- }
25
- })(), a = "@sheetxl/primitives", l = `
26
- export const FormulaContext = globalThis.${c}?.FormulaContext;
27
- export const ScalarType = globalThis.${c}?.ScalarType;
28
- export const Observable = globalThis.${c}?.Observable;
29
- export const IRange = globalThis.${c}?.IRange;
30
- export const FormulaError = globalThis.${c}?.FormulaError;
31
- // Add more exports as needed
32
- `, o = await e.build({ entryPoints: [u], bundle: !0, write: !1, format: "esm", plugins: [{ name: "sheetxl-esbuild-in-memory", setup(r) {
33
- const s = "sheetxl-" + (/* @__PURE__ */ new Date()).getTime();
34
- r.onResolve({ filter: new RegExp(`^(${u.replace("/", "\\/")}|${a})$`) }, (i) => ({ path: i.path, namespace: s })), r.onResolve({ filter: /.*/ }, (i) => {
35
- if (i.namespace !== s) return console.warn(`esbuild: Treating import "${i.path}" as external.`), { path: i.path, external: !0 };
36
- }), r.onLoad({ filter: /.*/, namespace: s }, (i) => {
37
- let m;
38
- if (i.path === u) m = d;
39
- else {
40
- if (i.path !== a) return { errors: [{ text: `Cannot load unknown path in ${s}: ${i.path}` }] };
41
- m = l;
42
- }
43
- return { contents: m, loader: "ts" };
44
- });
45
- } }], sourcemap: "inline", tsconfigRaw: Y, minify: !0, platform: "neutral" });
46
- if (o.outputFiles && o.outputFiles.length > 0) return o.outputFiles[0].text;
47
- throw o.errors && o.errors.length > 0 ? new Error(`esbuild bundling failed: ${o.errors.map((r) => r.text).join(`
48
- `)}`) : new Error("esbuild did not produce an output file.");
49
- } catch (e) {
50
- throw console.error("esbuild bundling process failed:", e), e;
51
- }
52
- }
53
- function _(t, d, u) {
54
- return (c) => {
55
- const e = c.factory, a = () => e.createExpressionStatement(e.createCallChain(e.createPropertyAccessExpression(e.createIdentifier(k), "checkRun"), e.createToken(t.SyntaxKind.QuestionDotToken), void 0, [e.createStringLiteral(d), e.createNumericLiteral(u)])), l = (r) => {
56
- const s = r.statements;
57
- let i = 0;
58
- for (; i < s.length && t.isExpressionStatement(s[i]) && t.isStringLiteral(s[i].expression); ) i++;
59
- return e.updateBlock(r, [...s.slice(0, i), a(), ...s.slice(i)]);
60
- }, o = (r) => {
61
- if (((s) => t.isForStatement(s) || t.isForInStatement(s) || t.isForOfStatement(s) || t.isWhileStatement(s) || t.isDoStatement(s))(r)) {
62
- const s = r.statement;
63
- return t.visitEachChild(r, (i) => {
64
- const m = o(i);
65
- return i === s ? (f = m, t.isBlock(f) ? l(f) : e.createBlock([a(), f], !0)) : m;
66
- var f;
67
- }, c);
68
- }
69
- if (t.isFunctionLike(r) && r.body) {
70
- const s = r.body;
71
- return t.visitEachChild(r, (i) => {
72
- const m = o(i);
73
- return i === s ? (f = m, t.isBlock(f) ? l(f) : e.createBlock([a(), e.createReturnStatement(f)], !0)) : m;
74
- var f;
75
- }, c);
76
- }
77
- return t.visitEachChild(r, o, c);
78
- };
79
- return (r) => t.visitNode(r, o);
80
- };
81
- }
82
- var ee = /* @__PURE__ */ new Set(["TS2339", "TS2551"]);
83
- function te(t, d, u) {
84
- let c = null;
85
- const e = (a) => {
86
- u < a.getStart(d) || u >= a.end || (a.getStart(d) === u && (c = a), t.forEachChild(a, e));
87
- };
88
- return t.forEachChild(d, e), c;
89
- }
90
- function ne(t, d) {
91
- const u = d.parent;
92
- if (!u || !t.isPropertyAccessExpression(u) || u.name !== d) return !1;
93
- let c = u, e = u.parent;
94
- for (; e && (t.isParenthesizedExpression(e) || t.isNonNullExpression(e)); ) c = e, e = e.parent;
95
- if (!e) return !1;
96
- if ((t.isCallExpression(e) || t.isPropertyAccessExpression(e) || t.isElementAccessExpression(e)) && e.expression === c) return !!e.questionDotToken;
97
- if (t.isTypeOfExpression(e)) return !0;
98
- if (t.isPrefixUnaryExpression(e)) return e.operator === t.SyntaxKind.ExclamationToken;
99
- if (t.isConditionalExpression(e)) return e.condition === c;
100
- if (t.isIfStatement(e) || t.isWhileStatement(e) || t.isDoStatement(e)) return e.expression === c;
101
- if (t.isBinaryExpression(e)) {
102
- const a = e.operatorToken.kind, l = t.SyntaxKind;
103
- if (a === l.AmpersandAmpersandToken || a === l.BarBarToken || a === l.QuestionQuestionToken) return e.left === c;
104
- if (a === l.EqualsEqualsEqualsToken || a === l.ExclamationEqualsEqualsToken || a === l.EqualsEqualsToken || a === l.ExclamationEqualsToken) return ((o, r) => r.kind === o.SyntaxKind.NullKeyword || o.isIdentifier(r) && r.text === "undefined")(t, e.left === c ? e.right : e.left);
105
- }
106
- return !1;
107
- }
108
- var ie = async () => `
109
- interface FirstTest {
110
- isTrue?: boolean;
111
- }
112
- `, v = null, P = "sheetxl.d.ts", q = "sheetxl-modules.d.ts", re = ["lib.webworker.d.ts", "lib.es2020.d.ts", "lib.esnext.asynciterable.d.ts"], O = /* @__PURE__ */ new Map(), R = null, B = null;
113
- async function oe() {
114
- return B || (B = import("./B_2CC0NvNtPBw_ad.mjs").then(async (t) => {
115
- const d = await z();
116
- return t.readLibFile(d, "lib.es5.d.ts") !== void 0 ? t.readLibFile : null;
117
- })), B;
118
- }
119
- async function z() {
120
- if (v) return v;
121
- try {
122
- const t = await (await import("./B_2CC0NvNtPBw_ad.mjs")).initialize();
123
- if (!t) throw new Error("TypeScript could not be loaded. Check your connection and try again.");
124
- return t;
125
- } catch (t) {
126
- throw v = null, t;
127
- } finally {
128
- v = null;
129
- }
130
- }
131
- async function de(t) {
132
- const d = t?.source ?? null;
133
- if (!d) return { module: null, diagnostics: [] };
134
- const u = (t.disableBundle || t.declarationsOnly) ?? !1, [c, e, a] = await Promise.all([ie(), z(), t.ambientTypes ? oe() : null]), l = a ? t.ambientTypes ?? null : null;
135
- let o = "";
136
- const r = { allowJs: !0, declaration: !1, sourceMap: !1, inlineSourceMap: !1, inlineSources: !1, isolatedModules: !0, preserveConstEnums: !1, module: 99, noResolve: !0, emitDeclarationOnly: !1, target: e.ScriptTarget.ES2020, ...l ? { lib: re, skipLibCheck: !0, strict: !0 } : {}, ...l && t.lenient ? { noImplicitAny: !1 } : {} }, s = "script", i = `${s}.ts`, m = "lib.d.ts", f = "global.d.ts", y = { [i]: d, [m]: `
137
- /**
138
- * Represents the completion of an asynchronous operation
139
- */
140
- interface Promise<T> {
141
- /**
142
- * Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
143
- * resolved value cannot be modified from the callback.
144
- * @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
145
- * @returns A Promise for the completion of the callback.
146
- */
147
- finally(onfinally?: (() => void) | undefined | null): Promise<T>;
148
- }
149
- `, [f]: c, ...l ? { [P]: l, [q]: `declare module '@sheetxl/primitives' { export = SheetXL; }
150
- ` } : {} }, F = (n) => y[n] ?? (a && n.startsWith("lib.") ? a(e, n) : void 0), j = { getSourceFile: (n, b, N, h) => {
151
- if (n === P) return R?.text !== l && (R = { text: l, file: e.createSourceFile(n, l, e.ScriptTarget.Latest, !1) }), R.file;
152
- if (y[n] === void 0) {
153
- let p = O.get(n);
154
- if (!p) {
155
- const S = F(n);
156
- if (S === void 0) return;
157
- p = e.createSourceFile(n, S, e.ScriptTarget.Latest, !1), O.set(n, p);
158
- }
159
- return p;
160
- }
161
- return e.createSourceFile(n, y[n], e.ScriptTarget.Latest, !0);
162
- }, fileExists: (n) => F(n) !== void 0, readFile: F, writeFile: (n, b) => {
163
- y[n] = b;
164
- }, getCurrentDirectory: () => "./", getCanonicalFileName: (n) => n, useCaseSensitiveFileNames: () => !0, getDefaultLibFileName: (n) => m, getNewLine: () => `
165
- ` }, x = e.createProgram([i, f, ...l ? [P, q] : []], r, j), K = x.getTypeChecker(), T = x.getSourceFile(i), C = t.runGuard;
166
- x.emit(void 0, void 0, void 0, void 0, C ? { before: [_(e, C.key, C.timeoutMs)] } : void 0), o = y[`${s}.js`] ?? "";
167
- const I = (n) => ({ start: n.start ?? 0, length: n.length ?? 0, severity: n.category === e.DiagnosticCategory.Warning ? "warning" : "error", code: `TS${n.code}`, message: e.flattenDiagnosticMessageText(n.messageText, `
168
- `) }), W = x.getSyntacticDiagnostics(T).map(I), Q = l ? x.getSemanticDiagnostics(T).filter((n) => n.category === e.DiagnosticCategory.Error || n.category === e.DiagnosticCategory.Warning).map(I) : [], $ = X(e, T, K, { builtInNames: t.builtInNames, isBuiltIn: t.isBuiltIn, lenient: !!l && t.lenient });
169
- let w = [...W, ...Q, ...$.diagnostics];
170
- l && t.lenient && (w = (function(n, b, N) {
171
- const h = [];
172
- for (const p of N) if (p.code !== V.MissingType) if (p.severity !== "error") h.push(p);
173
- else if (p.code === "TS2774") h.push({ ...p, severity: "warning" });
174
- else if (ee.has(p.code)) {
175
- const S = te(n, b, p.start);
176
- h.push(S && ne(n, S) ? { ...p, severity: "warning", message: `${p.message} Read as a probe, it is undefined.` } : p);
177
- } else h.push(p);
178
- return h;
179
- })(e, T, w));
180
- const U = $.functions, A = $.autoRun, G = w.some((n) => n.severity === "error"), J = `${H.uuidV4()}-script`;
181
- let D = null;
182
- if (G) o = "";
183
- else {
184
- try {
185
- u || (o = await Z(0, o, s));
186
- } catch {
187
- console.warn("Error bundling script");
188
- }
189
- const n = o.indexOf(M);
190
- n > -1 && (D = o.substring(n + M.length + 1, o.length), o = o.substring(0, n), o = o.replaceAll("globalThis." + k, k));
191
- }
192
- const L = { functions: U, commitId: J, source: d, language: "typescript", compiled: o };
193
- return D && (L.sourceMap = D), A && (L.autoRun = A), { module: L, diagnostics: w };
194
- }
195
- export {
196
- de as compileModule
197
- };