@ricsam/formula-engine 0.0.4 → 0.0.5

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.
@@ -36,7 +36,7 @@ var import_types = require("../core/types.cjs");
36
36
  var import_parser = require("../parser/parser.cjs");
37
37
  var import_utils = require("../core/utils.cjs");
38
38
  var import_evaluate_scalar_operator = require("../evaluator/evaluate-scalar-operator.cjs");
39
- var import_functions = require("../functions.cjs");
39
+ var import_function_registry = require("../functions/function-registry.cjs");
40
40
  var import_add = require("./arithmetic/add/add.cjs");
41
41
  var import_divide = require("./arithmetic/divide/divide.cjs");
42
42
  var import_multiply = require("./arithmetic/multiply/multiply.cjs");
@@ -650,7 +650,7 @@ class FormulaEvaluator {
650
650
  }
651
651
  }
652
652
  evaluateFunction(node, context) {
653
- const func = import_functions.functions[node.name];
653
+ const func = import_function_registry.functions[node.name];
654
654
  if (!func) {
655
655
  return {
656
656
  type: "error",
@@ -794,4 +794,4 @@ class FormulaEvaluator {
794
794
  }
795
795
  }
796
796
 
797
- //# debugId=649489FD9AA08ECC64756E2164756E21
797
+ //# debugId=DB11FB05E50DC17164756E2164756E21
@@ -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 evaluateScalarOperator,\n type EvaluateScalarOperatorOptions,\n} from \"../evaluator/evaluate-scalar-operator.cjs\";\nimport { functions } from \"../functions.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.tableName,\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 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\n context.appendContextDependency(astContextDependency);\n\n return result;\n }\n\n evaluateStructuredReference(\n node: StructuredReferenceNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\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, we need to find the table in the current workbook\n // and the formula will be evaluated differently based on the table (and workbook) we are evaluating it in\n context.addContextDependency(\"workbook\", \"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 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 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 expression = this.namedExpressionManager.resolveNamedExpression(\n node,\n context\n );\n\n if (!expression) {\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 return this.evaluateFormula(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 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.tableName,\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 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\n context.appendContextDependency(astContextDependency);\n\n return result;\n }\n\n evaluateStructuredReference(\n node: StructuredReferenceNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\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, we need to find the table in the current workbook\n // and the formula will be evaluated differently based on the table (and workbook) we are evaluating it in\n context.addContextDependency(\"workbook\", \"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 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 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 expression = this.namedExpressionManager.resolveNamedExpression(\n node,\n context\n );\n\n if (!expression) {\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 return this.evaluateFormula(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;AAaO,IAHP;AAI0B,IAA1B;AAcoB,IAApB;AACuB,IAAvB;AACyB,IAAzB;AACsB,IAAtB;AACyB,IAAzB;AACuB,IAAvB;AAC4B,IAA5B;AACmC,IAAnC;AACyB,IAAzB;AACgC,IAAhC;AAC0B,IAA1B;AAC4B,IAA5B;AAC8B,IAA9B;AACkC,IAAlC;AAAA;AAEO,MAAM,iBAAiB;AAAA,EAElB;AAAA,EACA;AAAA,EACA;AAAA,EAHV,WAAW,CACD,cACA,mBACA,wBACR;AAAA,IAHQ;AAAA,IACA;AAAA,IACA;AAAA;AAAA,EAIV,eAAe,CAIb,SACA,SAC0B;AAAA,IAC1B,MAAM,MAAM,2BAAa,OAAO;AAAA,IAEhC,OAAO,qCAAwB,QAAQ,gBAAgB,MAAM;AAAA,MAC3D,MAAM,SAAS,KAAK,aAAa,KAAK,OAAO;AAAA,MAC7C,OAAO;AAAA,KACR;AAAA;AAAA,EAGH,YAAY,CACV,MACA,SAC0B;AAAA,IAC1B,MAAM,iBAAiB;AAAA,SAClB,QAAQ;AAAA,MACX,WAAW,QAAQ;AAAA,IACrB;AAAA,IAEA,MAAM,UAAU,KAAK,kBAAkB,WAAW,MAAM,cAAc;AAAA,IAC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,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": "DB11FB05E50DC17164756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -26,12 +26,12 @@ var __export = (target, all) => {
26
26
  });
27
27
  };
28
28
 
29
- // src/functions/index.ts
30
- var exports_functions = {};
31
- __export(exports_functions, {
29
+ // src/functions/function-registry.ts
30
+ var exports_function_registry = {};
31
+ __export(exports_function_registry, {
32
32
  functions: () => functions
33
33
  });
34
- module.exports = __toCommonJS(exports_functions);
34
+ module.exports = __toCommonJS(exports_function_registry);
35
35
  var import_sequence = require("./array/sequence/sequence.cjs");
36
36
  var import_index_lookup = require("./lookup/index-lookup/index-lookup.cjs");
37
37
  var import_match = require("./lookup/match/match.cjs");
@@ -122,4 +122,4 @@ var functions = buildFunctionIndex({
122
122
  XLOOKUP: import_xlookup.XLOOKUP
123
123
  });
124
124
 
125
- //# debugId=DFDC71312AB793C064756E2164756E21
125
+ //# debugId=3A4C74F24D6EEB8664756E2164756E21
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../../src/functions/index.ts"],
3
+ "sources": ["../../../src/functions/function-registry.ts"],
4
4
  "sourcesContent": [
5
5
  "import type { FunctionDefinition } from \"../core/types.cjs\";\n// import { arrayFunctions } from \"./array/array-functions.cjs\";\n// import { infoFunctions } from \"./info/info-functions.cjs\";\n// import { logicalComparisonFunctions } from \"./logical/comparisons.cjs\";\n// import { logicalConditionFunctions } from \"./logical/conditions.cjs\";\n// import { lookupFunctions } from \"./lookup/lookup-functions.cjs\";\n// import { advancedMathFunctions } from \"./math/advanced.cjs\";\n// import { basicMathFunctions } from \"./math/basic.cjs\";\n// import { textFunctions } from \"./text/string-functions.cjs\";\nimport { SEQUENCE } from \"./array/sequence/sequence.cjs\";\nimport { INDEX } from \"./lookup/index-lookup/index-lookup.cjs\"; // Fixed import path\nimport { MATCH } from \"./lookup/match/match.cjs\";\nimport { COUNT } from \"./lookup/count/count.cjs\";\nimport { COUNTIF } from \"./lookup/count/countif.cjs\";\nimport { AVERAGE } from \"./math/average/average.cjs\";\nimport { AVERAGEIF } from \"./math/average/averageif.cjs\";\nimport { AVERAGEIFS } from \"./math/average/averageifs.cjs\";\nimport { MAX } from \"./math/max/max.cjs\";\nimport { MAXIFS } from \"./math/max/maxifs.cjs\";\nimport { MIN } from \"./math/min/min.cjs\";\nimport { MINIFS } from \"./math/min/minifs.cjs\";\nimport { SUM } from \"./math/sum/sum.cjs\";\nimport { SUMIF } from \"./math/sum/sumif.cjs\";\nimport { SUMIFS } from \"./math/sum/sumifs.cjs\";\nimport { COUNTIFS } from \"./lookup/count/countifs.cjs\";\nimport { MAXIF } from \"./math/max/maxif.cjs\";\nimport { MINIF } from \"./math/min/minif.cjs\";\nimport { CEILING } from \"./math/ceiling/ceiling.cjs\";\nimport { EXACT } from \"./text/exact/exact.cjs\";\nimport { FIND } from \"./text/find/find.cjs\";\nimport { LEFT } from \"./text/left/left.cjs\";\nimport { MID } from \"./text/mid/mid.cjs\";\nimport { LEN } from \"./text/len/len.cjs\";\nimport { RIGHT } from \"./text/right/right.cjs\";\nimport { CONCATENATE } from \"./text/concatenate/concatenate.cjs\";\nimport { AND } from \"./logical/and/and.cjs\";\nimport { IF } from \"./logical/if/if.cjs\";\nimport { IFERROR } from \"./logical/iferror/iferror.cjs\";\nimport { XLOOKUP } from \"./lookup/xlookup/xlookup.cjs\";\nimport { OR } from \"./logical/or/or.cjs\";\nimport { TEXTJOIN } from \"./text/textjoin/textjoin.cjs\";\nimport { ROW } from \"./information/row/row.cjs\";\nimport { COLUMN } from \"./information/column/column.cjs\";\nimport { CELL } from \"./information/cell/cell.cjs\";\nimport { ADDRESS } from \"./reference/address/address.cjs\";\nimport { INDIRECT } from \"./reference/indirect/indirect.cjs\";\nimport { OFFSET } from \"./reference/offset/offset.cjs\";\n\nconst buildFunctionIndex = (functions: Record<string, FunctionDefinition>) => {\n return Object.fromEntries(\n Object.entries(functions).flatMap(([name, func]) => {\n const base: [string, FunctionDefinition][] = [[name, func]];\n if (func.aliases) {\n func.aliases.forEach((alias) => {\n base.push([alias, func]);\n });\n }\n return base;\n })\n );\n};\n\nexport const functions: Record<string, FunctionDefinition> = buildFunctionIndex(\n {\n ADDRESS,\n AND,\n AVERAGE,\n AVERAGEIF,\n AVERAGEIFS,\n CEILING,\n CELL,\n COLUMN,\n CONCATENATE,\n COUNT,\n COUNTIF,\n COUNTIFS,\n EXACT,\n FIND,\n IF,\n IFERROR,\n INDEX,\n INDIRECT,\n LEFT,\n LEN,\n MATCH,\n MAX,\n MAXIF,\n MAXIFS,\n MID,\n MIN,\n MINIF,\n MINIFS,\n OFFSET,\n OR,\n RIGHT,\n ROW,\n SEQUENCE,\n SUM,\n SUMIF,\n SUMIFS,\n TEXTJOIN,\n XLOOKUP,\n }\n);\n"
6
6
  ],
7
7
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASyB,IAAzB;AACsB,IAAtB;AACsB,IAAtB;AACsB,IAAtB;AACwB,IAAxB;AACwB,IAAxB;AAC0B,IAA1B;AAC2B,IAA3B;AACoB,IAApB;AACuB,IAAvB;AACoB,IAApB;AACuB,IAAvB;AACoB,IAApB;AACsB,IAAtB;AACuB,IAAvB;AACyB,IAAzB;AACsB,IAAtB;AACsB,IAAtB;AACwB,IAAxB;AACsB,IAAtB;AACqB,IAArB;AACqB,IAArB;AACoB,IAApB;AACoB,IAApB;AACsB,IAAtB;AAC4B,IAA5B;AACoB,IAApB;AACmB,IAAnB;AACwB,IAAxB;AACwB,IAAxB;AACmB,IAAnB;AACyB,IAAzB;AACoB,IAApB;AACuB,IAAvB;AACqB,IAArB;AACwB,IAAxB;AACyB,IAAzB;AACuB,IAAvB;AAEA,IAAM,qBAAqB,CAAC,cAAkD;AAAA,EAC5E,OAAO,OAAO,YACZ,OAAO,QAAQ,SAAS,EAAE,QAAQ,EAAE,MAAM,UAAU;AAAA,IAClD,MAAM,OAAuC,CAAC,CAAC,MAAM,IAAI,CAAC;AAAA,IAC1D,IAAI,KAAK,SAAS;AAAA,MAChB,KAAK,QAAQ,QAAQ,CAAC,UAAU;AAAA,QAC9B,KAAK,KAAK,CAAC,OAAO,IAAI,CAAC;AAAA,OACxB;AAAA,IACH;AAAA,IACA,OAAO;AAAA,GACR,CACH;AAAA;AAGK,IAAM,YAAgD,mBAC3D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CACF;",
8
- "debugId": "DFDC71312AB793C064756E2164756E21",
8
+ "debugId": "3A4C74F24D6EEB8664756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/formula-engine",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "type": "commonjs"
5
5
  }
@@ -16,7 +16,7 @@ import {
16
16
  import {
17
17
  evaluateScalarOperator
18
18
  } from "../evaluator/evaluate-scalar-operator.mjs";
19
- import { functions } from "../functions.mjs";
19
+ import { functions } from "../functions/function-registry.mjs";
20
20
  import { add } from "./arithmetic/add/add.mjs";
21
21
  import { divide } from "./arithmetic/divide/divide.mjs";
22
22
  import { multiply } from "./arithmetic/multiply/multiply.mjs";
@@ -777,4 +777,4 @@ export {
777
777
  FormulaEvaluator
778
778
  };
779
779
 
780
- //# debugId=59D4031652ED86ED64756E2164756E21
780
+ //# debugId=D0163067F1378BC864756E2164756E21
@@ -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.mjs\";\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.mjs\";\nimport { parseFormula } from \"../parser/parser.mjs\";\n\nimport type { DependencyManager } from \"../core/managers/dependency-manager.mjs\";\nimport type { NamedExpressionManager } from \"../core/managers/named-expression-manager.mjs\";\nimport type { TableManager } from \"../core/managers/table-manager.mjs\";\nimport {\n captureEvaluationErrors,\n cellAddressToKey,\n getAbsoluteRange,\n getRangeIntersection,\n getRangeKey,\n getRelativeRange,\n isRangeOneCell,\n rangeAddressToKey,\n} from \"../core/utils.mjs\";\nimport {\n evaluateScalarOperator,\n type EvaluateScalarOperatorOptions,\n} from \"../evaluator/evaluate-scalar-operator.mjs\";\nimport { functions } from \"../functions.mjs\";\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.mjs\";\nimport { add } from \"./arithmetic/add/add.mjs\";\nimport { divide } from \"./arithmetic/divide/divide.mjs\";\nimport { multiply } from \"./arithmetic/multiply/multiply.mjs\";\nimport { power } from \"./arithmetic/power/power.mjs\";\nimport { subtract } from \"./arithmetic/subtract/subtract.mjs\";\nimport { equals } from \"./comparison/equals.mjs\";\nimport { greaterThan } from \"./comparison/greater-than.mjs\";\nimport { greaterThanOrEqual } from \"./comparison/greater-than-or-equal.mjs\";\nimport { lessThan } from \"./comparison/less-than.mjs\";\nimport { lessThanOrEqual } from \"./comparison/less-than-or-equal.mjs\";\nimport { notEquals } from \"./comparison/not-equals.mjs\";\nimport { concatenate } from \"./concatenation/concatenate.mjs\";\nimport { CellValueNode } from \"./dependency-nodes/cell-value-node.mjs\";\nimport { EvaluationContext } from \"./evaluation-context.mjs\";\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.tableName,\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 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\n context.appendContextDependency(astContextDependency);\n\n return result;\n }\n\n evaluateStructuredReference(\n node: StructuredReferenceNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\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, we need to find the table in the current workbook\n // and the formula will be evaluated differently based on the table (and workbook) we are evaluating it in\n context.addContextDependency(\"workbook\", \"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 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 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 expression = this.namedExpressionManager.resolveNamedExpression(\n node,\n context\n );\n\n if (!expression) {\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 return this.evaluateFormula(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.mjs\";\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.mjs\";\nimport { parseFormula } from \"../parser/parser.mjs\";\n\nimport type { DependencyManager } from \"../core/managers/dependency-manager.mjs\";\nimport type { NamedExpressionManager } from \"../core/managers/named-expression-manager.mjs\";\nimport type { TableManager } from \"../core/managers/table-manager.mjs\";\nimport {\n captureEvaluationErrors,\n cellAddressToKey,\n getAbsoluteRange,\n getRangeIntersection,\n getRangeKey,\n getRelativeRange,\n isRangeOneCell,\n rangeAddressToKey,\n} from \"../core/utils.mjs\";\nimport {\n evaluateScalarOperator,\n type EvaluateScalarOperatorOptions,\n} from \"../evaluator/evaluate-scalar-operator.mjs\";\nimport { functions } from \"../functions/function-registry.mjs\";\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.mjs\";\nimport { add } from \"./arithmetic/add/add.mjs\";\nimport { divide } from \"./arithmetic/divide/divide.mjs\";\nimport { multiply } from \"./arithmetic/multiply/multiply.mjs\";\nimport { power } from \"./arithmetic/power/power.mjs\";\nimport { subtract } from \"./arithmetic/subtract/subtract.mjs\";\nimport { equals } from \"./comparison/equals.mjs\";\nimport { greaterThan } from \"./comparison/greater-than.mjs\";\nimport { greaterThanOrEqual } from \"./comparison/greater-than-or-equal.mjs\";\nimport { lessThan } from \"./comparison/less-than.mjs\";\nimport { lessThanOrEqual } from \"./comparison/less-than-or-equal.mjs\";\nimport { notEquals } from \"./comparison/not-equals.mjs\";\nimport { concatenate } from \"./concatenation/concatenate.mjs\";\nimport { CellValueNode } from \"./dependency-nodes/cell-value-node.mjs\";\nimport { EvaluationContext } from \"./evaluation-context.mjs\";\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.tableName,\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 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\n context.appendContextDependency(astContextDependency);\n\n return result;\n }\n\n evaluateStructuredReference(\n node: StructuredReferenceNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\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, we need to find the table in the current workbook\n // and the formula will be evaluated differently based on the table (and workbook) we are evaluating it in\n context.addContextDependency(\"workbook\", \"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 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 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 expression = this.namedExpressionManager.resolveNamedExpression(\n node,\n context\n );\n\n if (!expression) {\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 return this.evaluateFormula(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
7
  "mappings": ";AAKA;AAAA;AAAA;AASA;AAKA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA;AAAA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5D;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": "59D4031652ED86ED64756E2164756E21",
8
+ "debugId": "D0163067F1378BC864756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,4 +1,4 @@
1
- // src/functions/index.ts
1
+ // src/functions/function-registry.ts
2
2
  import { SEQUENCE } from "./array/sequence/sequence.mjs";
3
3
  import { INDEX } from "./lookup/index-lookup/index-lookup.mjs";
4
4
  import { MATCH } from "./lookup/match/match.mjs";
@@ -92,4 +92,4 @@ export {
92
92
  functions
93
93
  };
94
94
 
95
- //# debugId=D3C4234AE873055B64756E2164756E21
95
+ //# debugId=412AE470DB80B9DF64756E2164756E21
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../../src/functions/index.ts"],
3
+ "sources": ["../../../src/functions/function-registry.ts"],
4
4
  "sourcesContent": [
5
5
  "import type { FunctionDefinition } from \"../core/types.mjs\";\n// import { arrayFunctions } from \"./array/array-functions.mjs\";\n// import { infoFunctions } from \"./info/info-functions.mjs\";\n// import { logicalComparisonFunctions } from \"./logical/comparisons.mjs\";\n// import { logicalConditionFunctions } from \"./logical/conditions.mjs\";\n// import { lookupFunctions } from \"./lookup/lookup-functions.mjs\";\n// import { advancedMathFunctions } from \"./math/advanced.mjs\";\n// import { basicMathFunctions } from \"./math/basic.mjs\";\n// import { textFunctions } from \"./text/string-functions.mjs\";\nimport { SEQUENCE } from \"./array/sequence/sequence.mjs\";\nimport { INDEX } from \"./lookup/index-lookup/index-lookup.mjs\"; // Fixed import path\nimport { MATCH } from \"./lookup/match/match.mjs\";\nimport { COUNT } from \"./lookup/count/count.mjs\";\nimport { COUNTIF } from \"./lookup/count/countif.mjs\";\nimport { AVERAGE } from \"./math/average/average.mjs\";\nimport { AVERAGEIF } from \"./math/average/averageif.mjs\";\nimport { AVERAGEIFS } from \"./math/average/averageifs.mjs\";\nimport { MAX } from \"./math/max/max.mjs\";\nimport { MAXIFS } from \"./math/max/maxifs.mjs\";\nimport { MIN } from \"./math/min/min.mjs\";\nimport { MINIFS } from \"./math/min/minifs.mjs\";\nimport { SUM } from \"./math/sum/sum.mjs\";\nimport { SUMIF } from \"./math/sum/sumif.mjs\";\nimport { SUMIFS } from \"./math/sum/sumifs.mjs\";\nimport { COUNTIFS } from \"./lookup/count/countifs.mjs\";\nimport { MAXIF } from \"./math/max/maxif.mjs\";\nimport { MINIF } from \"./math/min/minif.mjs\";\nimport { CEILING } from \"./math/ceiling/ceiling.mjs\";\nimport { EXACT } from \"./text/exact/exact.mjs\";\nimport { FIND } from \"./text/find/find.mjs\";\nimport { LEFT } from \"./text/left/left.mjs\";\nimport { MID } from \"./text/mid/mid.mjs\";\nimport { LEN } from \"./text/len/len.mjs\";\nimport { RIGHT } from \"./text/right/right.mjs\";\nimport { CONCATENATE } from \"./text/concatenate/concatenate.mjs\";\nimport { AND } from \"./logical/and/and.mjs\";\nimport { IF } from \"./logical/if/if.mjs\";\nimport { IFERROR } from \"./logical/iferror/iferror.mjs\";\nimport { XLOOKUP } from \"./lookup/xlookup/xlookup.mjs\";\nimport { OR } from \"./logical/or/or.mjs\";\nimport { TEXTJOIN } from \"./text/textjoin/textjoin.mjs\";\nimport { ROW } from \"./information/row/row.mjs\";\nimport { COLUMN } from \"./information/column/column.mjs\";\nimport { CELL } from \"./information/cell/cell.mjs\";\nimport { ADDRESS } from \"./reference/address/address.mjs\";\nimport { INDIRECT } from \"./reference/indirect/indirect.mjs\";\nimport { OFFSET } from \"./reference/offset/offset.mjs\";\n\nconst buildFunctionIndex = (functions: Record<string, FunctionDefinition>) => {\n return Object.fromEntries(\n Object.entries(functions).flatMap(([name, func]) => {\n const base: [string, FunctionDefinition][] = [[name, func]];\n if (func.aliases) {\n func.aliases.forEach((alias) => {\n base.push([alias, func]);\n });\n }\n return base;\n })\n );\n};\n\nexport const functions: Record<string, FunctionDefinition> = buildFunctionIndex(\n {\n ADDRESS,\n AND,\n AVERAGE,\n AVERAGEIF,\n AVERAGEIFS,\n CEILING,\n CELL,\n COLUMN,\n CONCATENATE,\n COUNT,\n COUNTIF,\n COUNTIFS,\n EXACT,\n FIND,\n IF,\n IFERROR,\n INDEX,\n INDIRECT,\n LEFT,\n LEN,\n MATCH,\n MAX,\n MAXIF,\n MAXIFS,\n MID,\n MIN,\n MINIF,\n MINIFS,\n OFFSET,\n OR,\n RIGHT,\n ROW,\n SEQUENCE,\n SUM,\n SUMIF,\n SUMIFS,\n TEXTJOIN,\n XLOOKUP,\n }\n);\n"
6
6
  ],
7
7
  "mappings": ";AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,IAAM,qBAAqB,CAAC,cAAkD;AAAA,EAC5E,OAAO,OAAO,YACZ,OAAO,QAAQ,SAAS,EAAE,QAAQ,EAAE,MAAM,UAAU;AAAA,IAClD,MAAM,OAAuC,CAAC,CAAC,MAAM,IAAI,CAAC;AAAA,IAC1D,IAAI,KAAK,SAAS;AAAA,MAChB,KAAK,QAAQ,QAAQ,CAAC,UAAU;AAAA,QAC9B,KAAK,KAAK,CAAC,OAAO,IAAI,CAAC;AAAA,OACxB;AAAA,IACH;AAAA,IACA,OAAO;AAAA,GACR,CACH;AAAA;AAGK,IAAM,YAAgD,mBAC3D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CACF;",
8
- "debugId": "D3C4234AE873055B64756E2164756E21",
8
+ "debugId": "412AE470DB80B9DF64756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/formula-engine",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "type": "module"
5
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ricsam/formula-engine",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "module": "./dist/mjs/lib.mjs",
5
5
  "scripts": {
6
6
  "test": "bun test",