Skip to content

Commit ca6ffcb

Browse files
committed
Add/update strict function unit documentation
This merges the color-units and random-with-units deprecation pages into a single shared function-units page, updates the color-units deprecations to reflect that Phase 2 has been enacted, and adds new function unit deprecations. See #511 See sass/sass#2904 See #662 See sass/sass#3374
1 parent c8b0841 commit ca6ffcb

File tree

5 files changed

+218
-122
lines changed

5 files changed

+218
-122
lines changed

config.rb

+5
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@
7171
redirect "d/#{basename}.html", to: "/documentation/breaking-changes/#{basename}"
7272
end
7373

74+
for url in %w[d/random-with-units documentation/breaking-changes/random-with-units
75+
d/breaking-changes/color-units documentation/breaking-changes/color-units] do
76+
redirect url, to: "/documentation/breaking-changes/function-units"
77+
end
78+
7479
redirect 'tutorial.html', to: '/guide'
7580
redirect 'download.html', to: '/install'
7681
redirect 'try.html', to: 'https://www.sassmeister.com'

source/documentation/breaking-changes.html.md.erb

+3-6
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,15 @@ time-sensitive, so they may be released with new minor version numbers instead.
2323

2424
These breaking changes are coming soon or have recently been released:
2525

26-
* [`random()` with units](breaking-changes/random-with-units) beginning in Dart
27-
Sass 1.54.5.
26+
* [Functions are stricter about which units they
27+
allow](breaking-changes/function-units) beginning in Dart Sass 1.32.0.
2828

29-
* [Selectors with invalid combinators will be
29+
* [Selectors with invalid combinators are
3030
invalid](breaking-changes/bogus-combinators) beginning in Dart Sass 1.54.0.
3131

3232
* [`/` is changing from a division operation to a list
3333
separator](breaking-changes/slash-div) beginning in Dart Sass 1.33.0.
3434

35-
* [Color functions are becoming more strict about
36-
units](breaking-changes/color-units) beginning in Dart Sass 1.32.0.
37-
3835
* [Parsing the special syntax of `@-moz-document` will be
3936
invalid](breaking-changes/moz-document) beginning in Dart Sass 1.7.2.
4037

source/documentation/breaking-changes/color-units.md.erb

-79
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
---
2+
title: "Breaking Change: Strict Function Units"
3+
introduction: >
4+
Various built-in functions will become stricter in which units they allow
5+
and will handle those units more consistently. This makes Sass more compatible
6+
with the CSS spec and helps catch errors more quickly.
7+
---
8+
9+
## Hue
10+
11+
<% impl_status dart: '1.32.0', libsass: false, ruby: false %>
12+
13+
When specifying a color's hue, CSS allows any [angle unit][] (`deg`, `grad`,
14+
`rad`, or `turn`). It also allows a unitless number, which is interpreted as
15+
`deg`. Historically, Sass has allowed *any* unit, and interpreted it as `deg`.
16+
This is particularly problematic because it meant that the valid CSS expression
17+
`hsl(0.5turn, 100%, 50%)` would be allowed by Sass but interpreted entirely
18+
wrong.
19+
20+
[angle unit]: https://drafts.csswg.org/css-values-4/#angles
21+
22+
To fix this issue and bring Sass in line with the CSS spec, we're making changes
23+
in multiple phases:
24+
25+
### Phase 1
26+
27+
<% impl_status dart: '1.32.0', libsass: false, ruby: false %>
28+
29+
At first, Sass just emitted a deprecation warning if you passed a number with a
30+
unit other than `deg` as a hue to any function. Passing a unitless number was
31+
still allowed.
32+
33+
### Phase 2
34+
35+
<% impl_status dart: '1.52.1', libsass: false, ruby: false %>
36+
37+
Next, we changed the way angle units are handled for hue parameters to match the
38+
CSS spec. This means that numbers with `grad`, `rad`, or `turn` units will be
39+
converted to `deg`: `0.5turn` will be converted to `180deg`, `100grad` will be
40+
converted to `90deg`, and so on.
41+
42+
Because this change is necessary to preserve CSS compatibility, according to the
43+
[Dart Sass compatibility policy] it was made with only a minor version bump.
44+
However, it changes as little behavior as possible to ensure that Sass
45+
interprets all valid CSS according to the CSS spec.
46+
47+
[Dart Sass compatibility policy]: https://github.com/sass/dart-sass#compatibility-policy
48+
49+
### Phase 3
50+
51+
<% impl_status dart: false, libsass: false, ruby: false %>
52+
53+
Finally, in Dart Sass 2.0.0 color functions will throw errors if they're passed
54+
a hue parameter with a non-angle unit. Unitless hues will still be allowed.
55+
56+
## Saturation and Lightness
57+
58+
When specifying an HSL color's saturation and lightness, CSS only allows `%`
59+
units. Even unitless numbers aren't allowed (unlike for the hue). Historically,
60+
Sass has allowed *any* unit, and interpreted it as `%`. You could even write
61+
`hsl(0, 100px, 50s)` and Sass would return the color `red`.
62+
63+
To fix this issue and bring Sass in line with the CSS spec, we're making changes
64+
in two phases:
65+
66+
### Phase 1
67+
68+
<% impl_status dart: '1.32.0', libsass: false, ruby: false %>
69+
70+
Currently, Sass just emits a deprecation warning if you pass a number with a
71+
unit other than `deg` as a hue to any function. Passing a unitless number was
72+
still allowed.
73+
74+
### Phase 2
75+
76+
<% impl_status dart: false, libsass: false, ruby: false %>
77+
78+
In Dart Sass 2.0.0 color functions will throw errors if they're passed a
79+
saturation or lightness parameter with no unit or a non-`%` unit.
80+
81+
## Alpha
82+
83+
When specifying a color's alpha value, CSS (as of [Colors Level 4]) allows
84+
either unitless values between 0 and 1 or `%` values between `0%` and `100%`. In
85+
most cases Sass follows this behavior, but the functions `color.adjust()` and
86+
`color.change()` have historically allowed *any* unit, and interpreted it as
87+
unitless. You could even write `color.change(red, $alpha: 1%)` and Sass would
88+
return the opaque color `black`.
89+
90+
[Colors Level 4]: https://www.w3.org/TR/css-color-4/#typedef-alpha-value
91+
92+
To fix this issue and bring Sass in line with the CSS spec, we're making changes
93+
in three phases:
94+
95+
### Phase 1
96+
97+
<% impl_status dart: '1.56.0', libsass: false, ruby: false %>
98+
99+
Currently, Sass just emits a deprecation warning if you pass a number with any
100+
unit, including `%`, as an alpha value to `color.change()` or `color.adjust()`.
101+
102+
### Phase 2
103+
104+
<% impl_status dart: false, libsass: false, ruby: false %>
105+
106+
Next, we'll change the way `%` units are handled for the alpha argument to
107+
`color.change()` and `color.adjust()`. Alphas with unit `%` will be divided by
108+
`100%`, converting them to unitless numbers between 0 and 1.
109+
110+
Because this change is a bug fix that improves consistency with other Sass
111+
functions, it will be made with only a minor version bump. It will be changed at
112+
minimum three months after Phase 1 is released, to give users time to adjust
113+
their code and avoid the bug.
114+
115+
[Dart Sass compatibility policy]: https://github.com/sass/dart-sass#compatibility-policy
116+
117+
### Phase 3
118+
119+
<% impl_status dart: false, libsass: false, ruby: false %>
120+
121+
Finally, in Dart Sass 2.0.0 `color.change()` and `color.adjust()` will throw
122+
errors if they're passed an alpha parameter with a non-`%` unit. Unitless alphas
123+
will still be allowed.
124+
125+
## `math.random()`
126+
127+
[The `math.random()` function] has historically ignored units in `$limit` and
128+
returned a unitless value. For example `math.random(100px)` would drop "px" and
129+
return a value like `42`.
130+
131+
A future version of Sass will stop ignoring units for the `$limit` argument and
132+
return a random integer with the same units.
133+
134+
[The `math.random()` function]: ../modules/math#random
135+
136+
<% example(autogen_css: false) do %>
137+
// Future Sass, doesn't work yet!
138+
@debug math.random(100px); // 42px
139+
===
140+
// Future Sass, doesn't work yet!
141+
@debug math.random(100px) // 42px
142+
<% end %>
143+
144+
### Phase 1
145+
146+
<% impl_status dart: '1.54.5', libsass: false, ruby: false %>
147+
148+
Currently, Sass emits a deprecation warning if you pass a `$limit` with units to
149+
`math.random()`.
150+
151+
### Phase 2
152+
153+
<% impl_status dart: false, libsass: false, ruby: false %>
154+
155+
In Dart Sass 2.0.0, passing a `$limit` number with units will be an error.
156+
157+
### Phase 3
158+
159+
<% impl_status dart: false, libsass: false, ruby: false %>
160+
161+
In a minor release after Dart Sass 2.0.0, passing a `$limit` number with units
162+
to the `math.random()` function will be allowed again. It will return a random
163+
integer the same units as `$limit`, instead of a unitless number.
164+
165+
## Weight
166+
167+
The [`color.mix()` function] and [`color.invert()` function] have both
168+
historically ignored units in their `$weight` arguments, despite that argument
169+
conceptually representing a percentage. A future version of Sass will require
170+
the unit `%`.
171+
172+
[`color.mix()` function]: ../modules/color#mix
173+
[`color.invert()` function]: ../modules/color#invert
174+
175+
### Phase 1
176+
177+
<% impl_status dart: '1.56.0', libsass: false, ruby: false %>
178+
179+
Currently, Sass emits a deprecation warning if you pass a `$weight` with no
180+
units or with units other than `%` to `color.mix()` or `color.invert()`.
181+
182+
### Phase 2
183+
184+
<% impl_status dart: false, libsass: false, ruby: false %>
185+
186+
In Dart Sass 2.0.0, `color.mix()` and `color.invert()` will throw errors if
187+
they're passed a `$weight` with no unit or a non-`%` unit.
188+
189+
## Index
190+
191+
The [`list.nth()` function] and [`list.set-nth()` function] have both
192+
historically ignored units in their `$n` arguments. A future version of Sass
193+
will forbid any units.
194+
195+
[`list.nth()` function]: ../modules/list#nth
196+
[`list.set-nth()` function]: ../modules/list#set-nth
197+
198+
### Phase 1
199+
200+
<% impl_status dart: '1.56.0', libsass: false, ruby: false %>
201+
202+
Currently, Sass emits a deprecation warning if you pass a `$weight` with no
203+
units or with units other than `%` to `color.mix()` or `color.invert()`.
204+
205+
### Phase 2
206+
207+
<% impl_status dart: false, libsass: false, ruby: false %>
208+
209+
In Dart Sass 2.0.0, `list.nth()` and `list.set-nth()` will throw errors if
210+
they're passed an index `$n` with a unit.

source/documentation/breaking-changes/random-with-units.md.erb

-37
This file was deleted.

0 commit comments

Comments
 (0)