Skip to content

Commit

Permalink
Throw a native SyntaxError if type is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesodland committed Feb 3, 2024
1 parent 9efccc2 commit 47e0ac6
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/numeric-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 47e0ac6

Please sign in to comment.