Skip to content

Commit

Permalink
Properly merge "all and" media queries
Browse files Browse the repository at this point in the history
Closes #537
  • Loading branch information
nex3 committed Dec 7, 2018
1 parent dad8491 commit 22f926e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.15.3

* Properly merge `all and` media queries. These queries were previously being
merged as though `all` referred to a specific media type, rather than all
media types.

## 1.15.2

### Node JS API
Expand Down
13 changes: 9 additions & 4 deletions lib/src/ast/css/media_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class CssMediaQuery {
/// Whether this media query only specifies features.
bool get isCondition => modifier == null && type == null;

/// Whether this media query matches all media types.
bool get matchesAllTypes => type == null || equalsIgnoreCase(type, 'all');

/// Parses a media query from [contents].
///
/// If passed, [url] is the name of the file from which [contents] comes.
Expand Down Expand Up @@ -77,7 +80,7 @@ class CssMediaQuery {
} else {
return MediaQueryMergeResult.unrepresentable;
}
} else if (ourType == null || theirType == null) {
} else if (this.matchesAllTypes || other.matchesAllTypes) {
return MediaQueryMergeResult.unrepresentable;
}

Expand Down Expand Up @@ -112,11 +115,13 @@ class CssMediaQuery {
// Otherwise, there's no way to represent the intersection.
return MediaQueryMergeResult.unrepresentable;
}
} else if (ourType == null) {
} else if (this.matchesAllTypes) {
modifier = theirModifier;
type = theirType;
// Omit the type if either input query did, since that indicates that they
// aren't targeting a browser that requires "all and".
type = (other.matchesAllTypes && ourType == null) ? null : theirType;
features = this.features.toList()..addAll(other.features);
} else if (theirType == null) {
} else if (other.matchesAllTypes) {
modifier = ourModifier;
type = ourType;
features = this.features.toList()..addAll(other.features);
Expand Down
9 changes: 8 additions & 1 deletion lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,14 @@ bool equalsIgnoreCase(String string1, String string2) {
if (identical(string1, string2)) return true;
if (string1 == null || string2 == null) return false;
if (string1.length != string2.length) return false;
return string1.toUpperCase() == string2.toUpperCase();

for (var i = 0; i < string1.length; i++) {
if (!characterEqualsIgnoreCase(
string1.codeUnitAt(i), string2.codeUnitAt(i))) {
return false;
}
}
return true;
}

/// Returns whether [string] starts with [prefix], ignoring ASCII case.
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: sass
version: 1.15.2
version: 1.15.3-dev
description: A Sass implementation in Dart.
author: Dart Team <[email protected]>
homepage: https://github.com/sass/dart-sass
Expand Down

0 comments on commit 22f926e

Please sign in to comment.