Skip to content

Commit

Permalink
Drop support for special @-moz-document parsing (#2428)
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 authored Nov 5, 2024
1 parent 01a2148 commit c0359d6
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 103 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 2.0.0

* **Breaking change:** The `@-moz-document` rule no longer has any special
parsing associated with it. It is now parsed like any other unknown plain CSS
at-rule, where Sass features are only allowed within `#{}` interpolation.

## 1.80.6

### Command-Line Interface
Expand Down
11 changes: 7 additions & 4 deletions lib/src/deprecation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ enum Deprecation {
// DO NOT EDIT. This section was generated from the language repo.
// See tool/grind/generate_deprecations.dart for details.
//
// Checksum: 47c97f7824eb25d7f1e64e3230938b88330d40b4
// Checksum: 651decb8bf8d0378b657241a5a0db7272c228fd4

/// Deprecation for passing a string directly to meta.call().
callString('call-string',
Expand All @@ -27,7 +27,9 @@ enum Deprecation {

/// Deprecation for @-moz-document.
mozDocument('moz-document',
deprecatedIn: '1.7.2', description: '@-moz-document.'),
deprecatedIn: '1.7.2',
obsoleteIn: '2.0.0',
description: '@-moz-document.'),

/// Deprecation for imports using relative canonical URLs.
relativeCanonical('relative-canonical',
Expand Down Expand Up @@ -175,9 +177,10 @@ enum Deprecation {
Version? get obsoleteIn => _obsoleteIn?.andThen(Version.parse);

/// Constructs a regular deprecation.
const Deprecation(this.id, {required String? deprecatedIn, this.description})
const Deprecation(this.id,
{required String? deprecatedIn, this.description, String? obsoleteIn})
: _deprecatedIn = deprecatedIn,
_obsoleteIn = null,
_obsoleteIn = obsoleteIn,
isFuture = false;

/// Constructs a future deprecation.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/js/deprecations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ final Map<String, Deprecation?> deprecations = {
})(),
description: deprecation.description,
deprecatedIn: deprecation.deprecatedIn,
obsoleteIn: deprecation.deprecatedIn),
obsoleteIn: deprecation.obsoleteIn),
};

/// Parses a list of [deprecations] from JS into an list of Dart [Deprecation]
Expand Down
1 change: 0 additions & 1 deletion lib/src/parse/css.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class CssParser extends ScssParser {
_forbiddenAtRule(start),
"import" => _cssImportRule(start),
"media" => mediaRule(start),
"-moz-document" => mozDocumentRule(start, name),
"supports" => supportsRule(start),
_ => unknownAtRule(start, name)
};
Expand Down
87 changes: 0 additions & 87 deletions lib/src/parse/stylesheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,6 @@ abstract class StylesheetParser extends Parser {
return mediaRule(start);
case "mixin":
return _mixinRule(start);
case "-moz-document":
return mozDocumentRule(start, name);
case "return":
return _disallowedAtRule(start);
case "supports":
Expand Down Expand Up @@ -1345,91 +1343,6 @@ abstract class StylesheetParser extends Parser {
});
}

/// Consumes a `@moz-document` rule.
///
/// Gecko's `@-moz-document` diverges from [the specification][] allows the
/// `url-prefix` and `domain` functions to omit quotation marks, contrary to
/// the standard.
///
/// [the specification]: http://www.w3.org/TR/css3-conditional/
@protected
AtRule mozDocumentRule(LineScannerState start, Interpolation name) {
var valueStart = scanner.state;
var buffer = InterpolationBuffer();
var needsDeprecationWarning = false;
while (true) {
if (scanner.peekChar() == $hash) {
var (expression, span) = singleInterpolation();
buffer.add(expression, span);
needsDeprecationWarning = true;
} else {
var identifierStart = scanner.state;
var identifier = this.identifier();
switch (identifier) {
case "url" || "url-prefix" || "domain":
if (_tryUrlContents(identifierStart, name: identifier)
case var contents?) {
buffer.addInterpolation(contents);
} else {
scanner.expectChar($lparen);
whitespace();
var argument = interpolatedString();
scanner.expectChar($rparen);

buffer
..write(identifier)
..writeCharCode($lparen)
..addInterpolation(argument.asInterpolation())
..writeCharCode($rparen);
}

// A url-prefix with no argument, or with an empty string as an
// argument, is not (yet) deprecated.
var trailing = buffer.trailingString;
if (!trailing.endsWith("url-prefix()") &&
!trailing.endsWith("url-prefix('')") &&
!trailing.endsWith('url-prefix("")')) {
needsDeprecationWarning = true;
}

case "regexp":
buffer.write("regexp(");
scanner.expectChar($lparen);
buffer.addInterpolation(interpolatedString().asInterpolation());
scanner.expectChar($rparen);
buffer.writeCharCode($rparen);
needsDeprecationWarning = true;

default:
error("Invalid function name.", scanner.spanFrom(identifierStart));
}
}

whitespace();
if (!scanner.scanChar($comma)) break;

buffer.writeCharCode($comma);
buffer.write(rawText(whitespace));
}

var value = buffer.interpolation(scanner.spanFrom(valueStart));
return _withChildren(_statement, start, (children, span) {
if (needsDeprecationWarning) {
warnings.add((
deprecation: Deprecation.mozDocument,
message:
"@-moz-document is deprecated and support will be removed in "
"Dart Sass 2.0.0.\n"
"\n"
"For details, see https://sass-lang.com/d/moz-document.",
span: span
));
}

return AtRule(name, span, value: value, children: children);
});
}

/// Consumes a `@return` rule.
///
/// [start] should point before the `@`.
Expand Down
4 changes: 4 additions & 0 deletions pkg/sass-parser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.5.0

* No user-visible changes.

## 0.4.3

* Add support for parsing the `@while` rule.
Expand Down
2 changes: 1 addition & 1 deletion pkg/sass-parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sass-parser",
"version": "0.4.3",
"version": "0.5.0-dev",
"description": "A PostCSS-compatible wrapper of the official Sass parser",
"repository": "sass/sass",
"author": "Google Inc.",
Expand Down
4 changes: 4 additions & 0 deletions pkg/sass_api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 15.0.0

* No user-visible changes.

## 14.1.2

* No user-visible changes.
Expand Down
4 changes: 2 additions & 2 deletions pkg/sass_api/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ name: sass_api
# Note: Every time we add a new Sass AST node, we need to bump the *major*
# version because it's a breaking change for anyone who's implementing the
# visitor interface(s).
version: 14.1.2
version: 15.0.0-dev
description: Additional APIs for Dart Sass.
homepage: https://github.com/sass/dart-sass

environment:
sdk: ">=3.3.0 <4.0.0"

dependencies:
sass: 1.80.6
sass: 2.0.0

dev_dependencies:
dartdoc: ^8.0.14
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.80.6
version: 2.0.0-dev
description: A Sass implementation in Dart.
homepage: https://github.com/sass/dart-sass

Expand Down
6 changes: 0 additions & 6 deletions test/deprecations_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ void main() {
_expectDeprecation("@if false {} @elseif false {}", Deprecation.elseif);
});

// Deprecated in 1.7.2
test("mozDocument is violated by most @-moz-document rules", () {
_expectDeprecation(
"@-moz-document url-prefix(foo) {}", Deprecation.mozDocument);
});

// Deprecated in 1.17.2
test("newGlobal is violated by declaring a new variable with !global", () {
_expectDeprecation(r"a {$foo: bar !global;}", Deprecation.newGlobal);
Expand Down

0 comments on commit c0359d6

Please sign in to comment.