@sheetxl/scripting 0.8.0-beta.9 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/LICENSE.md +8 -7
  2. package/README.md +2 -2
  3. package/browser/esm/BidIa4lARdYGHm03.mjs +4017 -0
  4. package/{node/esm/byRhqE863Yd8YyB5.mjs → browser/esm/CUERvTrIURHqOWKm.mjs} +281 -282
  5. package/browser/esm/{8IBYT7vkExASLJms.mjs → CwhaPB7R93eqixfq.mjs} +2 -2
  6. package/browser/esm/{DJmAxtGDsADOLRhd.mjs → DMYFyfVN7tu3bUMi.mjs} +1 -1
  7. package/browser/esm/DfSFyaySrD6y1NJY.mjs +17 -0
  8. package/browser/esm/index.mjs +3 -3
  9. package/node/esm/{DlnqsBJLAzuuPNOx.mjs → 2OiXgLd8VwO6IeDg.mjs} +1 -1
  10. package/node/esm/{Bj3F3BUcrLYUg3Dv.mjs → BDIcVjo-h3KFdXXo.mjs} +1 -1
  11. package/node/esm/BLO91PRuOQIsW_Ow.mjs +580 -0
  12. package/node/esm/index.mjs +9 -9
  13. package/node/esm/{Dp_cerCAQ8jL3dyP.mjs → oWHIRxwwLexnOwAn.mjs} +1 -1
  14. package/package.json +12 -8
  15. package/types/src/type/CompileOptions.d.ts +1 -1
  16. package/types/src/type/CompiledModule.d.ts +2 -2
  17. package/types/src/type/Diagnostic.d.ts +0 -2
  18. package/types/src/type/Types.d.ts +17 -0
  19. package/browser/cjs/12MLcWR439OVCXwt.cjs +0 -1
  20. package/browser/cjs/B6RS19boKbA_QGQ6.cjs +0 -2
  21. package/browser/cjs/Bn3oEXST6uP5oPU2.cjs +0 -1
  22. package/browser/cjs/C83wXnFq94exmYt9.cjs +0 -1
  23. package/browser/cjs/D5np5QScDyDDD_WJ.cjs +0 -1
  24. package/browser/cjs/DLi7EA_dfez5uwwY.cjs +0 -1
  25. package/browser/cjs/DcxyEv9XIOa5qfCm.cjs +0 -1
  26. package/browser/cjs/ZKJrH74dcPwEAgmF.cjs +0 -7
  27. package/browser/cjs/Zvz3TLLPKgPcJHB4.cjs +0 -3703
  28. package/browser/cjs/index.cjs +0 -1
  29. package/browser/cjs/stpzUglP-nPdX-Zi.cjs +0 -29
  30. package/browser/esm/B73J41HhbJvswDz1.mjs +0 -17
  31. package/browser/esm/BXhWTnlrRShaRGS5.mjs +0 -581
  32. package/browser/esm/ChXuG8IaqC3qeOH3.mjs +0 -3774
@@ -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("./DlnqsBJLAzuuPNOx.mjs");
7
+ const { createCompilerWorker: r } = await import("./2OiXgLd8VwO6IeDg.mjs");
8
8
  return this.workerWrapper = await r(), this.workerWrapper;
9
9
  }
10
10
  async compileModule(r) {
package/package.json CHANGED
@@ -1,21 +1,20 @@
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.9",
5
- "license": "SEE LICENSE IN <LICENSE>",
4
+ "version": "1.0.0",
5
+ "license": "SEE LICENSE IN LICENSE.md",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": {
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,15 +39,20 @@
40
39
  "scripting"
41
40
  ],
42
41
  "dependencies": {
43
- "@sheetxl/primitives": "^0.8.0-beta.9",
44
- "@sheetxl/utils": "^0.8.0-beta.9"
42
+ "@sheetxl/primitives": "^1.0.0",
43
+ "@sheetxl/utils": "^1.0.0"
45
44
  },
46
45
  "peerDependencies": {
47
46
  "esbuild-wasm": ">=0.25.7",
48
47
  "typescript": "^5.9.0 || ^6.0.0",
49
48
  "vite": "^8.0.0"
50
49
  },
50
+ "peerDependenciesMeta": {
51
+ "vite": {
52
+ "optional": true
53
+ }
54
+ },
51
55
  "devDependencies": {
52
- "@types/node": "^26.1.2"
56
+ "@types/node": "^26.6.6"
53
57
  }
54
58
  }
@@ -20,7 +20,7 @@ export interface CompileOptions {
20
20
  *
21
21
  * @remarks
22
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`).
23
+ * author wrote it (`wb.getWorksheet is not a function`, not `a.getWorksheet`).
24
24
  */
25
25
  minify?: boolean;
26
26
  /**
@@ -9,7 +9,7 @@ import { IFunction } from '@sheetxl/primitives';
9
9
  * as `IModule.JSON` in the SDK. Produced by `ScriptCompiler.compile` (Node, which returns
10
10
  * it inside a {@link CompileResult} alongside diagnostics) and executed compiler-free via
11
11
  * `loadCompiledModule`. Compile diagnostics are NOT part of this artifact — they live on
12
- * {@link CompileResult}. See `private-assets/design/SXLM-FORMAT.md` for the normative reference.
12
+ * {@link CompileResult}.
13
13
  */
14
14
  export interface CompiledModule {
15
15
  /**
@@ -73,7 +73,7 @@ export interface CompiledModule {
73
73
  *
74
74
  * @remarks
75
75
  * There is deliberately no sheet value here. A sheet's modules are stored BY the sheet
76
- * (`ISheet.JSON.modules`), so nothing has to name it and a module cannot be left behind pointing
76
+ * (`IWorksheet.JSON.modules`), so nothing has to name it and a module cannot be left behind pointing
77
77
  * at a sheet that no longer exists. This field exists only because a workbook holds both its
78
78
  * global modules and its own in one collection, which is the single case nesting cannot express.
79
79
  */
@@ -70,8 +70,6 @@ export declare const DiagnosticCode: Readonly<{
70
70
  readonly UntypedArray: "SXL2005";
71
71
  /** A generic type must be supplied exactly one type argument. */
72
72
  readonly GenericArity: "SXL2006";
73
- /** A return type cannot combine multiple modifiers (e.g. async + stream). */
74
- readonly MultipleModifiers: "SXL2007";
75
73
  /** A context parameter must be the first parameter. */
76
74
  readonly ContextNotFirst: "SXL2010";
77
75
  /** More than one `Lambda` parameter. */
@@ -14,6 +14,22 @@ export interface FunctionBinder {
14
14
  export interface FunctionProvider {
15
15
  (getContext: () => IFormulaContext, bindFn: FunctionBinder, mapBind?: Map<string, IFunction>): Map<string, IFunction>;
16
16
  }
17
+ /**
18
+ * One source module's declarations, without its implementations.
19
+ *
20
+ * @remarks
21
+ * A compiled formula package exports a list of these from its `declarations` entry, for a consumer
22
+ * that needs to know what each function accepts and returns (a file format, a linter) but never runs
23
+ * one. Importing it does not load the implementations.
24
+ */
25
+ export interface FunctionDeclarationModule {
26
+ /** The module's declarations, by function name. */
27
+ declarations: MinifiedDeclarations;
28
+ /** The category the module's functions belong to unless a declaration names its own. */
29
+ category?: string;
30
+ /** The enums the declarations refer to. */
31
+ enums?: MinifiedEnums;
32
+ }
17
33
  /**
18
34
  * Minified value.
19
35
  */
@@ -53,6 +69,7 @@ export interface MinifiedDeclaration {
53
69
  p?: MinifiedParameter[];
54
70
  r?: MinifiedValue;
55
71
  mx?: number;
72
+ h?: 1;
56
73
  }
57
74
  /**
58
75
  * The descriptor used for a function
@@ -1 +0,0 @@
1
- exports.TypeScriptCompiler=class{constructor(r={}){this.workerWrapper=null}async getWorkerWrapper(){if(this.workerWrapper)return this.workerWrapper;const{createCompilerWorker:r}=await Promise.resolve().then(()=>require("./Zvz3TLLPKgPcJHB4.cjs"));return this.workerWrapper=await r(),this.workerWrapper}async compileModule(r){try{return(await this.getWorkerWrapper()).execute(r)}catch(e){throw console.error("Failed to compile using worker:",e),e}}terminate(){this.workerWrapper?.terminate(),this.workerWrapper=null}};
@@ -1,2 +0,0 @@
1
- const t=require("./DLi7EA_dfez5uwwY.cjs");exports.loadCompiledModule=async function(r,e){let n=r;return e?.sourceMap&&(n+=`
2
- ${t.SOURCEMAP_IDENTIFIER}=${e.sourceMap}`),new Function("url","return import(url)")(`data:text/javascript,${encodeURIComponent(n)}`)};
@@ -1 +0,0 @@
1
- var r=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"}),a=[{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."}],i=(()=>{const n=new Map;for(const e of a)if(n.set(e.name,e),e.aliases)for(const t of e.aliases)n.set(t,e);return n})();function o(n){return(function(e){if(!e)return;const t=(e.startsWith("@")?e.slice(1):e).toLowerCase();return i.get(t)})(n)?.standalone===!0}Object.defineProperty(exports,"DiagnosticCode",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"DocTags",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"isStandaloneJSDocTag",{enumerable:!0,get:function(){return o}});
@@ -1 +0,0 @@
1
- var n=Object.defineProperty,o=(t,l)=>{let e={};for(var r in t)n(e,r,{get:t[r],enumerable:!0});return l||n(e,Symbol.toStringTag,{value:"Module"}),e},a=o({GLOBAL_CONTEXT_VARIABLE:()=>u}),u="__SHEETXL";Object.defineProperty(exports,"Constants_exports",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"GLOBAL_CONTEXT_VARIABLE",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"__exportAll",{enumerable:!0,get:function(){return o}});
@@ -1 +0,0 @@
1
- var a=Object.create;var t=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty;var y=(r,i,l,e)=>{if(i&&typeof i=="object"||typeof i=="function")for(let n of s(i))!p.call(r,n)&&n!==l&&t(r,n,{get:()=>i[n],enumerable:!(e=c(i,n))||e.enumerable});return r};var f=(r,i,l)=>(l=r!=null?a(u(r)):{},y(i||!r||!r.__esModule?t(l,"default",{value:r,enumerable:!0}):l,r));var o=null;exports.initialize=async function(){return o||(o=new Promise(async(r,i)=>{let l=null;try{l=await import("https://esm.sh/typescript@5.7.2")}catch(e){console.error("Error initializing Browser TypeScript module:",e)}l||(console.log("use script fallback"),o=null),r(l)}))},exports.readLibFile=function(r,i){};
@@ -1 +0,0 @@
1
- Object.defineProperty(exports,"SOURCEMAP_IDENTIFIER",{enumerable:!0,get:function(){return"//# sourceMappingURL"}});
@@ -1 +0,0 @@
1
- var e=null;exports.initialize=async function(){return e||(e=new Promise(async(r,s)=>{try{const i="0.20.2",a=`https://esm.sh/esbuild-wasm@${i}`,t=`https://esm.sh/esbuild-wasm@${i}/esbuild.wasm`,n=(await import(a)).default;await n.initialize({wasmURL:t,worker:!1}),r(n)}catch(i){console.error("Error initializing esbuild:",i),e=null,s(new Error("The script bundler could not be loaded. Check your connection and try again.",{cause:i}))}}))};
@@ -1,7 +0,0 @@
1
- const o=require("./Bn3oEXST6uP5oPU2.cjs");let Ne=require("@sheetxl/utils"),j=require("@sheetxl/primitives");var re=new Map([["IReferenceRange","p"],["IRange","r"]]),ie=new Set(Object.values(j.ValueKind).filter(a=>a!==j.ValueKind.Omitted)),le=new Map([["IWorkbook","workbook"],["ISheet","sheet"],["ICellRanges","ranges"],["ICellRange","range"]]),Ke=Array.from(le.keys()),oe=(a,R)=>{Array.from(R.keys()).forEach($=>{const S=R.get($);R.set(`${a}.${$}`,S)})},Le=new Map([["Scalar","*"],["Lambda","l"],["FormulaError.Known",j.ScalarType.Error],["Date",j.InteropScalarType.Date],["IRichData",j.InteropScalarType.RichData]]),Te=new Map([["Repeating","repeating"]]),Ie=new Set(["Flatten","SheetXL.Flatten"]),we=new Set(["AcceptError"]),De=new Set(["Omittable"]),xe=new Set(["NoLift"]),Ce=new Set(["NoFilter"]),Se=new Set(["Lazy"]),se=new Set(["ReportType"]),Re=/^[a-zA-Z_-￿][a-zA-Z0-9_.-￿]*$/,Ee=/^([a-z]{1,3})([0-9]+)$/i,Fe=/^r[0-9]*c[0-9]*$/i,V="SheetXL",_=a=>{const R=a.typeName.getText();return R.startsWith(`${V}.`)?R.slice(8):R};oe(V,re),oe(V,le),oe(V,Te),we.add(V+".AcceptError"),De.add(`${V}.Omittable`),xe.add(`${V}.NoLift`),Ce.add(`${V}.NoFilter`),Se.add(`${V}.Lazy`),se.add(`${V}.ReportType`);var Me=new Map([["Promise",()=>({async:!0})],["Observable",()=>({stream:!0})],["Volatile",()=>({volatile:!0})],[`${V}.Volatile`,()=>({volatile:!0})]]),he="__scriptContext__",be="script",Ue=new Set(["IScript.ScriptContext",`${V}.IScript.ScriptContext`,"ScriptContext"]),$e=(a,R)=>{const $=R.literal;if($===void 0)return;const S=a.SyntaxKind;switch($.kind){case S.StringLiteral:return $.text;case S.NumericLiteral:return parseFloat($.text);case S.TrueKeyword:return!0;case S.FalseKeyword:return!1;case S.NullKeyword:return null;case S.PrefixUnaryExpression:return $.operator===S.MinusToken&&$.operand?.kind===S.NumericLiteral?-parseFloat($.operand.text):void 0;default:return}},H=a=>{if(!a||a.length===0)return"";let R="";for(let $=0;$<a.length;$++){const S=a[$],B=S.kind;if(B!=="link"){if(B==="linkName"){const q=a[$+1];if(q?.kind==="linkText"&&q.text.trim())continue;R+=S.text;continue}R+=B!=="linkText"?S.text:S.text.trim()}}return R.replace(/\r\n?/g,`
2
- `).split(/\n[^\S\n]*\n\s*/).map($=>$.split(`
3
- `).map(S=>S.trim()).filter(Boolean).join(" ")).filter(Boolean).join(`
4
- `).trim()};function ve(a,R,$,S){const B=S?.builtInNames?.length?new Set(S.builtInNames.map(e=>e.toUpperCase())):null,q=[],W=new Map,Q=[];let X=null;const U=(e,n,s,l)=>{const{start:u,length:y}=(w=>{if(!w||typeof w.getStart!="function")return{start:0,length:0};try{return{start:w.getStart(),length:w.getWidth()}}catch{return{start:0,length:0}}})(e);Q.push({start:u,length:y,severity:s,code:n,message:l})},r=(e,n,s)=>{U(e,n,"error",s)},N=e=>e?.parent?.name?.escapedText,Z=(e,n,s,l,u=!1,y=!1,w=!1)=>{const T={count:0},p=F(e,n,s,l,T,u,y,w);T.count>=2&&(n.range||(n.range="m",T.count-=2),!l&&T.count>=1&&(T.count-=1,T.count>0&&r(e,o.DiagnosticCode.ArrayDepth,`Arrays of more than 2 dimensions are not supported: '${N(e)}'.`))),T.count>0&&(n.arrayDepth=T.count);const h=n.enum;return h&&(T.count>(w?1:0)||n.range)&&!pe.has(n)&&(n.valueOrRange||(r(e,o.DiagnosticCode.EnumPosition,`A list cannot hold the enum '${h.id}': '${n.name??N(e)}'. Its members reach the body as they are, so nothing checks them against the enum. Take one value per argument ('...x: ${h.id}[]'), or type the list by its scalar ('${h.type}').`),delete n.enum)),p},de=(e,n,s,l,u)=>{if(n!=="Lambda"&&n!==`${V}.Lambda`)return!1;const y=e.typeArguments;let w="*";if(y&&y.length===2)if(u&&y[0].kind===a.SyntaxKind.TupleType&&(s.lambdaArity=y[0].elements.length),y[1].kind===a.SyntaxKind.AnyKeyword)w="raw";else{const T={};F(y[1],T,l,!1,{count:0}),w=T.scalar??"*"}else if(y&&y.length===1&&y[0].kind!==a.SyntaxKind.TupleType&&y[0].kind!==a.SyntaxKind.ArrayType)if(u&&(s.lambdaArity=2),y[0].kind===a.SyntaxKind.AnyKeyword)w="raw";else{const T={};F(y[0],T,l,!1,{count:0}),w=T.scalar??"*"}return s.lambda=w,!0},ee=new Map,ce=new Map,ue=new Map,me=new Set,pe=new WeakSet,ge=e=>e!==void 0&&e.getSourceFile()===R,te=(e,n=!1)=>e.getJsDocTags($).find(l=>l.name==="name")?.text?.map(l=>l.text).join("").trim()||(n?Ne.CommonUtils.camelToPrettyCase(e.name):e.name),ye=e=>{const n=e.getJsDocTags($).find(s=>s.name==="deprecated");if(n)return n.text?.map(s=>s.text).join("").trim()||!0},ne=(e,n)=>{const s=a.isTypeReferenceNode(e)?e.typeName:void 0,l=s?$.getSymbolAtLocation(s):void 0,u=l?.declarations?.length?l:void 0;if(s){if(u&&u.flags&a.SymbolFlags.Alias)return void r(e,o.DiagnosticCode.EnumNotLocal,`'${s.getText()}' is imported, so its declaration cannot be read: '${n}'. An enum must be declared in the module that uses it.`);if(!(u&&u.flags&a.SymbolFlags.Type)){const i=s.getText();return(u?(u.flags&a.SymbolFlags.Variable)!==0:R.statements.some(d=>a.isVariableStatement(d)&&d.declarationList.declarations.some(b=>a.isIdentifier(b.name)&&b.name.text===i)))?void r(e,o.DiagnosticCode.EnumMissingAlias,`'${i}' is a value, not a type: '${n}'. Pair the object with a same-name type — 'type ${i} = typeof ${i}[keyof typeof ${i}];' — or declare it as 'enum ${i} { … }'.`):null}const t=ee.get(u);if(t!==void 0)return t;if(me.has(u))return}const y=[];let w=!1;if(u&&u.flags&a.SymbolFlags.Enum){if(!u.declarations?.some(ge))return void r(e,o.DiagnosticCode.EnumNotLocal,`'${u.name}' is not declared in this module: '${n}'. An enum must be declared in the module that uses it.`);w=!0;let t=!1;if(u.exports?.forEach(i=>{const d=i.valueDeclaration;if(!d||!a.isEnumMember(d))return;const b=$.getConstantValue(d);if(b===void 0)return r(d,o.DiagnosticCode.EnumMemberNotConstant,`'${u.name}.${i.name}' is not a constant number or string. A formula passes the VALUE, so every member needs one that can be read at compile time.`),void(t=!0);y.push([te(i,!0),b,d,H(i.getDocumentationComment($)),ye(i)])}),t)return void me.add(u)}else{const t=$.getTypeFromTypeNode(e),i=a.TypeFlags.Null|a.TypeFlags.Undefined|a.TypeFlags.Void,d=(t.isUnion()?t.types:[t]).filter(g=>!(g.flags&i)),b=[];for(const g of d){if(!(g.flags&(a.TypeFlags.NumberLiteral|a.TypeFlags.StringLiteral)))return u&&ee.set(u,null),null;b.push(g.value)}if(b.length===0)return null;const E=u?.declarations?.find(g=>a.isTypeAliasDeclaration(g)),K=a.isUnionTypeNode(e)?e:E?.type;if(K&&a.isUnionTypeNode(K)){const g=K.types.map(c=>{const C=$.getTypeFromTypeNode(c);return C.isLiteral()?C.value:void 0}),m=c=>{const C=g.indexOf(c);return C<0?g.length:C};b.sort((c,C)=>m(c)-m(C))}const A=u&&u.flags&a.SymbolFlags.Variable?u.valueDeclaration:void 0,P=new Set(b);if(u&&A&&ge(A))for(const g of $.getTypeOfSymbolAtLocation(u,A).getProperties()){const m=g.valueDeclaration,c=$.getTypeOfSymbolAtLocation(g,m??A);if(!(c.flags&(a.TypeFlags.NumberLiteral|a.TypeFlags.StringLiteral)))continue;const C=c.value;b.includes(C)&&(w=!0,P.delete(C),y.push([te(g,!0),C,m,H(g.getDocumentationComment($)),ye(g)]))}for(const g of b)P.has(g)&&y.push([String(g),g,void 0,null])}if(y.length===0)return null;const T=typeof y[0][1]=="number";if(y.some(([,t])=>typeof t=="number"!==T))return void r(e,o.DiagnosticCode.EnumMixed,`'${u?.name??e.getText()}' mixes number and string members: '${n}'. A parameter has one type, so an enum is all numbers or all strings.`);const p=u?te(u):y.map(([,t])=>String(t)).join("|"),h=u?void 0:ce.get(p);if(h)return h;if(w){const t=new Map;for(const[i,d,b,E]of y){const K=b?.name?.getText()??i,A=t.get(d);A!==void 0?U(b??e,o.DiagnosticCode.EnumDuplicateValue,"warning",`'${p}.${K}' has the same value as '${p}.${A}' (${JSON.stringify(d)}). A formula passes the value, so the two cannot be told apart.`):t.set(d,K),E===""&&U(b??e,o.DiagnosticCode.EnumMemberUndocumented,"warning",`'${p}.${K}' is missing a description. Add a doc comment above the member — it is what the argument dropdown shows.`)}}const L={id:p,type:T?j.ScalarType.Number:j.ScalarType.String,members:y.map(([t,i,,,d])=>d?[t,i,d]:[t,i])};u?ee.set(u,L):ce.set(p,L);const v=u?H(u.getDocumentationComment($)):"",f={};for(const[t,,,i]of y)i&&(f[t]={description:i});if(v||Object.keys(f).length>0){const t={};v&&(t.summary=v),Object.keys(f).length>0&&(t.members=f),ue.set(L,t)}return L},F=(e,n,s,l,u,y=!1,w=!1,T=!1)=>{if(e){if(e.kind===a.SyntaxKind.ParenthesizedType)return F(e.type,n,s,l,u,y,w,T);if(e.kind===a.SyntaxKind.UnionType){const p=v=>v.kind===a.SyntaxKind.UndefinedKeyword||v.kind===a.SyntaxKind.VoidKeyword||v.kind===a.SyntaxKind.NullKeyword||v.kind===a.SyntaxKind.LiteralType&&v.literal?.kind===a.SyntaxKind.NullKeyword,h=e.types.filter(v=>!p(v));if(h.length===1)return F(h[0],n,s,l,u,y,w,T);const L=ne(e,n.name??N(e));if(L===void 0)return;if(L!==null)return n.scalar=L.type,void(l&&(n.enum=L));if(!l)return void(n.scalar="*");if(h.length===2){const v=t=>t.kind===a.SyntaxKind.TypeReference&&a.isTypeReferenceNode(t)&&_(t)==="Lambda",f=h.findIndex(v);if(f>=0&&!v(h[1-f]))return F(h[1-f],n,s,l,u,y,w,T),void de(h[f],_(h[f]),n,s,l)}if(l&&h.length===2){const v=t=>{if(t.kind===a.SyntaxKind.TypeReference&&!t.typeArguments?.length)return re.get(_(t))},f=h.findIndex(t=>v(t)!==void 0);if(f>=0&&v(h[1-f])===void 0){const t={},i=u.count;if(F(h[1-f],t,s,l,u,y,!1),t.scalar&&!t.range&&t.lambda==null&&u.count===i){n.range=v(h[f]),n.scalar=t.scalar,n.valueOrRange=!0;const d=t.enum;return void(d&&(n.enum=d))}}}if(l&&h.length===2){const v=t=>t.kind===a.SyntaxKind.TypeReference&&!t.typeArguments?.length&&_(t)==="Scalar",f=h.findIndex(v);if(f>=0&&!v(h[1-f])){const t=ne(h[1-f],n.name??N(e));if(t===void 0)return;if(t!==null)return n.scalar="*",void(n.enum=t)}}return void r(e,o.DiagnosticCode.InvalidParamType,`Union parameter types are not supported: '${N(e)}'. Use a single type, optionally with '| null' or '| undefined', 'T | Lambda<…>' for a value-or-lambda slot, 'IRange | Scalar' for a value-or-range slot, or 'E | Scalar' for an uncoerced slot whose values an enum documents.`)}if(e.kind===a.SyntaxKind.NumberKeyword)n.scalar=j.ScalarType.Number;else if(e.kind===a.SyntaxKind.StringKeyword)n.scalar=j.ScalarType.String;else if(e.kind===a.SyntaxKind.BooleanKeyword)n.scalar=j.ScalarType.Boolean;else if(e.kind===a.SyntaxKind.UndefinedKeyword||e.kind===a.SyntaxKind.NullKeyword||e.kind===a.SyntaxKind.VoidKeyword){if(l)return void r(e,o.DiagnosticCode.UndefinedInput,`'undefined' is not a valid type for input: '${N(e)}'.`);n.scalar=j.ScalarType.Null}else if(e.kind===a.SyntaxKind.BigIntKeyword)n.scalar=j.ScalarType.Number;else if(e.kind===a.SyntaxKind.AnyKeyword)l&&(n.range="*");else if(e.kind===a.SyntaxKind.ArrayType){const p=e.elementType;if(!p)return void r(e,o.DiagnosticCode.UntypedArray,`'Array' must be typed: '${N(e)}'.`);if(l&&w){const h=n,L=h.name??N(e)??"parameter",v=h.acceptError;delete h.acceptError;const f={name:L};return Z(p,f,s,!0),v&&!f.acceptError&&(f.acceptError=!0),void(h.repeating=[f])}u.count++,F(p,n,s,l,u)}else if(e.kind!==a.SyntaxKind.TupleType)if(e.kind===a.SyntaxKind.TypeReference){const p=_(e);if(we.has(p)){const t=N(e);if(!l)return void r(e,o.DiagnosticCode.InvalidReturnType,`'${p}' is not a valid return type: '${t}'. It describes how an ARGUMENT is received.`);const i=n;if(i.acceptError)return void r(e,o.DiagnosticCode.InvalidParamType,`'${t}' declares 'AcceptError' more than once.`);const d=e.typeArguments;return d&&d.length===1?(i.acceptError=!0,F(d[0],n,s,l,u,y,w,T)):void r(e,o.DiagnosticCode.GenericArity,`'${p}' must be typed with exactly 1 type: '${t}'.`)}if(se.has(p)){const t=n.name??N(e);if(!l)return void r(e,o.DiagnosticCode.InvalidReturnType,`'ReportType' is not a valid return type: '${t}'. It describes how an ARGUMENT is received.`);const i=e.typeArguments;return i&&i.length===1?(n.reportType=!0,F(i[0],n,s,l,u,y,w,T)):void r(e,o.DiagnosticCode.GenericArity,`'${p}' must be typed with exactly 1 type: '${t}'.`)}if(xe.has(p)){const t=n.name??N(e);if(!l)return void r(e,o.DiagnosticCode.InvalidReturnType,`'NoLift' is not a valid return type: '${t}'. It describes how an ARGUMENT is received.`);const i=e.typeArguments;if(!i||i.length!==1)return void r(e,o.DiagnosticCode.GenericArity,`'${p}' must be typed with exactly 1 type: '${t}'.`);const d=n;d.noLift=!0;const b=u.count;return F(i[0],n,s,l,u,y,w,T),void((d.range||d.lambda!=null||d.repeating||u.count!==b)&&r(e,o.DiagnosticCode.InvalidParamType,`'${t}': 'NoLift' applies to a SCALAR parameter only - a range, list, repeating or lambda slot never lifts.`))}if(Ce.has(p)){const t=n.name??N(e);if(!l)return void r(e,o.DiagnosticCode.InvalidReturnType,`'NoFilter' is not a valid return type: '${t}'. It describes how an ARGUMENT is received.`);const i=e.typeArguments;if(!i||i.length!==1)return void r(e,o.DiagnosticCode.GenericArity,`'${p}' must be typed with exactly 1 type: '${t}'.`);const d=n;d.noFilter=!0;const b=u.count;if(F(i[0],n,s,l,u,y,w,T),d.range||d.lambda!=null||u.count!==b)return void r(e,o.DiagnosticCode.InvalidParamType,`'${t}': 'NoFilter' applies to a SCALAR slot only - a range, list or lambda slot has no members to coerce.`);const E=d.repeating;if(E){if(delete d.noFilter,E.length!==1)return void r(e,o.DiagnosticCode.InvalidParamType,`'${t}': 'NoFilter' over a repeating group applies to a period-1 group only - write it on the slot that takes the members.`);E[0].noFilter=!0}else w&&r(e,o.DiagnosticCode.InvalidParamType,`'${t}': 'NoFilter' applies to a REPEATING slot only - a single scalar argument has no members to coerce.`);return}if(De.has(p)){const t=n.name??N(e);if(!l)return void r(e,o.DiagnosticCode.InvalidReturnType,`'Omittable' is not a valid return type: '${t}'. It describes how an ARGUMENT is received.`);const i=e.typeArguments;if(!i||i.length<1||i.length>2)return void r(e,o.DiagnosticCode.GenericArity,`'${p}' must be typed with 1 or 2 types: '${t}'.`);const d=n;if(d.omittable=!0,i.length===2){const K=$e(a,i[1]);if(K===void 0)return void r(e,o.DiagnosticCode.InvalidParamType,`'${t}' declares '${p}' with a second type that is not a literal value. Use a number, string, boolean or null - the engine substitutes it for an omitted argument.`);d.omittedValue=K}const b=F(i[0],n,s,l,u,y,w,T),E=d.omittedValue;return d.enum&&E!=null&&!d.enum.members.some(([,K])=>K===E)&&r(i[1],o.DiagnosticCode.EnumOmittedValue,`'${t}': ${JSON.stringify(E)} is not a member of '${d.enum.id}'. An omitted argument must mean a member (${d.enum.members.map(([,K])=>JSON.stringify(K)).join(", ")}) or null.`),b}if(Se.has(p)){const t=n.name??N(e);if(!l)return void r(e,o.DiagnosticCode.InvalidReturnType,`'Lazy' is not a valid return type: '${t}'. It describes how an ARGUMENT is received.`);const i=n;if(i.lazy)return void r(e,o.DiagnosticCode.InvalidParamType,`'${t}' declares 'Lazy' more than once.`);const d=e.typeArguments;if(!d||d.length<1||d.length>2)return void r(e,o.DiagnosticCode.GenericArity,`'${p}' must be typed with 1 or 2 types: '${t}'.`);if(i.lazy=!0,d.length===2){const b=$e(a,d[1]);if(b===void 0)return void r(e,o.DiagnosticCode.InvalidParamType,`'${t}' declares '${p}' with a second type that is not a literal value. Use a number, string, boolean or null - the engine substitutes it for an absent argument.`);i.optional=!0,i.defaultValue=b}return F(d[0],n,s,l,u,y,w,T),void(i.enum?(r(e,o.DiagnosticCode.EnumPosition,`'${t}': 'Lazy' cannot hold the enum '${i.enum.id}'. The argument may never be evaluated, so there is no point at which it could be checked against the members.`),delete i.enum):i.lambda!=null?r(e,o.DiagnosticCode.InvalidParamType,`'${t}': 'Lazy' cannot be combined with a Lambda parameter - a callable slot is already the body's to call, or not.`):i.repeating&&r(e,o.DiagnosticCode.InvalidParamType,`'${t}': 'Lazy' applies to a VALUE, not to a repeating group - mark the group's slots instead.`))}if(Ie.has(p)){const t=n.name??N(e);if(!l)return void r(e,o.DiagnosticCode.InvalidReturnType,`'Flatten' is not a valid return type: '${t}'. It describes how an ARGUMENT is received.`);const i=e.typeArguments;return i&&i.length===1?(u.count++,F(i[0],n,s,l,u,y)):void r(e,o.DiagnosticCode.GenericArity,`'${p}' must be typed with exactly 1 type: '${t}'.`)}if(Te.get(p)==="repeating"){const t=n.name??N(e);if(!l)return void r(e,o.DiagnosticCode.RepeatingPosition,`'Repeating' is not a valid return type: '${t}'.`);if(u.count!==0)return void r(e,o.DiagnosticCode.RepeatingPosition,`'Repeating' cannot be nested inside another type: '${t}'.`);const i=n,d=e.typeArguments;if(!d||d.length<1||d.length>2)return void r(e,o.DiagnosticCode.GenericArity,`'${p}' must be typed with 1 type, optionally followed by a maximum argument count: '${t}'.`);let b;if(d.length===2){const A=d[1],P=A.kind===a.SyntaxKind.LiteralType?A.literal:null,g=P&&P.kind===a.SyntaxKind.NumericLiteral?Number(P.text):NaN;if(!Number.isInteger(g)||g<1||g>255)return void r(A,o.DiagnosticCode.RepeatingMax,`'${t}': '${p}'’s maximum must be a whole number between 1 and 255.`);b=g,s.maxArguments=g}if(T)return b===void 0?void r(e,o.DiagnosticCode.RepeatingPosition,`'${t}' is a rest parameter and a repeating group. A group already repeats — drop the '...', or give the group a maximum ('Repeating<T, 254>') if the ceiling is all you meant.`):F(d[0],n,s,l,u,y,w);const E=i.acceptError;delete i.acceptError;const K=((A,P,g,m)=>{const c=(M,k,x)=>{const D={name:M};return Z(k,D,g,!0),x&&(D.optional=!0),m&&!D.acceptError&&(D.acceptError=!0),D};if(A.kind!==a.SyntaxKind.TupleType)return[c(P,A,!1)];const C=A.elements;if(C.length<2)return r(A,o.DiagnosticCode.RepeatingSlots,`'${P}': a repeating group of period ${C.length} must be spelled 'Repeating<T>' without the tuple.`),null;const G=[];for(let M=0;M<C.length;M++){const k=C[M];if(k.kind!==a.SyntaxKind.NamedTupleMember)return r(k,o.DiagnosticCode.RepeatingSlots,`'${P}': every slot of a repeating group must be labelled, e.g. 'Repeating<[criteriaRange: IRange, criteria: Scalar]>'.`),null;const x=!!k.questionToken;if(x&&M!==C.length-1)return r(k,o.DiagnosticCode.RepeatingOptional,`'${P}': only the LAST slot of a repeating group may be optional (slot '${k.name?.getText?.()}' is not).`),null;G.push(c(k.name?.getText?.()??`${M}`,k.type,x))}return G})(d[0],t??"parameter",s,E);return void(K&&(i.repeating=K))}const h=re.get(p);let L=!1;h&&(n.range=h,L=!0);const v=Le.get(p);if(v&&(n.scalar=v),v!==void 0&&(L=!0),de(e,p,n,s,l))return;if(l){if(p==="Volatile"||p===`${V}.Volatile`)return void r(e,o.DiagnosticCode.InvalidParamType,`'Volatile' is not a valid parameter type: '${N(e)}'. It describes the function's RESULT, so it belongs on the return type.`);if(Ue.has(p))return he;const t=le.get(p);if(t)return t}else{const t=Me.get(p);if(t){const i=Object.assign(n,t());let d=0;if(i.async&&d++,i.stream&&d++,d>1)return void r(e,o.DiagnosticCode.MultipleModifiers,`'${p}' cannot have multiple modifiers: '${N(e)}'.`);L=!0}}if(!L){const t=ne(e,n.name??N(e));if(t===void 0)return;if(t!==null)return n.scalar=t.type,void(l&&(n.enum=t))}if(!L){const t="number, string, boolean, Scalar, Lambda, Date, FormulaError.Known, IRichData, IRange, IReferenceRange (and arrays of these; optionally wrapped in AcceptError<T>, or grouped with Repeating<T>)",i="number, string, boolean, Scalar, Date, FormulaError.Known, IRichData, IRange, Promise<T>, Observable<T>, Volatile<T> (and arrays of these)";let d;return d=l?y?`'${p}' is not a valid first parameter: '${N(e)}'. The first parameter is EITHER a macro target (making this a macro) OR a calculation input (making this a calculation function). Allowed: ${Ke.join(", ")} (macro target); ${t} (calculation input).`:`'${p}' is not a valid parameter type: '${N(e)}'. Allowed: ${t}.`:`'${p}' is not a valid return type: '${N(e)}'. Allowed: ${i}.`,void r(e,l?o.DiagnosticCode.InvalidParamType:o.DiagnosticCode.InvalidReturnType,d)}const f=e.typeArguments;if(f){if(f.length!==1)return void r(e,o.DiagnosticCode.GenericArity,`'${p}' must be typed with exactly 1 type: '${N(e)}'.`);const t=f[0],i=l&&a.isTypeReferenceNode(t)&&se.has(_(t)),d=n.reportType;i&&pe.add(n),Z(t,n,s,l),i&&d===void 0&&delete n.reportType;const b=n.enum;b&&!i&&(r(f[0],o.DiagnosticCode.EnumPosition,`'${p}' cannot hold the enum '${b.id}': '${N(e)}'. The members of a range reach the body as they are, so nothing checks them against the enum. Take the enum as a value, or type the range by its scalar ('${p}<${b.type}>').`),delete n.enum)}}else e.kind===a.SyntaxKind.FunctionType&&((p,h,L,v)=>{if(!v)return void r(p,o.DiagnosticCode.FunctionReturn,`Function type is not a valid return type: '${N(p)}'. Declare a 'Lambda' return instead.`);const f=p.type,t={};let i="*";f&&(f.kind===a.SyntaxKind.AnyKeyword?i="raw":(F(f,t,L,!1,{count:0}),i=t.scalar??"*"));const d=p.parameters;d&&!d.some(b=>b.dotDotDotToken)&&(h.lambdaArity=d.length),h.lambda=i})(e,n,s,l)}else r(e,o.DiagnosticCode.MissingType,`Type is not defined for '${n?.name??"return"}'.`)};try{a.forEachChild(R,e=>{if((n=>(a.getCombinedModifierFlags(n)&a.ModifierFlags.Export)!==0)(e)&&a.isFunctionDeclaration(e)){const n=e?.name?.getText();if(!e.body)return void r(e,o.DiagnosticCode.NoBody,`'${n}': function has no body.`);if(!n)return void r(e,o.DiagnosticCode.Anonymous,"Anonymous exported functions are not allowed.");const s={},l={parameters:{}};try{s.name=n;const u=$.getSymbolAtLocation(e.name),y=H(u?.getDocumentationComment($));y&&(l.summary=y);const w={};Z(e.type,w,s,!1),s.returnType=w;const T={};(g=>(a.getCombinedModifierFlags(g)&a.ModifierFlags.Default)!==0)(e)&&(T.default=!0,X=n),s.parameters=[];const p=new Map,h=new Map,L=new Set;let v=null,f=null,t=null,i=0,d=!1,b=0;for(let g=0;g<e.parameters.length;g++){const m=e.parameters[g],c={};c.name=m.name?.getText();const C=s.parameters.length===0;if(S?.lenient&&g===0&&!m.type&&T.default){s.context=be;continue}const G=Z(m.type,c,s,!0,C,!m.dotDotDotToken,!!m.dotDotDotToken);if(G===he){g===0&&s.context===void 0&&(s.context=be);continue}if(G){if(s.parameters.length!==0)return void r(m,o.DiagnosticCode.ContextNotFirst,`'${s.name}' contexts must be the first parameter: '${c.name}'.`);s.context=G;continue}if(c.lambda!==void 0){if(v!==null)return void r(m,o.DiagnosticCode.MultipleLambda,`'${s.name}' has more than one Lambda parameter ('${v}' and '${c.name}'). Only one Lambda parameter is allowed.`);v=c.name}else if(v!==null)return void r(m,o.DiagnosticCode.LambdaNotLast,`'${s.name}' Lambda parameter ('${v}') must be the last parameter, but '${c.name}' follows it.`);const M=c.optional===!0||m.initializer!==void 0&&m.initializer!==null||m.questionToken!==void 0&&m.questionToken!==null;let k;if(M&&(c.optional=!0,m.initializer))try{if(m.initializer.kind===a.SyntaxKind.StringLiteral)k=m.initializer.text;else if(m.initializer.kind===a.SyntaxKind.NumericLiteral)k=parseFloat(m.initializer.text);else if(m.initializer.kind===a.SyntaxKind.TrueKeyword||m.initializer.kind===a.SyntaxKind.FalseKeyword)k=m.initializer.kind===a.SyntaxKind.TrueKeyword;else if(m.initializer.kind===a.SyntaxKind.NullKeyword)k=null;else if(a.isPrefixUnaryExpression(m.initializer)&&m.initializer.operator===a.SyntaxKind.MinusToken&&m.initializer.operand.kind===a.SyntaxKind.NumericLiteral)k=-parseFloat(m.initializer.operand.text);else if(a.isPropertyAccessExpression(m.initializer)||a.isElementAccessExpression(m.initializer)){const O=$.getTypeAtLocation(m.initializer);O.flags&(a.TypeFlags.NumberLiteral|a.TypeFlags.StringLiteral)&&(k=O.value)}}catch(O){console.warn(`Couldn't extract default value for parameter '${c.name}'`,O)}m.dotDotDotToken&&(c.rest=!0);const x=c.repeating;if(x){if(c.rest)return void r(m,o.DiagnosticCode.RepeatingPosition,`'${s.name}' parameter '${c.name}' is both a rest parameter and a repeating group. A group already repeats — drop the '...'.`);if(M&&x.length===1)return void r(m,o.DiagnosticCode.RepeatingOptional,`'${s.name}' parameter '${c.name}' cannot be an optional repeating group. Use '...${c.name}: T[]' for zero-or-more, or drop the '?' for one-or-more.`);if(f!==null)return void r(m,o.DiagnosticCode.MultipleRepeating,`'${s.name}' has more than one repeating group ('${f}' and '${c.name}'). Only one is allowed — two would make the argument count ambiguous.`);if(t!==null)return void r(m,o.DiagnosticCode.RepeatingOptional,`'${s.name}' parameter '${t}' is optional and precedes the repeating group '${c.name}'. Every parameter outside a group must be required.`);f=c.name,i=x.length,d=x[x.length-1].optional===!0}else{if(f!==null&&c.rest)return void r(m,o.DiagnosticCode.RepeatingOptional,`'${s.name}' parameter '${c.name}' is a rest parameter and follows the repeating group '${f}'. Two variadic tails would make the argument count ambiguous.`);if(f!==null&&M){if(b>=i-1)return void r(m,o.DiagnosticCode.RepeatingOptional,i===1?`'${s.name}' parameter '${c.name}' is optional and follows the period-1 repeating group '${f}'. One more argument is indistinguishable from one more repetition — make it required, or give the group a period.`:`'${s.name}' has ${b+1} optional parameters after the repeating group '${f}', which has period ${i}. At most ${i-1} may be optional, or the argument count no longer decides the parse.`);if(d)return void r(m,o.DiagnosticCode.RepeatingOptional,`'${s.name}' parameter '${c.name}' is optional and follows '${f}', whose own last slot is already optional. Both omissions reach the same argument count — drop one.`);b++}}M&&!x&&(t=c.name);const D=(c.range?2:0)+(c.arrayDepth??0),Y=c.range==="r"||c.range==="p"||c.range==="*",I=c.rest||Y?3:2;if(D>I)return void r(m,o.DiagnosticCode.ArrayDepth,`'${s.name}' parameter '${c.name}' has an array depth of ${D}; the maximum is ${I}${c.rest?" for a rest parameter":" (use a rest parameter for one more level, or an IRange)"}.`);s.parameters.push(c);const z={description:""};l.parameters[c.name]=z;const ae=$.getSymbolAtLocation(m.name);z.description=H(ae?.getDocumentationComment($)),k!==void 0&&(c.defaultValue=k);for(const O of[c,...c.repeating??[]]){const J=O.enum?ue.get(O.enum):void 0;J&&((l.enums??={})[O.enum.id]=J)}if(p.set(c.name,c),h.set(c.name,m),x&&x.length>1){L.add(c.name);for(const O of x){const J=`${c.name}.${O.name}`;l.parameters[J]={description:""},p.set(J,O),h.set(J,m)}}}const E=s.maxArguments;if(E!==void 0){const g=s.parameters??[];if(!g.some(c=>c.rest===!0||c.repeating!==void 0))return void r(e,o.DiagnosticCode.RepeatingMax,`'${s.name}' declares a maximum of ${E} arguments but takes a fixed ${g.length}. A maximum only means something on a variadic tail.`);let m=0;for(const c of g)c.rest!==!0&&c.optional!==!0&&(m+=c.repeating?c.repeating.length:1);if(E<m)return void r(e,o.DiagnosticCode.RepeatingMax,`'${s.name}' declares a maximum of ${E} arguments but requires ${m}.`)}if(e.jsDoc&&e.jsDoc.length>0){const g=e.jsDoc,m=g.length;for(let c=0;c<m;c++){const C=g[c]?.tags;if(!C)continue;const G=C.length;for(let M=0;M<G;M++){const k=C[M];let x=k?.tagName?.text;if(!x)continue;x=x.toLowerCase();let D=k.comment;const Y=o.isStandaloneJSDocTag(x);if(typeof D=="string"||Y){if(typeof D=="string"&&(D=D.replace(/\r\n?/g,`
5
- `).trim()),Y||!D||(D=D.split(`
6
- `)[0].trim(),D&&D.length!==0)){if(D&&typeof D=="string"){const I=/\{@link(code|plain)?\s+([^}|]+)(?:\s*\|\s*([^}]+))?\}/g;let z,ae=D,O=[];for(;(z=I.exec(D))!==null;){const[J,Pe,Ae,fe]=z,ke=[Ae.trim()];fe&&ke.push(fe.trim())}D=ae,O.length>0&&x==="see"&&(l.links||(l.links=[]),l.links.push(...O))}if(x==="name"){const I=D;I!==n&&(l.name=I)}else if(x!=="description"){if(x==="param"){const I=k.name?.getText?.()??k.name?.text;if(!p.get(I)){r(k,o.DiagnosticCode.UnknownParam,`Parameter '${I}' not found in function '${n}'.`);continue}const z=l.parameters?.[I];z&&!z.description&&typeof D=="string"&&D&&(z.description=D)}else if(x==="returns"||x==="return")s.returnType.description=D;else if(x==="returnkind"){const I=(D??"").trim().toLowerCase();ie.has(I)?s.returnType.kind=I:r(k,o.DiagnosticCode.UnknownReturnKind,`'@returnKind ${I}' is not a known value kind. Known: ${[...ie].map(z=>`'${z}'`).join(", ")}.`)}else if(x==="category")l.category=D;else if(x==="deprecated"||x==="hidden"){let I=!0;const z=D?.toLowerCase();z==="false"?I=!1:z!=="true"&&(I=D),I!==!1&&(l.deprecated=I??!0)}}}}else x==="returnkind"&&r(k,o.DiagnosticCode.UnknownReturnKind,`'@returnKind' needs a value kind. Known: ${[...ie].map(I=>`'${I}'`).join(", ")}.`)}}}Object.keys(s.returnType).length===0&&delete s.returnType,Object.keys(T).length>0&&(s.behavior=T),l.summary||U(e.name??e,o.DiagnosticCode.MissingSummary,"warning",`'${n}': missing a description. Add a JSDoc comment above the function.`);const K=!s.context,A=K&&l.name||n;if(K&&!Re.test(A)){const g=l.name?`'@name ${l.name}'`:`'${A}'`;return void r(e.name??e,o.DiagnosticCode.InvalidName,`'${n}': ${g} cannot be called from a formula. A function name starts with a letter or '_', and continues with letters, digits, '_' or '.'.`+(l.name?"":" Add an '@name' tag to register it under another name."))}if(K&&!S?.isBuiltIn&&(g=>{if(Fe.test(g))return!0;const m=Ee.exec(g);if(!m)return!1;let c=0;for(const G of m[1].toUpperCase())c=26*c+(G.charCodeAt(0)-64);const C=Number(m[2]);return c<=16384&&C>=1&&C<=1048576})(A)){const g=l.name?`'@name ${l.name}'`:`'${A}'`;return void r(e.name??e,o.DiagnosticCode.InvalidName,`'${n}': ${g} cannot be called from a formula. It reads as a cell address.`+(l.name?"":" Add an '@name' tag to register it under another name."))}const P=W.get(A.toUpperCase());if(P!==void 0)return void r(e.name??e,o.DiagnosticCode.DuplicateName,`'${n}': '${A}' is already the name of '${P}' in this module.`);if(W.set(A.toUpperCase(),n),K&&B?.has(A.toUpperCase()))return void r(e.name??e,o.DiagnosticCode.BuiltInName,`'${A}' is a built-in function. Choose a different name - a calculation function cannot replace a built-in.`);if(K){const g=l.parameters??{};for(const[m,c]of Object.entries(g))if(!L.has(m)&&!c.description){const C=h.get(m);U(C,o.DiagnosticCode.MissingParamDescription,"warning",`'${n}': parameter '${m}' is missing a description. Add an '@param ${m}' tag.`)}}q.push([s,l])}catch(u){r(e,o.DiagnosticCode.ParseError,`'${n}': ${u.message}`)}}})}catch(e){r(void 0,o.DiagnosticCode.ParseError,`Unable to analyze module: ${e?.message??e}`)}return{functions:q,autoRun:X,diagnostics:Q}}exports.analyzeModule=ve,exports.lintScript=function(a,R,$){const S="script.ts",B="lib.d.ts",q={[S]:R??"",[B]:""},W=a.createProgram([S],{allowJs:!0,noResolve:!0,noLib:!0,isolatedModules:!0,module:99,target:a.ScriptTarget.ES2020},{getSourceFile:U=>{const r=q[U];if(r!==void 0)return a.createSourceFile(U,r,a.ScriptTarget.Latest,!0)},fileExists:U=>q[U]!==void 0,readFile:U=>q[U],writeFile:()=>{},getCurrentDirectory:()=>"./",getCanonicalFileName:U=>U,useCaseSensitiveFileNames:()=>!0,getDefaultLibFileName:()=>B,getNewLine:()=>`
7
- `}),Q=W.getTypeChecker(),X=W.getSourceFile(S);return X?ve(a,X,Q,$).diagnostics:[]};