From be097e6cf2349b5735f97f4b6a58b84cf34adcbb Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Tue, 10 Aug 2021 18:03:51 -0700 Subject: [PATCH] [First-Class Calc] Throw errors for definitely-incompatible units --- accepted/first-class-calc.changes.md | 2 + accepted/first-class-calc.md | 77 ++++++++++++++++++++++++---- 2 files changed, 69 insertions(+), 10 deletions(-) diff --git a/accepted/first-class-calc.changes.md b/accepted/first-class-calc.changes.md index ddf0f579..e02cbdbc 100644 --- a/accepted/first-class-calc.changes.md +++ b/accepted/first-class-calc.changes.md @@ -3,6 +3,8 @@ * Store interpolations as a separate data type so that they can be parenthesized when used in `CalculationOperation`s. +* Throw errors when combining units that are known to be incompatible. + * Allow variables in `CalcValue`s to return calculations. * Fix some broken formatting. diff --git a/accepted/first-class-calc.md b/accepted/first-class-calc.md index 208dd84d..fabec0f6 100644 --- a/accepted/first-class-calc.md +++ b/accepted/first-class-calc.md @@ -11,6 +11,9 @@ * ["Contagious" Calculations](#contagious-calculations) * [Interpolation in `calc()`](#interpolation-in-calc) * [Vendor Prefixed `calc()`](#vendor-prefixed-calc) +* [Definitions](#definitions) + * [Possibly-Compatible Units](#possibly-compatible-units) + * [Possibly-Compatible Numbers](#possibly-compatible-numbers) * [Syntax](#syntax) * [`SpecialFunctionExpression`](#specialfunctionexpression) * [`CalcExpression`](#calcexpression) @@ -200,6 +203,49 @@ vendor-prefixed `calc()` expressions will continue to be parsed as opaque special functions the way they always have, but they will not be interoperable with any of the new calculation features this proposal adds. +## Definitions + +### Possibly-Compatible Units + +Two units are *possibly-compatible* with one another if and only if either both +units appear in the same row in the following table, or either unit doesn't +appear in the following table. Units are matched case-insensitively to determine +possible-compatibility. + +> This is intended to be kept in sync with the unit types in [CSS Values and +> Units]. Note that all unknown units are possibly-compatible with all other +> units; this preserves forwards-compatibility with new units that are +> introduced in browsers over time. + +[CSS Values and Units]: https://www.w3.org/TR/css-values-3/ + +| Type | Units | +| -------------- | -------------------------------------------------------------------------------------------- | +| `` | `em`, `ex`, `ch`, `rem`, `vw`, `vh`, `vmin`, `vmax`, `cm`, `mm`, `Q`, `in`, `pt`, `pc`, `px` | +| `` | `deg`, `grad`, `rad`, `turn` | +| `