Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## 2.0.0

* **Breaking change:** `/` is now used for slash-separated lists rather than
division in SassScript. You can still use it for division within `calc()` and
other calculation expressions, or use `math.div()` instead.

* **Breaking change:** `@elseif` is no longer treated as equivalent to `@else
if`, and is now treated like any other unknown plain CSS at-rule.

Expand Down
23 changes: 5 additions & 18 deletions lib/src/ast/sass/expression/binary_operation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ final class BinaryOperationExpression extends Expression {
/// The right-hand operand.
final Expression right;

/// Whether this is a [BinaryOperator.dividedBy] operation that may be
/// interpreted as slash-separated numbers.
///
/// @nodoc
@internal
final bool allowsSlash;

FileSpan get span {
// Avoid creating a bunch of intermediate spans for multiple binary
// expressions in a row by moving to the left- and right-most expressions.
Expand All @@ -57,17 +50,7 @@ final class BinaryOperationExpression extends Expression {
.trim()
: span;

BinaryOperationExpression(this.operator, this.left, this.right)
: allowsSlash = false;

/// Creates a [BinaryOperator.dividedBy] operation that may be interpreted as
/// slash-separated numbers.
///
/// @nodoc
@internal
BinaryOperationExpression.slash(this.left, this.right)
: operator = BinaryOperator.dividedBy,
allowsSlash = true;
BinaryOperationExpression(this.operator, this.left, this.right);

T accept<T>(ExpressionVisitor<T> visitor) =>
visitor.visitBinaryOperationExpression(this);
Expand Down Expand Up @@ -151,6 +134,10 @@ enum BinaryOperator {
times('times', '*', 6, associative: true),

/// The division operator, `/`.
///
/// **Note:** This is never directly parsed by the Sass stylesheet. It's only
/// ever generated at runtime by reorienting the precedence of slash-separated
/// lists.
dividedBy('divided by', '/', 6),

/// The modulo operator, `%`.
Expand Down
11 changes: 8 additions & 3 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: 0be67f32391e119205f8e98cd15fa8e7382b6dd2
// Checksum: 0bd4067eac410d6d9ab05aab30a1f5bf0e602144

/// Deprecation for passing a string directly to meta.call().
callString('call-string',
Expand All @@ -40,7 +40,6 @@ enum Deprecation {
/// Deprecation for declaring new variables with !global.
newGlobal('new-global',
deprecatedIn: '1.17.2',
obsoleteIn: '2.0.0',
description: 'Declaring new variables with !global.'),

/// Deprecation for using color module functions in place of plain CSS functions.
Expand All @@ -51,7 +50,9 @@ enum Deprecation {

/// Deprecation for / operator for division.
slashDiv('slash-div',
deprecatedIn: '1.33.0', description: '/ operator for division.'),
deprecatedIn: '1.33.0',
obsoleteIn: '2.0.0',
description: '/ operator for division.'),

/// Deprecation for leading, trailing, and repeated combinators.
bogusCombinators('bogus-combinators',
Expand Down Expand Up @@ -145,6 +146,10 @@ enum Deprecation {
deprecatedIn: '1.91.0',
description: 'A rest parameter before a positional or named parameter.'),

/// Deprecation for the list.slash() function.
listSlash('list-slash',
deprecatedIn: '2.0.0', description: 'The list.slash() function.'),

// END AUTOGENERATED CODE

/// Used for deprecations coming from user-authored code.
Expand Down
26 changes: 0 additions & 26 deletions lib/src/functions/color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import '../deprecation.dart';
import '../evaluation_context.dart';
import '../exception.dart';
import '../module/built_in.dart';
import '../parse/scss.dart';
import '../util/map.dart';
import '../util/nullable.dart';
import '../util/number.dart';
Expand Down Expand Up @@ -1806,34 +1805,9 @@ Value _parseChannels(
"${pluralize('was', inputList.length, plural: 'were')} passed.",
name,
),
[...var initial, SassString(hasQuotes: false, :var text)] => switch (
text.split('/')) {
[_] => (input, null),
[var channel3, var alpha] => (
SassList([
...initial,
_parseNumberOrString(channel3),
], ListSeparator.space),
_parseNumberOrString(alpha),
),
_ => null,
},
[...var initial, SassNumber(asSlash: (var before, var after))] => (
SassList([...initial, before], ListSeparator.space),
after,
),
_ => (input, null),
};

/// Parses [text] as either a Sass number or an unquoted Sass string.
Value _parseNumberOrString(String text) {
try {
return ScssParser(text).parseNumber();
} on SassFormatException {
return SassString(text, quotes: false);
}
}

/// Creates a [SassColor] for the given [space] from the given channel values,
/// or throws a [SassScriptException] if the channel values are invalid.
///
Expand Down
10 changes: 10 additions & 0 deletions lib/src/functions/list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import 'dart:collection';
import 'package:collection/collection.dart';

import '../callable.dart';
import '../deprecation.dart';
import '../evaluation_context.dart';
import '../exception.dart';
import '../module/built_in.dart';
import '../value.dart';
Expand Down Expand Up @@ -152,6 +154,14 @@ final _isBracketed = _function(
);

final _slash = _function("slash", r"$elements...", (arguments) {
warnForDeprecation(
'list.slash() is no longer necessary. Sass now supports slash-separated '
'list literals.\n'
'This function is deprecated and will be removed in Dart 3.0.0.\n'
'More info and automated migrator: https://sass-lang.com/d/slash-div',
Deprecation.listSlash,
);

var list = arguments[0].asList;
if (list.length < 2) {
throw SassScriptException("At least two elements are required.");
Expand Down
12 changes: 2 additions & 10 deletions lib/src/functions/math.dart
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,8 @@ final _randomFunction = _function("random", r"$limit: null", (arguments) {
});

final _div = _function("div", r"$number1, $number2", (arguments) {
var number1 = arguments[0];
var number2 = arguments[1];

if (number1 is! SassNumber || number2 is! SassNumber) {
warn(
"math.div() will only support number arguments in a future release.\n"
"Use list.slash() instead for a slash separator.",
);
}

var number1 = arguments[0].assertNumber('number1');
var number2 = arguments[1].assertNumber('number2');
return number1.dividedBy(number2);
});

Expand Down
Loading
Loading