diff --git a/src/formulas/parser.ts b/src/formulas/parser.ts index 9560e1df13..1afd2a59bd 100644 --- a/src/formulas/parser.ts +++ b/src/formulas/parser.ts @@ -2,7 +2,7 @@ import { DEFAULT_ERROR_MESSAGE } from "../constants"; import { parseNumber, removeStringQuotes } from "../helpers/index"; import { _t } from "../translation"; import { DEFAULT_LOCALE } from "../types"; -import { BadExpressionError, InvalidReferenceError } from "../types/errors"; +import { BadExpressionError, CellErrorType } from "../types/errors"; import { rangeTokenize } from "./range_tokenizer"; import { Token } from "./tokenizer"; @@ -113,7 +113,11 @@ function parseOperand(tokens: Token[]): AST { case "STRING": return { type: "STRING", value: removeStringQuotes(current.value) }; case "INVALID_REFERENCE": - throw new InvalidReferenceError(); + return { + type: "REFERENCE", + value: CellErrorType.InvalidReference, + }; + case "REFERENCE": if (tokens[0]?.value === ":" && tokens[1]?.type === "REFERENCE") { tokens.shift(); diff --git a/tests/evaluation/parser.test.ts b/tests/evaluation/parser.test.ts index 8626e241bc..00ff8ba05f 100644 --- a/tests/evaluation/parser.test.ts +++ b/tests/evaluation/parser.test.ts @@ -1,5 +1,5 @@ import { astToFormula, parse } from "../../src"; -import { InvalidReferenceError } from "../../src/types/errors"; +import { CellErrorType } from "../../src/types/errors"; describe("parser", () => { test("can parse a function call with no argument", () => { @@ -168,7 +168,10 @@ describe("parser", () => { }); test("Can parse invalid references", () => { - expect(() => parse("#REF")).toThrowError(new InvalidReferenceError().message); + expect(parse("#REF")).toEqual({ + type: "REFERENCE", + value: CellErrorType.InvalidReference, + }); }); test("Cannot parse empty string", () => {