diff --git a/src/numeric-values.js b/src/numeric-values.js index 5756d76..9da3e12 100644 --- a/src/numeric-values.js +++ b/src/numeric-values.js @@ -765,13 +765,20 @@ function reifyMathExpression(num) { const root = convertTokensToAST([...num.values]); // 4. Recursively transform the expression tree into objects - // TODO: Update when we have clarification on where simplify a calculation should be run: - // https://github.com/w3c/csswg-drafts/issues/9870 - const numericValue = simplifyCalculation(transformToCSSNumericValue(root)); - if (numericValue instanceof CSSUnitValue) { - return new CSSMathSum(numericValue); + const numericValue = transformToCSSNumericValue(root); + let simplifiedValue; + try { + // TODO: Update when we have clarification on where simplify a calculation should be run: + // https://github.com/w3c/csswg-drafts/issues/9870 + simplifiedValue = simplifyCalculation(numericValue); + } catch (e) { + // Use insertRule to trigger native SyntaxError on TypeError + (new CSSStyleSheet()).insertRule('error', 0); + } + if (simplifiedValue instanceof CSSUnitValue) { + return new CSSMathSum(simplifiedValue); } else { - return numericValue; + return simplifiedValue; } }