Skip to content

Commit

Permalink
Make :is() behave like :matches() (#1315)
Browse files Browse the repository at this point in the history
  • Loading branch information
jathak committed May 20, 2021
1 parent c247890 commit efe680e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Expand Up @@ -3,7 +3,7 @@
* Deprecate the use of `/` for division. The new `math.div()` function should be
used instead. See [this page][] for details.

[this page]: https://sass-lang.com/documentation/breaking-changes/slash-div
[this page]: https://sass-lang.com/documentation/breaking-changes/slash-div

* Add a `list.slash()` function that returns a slash-separated list.

Expand All @@ -15,6 +15,10 @@
made slash-free in both cases. This is a behavioral change, but it's unlikely
to affect any real-world stylesheets.

* [`:is()`][] now behaves identically to `:matches()`.

[`:is()`]: https://developer.mozilla.org/en-US/docs/Web/CSS/:is

* Fix a bug where non-integer numbers that were very close to integer
values would be incorrectly formatted in CSS.

Expand Down
6 changes: 5 additions & 1 deletion lib/src/extend/extension_store.dart
Expand Up @@ -818,9 +818,13 @@ class ExtensionStore {
// become `.foo:not(.bar)`. However, this is a narrow edge case and
// supporting it properly would make this code and the code calling it
// a lot more complicated, so it's not supported for now.
if (innerPseudo.normalizedName != 'matches') return [];
if (innerPseudo.normalizedName != 'is' &&
innerPseudo.normalizedName != 'matches') {
return [];
}
return innerSelector.components;

case 'is':
case 'matches':
case 'any':
case 'current':
Expand Down
9 changes: 8 additions & 1 deletion lib/src/extend/functions.dart
Expand Up @@ -21,7 +21,13 @@ import '../utils.dart';
/// subselectors of their arguments.
///
/// For example, `.foo` is a superselector of `:matches(.foo)`.
final _subselectorPseudos = {'matches', 'any', 'nth-child', 'nth-last-child'};
final _subselectorPseudos = {
'is',
'matches',
'any',
'nth-child',
'nth-last-child'
};

/// Returns the contents of a [SelectorList] that matches only elements that are
/// matched by both [complex1] and [complex2].
Expand Down Expand Up @@ -734,6 +740,7 @@ bool _selectorPseudoIsSuperselector(
var selector1 = selector1_; // dart-lang/sdk#45348

switch (pseudo1.normalizedName) {
case 'is':
case 'matches':
case 'any':
var selectors = _selectorPseudoArgs(compound2, pseudo1.name);
Expand Down
1 change: 1 addition & 0 deletions lib/src/parse/selector.dart
Expand Up @@ -13,6 +13,7 @@ import 'parser.dart';
/// Pseudo-class selectors that take unadorned selectors as arguments.
final _selectorPseudoClasses = {
"not",
"is",
"matches",
"current",
"any",
Expand Down

0 comments on commit efe680e

Please sign in to comment.