Skip to content

Commit 68ca5d0

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 68ca5d0

File tree

5 files changed

+216
-122
lines changed

5 files changed

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