diff --git a/CHANGELOG.md b/CHANGELOG.md index d6fd01f8e..8cdd8c998 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Fixed unbounded parser cache growth in long-running instances that process many distinct formulas, including when undo is disabled. [#1635](https://github.com/handsontable/hyperformula/issues/1635) - Fixed array formulas spilling past the `maxRows` and `maxColumns` limits: they now return `#SPILL!` when their result extends beyond the sheet edge. [#1774](https://github.com/handsontable/hyperformula/pull/1774) - Fixed the `ADDRESS` function adding the sheet separator (`!`) when the `sheetName` argument is an empty argument slot (e.g. `=ADDRESS(2,3,1,FALSE(),)` now returns `R2C3` instead of `!R2C3`), while an explicit `""` still adds it. [#1641](https://github.com/handsontable/hyperformula/issues/1641) +- Fixed `IMSUM`, `IMPRODUCT` and `TEXTJOIN` throwing an uncaught `RangeError` for very large ranges, such as `=IMSUM(A1:D40000)`, which stopped the recalculation; they now return a result or an error value in the cell. [#1901](https://github.com/handsontable/hyperformula/pull/1901) ## [3.5.0] - 2026-10-09 diff --git a/hyperformula/dev-docs/INTERPRETER.md b/hyperformula/dev-docs/INTERPRETER.md index 66f8e9811..df52b5f37 100644 --- a/hyperformula/dev-docs/INTERPRETER.md +++ b/hyperformula/dev-docs/INTERPRETER.md @@ -20,6 +20,7 @@ - **Coerce through `ArithmeticHelper`.** Never write ad-hoc string-to-number or value-to-boolean conversion inside a function; the coercion rules are spreadsheet semantics, not JavaScript semantics, and they are already implemented once. - **Errors are values.** Return a `CellError` with a message from `hyperformula/src/error-message.ts`. Do not throw: a thrown error escapes the evaluation of one cell and takes the recalculation with it. +- **Never spread a range's values into a call.** `push(...values)` and `Math.max(...values)` pass one argument per value, and a range or array of about 125,000 values (Node 24, default stack size) throws `RangeError: Maximum call stack size exceeded` out of the recalculation. Append in a loop. - **The registry is keyed by id, not by implementation.** A custom plugin can be registered over a built-in id. Do not assume the plugin you are reading is the one that will answer for that id at run time. - **Evaluate each argument once.** Evaluating the same argument twice doubles its cost and, when it contains a volatile function such as `RAND`, can see two different values. - **This is the hot path.** `Interpreter.evaluateAst` runs once per formula, and once per cell for array-broadcast arguments. Allocation inside a per-cell loop is measurable. diff --git a/hyperformula/src/interpreter/ArithmeticHelper.ts b/hyperformula/src/interpreter/ArithmeticHelper.ts index ca972aaa9..2b81df42f 100644 --- a/hyperformula/src/interpreter/ArithmeticHelper.ts +++ b/hyperformula/src/interpreter/ArithmeticHelper.ts @@ -322,7 +322,9 @@ export class ArithmeticHelper { if (arr instanceof CellError) { return arr } else { - expandedVals.push(...arr) + for (const value of arr) { + expandedVals.push(value) + } } } else { expandedVals.push(val) diff --git a/hyperformula/src/interpreter/plugin/TextPlugin.ts b/hyperformula/src/interpreter/plugin/TextPlugin.ts index 603e1a1d3..9f3b58ecd 100644 --- a/hyperformula/src/interpreter/plugin/TextPlugin.ts +++ b/hyperformula/src/interpreter/plugin/TextPlugin.ts @@ -544,7 +544,9 @@ export class TextPlugin extends FunctionPlugin implements FunctionPluginTypechec if (coerced instanceof CellError) { return coerced } - texts.push(...coerced) + for (const text of coerced) { + texts.push(text) + } } const parts = ignoreEmpty ? texts.filter((t) => t !== '') : texts