@ricsam/formula-engine 0.2.9 → 0.2.11

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 (46) hide show
  1. package/README.md +40 -0
  2. package/dist/cjs/core/engine.cjs +79 -3
  3. package/dist/cjs/core/engine.cjs.map +3 -3
  4. package/dist/cjs/core/managers/dependency-manager.cjs +151 -67
  5. package/dist/cjs/core/managers/dependency-manager.cjs.map +3 -3
  6. package/dist/cjs/core/managers/named-expression-manager.cjs +18 -16
  7. package/dist/cjs/core/managers/named-expression-manager.cjs.map +3 -3
  8. package/dist/cjs/core/managers/workbook-manager.cjs +197 -1
  9. package/dist/cjs/core/managers/workbook-manager.cjs.map +3 -3
  10. package/dist/cjs/core/types.cjs.map +2 -2
  11. package/dist/cjs/core/workbook-renamer.cjs.map +1 -1
  12. package/dist/cjs/evaluator/formula-evaluator.cjs +22 -48
  13. package/dist/cjs/evaluator/formula-evaluator.cjs.map +3 -3
  14. package/dist/cjs/functions/math/sum/summation-utils.cjs +2 -2
  15. package/dist/cjs/functions/math/sum/summation-utils.cjs.map +2 -2
  16. package/dist/cjs/package.json +1 -1
  17. package/dist/cjs/parser/formatter.cjs +3 -4
  18. package/dist/cjs/parser/formatter.cjs.map +3 -3
  19. package/dist/cjs/parser/parser.cjs +24 -216
  20. package/dist/cjs/parser/parser.cjs.map +3 -3
  21. package/dist/mjs/core/engine.mjs +79 -3
  22. package/dist/mjs/core/engine.mjs.map +3 -3
  23. package/dist/mjs/core/managers/dependency-manager.mjs +151 -67
  24. package/dist/mjs/core/managers/dependency-manager.mjs.map +3 -3
  25. package/dist/mjs/core/managers/named-expression-manager.mjs +18 -16
  26. package/dist/mjs/core/managers/named-expression-manager.mjs.map +3 -3
  27. package/dist/mjs/core/managers/workbook-manager.mjs +197 -1
  28. package/dist/mjs/core/managers/workbook-manager.mjs.map +3 -3
  29. package/dist/mjs/core/types.mjs.map +2 -2
  30. package/dist/mjs/core/workbook-renamer.mjs.map +1 -1
  31. package/dist/mjs/evaluator/formula-evaluator.mjs +22 -48
  32. package/dist/mjs/evaluator/formula-evaluator.mjs.map +3 -3
  33. package/dist/mjs/functions/math/sum/summation-utils.mjs +2 -2
  34. package/dist/mjs/functions/math/sum/summation-utils.mjs.map +2 -2
  35. package/dist/mjs/package.json +1 -1
  36. package/dist/mjs/parser/formatter.mjs +3 -4
  37. package/dist/mjs/parser/formatter.mjs.map +3 -3
  38. package/dist/mjs/parser/parser.mjs +24 -216
  39. package/dist/mjs/parser/parser.mjs.map +3 -3
  40. package/dist/types/core/engine.d.ts +17 -1
  41. package/dist/types/core/managers/dependency-manager.d.ts +4 -0
  42. package/dist/types/core/managers/named-expression-manager.d.ts +1 -0
  43. package/dist/types/core/managers/workbook-manager.d.ts +23 -1
  44. package/dist/types/core/types.d.ts +35 -0
  45. package/dist/types/parser/parser.d.ts +4 -6
  46. package/package.json +1 -1
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../src/core/types.ts"],
4
4
  "sourcesContent": [
5
- "/**\n * Core type definitions for FormulaEngine\n * This file contains all fundamental types used throughout the engine\n */\n\nimport type { EvaluationContext } from \"../evaluator/evaluation-context.cjs\";\nimport type { FormulaEvaluator } from \"../evaluator/formula-evaluator.cjs\";\nimport type { FunctionNode } from \"../parser/ast.cjs\";\nimport type { DependencyNode } from \"./managers/dependency-node.cjs\";\nimport type { LookupOrder } from \"./managers/range-eval-order-builder.cjs\";\n\n// Cell addressing types\nexport interface CellAddress {\n sheetName: string;\n workbookName: string;\n colIndex: number;\n rowIndex: number;\n}\n\nexport interface RangeAddress {\n sheetName: string;\n workbookName: string;\n range: SpreadsheetRange;\n}\n\nexport interface LocalCellAddress {\n colIndex: number;\n rowIndex: number;\n}\n\nexport type ArethmeticEvaluator = (\n left: CellValue,\n right: CellValue,\n context: EvaluationContext\n) => CellValue | ErrorEvaluationResult;\n\nexport type PositiveInfinity = {\n type: \"infinity\";\n sign: \"positive\";\n};\n\nexport type CellInfinity = {\n type: \"infinity\";\n sign: \"positive\" | \"negative\";\n};\n\nexport type CellNumber = {\n type: \"number\";\n value: number;\n};\n\nexport type SpreadsheetRangeEnd = CellNumber | PositiveInfinity;\n\nexport type SpreadsheetRange = {\n start: {\n col: number;\n row: number;\n };\n end: {\n col: SpreadsheetRangeEnd;\n row: SpreadsheetRangeEnd;\n };\n};\n\nexport type RelativeRange = {\n start: {\n col: number;\n row: number;\n };\n width: SpreadsheetRangeEnd;\n height: SpreadsheetRangeEnd;\n};\n\nexport type FiniteSpreadsheetRange = {\n start: {\n col: number;\n row: number;\n };\n end: {\n col: number;\n row: number;\n };\n};\n\nexport type CellString = {\n type: \"string\";\n value: string;\n};\n\nexport type CellBoolean = {\n type: \"boolean\";\n value: boolean;\n};\n\n// Cell value types\nexport type CellValue = CellNumber | CellString | CellBoolean | CellInfinity;\n/**\n * undefined and \"\" are considered empty values\n * undefineds are converted to \"\" in the engine\n *\n * any empty values are deleted from the sheet content\n */\nexport type SerializedCellValue = string | number | boolean | undefined;\n\n// Named expressions\nexport interface NamedExpression {\n name: string;\n expression: string;\n}\n\nexport interface TableDefinition {\n name: string;\n start: {\n rowIndex: number;\n colIndex: number;\n };\n headers: Map<string, { name: string; index: number }>;\n endRow: SpreadsheetRangeEnd;\n sheetName: string;\n workbookName: string;\n}\n\n// Formula errors\nexport enum FormulaError {\n DIV0 = \"#DIV/0!\",\n NA = \"#N/A\",\n NAME = \"#NAME?\",\n NUM = \"#NUM!\",\n REF = \"#REF!\",\n VALUE = \"#VALUE!\",\n CYCLE = \"#CYCLE!\",\n ERROR = \"#ERROR!\",\n SPILL = \"#SPILL!\",\n}\n\n// Sheet structure\nexport interface Sheet<TCellMetadata = unknown, TSheetMetadata = unknown> {\n name: string;\n index: number; // 0-based index of the sheet\n content: Map<string, SerializedCellValue>;\n /**\n * Cell metadata - arbitrary consumer-defined data per cell\n * Examples: rich text content, links, comments, custom app data\n * The engine stores and copies this data but doesn't interpret it\n * Keyed by cell reference (e.g., \"A1\")\n */\n metadata: Map<string, TCellMetadata>;\n /**\n * Sheet-level metadata - arbitrary consumer-defined data for the entire sheet\n * Examples: text boxes, drawings, frozen panes, print settings\n * The engine stores and copies this data but doesn't interpret it\n */\n sheetMetadata: TSheetMetadata;\n}\n\nexport interface Workbook<\n TCellMetadata = unknown,\n TSheetMetadata = unknown,\n TWorkbookMetadata = unknown\n> {\n name: string;\n sheets: Map<string, Sheet<TCellMetadata, TSheetMetadata>>;\n /**\n * Workbook-level metadata - arbitrary consumer-defined data for the entire workbook\n * Examples: themes, custom ribbons, document properties, workbook settings\n * The engine stores and copies this data but doesn't interpret it\n */\n workbookMetadata: TWorkbookMetadata;\n}\n\n/**\n * Tracked reference - a stable reference to a range that updates automatically\n * when workbooks/sheets are renamed and becomes invalid when they're deleted\n */\nexport interface TrackedReference {\n id: string; // UUID\n address: RangeAddress; // The range being tracked\n isValid: boolean; // False if sheet/workbook deleted\n}\n\nexport type ValueEvaluationResult = {\n type: \"value\";\n result: CellValue;\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n */\n sourceCell?: CellAddress;\n};\n\nexport type AwaitingEvaluationResult = {\n type: \"awaiting-evaluation\";\n waitingFor: DependencyNode;\n errAddress: DependencyNode;\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n */\n sourceCell?: CellAddress;\n};\n\nexport type DoesNotSpillResult = {\n type: \"does-not-spill\";\n};\n\nexport type ErrorEvaluationResult =\n | {\n type: \"error\";\n err: FormulaError;\n errAddress: DependencyNode;\n message: string;\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n */\n sourceCell?: CellAddress;\n }\n | AwaitingEvaluationResult;\n\nexport type SingleEvaluationResult =\n | ValueEvaluationResult\n | ErrorEvaluationResult;\n\nexport type SpilledValuesEvaluator = (\n spillOffset: { x: number; y: number },\n context: EvaluationContext\n) => SingleEvaluationResult;\n\nexport type SpilledValuesEvaluationResult = {\n type: \"spilled-values\";\n\n /**\n * When a raw range is evaluated, we will add it to the sourceRange so it can be used e.g. for context dependent functions\n */\n sourceRange?: RangeAddress;\n\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n * sourceCell will only be defined on a spilledValue when a single value is looked up,\n */\n sourceCell?: CellAddress;\n\n spillArea: (origin: CellAddress) => SpreadsheetRange;\n /**\n * for debugging we add a source string to denote where the spilled values were created\n */\n source: string;\n evaluate: SpilledValuesEvaluator;\n /**\n * evaluateAllCells evaluates all non-empty cells in the spilled range.\n * Because a spilled range can be open-ended, we need to have logic for which cells we should evaluate.\n * e.g. when evaluating a range such as D:D only the cells in the current sheet residing in\n * column D should be evaluated and cells producing spilled values that spill onto D:D.\n *\n * In order to evaluate spilled cells in D:D the range evaluateAllCells need to get all cells in the\n * the intersection of the spilled range and D:D, for that reason evaluateAllCells gets an intersection parameter,\n * where the intersection is relative to the origin.\n *\n * #### Producers:\n * In e.g. SEQUENCE and evaluateRange we have logic for which cells in a spilled range we should evaluate,\n *\n * #### Nesting:\n * e.g. evaluation of scalar operators where we want to nest e.g. `5 * right.evaluate()`\n * can be implemented by calling\n * ```ts\n * const vals = child.evaluateAllCells.call(this, options);\n * return vals.map(val => ({ ...val, result: 5 * val.result }));\n * ```\n *\n * #### Consumers:\n * Only functions that need access to all spilled values in a range end up calling evaluateAllCells, e.g.\n * SUM, MIN, MAX, MATCH. Other types of functions like INDEX doesn't need to evaluate all cells in a range,\n * but does a lookup into a spilled range using the evaluate method.\n *\n */\n evaluateAllCells: (\n this: FormulaEvaluator,\n options: {\n /**\n * an intersection relative to the origin\n */\n intersection?: SpreadsheetRange;\n evaluate: SpilledValuesEvaluator;\n context: EvaluationContext;\n /**\n * origin is the cell address that the spilled range is spilled from\n * e.g. in A3=B2:B4 the origin is A3\n */\n origin: CellAddress;\n\n lookupOrder: LookupOrder;\n }\n ) => EvaluateAllCellsResult;\n};\n\nexport type EvaluateAllCellsResult =\n | ErrorEvaluationResult\n | {\n type: \"values\";\n values: CellInRangeResult[];\n };\n\nexport type CellInRangeResult = {\n result: SingleEvaluationResult;\n relativePos: { x: number; y: number };\n};\n\nexport type FunctionEvaluationResult =\n | SingleEvaluationResult\n | SpilledValuesEvaluationResult;\n\nexport type SpilledValue = {\n /**\n * spillOnto is the range that the spilled value is spilled onto\n */\n spillOnto: SpreadsheetRange;\n /**\n * origin is the cell address that the spilled value is spilled from\n */\n origin: CellAddress;\n};\n\n/**\n * Function definition\n */\nexport interface FunctionDefinition {\n name: string;\n evaluate: (\n this: FormulaEvaluator,\n node: FunctionNode,\n context: EvaluationContext\n ) => FunctionEvaluationResult;\n aliases?: string[];\n}\n\n/**\n * Evaluation result\n */\nexport type EvaluationResult = {\n dependencies: Set<string>;\n} & FunctionEvaluationResult;\n\nexport type SCC = {\n id: number;\n nodes: Set<DependencyNode>; // All nodes considering soft + hard edges\n evaluationOrder: DependencyNode[]; // Flat topologically ordered list\n resolved: boolean;\n hardEdgeSCCs: Set<DependencyNode>[]; // SCCs formed by only hard edges (regular dependencies)\n};\n\nexport type SCCDAG = {\n sccList: SCC[];\n sccGraph: Map<number, Set<number>>; // Adjacency list of SCC dependencies\n};\n\nexport type EvaluationOrder = {\n evaluationOrder: Set<DependencyNode>;\n hasCycle: boolean;\n cycleNodes?: Set<DependencyNode>;\n hash: string;\n sccDAG?: SCCDAG;\n};\n\n// Conditional Styling types\nexport interface LCHColor {\n l: number; // Lightness: 0-100\n c: number; // Chroma: 0-150+\n h: number; // Hue: 0-360\n}\n\nexport interface FormulaStyleCondition {\n type: \"formula\";\n formula: string;\n color: LCHColor;\n}\n\nexport interface GradientStyleCondition {\n type: \"gradient\";\n min:\n | { type: \"lowest_value\"; color: LCHColor }\n | { type: \"number\"; color: LCHColor; valueFormula: string };\n max:\n | { type: \"highest_value\"; color: LCHColor }\n | { type: \"number\"; color: LCHColor; valueFormula: string };\n}\n\nexport type StyleCondition = FormulaStyleCondition | GradientStyleCondition;\n\nexport interface ConditionalStyle {\n areas: RangeAddress[];\n condition: StyleCondition;\n}\n\nexport interface DirectCellStyle {\n areas: RangeAddress[];\n style: CellStyle;\n}\n\nexport interface CellStyle {\n backgroundColor?: string; // Hex color format\n color?: string; // Text color in hex format\n fontSize?: number; // Font size in pixels\n bold?: boolean;\n italic?: boolean;\n underline?: boolean;\n}\n\nexport interface CopyCellsOptions {\n /**\n * Whether this is a cut operation (clears source cells after copying)\n * @default false\n */\n cut?: boolean;\n /**\n * What to include in the copy operation.\n * - Use 'all' as shorthand for ['content', 'style', 'metadata']\n * - Use array for fine-grained control over what to copy:\n * - ['content'] - copy only values/formulas\n * - ['style'] - copy only formatting\n * - ['metadata'] - copy only metadata (rich text, links, etc.)\n * - ['content', 'style'] - copy content and formatting\n * - ['content', 'metadata'] - copy content and metadata\n * - ['style', 'metadata'] - copy formatting and metadata\n * - ['content', 'style', 'metadata'] - same as 'all'\n * @default 'all'\n */\n include?: \"all\" | (\"content\" | \"style\" | \"metadata\")[];\n /**\n * The type of the content to copy\n * value: Copy the value from the source to the target,\n * e.g. if the cell has the formula =123 + 123 then the value is 246\n * formula: Copy the formula from the source to the target,\n * e.g. if the cell has the formula =123 + 123 then the formula is =123 + 123 is copied\n * @default 'formula'\n */\n type?: \"value\" | \"formula\";\n}\n"
5
+ "/**\n * Core type definitions for FormulaEngine\n * This file contains all fundamental types used throughout the engine\n */\n\nimport type { EvaluationContext } from \"../evaluator/evaluation-context.cjs\";\nimport type { FormulaEvaluator } from \"../evaluator/formula-evaluator.cjs\";\nimport type { FunctionNode } from \"../parser/ast.cjs\";\nimport type { DependencyNode } from \"./managers/dependency-node.cjs\";\nimport type { LookupOrder } from \"./managers/range-eval-order-builder.cjs\";\n\n// Cell addressing types\nexport interface CellAddress {\n sheetName: string;\n workbookName: string;\n colIndex: number;\n rowIndex: number;\n}\n\nexport interface RangeAddress {\n sheetName: string;\n workbookName: string;\n range: SpreadsheetRange;\n}\n\nexport interface LocalCellAddress {\n colIndex: number;\n rowIndex: number;\n}\n\nexport type ArethmeticEvaluator = (\n left: CellValue,\n right: CellValue,\n context: EvaluationContext\n) => CellValue | ErrorEvaluationResult;\n\nexport type PositiveInfinity = {\n type: \"infinity\";\n sign: \"positive\";\n};\n\nexport type CellInfinity = {\n type: \"infinity\";\n sign: \"positive\" | \"negative\";\n};\n\nexport type CellNumber = {\n type: \"number\";\n value: number;\n};\n\nexport type SpreadsheetRangeEnd = CellNumber | PositiveInfinity;\n\nexport type SpreadsheetRange = {\n start: {\n col: number;\n row: number;\n };\n end: {\n col: SpreadsheetRangeEnd;\n row: SpreadsheetRangeEnd;\n };\n};\n\nexport type RelativeRange = {\n start: {\n col: number;\n row: number;\n };\n width: SpreadsheetRangeEnd;\n height: SpreadsheetRangeEnd;\n};\n\nexport type FiniteSpreadsheetRange = {\n start: {\n col: number;\n row: number;\n };\n end: {\n col: number;\n row: number;\n };\n};\n\nexport type CellString = {\n type: \"string\";\n value: string;\n};\n\nexport type CellBoolean = {\n type: \"boolean\";\n value: boolean;\n};\n\n// Cell value types\nexport type CellValue = CellNumber | CellString | CellBoolean | CellInfinity;\n/**\n * undefined and \"\" are considered empty values\n * undefineds are converted to \"\" in the engine\n *\n * any empty values are deleted from the sheet content\n */\nexport type SerializedCellValue = string | number | boolean | undefined;\n\nexport interface SearchOptions {\n workbookName?: string;\n sheetName?: string;\n caseSensitive?: boolean;\n}\n\nexport interface SearchMatch {\n workbookName: string;\n sheetName: string;\n cellReference: string;\n cellContent: string;\n contentKind: \"formula\" | \"text\";\n occurrenceIndex: number;\n startIndex: number;\n endIndexExclusive: number;\n matchedText: string;\n}\n\nexport interface ReplaceTarget {\n workbookName: string;\n sheetName: string;\n cellReference: string;\n occurrenceIndex: number;\n}\n\nexport interface ReplaceChange {\n workbookName: string;\n sheetName: string;\n cellReference: string;\n contentKind: \"formula\" | \"text\";\n occurrenceIndex: number;\n startIndex: number;\n endIndexExclusive: number;\n matchedText: string;\n replacementText: string;\n beforeContent: string;\n afterContent: string;\n}\n\n// Named expressions\nexport interface NamedExpression {\n name: string;\n expression: string;\n}\n\nexport interface TableDefinition {\n name: string;\n start: {\n rowIndex: number;\n colIndex: number;\n };\n headers: Map<string, { name: string; index: number }>;\n endRow: SpreadsheetRangeEnd;\n sheetName: string;\n workbookName: string;\n}\n\n// Formula errors\nexport enum FormulaError {\n DIV0 = \"#DIV/0!\",\n NA = \"#N/A\",\n NAME = \"#NAME?\",\n NUM = \"#NUM!\",\n REF = \"#REF!\",\n VALUE = \"#VALUE!\",\n CYCLE = \"#CYCLE!\",\n ERROR = \"#ERROR!\",\n SPILL = \"#SPILL!\",\n}\n\n// Sheet structure\nexport interface Sheet<TCellMetadata = unknown, TSheetMetadata = unknown> {\n name: string;\n index: number; // 0-based index of the sheet\n content: Map<string, SerializedCellValue>;\n /**\n * Cell metadata - arbitrary consumer-defined data per cell\n * Examples: rich text content, links, comments, custom app data\n * The engine stores and copies this data but doesn't interpret it\n * Keyed by cell reference (e.g., \"A1\")\n */\n metadata: Map<string, TCellMetadata>;\n /**\n * Sheet-level metadata - arbitrary consumer-defined data for the entire sheet\n * Examples: text boxes, drawings, frozen panes, print settings\n * The engine stores and copies this data but doesn't interpret it\n */\n sheetMetadata: TSheetMetadata;\n}\n\nexport interface Workbook<\n TCellMetadata = unknown,\n TSheetMetadata = unknown,\n TWorkbookMetadata = unknown\n> {\n name: string;\n sheets: Map<string, Sheet<TCellMetadata, TSheetMetadata>>;\n /**\n * Workbook-level metadata - arbitrary consumer-defined data for the entire workbook\n * Examples: themes, custom ribbons, document properties, workbook settings\n * The engine stores and copies this data but doesn't interpret it\n */\n workbookMetadata: TWorkbookMetadata;\n}\n\n/**\n * Tracked reference - a stable reference to a range that updates automatically\n * when workbooks/sheets are renamed and becomes invalid when they're deleted\n */\nexport interface TrackedReference {\n id: string; // UUID\n address: RangeAddress; // The range being tracked\n isValid: boolean; // False if sheet/workbook deleted\n}\n\nexport type ValueEvaluationResult = {\n type: \"value\";\n result: CellValue;\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n */\n sourceCell?: CellAddress;\n};\n\nexport type AwaitingEvaluationResult = {\n type: \"awaiting-evaluation\";\n waitingFor: DependencyNode;\n errAddress: DependencyNode;\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n */\n sourceCell?: CellAddress;\n};\n\nexport type DoesNotSpillResult = {\n type: \"does-not-spill\";\n};\n\nexport type ErrorEvaluationResult =\n | {\n type: \"error\";\n err: FormulaError;\n errAddress: DependencyNode;\n message: string;\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n */\n sourceCell?: CellAddress;\n }\n | AwaitingEvaluationResult;\n\nexport type SingleEvaluationResult =\n | ValueEvaluationResult\n | ErrorEvaluationResult;\n\nexport type SpilledValuesEvaluator = (\n spillOffset: { x: number; y: number },\n context: EvaluationContext\n) => SingleEvaluationResult;\n\nexport type SpilledValuesEvaluationResult = {\n type: \"spilled-values\";\n\n /**\n * When a raw range is evaluated, we will add it to the sourceRange so it can be used e.g. for context dependent functions\n */\n sourceRange?: RangeAddress;\n\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n * sourceCell will only be defined on a spilledValue when a single value is looked up,\n */\n sourceCell?: CellAddress;\n\n spillArea: (origin: CellAddress) => SpreadsheetRange;\n /**\n * for debugging we add a source string to denote where the spilled values were created\n */\n source: string;\n evaluate: SpilledValuesEvaluator;\n /**\n * evaluateAllCells evaluates all non-empty cells in the spilled range.\n * Because a spilled range can be open-ended, we need to have logic for which cells we should evaluate.\n * e.g. when evaluating a range such as D:D only the cells in the current sheet residing in\n * column D should be evaluated and cells producing spilled values that spill onto D:D.\n *\n * In order to evaluate spilled cells in D:D the range evaluateAllCells need to get all cells in the\n * the intersection of the spilled range and D:D, for that reason evaluateAllCells gets an intersection parameter,\n * where the intersection is relative to the origin.\n *\n * #### Producers:\n * In e.g. SEQUENCE and evaluateRange we have logic for which cells in a spilled range we should evaluate,\n *\n * #### Nesting:\n * e.g. evaluation of scalar operators where we want to nest e.g. `5 * right.evaluate()`\n * can be implemented by calling\n * ```ts\n * const vals = child.evaluateAllCells.call(this, options);\n * return vals.map(val => ({ ...val, result: 5 * val.result }));\n * ```\n *\n * #### Consumers:\n * Only functions that need access to all spilled values in a range end up calling evaluateAllCells, e.g.\n * SUM, MIN, MAX, MATCH. Other types of functions like INDEX doesn't need to evaluate all cells in a range,\n * but does a lookup into a spilled range using the evaluate method.\n *\n */\n evaluateAllCells: (\n this: FormulaEvaluator,\n options: {\n /**\n * an intersection relative to the origin\n */\n intersection?: SpreadsheetRange;\n evaluate: SpilledValuesEvaluator;\n context: EvaluationContext;\n /**\n * origin is the cell address that the spilled range is spilled from\n * e.g. in A3=B2:B4 the origin is A3\n */\n origin: CellAddress;\n\n lookupOrder: LookupOrder;\n }\n ) => EvaluateAllCellsResult;\n};\n\nexport type EvaluateAllCellsResult =\n | ErrorEvaluationResult\n | {\n type: \"values\";\n values: CellInRangeResult[];\n };\n\nexport type CellInRangeResult = {\n result: SingleEvaluationResult;\n relativePos: { x: number; y: number };\n};\n\nexport type FunctionEvaluationResult =\n | SingleEvaluationResult\n | SpilledValuesEvaluationResult;\n\nexport type SpilledValue = {\n /**\n * spillOnto is the range that the spilled value is spilled onto\n */\n spillOnto: SpreadsheetRange;\n /**\n * origin is the cell address that the spilled value is spilled from\n */\n origin: CellAddress;\n};\n\n/**\n * Function definition\n */\nexport interface FunctionDefinition {\n name: string;\n evaluate: (\n this: FormulaEvaluator,\n node: FunctionNode,\n context: EvaluationContext\n ) => FunctionEvaluationResult;\n aliases?: string[];\n}\n\n/**\n * Evaluation result\n */\nexport type EvaluationResult = {\n dependencies: Set<string>;\n} & FunctionEvaluationResult;\n\nexport type SCC = {\n id: number;\n nodes: Set<DependencyNode>; // All nodes considering soft + hard edges\n evaluationOrder: DependencyNode[]; // Flat topologically ordered list\n resolved: boolean;\n hardEdgeSCCs: Set<DependencyNode>[]; // SCCs formed by only hard edges (regular dependencies)\n};\n\nexport type SCCDAG = {\n sccList: SCC[];\n sccGraph: Map<number, Set<number>>; // Adjacency list of SCC dependencies\n};\n\nexport type EvaluationOrder = {\n evaluationOrder: Set<DependencyNode>;\n hasCycle: boolean;\n cycleNodes?: Set<DependencyNode>;\n hash: string;\n sccDAG?: SCCDAG;\n};\n\n// Conditional Styling types\nexport interface LCHColor {\n l: number; // Lightness: 0-100\n c: number; // Chroma: 0-150+\n h: number; // Hue: 0-360\n}\n\nexport interface FormulaStyleCondition {\n type: \"formula\";\n formula: string;\n color: LCHColor;\n}\n\nexport interface GradientStyleCondition {\n type: \"gradient\";\n min:\n | { type: \"lowest_value\"; color: LCHColor }\n | { type: \"number\"; color: LCHColor; valueFormula: string };\n max:\n | { type: \"highest_value\"; color: LCHColor }\n | { type: \"number\"; color: LCHColor; valueFormula: string };\n}\n\nexport type StyleCondition = FormulaStyleCondition | GradientStyleCondition;\n\nexport interface ConditionalStyle {\n areas: RangeAddress[];\n condition: StyleCondition;\n}\n\nexport interface DirectCellStyle {\n areas: RangeAddress[];\n style: CellStyle;\n}\n\nexport interface CellStyle {\n backgroundColor?: string; // Hex color format\n color?: string; // Text color in hex format\n fontSize?: number; // Font size in pixels\n bold?: boolean;\n italic?: boolean;\n underline?: boolean;\n}\n\nexport interface CopyCellsOptions {\n /**\n * Whether this is a cut operation (clears source cells after copying)\n * @default false\n */\n cut?: boolean;\n /**\n * What to include in the copy operation.\n * - Use 'all' as shorthand for ['content', 'style', 'metadata']\n * - Use array for fine-grained control over what to copy:\n * - ['content'] - copy only values/formulas\n * - ['style'] - copy only formatting\n * - ['metadata'] - copy only metadata (rich text, links, etc.)\n * - ['content', 'style'] - copy content and formatting\n * - ['content', 'metadata'] - copy content and metadata\n * - ['style', 'metadata'] - copy formatting and metadata\n * - ['content', 'style', 'metadata'] - same as 'all'\n * @default 'all'\n */\n include?: \"all\" | (\"content\" | \"style\" | \"metadata\")[];\n /**\n * The type of the content to copy\n * value: Copy the value from the source to the target,\n * e.g. if the cell has the formula =123 + 123 then the value is 246\n * formula: Copy the formula from the source to the target,\n * e.g. if the cell has the formula =123 + 123 then the formula is =123 + 123 is copied\n * @default 'formula'\n */\n type?: \"value\" | \"formula\";\n}\n"
6
6
  ],
7
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2HO,IAAK;AAAA,CAAL,CAAK,kBAAL;AAAA,EACL,wBAAO;AAAA,EACP,sBAAK;AAAA,EACL,wBAAO;AAAA,EACP,uBAAM;AAAA,EACN,uBAAM;AAAA,EACN,yBAAQ;AAAA,EACR,yBAAQ;AAAA,EACR,yBAAQ;AAAA,EACR,yBAAQ;AAAA,GATE;",
7
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkKO,IAAK;AAAA,CAAL,CAAK,kBAAL;AAAA,EACL,wBAAO;AAAA,EACP,sBAAK;AAAA,EACL,wBAAO;AAAA,EACP,uBAAM;AAAA,EACN,uBAAM;AAAA,EACN,yBAAQ;AAAA,EACR,yBAAQ;AAAA,EACR,yBAAQ;AAAA,EACR,yBAAQ;AAAA,GATE;",
8
8
  "debugId": "5EC6531CF2E47C8764756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -2,7 +2,7 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../src/core/workbook-renamer.ts"],
4
4
  "sourcesContent": [
5
- "/**\n * Workbook renamer utility for updating cross-workbook references in formulas\n */\n\nimport { parseFormula } from \"../parser/parser.cjs\";\nimport { astToString } from \"../parser/formatter.cjs\";\nimport { transformAST } from \"./ast-traverser.cjs\";\nimport type { ASTNode } from \"../parser/ast.cjs\";\n\n/**\n * Renames workbook references in a formula string\n * @param formula The formula string (without the leading =)\n * @param oldWorkbookName The old workbook name to replace\n * @param newWorkbookName The new workbook name to use\n * @returns The updated formula string\n */\nexport function renameWorkbookInFormula(options: {\n formula: string;\n oldWorkbookName: string;\n newWorkbookName: string;\n}): string {\n const { formula, oldWorkbookName, newWorkbookName } = options;\n try {\n const ast = parseFormula(formula);\n \n const updatedAst = transformAST(ast, (node) => {\n // Handle cross-workbook references (e.g., [MyWorkbook]Sheet1!A1)\n if (node.type === \"reference\" && node.workbookName === oldWorkbookName) {\n return {\n ...node,\n workbookName: newWorkbookName,\n };\n }\n \n // Handle range references with workbook names (e.g., [MyWorkbook]Sheet1!A1:B2)\n if (node.type === \"range\" && node.workbookName === oldWorkbookName) {\n return {\n ...node,\n workbookName: newWorkbookName,\n };\n }\n \n // Handle named expressions with workbook names\n if (node.type === \"named-expression\" && node.workbookName === oldWorkbookName) {\n return {\n ...node,\n workbookName: newWorkbookName,\n };\n }\n \n // Handle structured references with workbook names (e.g., [MyWorkbook]Sheet1!Table1[Column1])\n if (node.type === \"structured-reference\" && node.workbookName === oldWorkbookName) {\n return {\n ...node,\n workbookName: newWorkbookName,\n };\n }\n \n // Handle 3D ranges with workbook names (e.g., [MyWorkbook]Sheet1:Sheet3!A1:C5)\n if (node.type === \"3d-range\" && node.workbookName === oldWorkbookName) {\n return {\n ...node,\n workbookName: newWorkbookName,\n };\n }\n \n return node;\n });\n \n return astToString(updatedAst);\n } catch (error) {\n // If parsing fails, return the original formula\n return formula;\n }\n}\n\n/**\n * Checks if a formula references a specific workbook\n * @param formula The formula string (without the leading =)\n * @param workbookName The workbook name to check for\n * @returns True if the formula references the workbook\n */\nexport function formulaReferencesWorkbook(formula: string, workbookName: string): boolean {\n try {\n const referencedWorkbooks = getReferencedWorkbookNames(formula);\n return referencedWorkbooks.includes(workbookName);\n } catch (error) {\n // If parsing fails, assume no reference\n return false;\n }\n}\n\n/**\n * Gets all workbook names referenced in a formula\n * @param formula The formula string (without the leading =)\n * @returns Array of unique workbook names referenced in the formula\n */\nexport function getReferencedWorkbookNames(formula: string): string[] {\n try {\n const ast = parseFormula(formula);\n const workbookNames = new Set<string>();\n\n transformAST(ast, (node) => {\n // Handle cross-workbook references\n if ((node.type === \"reference\" || \n node.type === \"range\" || \n node.type === \"named-expression\" || \n node.type === \"structured-reference\" ||\n node.type === \"3d-range\") && \n node.workbookName) {\n workbookNames.add(node.workbookName);\n }\n \n return node;\n });\n\n return Array.from(workbookNames);\n } catch (error) {\n // If parsing fails, return empty array\n return [];\n }\n}\n"
5
+ "/**\n * Workbook renamer utility for updating cross-workbook references in formulas\n */\n\nimport { parseFormula } from \"../parser/parser.cjs\";\nimport { astToString } from \"../parser/formatter.cjs\";\nimport { transformAST } from \"./ast-traverser.cjs\";\nimport type { ASTNode } from \"../parser/ast.cjs\";\n\n/**\n * Renames workbook references in a formula string\n * @param formula The formula string (without the leading =)\n * @param oldWorkbookName The old workbook name to replace\n * @param newWorkbookName The new workbook name to use\n * @returns The updated formula string\n */\nexport function renameWorkbookInFormula(options: {\n formula: string;\n oldWorkbookName: string;\n newWorkbookName: string;\n}): string {\n const { formula, oldWorkbookName, newWorkbookName } = options;\n try {\n const ast = parseFormula(formula);\n \n const updatedAst = transformAST(ast, (node) => {\n // Handle cross-workbook references (e.g., [MyWorkbook]Sheet1!A1)\n if (node.type === \"reference\" && node.workbookName === oldWorkbookName) {\n return {\n ...node,\n workbookName: newWorkbookName,\n };\n }\n \n // Handle range references with workbook names (e.g., [MyWorkbook]Sheet1!A1:B2)\n if (node.type === \"range\" && node.workbookName === oldWorkbookName) {\n return {\n ...node,\n workbookName: newWorkbookName,\n };\n }\n \n // Handle named expressions with workbook names\n if (node.type === \"named-expression\" && node.workbookName === oldWorkbookName) {\n return {\n ...node,\n workbookName: newWorkbookName,\n };\n }\n \n // Handle structured references with workbook names (e.g., [MyWorkbook]!Table1[Column1])\n if (node.type === \"structured-reference\" && node.workbookName === oldWorkbookName) {\n return {\n ...node,\n workbookName: newWorkbookName,\n };\n }\n \n // Handle 3D ranges with workbook names (e.g., [MyWorkbook]Sheet1:Sheet3!A1:C5)\n if (node.type === \"3d-range\" && node.workbookName === oldWorkbookName) {\n return {\n ...node,\n workbookName: newWorkbookName,\n };\n }\n \n return node;\n });\n \n return astToString(updatedAst);\n } catch (error) {\n // If parsing fails, return the original formula\n return formula;\n }\n}\n\n/**\n * Checks if a formula references a specific workbook\n * @param formula The formula string (without the leading =)\n * @param workbookName The workbook name to check for\n * @returns True if the formula references the workbook\n */\nexport function formulaReferencesWorkbook(formula: string, workbookName: string): boolean {\n try {\n const referencedWorkbooks = getReferencedWorkbookNames(formula);\n return referencedWorkbooks.includes(workbookName);\n } catch (error) {\n // If parsing fails, assume no reference\n return false;\n }\n}\n\n/**\n * Gets all workbook names referenced in a formula\n * @param formula The formula string (without the leading =)\n * @returns Array of unique workbook names referenced in the formula\n */\nexport function getReferencedWorkbookNames(formula: string): string[] {\n try {\n const ast = parseFormula(formula);\n const workbookNames = new Set<string>();\n\n transformAST(ast, (node) => {\n // Handle cross-workbook references\n if ((node.type === \"reference\" || \n node.type === \"range\" || \n node.type === \"named-expression\" || \n node.type === \"structured-reference\" ||\n node.type === \"3d-range\") && \n node.workbookName) {\n workbookNames.add(node.workbookName);\n }\n \n return node;\n });\n\n return Array.from(workbookNames);\n } catch (error) {\n // If parsing fails, return empty array\n return [];\n }\n}\n"
6
6
  ],
7
7
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAI6B,IAA7B;AAC4B,IAA5B;AAC6B,IAA7B;AAUO,SAAS,uBAAuB,CAAC,SAI7B;AAAA,EACT,QAAQ,SAAS,iBAAiB,oBAAoB;AAAA,EACtD,IAAI;AAAA,IACF,MAAM,MAAM,2BAAa,OAAO;AAAA,IAEhC,MAAM,aAAa,kCAAa,KAAK,CAAC,SAAS;AAAA,MAE7C,IAAI,KAAK,SAAS,eAAe,KAAK,iBAAiB,iBAAiB;AAAA,QACtE,OAAO;AAAA,aACF;AAAA,UACH,cAAc;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Aa;AAAA,IAC/B,OAAO,OAAO;AAAA,IAEd,OAAO,CAAC;AAAA;AAAA;",
8
8
  "debugId": "19CD3826FBA48AA364756E2164756E21",
@@ -175,6 +175,22 @@ class FormulaEvaluator {
175
175
  }
176
176
  const rowIndex = context.cellAddress.rowIndex;
177
177
  const tableStart = table.start;
178
+ const createResolvedTableRangeNode = (range) => ({
179
+ type: "range",
180
+ range,
181
+ isAbsolute: {
182
+ start: {
183
+ col: true,
184
+ row: true
185
+ },
186
+ end: {
187
+ col: true,
188
+ row: true
189
+ }
190
+ },
191
+ sheetName: table.sheetName,
192
+ workbookName: table.workbookName
193
+ });
178
194
  if (node.selector) {
179
195
  let startRow;
180
196
  let endRow;
@@ -222,21 +238,7 @@ class FormulaEvaluator {
222
238
  col: { type: "number", value: endColIndex }
223
239
  }
224
240
  };
225
- return this.evaluateRange({
226
- type: "range",
227
- range,
228
- isAbsolute: {
229
- start: {
230
- col: true,
231
- row: true
232
- },
233
- end: {
234
- col: true,
235
- row: true
236
- }
237
- },
238
- sheetName: table.sheetName
239
- }, context);
241
+ return this.evaluateRange(createResolvedTableRangeNode(range), context);
240
242
  } else {
241
243
  const range = {
242
244
  start: {
@@ -251,21 +253,7 @@ class FormulaEvaluator {
251
253
  }
252
254
  }
253
255
  };
254
- return this.evaluateRange({
255
- type: "range",
256
- range,
257
- isAbsolute: {
258
- start: {
259
- col: true,
260
- row: true
261
- },
262
- end: {
263
- col: true,
264
- row: true
265
- }
266
- },
267
- sheetName: table.sheetName
268
- }, context);
256
+ return this.evaluateRange(createResolvedTableRangeNode(range), context);
269
257
  }
270
258
  }
271
259
  if (node.cols) {
@@ -291,21 +279,7 @@ class FormulaEvaluator {
291
279
  col: { type: "number", value: endColIndex }
292
280
  }
293
281
  };
294
- return this.evaluateRange({
295
- type: "range",
296
- range,
297
- isAbsolute: {
298
- start: {
299
- col: true,
300
- row: true
301
- },
302
- end: {
303
- col: true,
304
- row: true
305
- }
306
- },
307
- sheetName: table.sheetName
308
- }, context);
282
+ return this.evaluateRange(createResolvedTableRangeNode(range), context);
309
283
  }
310
284
  return {
311
285
  type: "error",
@@ -362,7 +336,7 @@ class FormulaEvaluator {
362
336
  context2.addContextDependency("sheet");
363
337
  } else if (!node.workbookName) {
364
338
  context2.addContextDependency("workbook");
365
- } else {}
339
+ }
366
340
  const originSheetName = node.sheetName ?? context2.cellAddress.sheetName;
367
341
  const originWorkbookName = node.workbookName ?? context2.cellAddress.workbookName;
368
342
  const colIndex = node.range.start.col + spillOffset.x;
@@ -628,7 +602,7 @@ class FormulaEvaluator {
628
602
  context.addContextDependency("sheet");
629
603
  } else if (!node.workbookName) {
630
604
  context.addContextDependency("workbook");
631
- } else {}
605
+ }
632
606
  if (evalNode instanceof import_cell_value_node.CellValueNode && evalNode.spillMeta) {
633
607
  if (evalNode.spillMeta.evaluationResult.type === "spilled-values") {
634
608
  return {
@@ -837,4 +811,4 @@ class FormulaEvaluator {
837
811
  }
838
812
  }
839
813
 
840
- //# debugId=B36B15FC774F83C164756E2164756E21
814
+ //# debugId=3D1653EF8566F26E64756E2164756E21
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../src/evaluator/formula-evaluator.ts"],
4
4
  "sourcesContent": [
5
- "import type {\n LocalCellAddress,\n RangeAddress,\n SingleEvaluationResult,\n} from \"../core/types.cjs\";\nimport {\n FormulaError,\n type CellAddress,\n type CellValue,\n type FunctionEvaluationResult,\n type SpreadsheetRange,\n type SpreadsheetRangeEnd,\n type TableDefinition,\n} from \"../core/types.cjs\";\nimport { parseFormula } from \"../parser/parser.cjs\";\n\nimport type { DependencyManager } from \"../core/managers/dependency-manager.cjs\";\nimport type { NamedExpressionManager } from \"../core/managers/named-expression-manager.cjs\";\nimport type { TableManager } from \"../core/managers/table-manager.cjs\";\nimport {\n captureEvaluationErrors,\n cellAddressToKey,\n getAbsoluteRange,\n getRangeIntersection,\n getRangeKey,\n getRelativeRange,\n isRangeOneCell,\n rangeAddressToKey,\n} from \"../core/utils.cjs\";\nimport {\n getNamedExpressionResourceKey,\n getSheetResourceKey,\n getTableResourceKey,\n getWorkbookResourceKey,\n} from \"../core/resource-keys.cjs\";\nimport {\n evaluateScalarOperator,\n type EvaluateScalarOperatorOptions,\n} from \"../evaluator/evaluate-scalar-operator.cjs\";\nimport { functions } from \"../functions/function-registry.cjs\";\nimport type {\n ArrayNode,\n ASTNode,\n BinaryOpNode,\n FunctionNode,\n NamedExpressionNode,\n RangeNode,\n ReferenceNode,\n StructuredReferenceNode,\n ThreeDRangeNode,\n UnaryOpNode,\n ValueNode,\n} from \"../parser/ast.cjs\";\nimport { add } from \"./arithmetic/add/add.cjs\";\nimport { divide } from \"./arithmetic/divide/divide.cjs\";\nimport { multiply } from \"./arithmetic/multiply/multiply.cjs\";\nimport { power } from \"./arithmetic/power/power.cjs\";\nimport { subtract } from \"./arithmetic/subtract/subtract.cjs\";\nimport { equals } from \"./comparison/equals.cjs\";\nimport { greaterThan } from \"./comparison/greater-than.cjs\";\nimport { greaterThanOrEqual } from \"./comparison/greater-than-or-equal.cjs\";\nimport { lessThan } from \"./comparison/less-than.cjs\";\nimport { lessThanOrEqual } from \"./comparison/less-than-or-equal.cjs\";\nimport { notEquals } from \"./comparison/not-equals.cjs\";\nimport { concatenate } from \"./concatenation/concatenate.cjs\";\nimport { CellValueNode } from \"./dependency-nodes/cell-value-node.cjs\";\nimport { EvaluationContext } from \"./evaluation-context.cjs\";\n\nexport class FormulaEvaluator {\n constructor(\n private tableManager: TableManager,\n private dependencyManager: DependencyManager,\n private namedExpressionManager: NamedExpressionManager\n ) {}\n\n // evaluator methods\n evaluateFormula(\n /**\n * formula is the formula to evaluate, without the leading =\n */\n formula: string,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const ast = parseFormula(formula);\n\n return captureEvaluationErrors(context.dependencyNode, () => {\n const result = this.evaluateNode(ast, context);\n return result;\n });\n }\n\n evaluateNode(\n node: ASTNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const currentContext = {\n ...context.cellAddress,\n tableName: context.cacheTableName,\n };\n\n const astNode = this.dependencyManager.getAstNode(node, currentContext);\n context.dependencyNode.addDependency(astNode);\n\n // if (astNode.evaluationResult.type !== \"awaiting-evaluation\") {\n // return astNode.evaluationResult;\n // }\n\n if (astNode.resolved) {\n const astContextDependency = astNode.getContextDependency();\n context.appendContextDependency(astContextDependency);\n return astNode.evaluationResult;\n }\n\n this.dependencyManager.unregisterNode(astNode);\n astNode.resetDirectDepsUpdated();\n\n function runEvaluation(\n this: FormulaEvaluator,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n switch (node.type) {\n case \"value\":\n return {\n type: \"value\",\n result: this.evaluateValue(node),\n };\n case \"infinity\":\n return {\n type: \"value\",\n result: {\n type: \"infinity\",\n sign: \"positive\",\n },\n };\n case \"binary-op\":\n return this.evaluateBinaryOp(node, context);\n\n case \"reference\":\n return this.evaluateReference(node, context);\n\n case \"named-expression\":\n return this.evaluateNamedExpression(node, context);\n\n case \"structured-reference\":\n return this.evaluateStructuredReference(node, context);\n\n case \"function\":\n return this.evaluateFunction(node, context);\n\n case \"range\":\n return this.evaluateRange(node, context);\n\n case \"unary-op\":\n return this.evaluateUnaryOp(node, context);\n\n case \"3d-range\":\n return this.evaluate3DRange(node, context);\n\n case \"array\":\n return this.evaluateArray(node, context);\n\n default:\n return {\n type: \"error\",\n err: FormulaError.ERROR,\n message: \"WIP: unimplemented support for \" + node.type,\n errAddress: context.dependencyNode,\n };\n }\n }\n const newContext = new EvaluationContext(\n this.tableManager,\n astNode,\n context.cellAddress\n );\n const result = captureEvaluationErrors(astNode, () =>\n runEvaluation.call(this, newContext)\n );\n astNode.setEvaluationResult(result);\n const astContextDependency = newContext.getContextDependency();\n\n astNode.setContextDependency(astContextDependency);\n this.dependencyManager.registerNode(astNode);\n\n context.appendContextDependency(astContextDependency);\n\n return result;\n }\n\n evaluateStructuredReference(\n node: StructuredReferenceNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const resourceWorkbookName =\n node.workbookName ?? context.cellAddress.workbookName;\n if (node.tableName) {\n context.dependencyNode.addDependency(\n this.dependencyManager.getResourceNode(\n getTableResourceKey({\n workbookName: resourceWorkbookName,\n tableName: node.tableName,\n })\n )\n );\n }\n\n // the tables are never dependent on the sheet, interesetingly enough\n let table: TableDefinition | undefined;\n if (node.tableName && node.workbookName) {\n // this expression will evaluate to the same value regardless of where in the workbooks we are evaluating it in\n table = this.tableManager\n .getTables(node.workbookName)\n .get(node.tableName);\n } else if (node.tableName) {\n // different workbooks could have different tables with the same name\n // so it can differ based on the workbook we are evaluating it in\n context.addContextDependency(\"workbook\");\n table = this.tableManager\n .getTables(context.cellAddress.workbookName)\n .get(node.tableName);\n } else {\n // If no table nor workbook name is provided, the current cell's table\n // membership determines the result.\n context.addContextDependency(\"workbook\", \"sheet\", \"table\");\n table = this.tableManager.isCellInTable(context.cellAddress);\n }\n\n if (node.isCurrentRow) {\n context.addContextDependency(\"row\");\n }\n\n if (!table) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: `Table ${node.tableName} not found`,\n errAddress: context.dependencyNode,\n };\n }\n\n const rowIndex = context.cellAddress.rowIndex;\n const tableStart = table.start;\n\n // Handle selector-based references\n if (node.selector) {\n let startRow: number;\n let endRow: SpreadsheetRangeEnd;\n\n switch (node.selector) {\n case \"#Headers\":\n startRow = table.start.rowIndex;\n endRow = { type: \"number\", value: table.start.rowIndex };\n break;\n case \"#Data\":\n startRow = table.start.rowIndex + 1;\n endRow = table.endRow;\n break;\n case \"#All\":\n startRow = table.start.rowIndex;\n endRow = table.endRow;\n break;\n default:\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: `Unknown table selector: ${node.selector}`,\n errAddress: context.dependencyNode,\n };\n }\n\n // If we also have column specification, use those columns\n if (node.cols) {\n const startCol = table.headers.get(node.cols.startCol);\n const endCol = table.headers.get(node.cols.endCol);\n if (!startCol || !endCol) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: `Column ${node.cols.startCol} or ${node.cols.endCol} not found in table ${table.name}`,\n errAddress: context.dependencyNode,\n };\n }\n const startColIndex = tableStart.colIndex + startCol.index;\n const endColIndex = tableStart.colIndex + endCol.index;\n\n const range: SpreadsheetRange = {\n start: {\n row: startRow,\n col: startColIndex,\n },\n end: {\n row: endRow,\n col: { type: \"number\", value: endColIndex },\n },\n };\n\n return this.evaluateRange(\n {\n type: \"range\",\n range,\n isAbsolute: {\n start: {\n col: true,\n row: true,\n },\n end: {\n col: true,\n row: true,\n },\n },\n sheetName: table.sheetName,\n },\n context\n );\n } else {\n // No column specification, return entire row(s) for the selector\n const range: SpreadsheetRange = {\n start: {\n row: startRow,\n col: tableStart.colIndex,\n },\n end: {\n row: endRow,\n col: {\n type: \"number\",\n value: tableStart.colIndex + table.headers.size - 1,\n },\n },\n };\n\n return this.evaluateRange(\n {\n type: \"range\",\n range,\n isAbsolute: {\n start: {\n col: true,\n row: true,\n },\n end: {\n col: true,\n row: true,\n },\n },\n sheetName: table.sheetName,\n },\n context\n );\n }\n }\n\n // Handle column-only references (no selector)\n if (node.cols) {\n const startCol = table.headers.get(node.cols.startCol);\n const endCol = table.headers.get(node.cols.endCol);\n if (!startCol || !endCol) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: `Column ${node.cols.startCol} or ${node.cols.endCol} not found in table ${table.name}`,\n errAddress: context.dependencyNode,\n };\n }\n const startColIndex = tableStart.colIndex + startCol.index;\n const endColIndex = tableStart.colIndex + endCol.index;\n const range: SpreadsheetRange = {\n start: {\n row: node.isCurrentRow ? rowIndex : table.start.rowIndex + 1,\n col: startColIndex,\n },\n end: {\n row: node.isCurrentRow\n ? { type: \"number\", value: rowIndex }\n : table.endRow,\n col: { type: \"number\", value: endColIndex },\n },\n };\n\n return this.evaluateRange(\n {\n type: \"range\",\n range,\n isAbsolute: {\n start: {\n col: true,\n row: true,\n },\n end: {\n col: true,\n row: true,\n },\n },\n sheetName: table.sheetName,\n },\n context\n );\n }\n\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: \"Structured reference must specify either a selector or columns\",\n errAddress: context.dependencyNode,\n };\n }\n\n /**\n * Evaluates a value node\n */\n evaluateValue(node: ValueNode): CellValue {\n return node.value;\n }\n\n evaluate3DRange(\n node: ThreeDRangeNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n throw new Error(\"WIP: 3d range is not implemented\");\n /*\n const startSheet = this.sheets.get(node.startSheet);\n const endSheet = this.sheets.get(node.endSheet);\n if (!startSheet || !endSheet) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: `Sheet ${node.startSheet} or ${node.endSheet} not found`,\n };\n }\n\n let numCols = 0;\n let numRows = 0;\n for (let i = startSheet.index; i <= endSheet.index; i++) {\n if (node.reference.type === \"reference\") {\n numCols += 1;\n } else {\n numCols += node.reference.range.end.col.value - node.reference.range.start.col.value + 1;\n }\n\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: `Sheet ${i} not found`,\n };\n }\n\n return {\n type: \"spilled-values\",\n spillArea: (origin: CellAddress) => ({\n start: {\n col: origin.colIndex,\n row: origin.rowIndex,\n },\n end: {\n col: { type: \"number\", value: origin.colIndex },\n row: {\n type: \"number\",\n value: origin.rowIndex + numSheets - 1,\n },\n },\n }),\n source: `range`,\n originResult:\n originResult.type === \"value\"\n ? originResult.result\n : originResult.originResult,\n evaluate: (spilledCell, context) => {\n const colIndex = range.start.col + spilledCell.spillOffset.x;\n const rowIndex = range.start.row + spilledCell.spillOffset.y;\n const sheetName = node.sheetName ?? context.currentSheet;\n return this.evalTimeSafeEvaluateCell(\n {\n colIndex,\n rowIndex,\n sheetName,\n },\n context\n );\n },\n };\n */\n }\n\n evaluateRange(\n node: RangeNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n if (isRangeOneCell(node.range)) {\n return this.evaluateReference(\n {\n type: \"reference\",\n address: {\n colIndex: node.range.start.col,\n rowIndex: node.range.start.row,\n },\n isAbsolute: {\n col: node.isAbsolute.start.col || node.isAbsolute.end.col,\n row: node.isAbsolute.start.row || node.isAbsolute.end.row,\n },\n sheetName: node.sheetName,\n },\n context\n );\n }\n\n const debugRange = getRangeKey(node.range);\n\n const rangeAddress: RangeAddress = {\n sheetName: node.sheetName ?? context.cellAddress.sheetName,\n workbookName: node.workbookName ?? context.cellAddress.workbookName,\n range: node.range,\n };\n\n if (node.workbookName) {\n context.dependencyNode.addDependency(\n this.dependencyManager.getResourceNode(\n getWorkbookResourceKey(node.workbookName)\n )\n );\n }\n if (node.sheetName) {\n context.dependencyNode.addDependency(\n this.dependencyManager.getResourceNode(\n getSheetResourceKey({\n workbookName: rangeAddress.workbookName,\n sheetName: node.sheetName,\n })\n )\n );\n }\n\n return {\n type: \"spilled-values\",\n spillArea: (origin) => this.projectRange(node.range, origin),\n source: `range ${debugRange}`,\n sourceRange: rangeAddress,\n evaluate: (spillOffset, context) => {\n if (!node.sheetName && !node.workbookName) {\n // e.g. the result from A4:A9 will depend in which sheet and workbook we are evaluating it in\n context.addContextDependency(\"workbook\", \"sheet\");\n } else if (!node.sheetName) {\n // e.g. the result from [Workbook1]A4:A9 will depend in which sheet we are evaluating it in\n context.addContextDependency(\"sheet\");\n } else if (!node.workbookName) {\n // e.g. the result from Sheet1!A4:A9 will depend in which workbook we are evaluating it in\n context.addContextDependency(\"workbook\");\n } else {\n // if we have both sheetName and workbookName, we don't need to add any context dependencies\n }\n\n const originSheetName = node.sheetName ?? context.cellAddress.sheetName;\n const originWorkbookName =\n node.workbookName ?? context.cellAddress.workbookName;\n const colIndex = node.range.start.col + spillOffset.x;\n const rowIndex = node.range.start.row + spillOffset.y;\n\n const cellAddress: CellAddress = {\n colIndex,\n rowIndex,\n sheetName: originSheetName,\n workbookName: originWorkbookName,\n };\n\n const evalNode = this.dependencyManager.getCellValueOrEmptyCellNode(\n cellAddressToKey(cellAddress)\n );\n context.dependencyNode.addDependency(evalNode);\n\n const result = evalNode.evaluationResult;\n\n return result;\n },\n evaluateAllCells: function ({\n evaluate,\n intersection,\n context,\n origin,\n lookupOrder,\n }) {\n let range = node.range;\n if (intersection) {\n // When we have an intersection, it's defined relative to where the spilled range\n // will appear (the origin). However, we need to evaluate cells from the source\n // range (node.range). So we must translate the intersection coordinates back\n // to the source range's coordinate system.\n //\n // Example: If source range A1:C3 spills to D5:F7, and we want intersection E6:F7,\n // we need to translate E6:F7 (relative to D5) to B2:C3 (relative to A1).\n\n // Calculate the offset of the intersection from the spill origin\n const relativeRange = getRelativeRange(intersection, origin);\n const start: LocalCellAddress = {\n colIndex: node.range.start.col,\n rowIndex: node.range.start.row,\n };\n const projectedIntersection = getAbsoluteRange(relativeRange, start);\n const calculateIntersection = getRangeIntersection(\n node.range,\n projectedIntersection\n );\n if (calculateIntersection) {\n range = calculateIntersection;\n }\n }\n\n const address: RangeAddress = {\n range,\n sheetName: node.sheetName ?? context.cellAddress.sheetName,\n workbookName: node.workbookName ?? context.cellAddress.workbookName,\n };\n\n const rangeNode = this.dependencyManager.getRangeNode(\n rangeAddressToKey(address)\n );\n\n context.dependencyNode.addDependency(rangeNode);\n\n return this.dependencyManager.getRangeNode(rangeAddressToKey(address))\n .result;\n },\n };\n }\n\n evaluateArray(\n node: ArrayNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const firstRow = node.elements[0];\n if (!firstRow) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: \"Array is empty\",\n errAddress: context.dependencyNode,\n };\n }\n const firstCell = firstRow[0];\n if (!firstCell) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: \"Array is empty\",\n errAddress: context.dependencyNode,\n };\n }\n const originResult = this.evaluateNode(firstCell, context);\n if (\n originResult.type === \"error\" ||\n originResult.type === \"awaiting-evaluation\"\n ) {\n return originResult;\n }\n return {\n type: \"spilled-values\",\n spillArea: (origin) => ({\n start: {\n col: origin.colIndex,\n row: origin.rowIndex,\n },\n end: {\n col: {\n type: \"number\",\n value: origin.colIndex + firstRow.length - 1,\n },\n row: {\n type: \"number\",\n value: origin.rowIndex + node.elements.length - 1,\n },\n },\n }),\n source: `array`,\n evaluate: (spillOffset, context) => {\n const row = node.elements[spillOffset.y];\n if (!row) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: \"Array is empty\",\n errAddress: context.dependencyNode,\n };\n }\n const cell = row[spillOffset.x];\n if (!cell) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: \"Array is empty\",\n errAddress: context.dependencyNode,\n };\n }\n const result = this.evaluateNode(cell, context);\n if (result.type === \"spilled-values\") {\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: \"Arrays cannot contain spilled values\",\n errAddress: context.dependencyNode,\n };\n }\n return result;\n },\n evaluateAllCells: (intersectingRange) => {\n throw new Error(\"WIP: evaluateAllCells for array is not implemented\");\n },\n };\n }\n\n /**\n * Evaluates a unary operation\n */\n evaluateUnaryOp(\n node: UnaryOpNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const operandResult = this.evaluateNode(node.operand, context);\n\n if (\n operandResult.type === \"error\" ||\n operandResult.type === \"awaiting-evaluation\"\n ) {\n return operandResult;\n }\n\n if (operandResult.type === \"spilled-values\") {\n return {\n type: \"spilled-values\",\n spillArea: (origin) => operandResult.spillArea(origin),\n source: `unary ${node.operator} operation`,\n evaluate: (spilledCell, context) => {\n const spillResult = operandResult.evaluate(spilledCell, context);\n if (\n !spillResult ||\n spillResult.type === \"error\" ||\n spillResult.type === \"awaiting-evaluation\"\n ) {\n return spillResult;\n }\n if (spillResult.type !== \"value\") {\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: \"Invalid spilled result for unary operation\",\n errAddress: context.dependencyNode,\n };\n }\n return this.evaluateUnaryScalar(\n node.operator,\n spillResult.result,\n context\n );\n },\n evaluateAllCells: function (options) {\n const cellValues = operandResult.evaluateAllCells.call(this, options);\n if (cellValues.type !== \"values\") {\n return cellValues;\n }\n return {\n type: \"values\",\n values: cellValues.values.map((cellValue) => {\n if (\n cellValue.result.type === \"error\" ||\n cellValue.result.type === \"awaiting-evaluation\"\n ) {\n return cellValue;\n } else {\n return {\n result: this.evaluateUnaryScalar(\n node.operator,\n cellValue.result.result,\n context\n ),\n relativePos: cellValue.relativePos,\n };\n }\n }),\n };\n },\n };\n }\n\n if (operandResult.type === \"value\") {\n return this.evaluateUnaryScalar(\n node.operator,\n operandResult.result,\n context\n );\n }\n\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: \"Invalid operand for unary operation\",\n errAddress: context.dependencyNode,\n };\n }\n\n /**\n * Evaluates a unary scalar operation\n */\n private evaluateUnaryScalar(\n operator: \"+\" | \"-\" | \"%\",\n operand: CellValue,\n context: EvaluationContext\n ): SingleEvaluationResult {\n if (operand.type !== \"number\" && operand.type !== \"infinity\") {\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: `Cannot apply unary ${operator} to non-number`,\n errAddress: context.dependencyNode,\n };\n }\n if (operand.type === \"infinity\") {\n if (operator === \"%\") {\n return {\n type: \"error\",\n err: FormulaError.NUM,\n message: \"Cannot apply % to infinity\",\n errAddress: context.dependencyNode,\n };\n }\n return {\n type: \"value\",\n result: {\n type: \"infinity\",\n sign: operator === \"+\" ? \"positive\" : \"negative\",\n },\n };\n }\n switch (operator) {\n case \"+\":\n return { type: \"value\", result: operand };\n\n case \"-\":\n return {\n type: \"value\",\n result: {\n type: \"number\",\n value: -operand.value,\n },\n };\n\n case \"%\":\n return {\n type: \"value\",\n result: { type: \"number\", value: operand.value / 100 },\n };\n\n default:\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: `Unknown unary operator: ${operator}`,\n errAddress: context.dependencyNode,\n };\n }\n }\n\n /**\n * Evaluates a binary operation\n */\n evaluateBinaryOp(\n node: BinaryOpNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const left = this.evaluateNode(node.left, context);\n const right = this.evaluateNode(node.right, context);\n\n if (left.type === \"error\" || left.type === \"awaiting-evaluation\") {\n return left;\n }\n if (right.type === \"error\" || right.type === \"awaiting-evaluation\") {\n return right;\n }\n\n // Scalar operation\n return this.evaluateBinaryScalar(node.operator, left, right, context);\n }\n\n /**\n * Evaluates a reference node\n */\n evaluateReference(\n node: ReferenceNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const cellAddress: CellAddress = {\n ...node.address,\n sheetName: node.sheetName ?? context.cellAddress.sheetName,\n workbookName: node.workbookName ?? context.cellAddress.workbookName,\n };\n\n if (node.workbookName) {\n context.dependencyNode.addDependency(\n this.dependencyManager.getResourceNode(\n getWorkbookResourceKey(node.workbookName)\n )\n );\n }\n if (node.sheetName) {\n context.dependencyNode.addDependency(\n this.dependencyManager.getResourceNode(\n getSheetResourceKey({\n workbookName: cellAddress.workbookName,\n sheetName: node.sheetName,\n })\n )\n );\n }\n\n const key = cellAddressToKey(cellAddress);\n const evalNode = this.dependencyManager.getCellValueOrEmptyCellNode(key);\n context.dependencyNode.addDependency(evalNode);\n\n if (!node.sheetName && !node.workbookName) {\n // e.g. the result from A4:A9 will depend in which sheet and workbook we are evaluating it in\n context.addContextDependency(\"workbook\", \"sheet\");\n } else if (!node.sheetName) {\n // e.g. the result from [Workbook1]A4:A9 will depend in which sheet we are evaluating it in\n context.addContextDependency(\"sheet\");\n } else if (!node.workbookName) {\n // e.g. the result from Sheet1!A4:A9 will depend in which workbook we are evaluating it in\n context.addContextDependency(\"workbook\");\n } else {\n // if we have both sheetName and workbookName, we don't need to add any context dependencies\n }\n\n if (evalNode instanceof CellValueNode && evalNode.spillMeta) {\n if (evalNode.spillMeta.evaluationResult.type === \"spilled-values\") {\n return {\n ...evalNode.spillMeta.evaluationResult,\n sourceCell: cellAddress,\n sourceRange: undefined,\n };\n }\n }\n\n return { ...evalNode.evaluationResult, sourceCell: cellAddress };\n }\n\n /**\n * Evaluates a named expression node\n */\n evaluateNamedExpression(\n node: NamedExpressionNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const resolvedExpression =\n this.namedExpressionManager.resolveNamedExpressionWithScope(\n node,\n context\n );\n\n if (!resolvedExpression) {\n return {\n type: \"error\",\n err: FormulaError.NAME,\n message: `Named expression ${node.name} not found`,\n errAddress: context.dependencyNode,\n };\n }\n\n context.dependencyNode.addDependency(\n this.dependencyManager.getResourceNode(\n getNamedExpressionResourceKey({\n expressionName: node.name,\n workbookName:\n resolvedExpression.scope.type === \"global\"\n ? undefined\n : resolvedExpression.scope.workbookName,\n sheetName:\n resolvedExpression.scope.type === \"sheet\"\n ? resolvedExpression.scope.sheetName\n : undefined,\n })\n )\n );\n\n return this.evaluateFormula(resolvedExpression.expression, context);\n }\n\n /**\n * Binary scalar operations\n */\n evaluateBinaryScalar(\n operator: string,\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n switch (operator) {\n case \"+\":\n return this.add(left, right, context);\n case \"-\":\n return this.subtract(left, right, context);\n case \"*\":\n return this.multiply(left, right, context);\n case \"/\":\n return this.divide(left, right, context);\n case \"^\":\n return this.power(left, right, context);\n\n case \"&\":\n return this.concatenateOp(left, right, context);\n case \"=\":\n return this.equalsOp(left, right, context);\n case \"<>\":\n return this.notEqualsOp(left, right, context);\n case \"<\":\n return this.lessThanOp(left, right, context);\n case \"<=\":\n return this.lessThanOrEqualOp(left, right, context);\n case \">\":\n return this.greaterThanOp(left, right, context);\n case \">=\":\n return this.greaterThanOrEqualOp(left, right, context);\n default:\n return {\n type: \"error\",\n err: FormulaError.ERROR,\n message: `Unknown binary operator: ${operator}`,\n errAddress: context.dependencyNode,\n };\n }\n }\n\n evaluateFunction(\n node: FunctionNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const func = functions[node.name];\n if (!func) {\n return {\n type: \"error\",\n err: FormulaError.NAME,\n message: `Function ${node.name} not found`,\n errAddress: context.dependencyNode,\n };\n }\n return func.evaluate.call(this, node, context);\n }\n\n // Arithmetic operations\n add(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: add,\n context,\n name: \"add\",\n });\n }\n\n multiply(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: multiply,\n context,\n name: \"multiply\",\n });\n }\n\n divide(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: divide,\n context,\n name: \"divide\",\n });\n }\n\n evaluateScalarOperator(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n options: EvaluateScalarOperatorOptions\n ): FunctionEvaluationResult {\n return evaluateScalarOperator.call(this, left, right, options);\n }\n\n subtract(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: subtract,\n context,\n name: \"subtract\",\n });\n }\n\n power(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: power,\n context,\n name: \"power\",\n });\n }\n\n // Comparison operations\n equalsOp(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: equals,\n context,\n name: \"equals\",\n });\n }\n\n notEqualsOp(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: notEquals,\n context,\n name: \"notEquals\",\n });\n }\n\n lessThanOp(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: lessThan,\n context,\n name: \"lessThan\",\n });\n }\n\n lessThanOrEqualOp(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: lessThanOrEqual,\n context,\n name: \"lessThanOrEqual\",\n });\n }\n\n greaterThanOp(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: greaterThan,\n context,\n name: \"greaterThan\",\n });\n }\n\n greaterThanOrEqualOp(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: greaterThanOrEqual,\n context,\n name: \"greaterThanOrEqual\",\n });\n }\n\n // Concatenation operation\n concatenateOp(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: concatenate,\n context,\n name: \"concatenate\",\n });\n }\n\n projectRange(\n range: SpreadsheetRange,\n originCellAddress: CellAddress\n ): SpreadsheetRange {\n const offsetLeft = originCellAddress.colIndex - range.start.col;\n const offsetTop = originCellAddress.rowIndex - range.start.row;\n return {\n start: {\n col: range.start.col + offsetLeft,\n row: range.start.row + offsetTop,\n },\n end: {\n col:\n range.end.col.type === \"number\"\n ? { type: \"number\", value: range.end.col.value + offsetLeft }\n : range.end.col,\n row:\n range.end.row.type === \"number\"\n ? { type: \"number\", value: range.end.row.value + offsetTop }\n : range.end.row,\n },\n };\n }\n\n unionRanges(\n range1: SpreadsheetRange,\n range2: SpreadsheetRange\n ): SpreadsheetRange {\n const endCol = ((): SpreadsheetRangeEnd => {\n if (\n range1.end.col.type === \"infinity\" ||\n range2.end.col.type === \"infinity\"\n ) {\n return { type: \"infinity\", sign: \"positive\" };\n }\n return {\n type: \"number\",\n value: Math.max(range1.end.col.value, range2.end.col.value),\n };\n })();\n\n const endRow = ((): SpreadsheetRangeEnd => {\n if (\n range1.end.row.type === \"infinity\" ||\n range2.end.row.type === \"infinity\"\n ) {\n return { type: \"infinity\", sign: \"positive\" };\n }\n return {\n type: \"number\",\n value: Math.max(range1.end.row.value, range2.end.row.value),\n };\n })();\n\n return {\n start: {\n col: Math.min(range1.start.col, range2.start.col),\n row: Math.min(range1.start.row, range2.start.row),\n },\n end: {\n col: endCol,\n row: endRow,\n },\n };\n }\n}\n"
5
+ "import type {\n LocalCellAddress,\n RangeAddress,\n SingleEvaluationResult,\n} from \"../core/types.cjs\";\nimport {\n FormulaError,\n type CellAddress,\n type CellValue,\n type FunctionEvaluationResult,\n type SpreadsheetRange,\n type SpreadsheetRangeEnd,\n type TableDefinition,\n} from \"../core/types.cjs\";\nimport { parseFormula } from \"../parser/parser.cjs\";\n\nimport type { DependencyManager } from \"../core/managers/dependency-manager.cjs\";\nimport type { NamedExpressionManager } from \"../core/managers/named-expression-manager.cjs\";\nimport type { TableManager } from \"../core/managers/table-manager.cjs\";\nimport {\n captureEvaluationErrors,\n cellAddressToKey,\n getAbsoluteRange,\n getRangeIntersection,\n getRangeKey,\n getRelativeRange,\n isRangeOneCell,\n rangeAddressToKey,\n} from \"../core/utils.cjs\";\nimport {\n getNamedExpressionResourceKey,\n getSheetResourceKey,\n getTableResourceKey,\n getWorkbookResourceKey,\n} from \"../core/resource-keys.cjs\";\nimport {\n evaluateScalarOperator,\n type EvaluateScalarOperatorOptions,\n} from \"../evaluator/evaluate-scalar-operator.cjs\";\nimport { functions } from \"../functions/function-registry.cjs\";\nimport type {\n ArrayNode,\n ASTNode,\n BinaryOpNode,\n FunctionNode,\n NamedExpressionNode,\n RangeNode,\n ReferenceNode,\n StructuredReferenceNode,\n ThreeDRangeNode,\n UnaryOpNode,\n ValueNode,\n} from \"../parser/ast.cjs\";\nimport { add } from \"./arithmetic/add/add.cjs\";\nimport { divide } from \"./arithmetic/divide/divide.cjs\";\nimport { multiply } from \"./arithmetic/multiply/multiply.cjs\";\nimport { power } from \"./arithmetic/power/power.cjs\";\nimport { subtract } from \"./arithmetic/subtract/subtract.cjs\";\nimport { equals } from \"./comparison/equals.cjs\";\nimport { greaterThan } from \"./comparison/greater-than.cjs\";\nimport { greaterThanOrEqual } from \"./comparison/greater-than-or-equal.cjs\";\nimport { lessThan } from \"./comparison/less-than.cjs\";\nimport { lessThanOrEqual } from \"./comparison/less-than-or-equal.cjs\";\nimport { notEquals } from \"./comparison/not-equals.cjs\";\nimport { concatenate } from \"./concatenation/concatenate.cjs\";\nimport { CellValueNode } from \"./dependency-nodes/cell-value-node.cjs\";\nimport { EvaluationContext } from \"./evaluation-context.cjs\";\n\nexport class FormulaEvaluator {\n constructor(\n private tableManager: TableManager,\n private dependencyManager: DependencyManager,\n private namedExpressionManager: NamedExpressionManager\n ) {}\n\n // evaluator methods\n evaluateFormula(\n /**\n * formula is the formula to evaluate, without the leading =\n */\n formula: string,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const ast = parseFormula(formula);\n\n return captureEvaluationErrors(context.dependencyNode, () => {\n const result = this.evaluateNode(ast, context);\n return result;\n });\n }\n\n evaluateNode(\n node: ASTNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const currentContext = {\n ...context.cellAddress,\n tableName: context.cacheTableName,\n };\n\n const astNode = this.dependencyManager.getAstNode(node, currentContext);\n context.dependencyNode.addDependency(astNode);\n\n // if (astNode.evaluationResult.type !== \"awaiting-evaluation\") {\n // return astNode.evaluationResult;\n // }\n\n if (astNode.resolved) {\n const astContextDependency = astNode.getContextDependency();\n context.appendContextDependency(astContextDependency);\n return astNode.evaluationResult;\n }\n\n this.dependencyManager.unregisterNode(astNode);\n astNode.resetDirectDepsUpdated();\n\n function runEvaluation(\n this: FormulaEvaluator,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n switch (node.type) {\n case \"value\":\n return {\n type: \"value\",\n result: this.evaluateValue(node),\n };\n case \"infinity\":\n return {\n type: \"value\",\n result: {\n type: \"infinity\",\n sign: \"positive\",\n },\n };\n case \"binary-op\":\n return this.evaluateBinaryOp(node, context);\n\n case \"reference\":\n return this.evaluateReference(node, context);\n\n case \"named-expression\":\n return this.evaluateNamedExpression(node, context);\n\n case \"structured-reference\":\n return this.evaluateStructuredReference(node, context);\n\n case \"function\":\n return this.evaluateFunction(node, context);\n\n case \"range\":\n return this.evaluateRange(node, context);\n\n case \"unary-op\":\n return this.evaluateUnaryOp(node, context);\n\n case \"3d-range\":\n return this.evaluate3DRange(node, context);\n\n case \"array\":\n return this.evaluateArray(node, context);\n\n default:\n return {\n type: \"error\",\n err: FormulaError.ERROR,\n message: \"WIP: unimplemented support for \" + node.type,\n errAddress: context.dependencyNode,\n };\n }\n }\n const newContext = new EvaluationContext(\n this.tableManager,\n astNode,\n context.cellAddress\n );\n const result = captureEvaluationErrors(astNode, () =>\n runEvaluation.call(this, newContext)\n );\n astNode.setEvaluationResult(result);\n const astContextDependency = newContext.getContextDependency();\n\n astNode.setContextDependency(astContextDependency);\n this.dependencyManager.registerNode(astNode);\n\n context.appendContextDependency(astContextDependency);\n\n return result;\n }\n\n evaluateStructuredReference(\n node: StructuredReferenceNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const resourceWorkbookName =\n node.workbookName ?? context.cellAddress.workbookName;\n if (node.tableName) {\n context.dependencyNode.addDependency(\n this.dependencyManager.getResourceNode(\n getTableResourceKey({\n workbookName: resourceWorkbookName,\n tableName: node.tableName,\n })\n )\n );\n }\n\n // the tables are never dependent on the sheet, interesetingly enough\n let table: TableDefinition | undefined;\n if (node.tableName && node.workbookName) {\n // this expression will evaluate to the same value regardless of where in the workbooks we are evaluating it in\n table = this.tableManager\n .getTables(node.workbookName)\n .get(node.tableName);\n } else if (node.tableName) {\n // different workbooks could have different tables with the same name\n // so it can differ based on the workbook we are evaluating it in\n context.addContextDependency(\"workbook\");\n table = this.tableManager\n .getTables(context.cellAddress.workbookName)\n .get(node.tableName);\n } else {\n // If no table nor workbook name is provided, the current cell's table\n // membership determines the result.\n context.addContextDependency(\"workbook\", \"sheet\", \"table\");\n table = this.tableManager.isCellInTable(context.cellAddress);\n }\n\n if (node.isCurrentRow) {\n context.addContextDependency(\"row\");\n }\n\n if (!table) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: `Table ${node.tableName} not found`,\n errAddress: context.dependencyNode,\n };\n }\n\n const rowIndex = context.cellAddress.rowIndex;\n const tableStart = table.start;\n const createResolvedTableRangeNode = (range: SpreadsheetRange): RangeNode => ({\n type: \"range\",\n range,\n isAbsolute: {\n start: {\n col: true,\n row: true,\n },\n end: {\n col: true,\n row: true,\n },\n },\n sheetName: table.sheetName,\n workbookName: table.workbookName,\n });\n\n // Handle selector-based references\n if (node.selector) {\n let startRow: number;\n let endRow: SpreadsheetRangeEnd;\n\n switch (node.selector) {\n case \"#Headers\":\n startRow = table.start.rowIndex;\n endRow = { type: \"number\", value: table.start.rowIndex };\n break;\n case \"#Data\":\n startRow = table.start.rowIndex + 1;\n endRow = table.endRow;\n break;\n case \"#All\":\n startRow = table.start.rowIndex;\n endRow = table.endRow;\n break;\n default:\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: `Unknown table selector: ${node.selector}`,\n errAddress: context.dependencyNode,\n };\n }\n\n // If we also have column specification, use those columns\n if (node.cols) {\n const startCol = table.headers.get(node.cols.startCol);\n const endCol = table.headers.get(node.cols.endCol);\n if (!startCol || !endCol) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: `Column ${node.cols.startCol} or ${node.cols.endCol} not found in table ${table.name}`,\n errAddress: context.dependencyNode,\n };\n }\n const startColIndex = tableStart.colIndex + startCol.index;\n const endColIndex = tableStart.colIndex + endCol.index;\n\n const range: SpreadsheetRange = {\n start: {\n row: startRow,\n col: startColIndex,\n },\n end: {\n row: endRow,\n col: { type: \"number\", value: endColIndex },\n },\n };\n\n return this.evaluateRange(\n createResolvedTableRangeNode(range),\n context\n );\n } else {\n // No column specification, return entire row(s) for the selector\n const range: SpreadsheetRange = {\n start: {\n row: startRow,\n col: tableStart.colIndex,\n },\n end: {\n row: endRow,\n col: {\n type: \"number\",\n value: tableStart.colIndex + table.headers.size - 1,\n },\n },\n };\n\n return this.evaluateRange(\n createResolvedTableRangeNode(range),\n context\n );\n }\n }\n\n // Handle column-only references (no selector)\n if (node.cols) {\n const startCol = table.headers.get(node.cols.startCol);\n const endCol = table.headers.get(node.cols.endCol);\n if (!startCol || !endCol) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: `Column ${node.cols.startCol} or ${node.cols.endCol} not found in table ${table.name}`,\n errAddress: context.dependencyNode,\n };\n }\n const startColIndex = tableStart.colIndex + startCol.index;\n const endColIndex = tableStart.colIndex + endCol.index;\n const range: SpreadsheetRange = {\n start: {\n row: node.isCurrentRow ? rowIndex : table.start.rowIndex + 1,\n col: startColIndex,\n },\n end: {\n row: node.isCurrentRow\n ? { type: \"number\", value: rowIndex }\n : table.endRow,\n col: { type: \"number\", value: endColIndex },\n },\n };\n\n return this.evaluateRange(\n createResolvedTableRangeNode(range),\n context\n );\n }\n\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: \"Structured reference must specify either a selector or columns\",\n errAddress: context.dependencyNode,\n };\n }\n\n /**\n * Evaluates a value node\n */\n evaluateValue(node: ValueNode): CellValue {\n return node.value;\n }\n\n evaluate3DRange(\n node: ThreeDRangeNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n throw new Error(\"WIP: 3d range is not implemented\");\n /*\n const startSheet = this.sheets.get(node.startSheet);\n const endSheet = this.sheets.get(node.endSheet);\n if (!startSheet || !endSheet) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: `Sheet ${node.startSheet} or ${node.endSheet} not found`,\n };\n }\n\n let numCols = 0;\n let numRows = 0;\n for (let i = startSheet.index; i <= endSheet.index; i++) {\n if (node.reference.type === \"reference\") {\n numCols += 1;\n } else {\n numCols += node.reference.range.end.col.value - node.reference.range.start.col.value + 1;\n }\n\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: `Sheet ${i} not found`,\n };\n }\n\n return {\n type: \"spilled-values\",\n spillArea: (origin: CellAddress) => ({\n start: {\n col: origin.colIndex,\n row: origin.rowIndex,\n },\n end: {\n col: { type: \"number\", value: origin.colIndex },\n row: {\n type: \"number\",\n value: origin.rowIndex + numSheets - 1,\n },\n },\n }),\n source: `range`,\n originResult:\n originResult.type === \"value\"\n ? originResult.result\n : originResult.originResult,\n evaluate: (spilledCell, context) => {\n const colIndex = range.start.col + spilledCell.spillOffset.x;\n const rowIndex = range.start.row + spilledCell.spillOffset.y;\n const sheetName = node.sheetName ?? context.currentSheet;\n return this.evalTimeSafeEvaluateCell(\n {\n colIndex,\n rowIndex,\n sheetName,\n },\n context\n );\n },\n };\n */\n }\n\n evaluateRange(\n node: RangeNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n if (isRangeOneCell(node.range)) {\n return this.evaluateReference(\n {\n type: \"reference\",\n address: {\n colIndex: node.range.start.col,\n rowIndex: node.range.start.row,\n },\n isAbsolute: {\n col: node.isAbsolute.start.col || node.isAbsolute.end.col,\n row: node.isAbsolute.start.row || node.isAbsolute.end.row,\n },\n sheetName: node.sheetName,\n },\n context\n );\n }\n\n const debugRange = getRangeKey(node.range);\n\n const rangeAddress: RangeAddress = {\n sheetName: node.sheetName ?? context.cellAddress.sheetName,\n workbookName: node.workbookName ?? context.cellAddress.workbookName,\n range: node.range,\n };\n\n if (node.workbookName) {\n context.dependencyNode.addDependency(\n this.dependencyManager.getResourceNode(\n getWorkbookResourceKey(node.workbookName)\n )\n );\n }\n if (node.sheetName) {\n context.dependencyNode.addDependency(\n this.dependencyManager.getResourceNode(\n getSheetResourceKey({\n workbookName: rangeAddress.workbookName,\n sheetName: node.sheetName,\n })\n )\n );\n }\n\n return {\n type: \"spilled-values\",\n spillArea: (origin) => this.projectRange(node.range, origin),\n source: `range ${debugRange}`,\n sourceRange: rangeAddress,\n evaluate: (spillOffset, context) => {\n if (!node.sheetName && !node.workbookName) {\n // e.g. the result from A4:A9 will depend in which sheet and workbook we are evaluating it in\n context.addContextDependency(\"workbook\", \"sheet\");\n } else if (!node.sheetName) {\n // e.g. the result from [Workbook1]A4:A9 will depend in which sheet we are evaluating it in\n context.addContextDependency(\"sheet\");\n } else if (!node.workbookName) {\n // e.g. the result from Sheet1!A4:A9 will depend in which workbook we are evaluating it in\n context.addContextDependency(\"workbook\");\n } else {\n // if we have both sheetName and workbookName, we don't need to add any context dependencies\n }\n\n const originSheetName = node.sheetName ?? context.cellAddress.sheetName;\n const originWorkbookName =\n node.workbookName ?? context.cellAddress.workbookName;\n const colIndex = node.range.start.col + spillOffset.x;\n const rowIndex = node.range.start.row + spillOffset.y;\n\n const cellAddress: CellAddress = {\n colIndex,\n rowIndex,\n sheetName: originSheetName,\n workbookName: originWorkbookName,\n };\n\n const evalNode = this.dependencyManager.getCellValueOrEmptyCellNode(\n cellAddressToKey(cellAddress)\n );\n context.dependencyNode.addDependency(evalNode);\n\n const result = evalNode.evaluationResult;\n\n return result;\n },\n evaluateAllCells: function ({\n evaluate,\n intersection,\n context,\n origin,\n lookupOrder,\n }) {\n let range = node.range;\n if (intersection) {\n // When we have an intersection, it's defined relative to where the spilled range\n // will appear (the origin). However, we need to evaluate cells from the source\n // range (node.range). So we must translate the intersection coordinates back\n // to the source range's coordinate system.\n //\n // Example: If source range A1:C3 spills to D5:F7, and we want intersection E6:F7,\n // we need to translate E6:F7 (relative to D5) to B2:C3 (relative to A1).\n\n // Calculate the offset of the intersection from the spill origin\n const relativeRange = getRelativeRange(intersection, origin);\n const start: LocalCellAddress = {\n colIndex: node.range.start.col,\n rowIndex: node.range.start.row,\n };\n const projectedIntersection = getAbsoluteRange(relativeRange, start);\n const calculateIntersection = getRangeIntersection(\n node.range,\n projectedIntersection\n );\n if (calculateIntersection) {\n range = calculateIntersection;\n }\n }\n\n const address: RangeAddress = {\n range,\n sheetName: node.sheetName ?? context.cellAddress.sheetName,\n workbookName: node.workbookName ?? context.cellAddress.workbookName,\n };\n\n const rangeNode = this.dependencyManager.getRangeNode(\n rangeAddressToKey(address)\n );\n\n context.dependencyNode.addDependency(rangeNode);\n\n return this.dependencyManager.getRangeNode(rangeAddressToKey(address))\n .result;\n },\n };\n }\n\n evaluateArray(\n node: ArrayNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const firstRow = node.elements[0];\n if (!firstRow) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: \"Array is empty\",\n errAddress: context.dependencyNode,\n };\n }\n const firstCell = firstRow[0];\n if (!firstCell) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: \"Array is empty\",\n errAddress: context.dependencyNode,\n };\n }\n const originResult = this.evaluateNode(firstCell, context);\n if (\n originResult.type === \"error\" ||\n originResult.type === \"awaiting-evaluation\"\n ) {\n return originResult;\n }\n return {\n type: \"spilled-values\",\n spillArea: (origin) => ({\n start: {\n col: origin.colIndex,\n row: origin.rowIndex,\n },\n end: {\n col: {\n type: \"number\",\n value: origin.colIndex + firstRow.length - 1,\n },\n row: {\n type: \"number\",\n value: origin.rowIndex + node.elements.length - 1,\n },\n },\n }),\n source: `array`,\n evaluate: (spillOffset, context) => {\n const row = node.elements[spillOffset.y];\n if (!row) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: \"Array is empty\",\n errAddress: context.dependencyNode,\n };\n }\n const cell = row[spillOffset.x];\n if (!cell) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: \"Array is empty\",\n errAddress: context.dependencyNode,\n };\n }\n const result = this.evaluateNode(cell, context);\n if (result.type === \"spilled-values\") {\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: \"Arrays cannot contain spilled values\",\n errAddress: context.dependencyNode,\n };\n }\n return result;\n },\n evaluateAllCells: (intersectingRange) => {\n throw new Error(\"WIP: evaluateAllCells for array is not implemented\");\n },\n };\n }\n\n /**\n * Evaluates a unary operation\n */\n evaluateUnaryOp(\n node: UnaryOpNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const operandResult = this.evaluateNode(node.operand, context);\n\n if (\n operandResult.type === \"error\" ||\n operandResult.type === \"awaiting-evaluation\"\n ) {\n return operandResult;\n }\n\n if (operandResult.type === \"spilled-values\") {\n return {\n type: \"spilled-values\",\n spillArea: (origin) => operandResult.spillArea(origin),\n source: `unary ${node.operator} operation`,\n evaluate: (spilledCell, context) => {\n const spillResult = operandResult.evaluate(spilledCell, context);\n if (\n !spillResult ||\n spillResult.type === \"error\" ||\n spillResult.type === \"awaiting-evaluation\"\n ) {\n return spillResult;\n }\n if (spillResult.type !== \"value\") {\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: \"Invalid spilled result for unary operation\",\n errAddress: context.dependencyNode,\n };\n }\n return this.evaluateUnaryScalar(\n node.operator,\n spillResult.result,\n context\n );\n },\n evaluateAllCells: function (options) {\n const cellValues = operandResult.evaluateAllCells.call(this, options);\n if (cellValues.type !== \"values\") {\n return cellValues;\n }\n return {\n type: \"values\",\n values: cellValues.values.map((cellValue) => {\n if (\n cellValue.result.type === \"error\" ||\n cellValue.result.type === \"awaiting-evaluation\"\n ) {\n return cellValue;\n } else {\n return {\n result: this.evaluateUnaryScalar(\n node.operator,\n cellValue.result.result,\n context\n ),\n relativePos: cellValue.relativePos,\n };\n }\n }),\n };\n },\n };\n }\n\n if (operandResult.type === \"value\") {\n return this.evaluateUnaryScalar(\n node.operator,\n operandResult.result,\n context\n );\n }\n\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: \"Invalid operand for unary operation\",\n errAddress: context.dependencyNode,\n };\n }\n\n /**\n * Evaluates a unary scalar operation\n */\n private evaluateUnaryScalar(\n operator: \"+\" | \"-\" | \"%\",\n operand: CellValue,\n context: EvaluationContext\n ): SingleEvaluationResult {\n if (operand.type !== \"number\" && operand.type !== \"infinity\") {\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: `Cannot apply unary ${operator} to non-number`,\n errAddress: context.dependencyNode,\n };\n }\n if (operand.type === \"infinity\") {\n if (operator === \"%\") {\n return {\n type: \"error\",\n err: FormulaError.NUM,\n message: \"Cannot apply % to infinity\",\n errAddress: context.dependencyNode,\n };\n }\n return {\n type: \"value\",\n result: {\n type: \"infinity\",\n sign: operator === \"+\" ? \"positive\" : \"negative\",\n },\n };\n }\n switch (operator) {\n case \"+\":\n return { type: \"value\", result: operand };\n\n case \"-\":\n return {\n type: \"value\",\n result: {\n type: \"number\",\n value: -operand.value,\n },\n };\n\n case \"%\":\n return {\n type: \"value\",\n result: { type: \"number\", value: operand.value / 100 },\n };\n\n default:\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: `Unknown unary operator: ${operator}`,\n errAddress: context.dependencyNode,\n };\n }\n }\n\n /**\n * Evaluates a binary operation\n */\n evaluateBinaryOp(\n node: BinaryOpNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const left = this.evaluateNode(node.left, context);\n const right = this.evaluateNode(node.right, context);\n\n if (left.type === \"error\" || left.type === \"awaiting-evaluation\") {\n return left;\n }\n if (right.type === \"error\" || right.type === \"awaiting-evaluation\") {\n return right;\n }\n\n // Scalar operation\n return this.evaluateBinaryScalar(node.operator, left, right, context);\n }\n\n /**\n * Evaluates a reference node\n */\n evaluateReference(\n node: ReferenceNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const cellAddress: CellAddress = {\n ...node.address,\n sheetName: node.sheetName ?? context.cellAddress.sheetName,\n workbookName: node.workbookName ?? context.cellAddress.workbookName,\n };\n\n if (node.workbookName) {\n context.dependencyNode.addDependency(\n this.dependencyManager.getResourceNode(\n getWorkbookResourceKey(node.workbookName)\n )\n );\n }\n if (node.sheetName) {\n context.dependencyNode.addDependency(\n this.dependencyManager.getResourceNode(\n getSheetResourceKey({\n workbookName: cellAddress.workbookName,\n sheetName: node.sheetName,\n })\n )\n );\n }\n\n const key = cellAddressToKey(cellAddress);\n const evalNode = this.dependencyManager.getCellValueOrEmptyCellNode(key);\n context.dependencyNode.addDependency(evalNode);\n\n if (!node.sheetName && !node.workbookName) {\n // e.g. the result from A4:A9 will depend in which sheet and workbook we are evaluating it in\n context.addContextDependency(\"workbook\", \"sheet\");\n } else if (!node.sheetName) {\n // e.g. the result from [Workbook1]A4:A9 will depend in which sheet we are evaluating it in\n context.addContextDependency(\"sheet\");\n } else if (!node.workbookName) {\n // e.g. the result from Sheet1!A4:A9 will depend in which workbook we are evaluating it in\n context.addContextDependency(\"workbook\");\n } else {\n // if we have both sheetName and workbookName, we don't need to add any context dependencies\n }\n\n if (evalNode instanceof CellValueNode && evalNode.spillMeta) {\n if (evalNode.spillMeta.evaluationResult.type === \"spilled-values\") {\n return {\n ...evalNode.spillMeta.evaluationResult,\n sourceCell: cellAddress,\n sourceRange: undefined,\n };\n }\n }\n\n return { ...evalNode.evaluationResult, sourceCell: cellAddress };\n }\n\n /**\n * Evaluates a named expression node\n */\n evaluateNamedExpression(\n node: NamedExpressionNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const resolvedExpression =\n this.namedExpressionManager.resolveNamedExpressionWithScope(\n node,\n context\n );\n\n if (!resolvedExpression) {\n return {\n type: \"error\",\n err: FormulaError.NAME,\n message: `Named expression ${node.name} not found`,\n errAddress: context.dependencyNode,\n };\n }\n\n context.dependencyNode.addDependency(\n this.dependencyManager.getResourceNode(\n getNamedExpressionResourceKey({\n expressionName: node.name,\n workbookName:\n resolvedExpression.scope.type === \"global\"\n ? undefined\n : resolvedExpression.scope.workbookName,\n sheetName:\n resolvedExpression.scope.type === \"sheet\"\n ? resolvedExpression.scope.sheetName\n : undefined,\n })\n )\n );\n\n return this.evaluateFormula(resolvedExpression.expression, context);\n }\n\n /**\n * Binary scalar operations\n */\n evaluateBinaryScalar(\n operator: string,\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n switch (operator) {\n case \"+\":\n return this.add(left, right, context);\n case \"-\":\n return this.subtract(left, right, context);\n case \"*\":\n return this.multiply(left, right, context);\n case \"/\":\n return this.divide(left, right, context);\n case \"^\":\n return this.power(left, right, context);\n\n case \"&\":\n return this.concatenateOp(left, right, context);\n case \"=\":\n return this.equalsOp(left, right, context);\n case \"<>\":\n return this.notEqualsOp(left, right, context);\n case \"<\":\n return this.lessThanOp(left, right, context);\n case \"<=\":\n return this.lessThanOrEqualOp(left, right, context);\n case \">\":\n return this.greaterThanOp(left, right, context);\n case \">=\":\n return this.greaterThanOrEqualOp(left, right, context);\n default:\n return {\n type: \"error\",\n err: FormulaError.ERROR,\n message: `Unknown binary operator: ${operator}`,\n errAddress: context.dependencyNode,\n };\n }\n }\n\n evaluateFunction(\n node: FunctionNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const func = functions[node.name];\n if (!func) {\n return {\n type: \"error\",\n err: FormulaError.NAME,\n message: `Function ${node.name} not found`,\n errAddress: context.dependencyNode,\n };\n }\n return func.evaluate.call(this, node, context);\n }\n\n // Arithmetic operations\n add(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: add,\n context,\n name: \"add\",\n });\n }\n\n multiply(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: multiply,\n context,\n name: \"multiply\",\n });\n }\n\n divide(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: divide,\n context,\n name: \"divide\",\n });\n }\n\n evaluateScalarOperator(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n options: EvaluateScalarOperatorOptions\n ): FunctionEvaluationResult {\n return evaluateScalarOperator.call(this, left, right, options);\n }\n\n subtract(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: subtract,\n context,\n name: \"subtract\",\n });\n }\n\n power(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: power,\n context,\n name: \"power\",\n });\n }\n\n // Comparison operations\n equalsOp(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: equals,\n context,\n name: \"equals\",\n });\n }\n\n notEqualsOp(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: notEquals,\n context,\n name: \"notEquals\",\n });\n }\n\n lessThanOp(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: lessThan,\n context,\n name: \"lessThan\",\n });\n }\n\n lessThanOrEqualOp(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: lessThanOrEqual,\n context,\n name: \"lessThanOrEqual\",\n });\n }\n\n greaterThanOp(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: greaterThan,\n context,\n name: \"greaterThan\",\n });\n }\n\n greaterThanOrEqualOp(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: greaterThanOrEqual,\n context,\n name: \"greaterThanOrEqual\",\n });\n }\n\n // Concatenation operation\n concatenateOp(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: concatenate,\n context,\n name: \"concatenate\",\n });\n }\n\n projectRange(\n range: SpreadsheetRange,\n originCellAddress: CellAddress\n ): SpreadsheetRange {\n const offsetLeft = originCellAddress.colIndex - range.start.col;\n const offsetTop = originCellAddress.rowIndex - range.start.row;\n return {\n start: {\n col: range.start.col + offsetLeft,\n row: range.start.row + offsetTop,\n },\n end: {\n col:\n range.end.col.type === \"number\"\n ? { type: \"number\", value: range.end.col.value + offsetLeft }\n : range.end.col,\n row:\n range.end.row.type === \"number\"\n ? { type: \"number\", value: range.end.row.value + offsetTop }\n : range.end.row,\n },\n };\n }\n\n unionRanges(\n range1: SpreadsheetRange,\n range2: SpreadsheetRange\n ): SpreadsheetRange {\n const endCol = ((): SpreadsheetRangeEnd => {\n if (\n range1.end.col.type === \"infinity\" ||\n range2.end.col.type === \"infinity\"\n ) {\n return { type: \"infinity\", sign: \"positive\" };\n }\n return {\n type: \"number\",\n value: Math.max(range1.end.col.value, range2.end.col.value),\n };\n })();\n\n const endRow = ((): SpreadsheetRangeEnd => {\n if (\n range1.end.row.type === \"infinity\" ||\n range2.end.row.type === \"infinity\"\n ) {\n return { type: \"infinity\", sign: \"positive\" };\n }\n return {\n type: \"number\",\n value: Math.max(range1.end.row.value, range2.end.row.value),\n };\n })();\n\n return {\n start: {\n col: Math.min(range1.start.col, range2.start.col),\n row: Math.min(range1.start.row, range2.start.row),\n },\n end: {\n col: endCol,\n row: endRow,\n },\n };\n }\n}\n"
6
6
  ],
7
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaO,IARP;AAS6B,IAA7B;AAcO,IATP;AAeO,IALP;AASO,IAHP;AAI0B,IAA1B;AAcoB,IAApB;AACuB,IAAvB;AACyB,IAAzB;AACsB,IAAtB;AACyB,IAAzB;AACuB,IAAvB;AAC4B,IAA5B;AACmC,IAAnC;AACyB,IAAzB;AACgC,IAAhC;A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,YAAY,MAAM,WAAW;AAAA,MAC9C;AAAA,MACA,OAAO;AAAA,QACL,MAAM;AAAA,QACN,OAAO,KAAK,IAAI,OAAO,IAAI,IAAI,OAAO,OAAO,IAAI,IAAI,KAAK;AAAA,MAC5D;AAAA,OACC;AAAA,IAEH,OAAO;AAAA,MACL,OAAO;AAAA,QACL,KAAK,KAAK,IAAI,OAAO,MAAM,KAAK,OAAO,MAAM,GAAG;AAAA,QAChD,KAAK,KAAK,IAAI,OAAO,MAAM,KAAK,OAAO,MAAM,GAAG;AAAA,MAClD;AAAA,MACA,KAAK;AAAA,QACH,KAAK;AAAA,QACL,KAAK;AAAA,MACP;AAAA,IACF;AAAA;AAEJ;",
8
+ "debugId": "3D1653EF8566F26E64756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -55,7 +55,7 @@ function performSummation(results) {
55
55
  type: "value",
56
56
  result: result.result
57
57
  };
58
- } else {}
58
+ }
59
59
  }
60
60
  }
61
61
  return {
@@ -64,4 +64,4 @@ function performSummation(results) {
64
64
  };
65
65
  }
66
66
 
67
- //# debugId=7C56A64EF8A4C19464756E2164756E21
67
+ //# debugId=32045F11E65F066364756E2164756E21
@@ -4,7 +4,7 @@
4
4
  "sourcesContent": [
5
5
  "import {\n FormulaError,\n type FunctionEvaluationResult,\n type SingleEvaluationResult,\n type CellInfinity,\n} from \"../../../core/types.cjs\";\nimport type { EvaluationContext } from \"../../../evaluator/evaluation-context.cjs\";\nimport type { FormulaEvaluator } from \"../../../evaluator/formula-evaluator.cjs\";\nimport type { FunctionNode } from \"../../../parser/ast.cjs\";\n\n/**\n * Result type for processInfinity in sum functions\n */\nexport type ProcessInfinityResult<T> =\n | { type: \"infinity\"; infinity: CellInfinity }\n | { type: \"state\"; state: T };\n\n/**\n * Perform summation with error propagation\n * Used when errors should be propagated instead of skipped (e.g., SUM with direct error arguments)\n *\n * @param results - Iterator of SingleEvaluationResults to sum\n * @returns FunctionEvaluationResult with the sum, infinity, or first error encountered\n */\nexport function performSummation(\n results: Iterable<SingleEvaluationResult>\n): FunctionEvaluationResult {\n let sum = 0;\n let hasValues = false;\n\n for (const result of results) {\n if (result.type === \"value\") {\n if (result.result.type === \"number\") {\n sum += result.result.value;\n hasValues = true;\n } else if (result.result.type === \"infinity\") {\n // Infinity dominates - return immediately\n return {\n type: \"value\",\n result: result.result,\n };\n } else {\n // Non-numeric values (strings, booleans) are ignored in summation\n }\n }\n }\n\n return {\n type: \"value\",\n result: { type: \"number\", value: sum },\n };\n}\n"
6
6
  ],
7
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBO,SAAS,gBAAgB,CAC9B,SAC0B;AAAA,EAC1B,IAAI,MAAM;AAAA,EACV,IAAI,YAAY;AAAA,EAEhB,WAAW,UAAU,SAAS;AAAA,IAC5B,IAAI,OAAO,SAAS,SAAS;AAAA,MAC3B,IAAI,OAAO,OAAO,SAAS,UAAU;AAAA,QACnC,OAAO,OAAO,OAAO;AAAA,QACrB,YAAY;AAAA,MACd,EAAO,SAAI,OAAO,OAAO,SAAS,YAAY;AAAA,QAE5C,OAAO;AAAA,UACL,MAAM;AAAA,UACN,QAAQ,OAAO;AAAA,QACjB;AAAA,MACF,EAAO;AAAA,IAGT;AAAA,EACF;AAAA,EAEA,OAAO;AAAA,IACL,MAAM;AAAA,IACN,QAAQ,EAAE,MAAM,UAAU,OAAO,IAAI;AAAA,EACvC;AAAA;",
8
- "debugId": "7C56A64EF8A4C19464756E2164756E21",
7
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBO,SAAS,gBAAgB,CAC9B,SAC0B;AAAA,EAC1B,IAAI,MAAM;AAAA,EACV,IAAI,YAAY;AAAA,EAEhB,WAAW,UAAU,SAAS;AAAA,IAC5B,IAAI,OAAO,SAAS,SAAS;AAAA,MAC3B,IAAI,OAAO,OAAO,SAAS,UAAU;AAAA,QACnC,OAAO,OAAO,OAAO;AAAA,QACrB,YAAY;AAAA,MACd,EAAO,SAAI,OAAO,OAAO,SAAS,YAAY;AAAA,QAE5C,OAAO;AAAA,UACL,MAAM;AAAA,UACN,QAAQ,OAAO;AAAA,QACjB;AAAA,MACF;AAAA,IAGF;AAAA,EACF;AAAA,EAEA,OAAO;AAAA,IACL,MAAM;AAAA,IACN,QAAQ,EAAE,MAAM,UAAU,OAAO,IAAI;AAAA,EACvC;AAAA;",
8
+ "debugId": "32045F11E65F066364756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/formula-engine",
3
- "version": "0.2.9",
3
+ "version": "0.2.11",
4
4
  "type": "commonjs"
5
5
  }
@@ -277,9 +277,8 @@ function formatStructuredReference(ast) {
277
277
  }
278
278
  let result = "";
279
279
  if (workbookName) {
280
- result += `[${workbookName}]`;
281
- }
282
- if (sheetName) {
280
+ result += `[${workbookName}]!`;
281
+ } else if (sheetName) {
283
282
  const quotedSheet = sheetName.includes(" ") ? `'${sheetName}'` : sheetName;
284
283
  result += `${quotedSheet}!`;
285
284
  }
@@ -326,4 +325,4 @@ function isSerializedCellValueEqual(a, b) {
326
325
  return normalizedA === normalizedB;
327
326
  }
328
327
 
329
- //# debugId=DEDFCFE61428B68064756E2164756E21
328
+ //# debugId=1755F00DD1DD7AC364756E2164756E21