Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 1.78.0

* `@import` is now officially deprecated, as are global built-in functions that
are available within built-in modules. See [the Sass blog post] for more
details on the deprecation process.

[the Sass blog]: https://sass-lang.com/blog/import-is-deprecated/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The link reference does not match

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Good catch!


## 1.77.8

* No user-visible changes.
Expand Down
3 changes: 2 additions & 1 deletion lib/src/callable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import 'utils.dart';
import 'value.dart';

export 'callable/async.dart';
export 'callable/async_built_in.dart' show AsyncBuiltInCallable;
export 'callable/async_built_in.dart'
show AsyncBuiltInCallable, warnForGlobalBuiltIn;
export 'callable/built_in.dart' show BuiltInCallable;
export 'callable/plain_css.dart';
export 'callable/user_defined.dart';
Expand Down
21 changes: 21 additions & 0 deletions lib/src/callable/async_built_in.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import 'dart:async';

import '../ast/sass.dart';
import '../deprecation.dart';
import '../evaluation_context.dart';
import '../value.dart';
import 'async.dart';

Expand Down Expand Up @@ -83,4 +85,23 @@ class AsyncBuiltInCallable implements AsyncCallable {
(ArgumentDeclaration, Callback) callbackFor(
int positional, Set<String> names) =>
(_arguments, _callback);

/// Returns a copy of this callable that emits a deprecation warning.
AsyncBuiltInCallable withDeprecationWarning(String module,
[String? newName]) =>
AsyncBuiltInCallable.parsed(name, _arguments, (args) {
warnForGlobalBuiltIn(module, newName ?? name);
return _callback(args);
}, acceptsContent: acceptsContent);
}

/// Emits a deprecation warning for a global built-in function that is now
/// available as function [name] in built-in module [module].
void warnForGlobalBuiltIn(String module, String name) {
warnForDeprecation(
'Global built-in functions are deprecated and '
'will be removed in Dart Sass 3.0.0.\n'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style nit: only split strings at newlines or just before you'd hit the 80 char limit.

'Use $module.$name instead.\n\n'
'More info and automated migrator: https://sass-lang.com/d/import',
Deprecation.globalBuiltin);
}
16 changes: 16 additions & 0 deletions lib/src/callable/built_in.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,20 @@ final class BuiltInCallable implements Callable, AsyncBuiltInCallable {
/// Returns a copy of this callable with the given [name].
BuiltInCallable withName(String name) =>
BuiltInCallable._(name, _overloads, acceptsContent);

/// Returns a copy of this callable that emits a deprecation warning.
BuiltInCallable withDeprecationWarning(String module, [String? newName]) =>
BuiltInCallable._(
name,
[
for (var (declaration, function) in _overloads)
(
declaration,
(args) {
warnForGlobalBuiltIn(module, newName ?? name);
return function(args);
}
)
],
acceptsContent);
}
10 changes: 8 additions & 2 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: 309e4f1f008f08379b824ab6094e13df2e18e187
// Checksum: 89166027dc458357cbea646fd77fa44d9d7461cb

/// Deprecation for passing a string directly to meta.call().
callString('call-string',
Expand Down Expand Up @@ -96,7 +96,13 @@ enum Deprecation {
description: 'Declarations after or between nested rules.'),

/// Deprecation for @import rules.
import.future('import', description: '@import rules.'),
import('import', deprecatedIn: '1.78.0', description: '@import rules.'),

/// Deprecation for global built-in functions that are available in sass: modules.
globalBuiltin('global-builtin',
deprecatedIn: '1.78.0',
description:
'Global built-in functions that are available in sass: modules.'),

// END AUTOGENERATED CODE

Expand Down
41 changes: 26 additions & 15 deletions lib/src/functions/color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ final _microsoftFilterStart = RegExp(r'^[a-zA-Z]+\s*=');
/// The global definitions of Sass color functions.
final global = UnmodifiableListView([
// ### RGB
_red, _green, _blue, _mix,
_red.withDeprecationWarning('color'), _green.withDeprecationWarning('color'),
_blue.withDeprecationWarning('color'), _mix.withDeprecationWarning('color'),

BuiltInCallable.overloadedFunction("rgb", {
r"$red, $green, $blue, $alpha": (arguments) => _rgb("rgb", arguments),
Expand Down Expand Up @@ -66,10 +67,13 @@ final global = UnmodifiableListView([
red: 255 - color.red, green: 255 - color.green, blue: 255 - color.blue);

return _mixColors(inverse, color, weight);
}),
}).withDeprecationWarning('color'),

// ### HSL
_hue, _saturation, _lightness, _complement,
_hue.withDeprecationWarning('color'),
_saturation.withDeprecationWarning('color'),
_lightness.withDeprecationWarning('color'),
_complement.withDeprecationWarning('color'),

BuiltInCallable.overloadedFunction("hsl", {
r"$hue, $saturation, $lightness, $alpha": (arguments) =>
Expand Down Expand Up @@ -116,7 +120,7 @@ final global = UnmodifiableListView([
// Use the native CSS `grayscale` filter function.
return _functionString('grayscale', arguments);
}

warnForGlobalBuiltIn('color', 'grayscale');
var color = arguments[0].assertColor("color");
return color.changeHsl(saturation: 0);
}),
Expand All @@ -125,23 +129,23 @@ final global = UnmodifiableListView([
var color = arguments[0].assertColor("color");
var degrees = _angleValue(arguments[1], "degrees");
return color.changeHsl(hue: color.hue + degrees);
}),
}).withDeprecationWarning('color', 'adjust'),

_function("lighten", r"$color, $amount", (arguments) {
var color = arguments[0].assertColor("color");
var amount = arguments[1].assertNumber("amount");
return color.changeHsl(
lightness: (color.lightness + amount.valueInRange(0, 100, "amount"))
.clamp(0, 100));
}),
}).withDeprecationWarning('color', 'adjust'),

_function("darken", r"$color, $amount", (arguments) {
var color = arguments[0].assertColor("color");
var amount = arguments[1].assertNumber("amount");
return color.changeHsl(
lightness: (color.lightness - amount.valueInRange(0, 100, "amount"))
.clamp(0, 100));
}),
}).withDeprecationWarning('color', 'adjust'),

BuiltInCallable.overloadedFunction("saturate", {
r"$amount": (arguments) {
Expand All @@ -153,6 +157,7 @@ final global = UnmodifiableListView([
return SassString("saturate(${number.toCssString()})", quotes: false);
},
r"$color, $amount": (arguments) {
warnForGlobalBuiltIn('color', 'adjust');
var color = arguments[0].assertColor("color");
var amount = arguments[1].assertNumber("amount");
return color.changeHsl(
Expand All @@ -167,13 +172,17 @@ final global = UnmodifiableListView([
return color.changeHsl(
saturation: (color.saturation - amount.valueInRange(0, 100, "amount"))
.clamp(0, 100));
}),
}).withDeprecationWarning('color', 'adjust'),

// ### Opacity
_function("opacify", r"$color, $amount", _opacify),
_function("fade-in", r"$color, $amount", _opacify),
_function("transparentize", r"$color, $amount", _transparentize),
_function("fade-out", r"$color, $amount", _transparentize),
_function("opacify", r"$color, $amount", _opacify)
.withDeprecationWarning('color', 'adjust'),
_function("fade-in", r"$color, $amount", _opacify)
.withDeprecationWarning('color', 'adjust'),
_function("transparentize", r"$color, $amount", _transparentize)
.withDeprecationWarning('color', 'adjust'),
_function("fade-out", r"$color, $amount", _transparentize)
.withDeprecationWarning('color', 'adjust'),

BuiltInCallable.overloadedFunction("alpha", {
r"$color": (arguments) {
Expand All @@ -184,6 +193,7 @@ final global = UnmodifiableListView([
// Support the proprietary Microsoft alpha() function.
return _functionString("alpha", arguments);
}
warnForGlobalBuiltIn('color', 'alpha');

var color = argument.assertColor("color");
return SassNumber(color.alpha);
Expand Down Expand Up @@ -215,15 +225,16 @@ final global = UnmodifiableListView([
return _functionString("opacity", arguments);
}

warnForGlobalBuiltIn('color', 'opacity');
var color = arguments[0].assertColor("color");
return SassNumber(color.alpha);
}),

// ### Miscellaneous
_ieHexStr,
_adjust.withName("adjust-color"),
_scale.withName("scale-color"),
_change.withName("change-color")
_adjust.withDeprecationWarning('color').withName("adjust-color"),
_scale.withDeprecationWarning('color').withName("scale-color"),
_change.withDeprecationWarning('color').withName("change-color")
]);

/// The Sass color module.
Expand Down
11 changes: 9 additions & 2 deletions lib/src/functions/list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ import '../value.dart';

/// The global definitions of Sass list functions.
final global = UnmodifiableListView([
_length, _nth, _setNth, _join, _append, _zip, _index, _isBracketed, //
_separator.withName("list-separator")
_length.withDeprecationWarning('list'),
_nth.withDeprecationWarning('list'),
_setNth.withDeprecationWarning('list'),
_join.withDeprecationWarning('list'),
_append.withDeprecationWarning('list'),
_zip.withDeprecationWarning('list'),
_index.withDeprecationWarning('list'),
_isBracketed.withDeprecationWarning('list'),
_separator.withDeprecationWarning('list').withName("list-separator")
]);

/// The Sass list module.
Expand Down
12 changes: 6 additions & 6 deletions lib/src/functions/map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import '../value.dart';

/// The global definitions of Sass map functions.
final global = UnmodifiableListView([
_get.withName("map-get"),
_merge.withName("map-merge"),
_remove.withName("map-remove"),
_keys.withName("map-keys"),
_values.withName("map-values"),
_hasKey.withName("map-has-key")
_get.withDeprecationWarning('map').withName("map-get"),
_merge.withDeprecationWarning('map').withName("map-merge"),
_remove.withDeprecationWarning('map').withName("map-remove"),
_keys.withDeprecationWarning('map').withName("map-keys"),
_values.withDeprecationWarning('map').withName("map-values"),
_hasKey.withDeprecationWarning('map').withName("map-has-key")
]);

/// The Sass map module.
Expand Down
16 changes: 12 additions & 4 deletions lib/src/functions/math.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,23 @@ final global = UnmodifiableListView([
"To emit a CSS abs() now: abs(#{$number})\n"
"More info: https://sass-lang.com/d/abs-percent",
Deprecation.absPercent);
} else {
warnForGlobalBuiltIn('math', 'abs');
}
return SassNumber.withUnits(number.value.abs(),
numeratorUnits: number.numeratorUnits,
denominatorUnits: number.denominatorUnits);
}),

_ceil, _floor, _max, _min, _percentage, _randomFunction, _round, _unit, //
_compatible.withName("comparable"),
_isUnitless.withName("unitless"),
_ceil.withDeprecationWarning('math'),
_floor.withDeprecationWarning('math'),
_max.withDeprecationWarning('math'),
_min.withDeprecationWarning('math'),
_percentage.withDeprecationWarning('math'),
_randomFunction.withDeprecationWarning('math'),
_round.withDeprecationWarning('math'),
_unit.withDeprecationWarning('math'),
_compatible.withDeprecationWarning('math').withName("comparable"),
_isUnitless.withDeprecationWarning('math').withName("unitless"),
]);

/// The Sass math module.
Expand Down
25 changes: 14 additions & 11 deletions lib/src/functions/meta.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,18 @@ final _features = {
"custom-property"
};

/// The global definitions of Sass introspection functions.
final global = UnmodifiableListView([
// This is only a partial list of meta functions. The rest are defined in the
// evaluator, because they need access to context that's only available at
// runtime.
/// Sass introspection functions that exist as both global functions and in the
/// `sass:meta` module that do not require access to context that's only
/// available at runtime.
///
/// Additional functions are defined in the evaluator.
final _shared = UnmodifiableListView([
_function("feature-exists", r"$feature", (arguments) {
var feature = arguments[0].assertString("feature");
return SassBoolean(_features.contains(feature.text));
}),

_function("inspect", r"$value",
(arguments) => SassString(arguments.first.toString(), quotes: false)),

_function(
"type-of",
r"$value",
Expand All @@ -52,7 +51,6 @@ final global = UnmodifiableListView([
_ => throw "[BUG] Unknown value type ${arguments[0]}"
},
quotes: false)),

_function("keywords", r"$args", (arguments) {
if (arguments[0] case SassArgumentList(:var keywords)) {
return SassMap({
Expand All @@ -65,9 +63,14 @@ final global = UnmodifiableListView([
})
]);

/// The definitions of Sass introspection functions that are only available from
/// the `sass:meta` module, not as global functions.
final local = UnmodifiableListView([
/// The global definitions of Sass introspection functions.
final global = UnmodifiableListView(
[for (var function in _shared) function.withDeprecationWarning('meta')]);

/// The versions of Sass introspection functions defined in the `sass:meta`
/// module.
final moduleFunctions = UnmodifiableListView([
..._shared,
_function("calc-name", r"$calc", (arguments) {
var calculation = arguments[0].assertCalculation("calc");
return SassString(calculation.name);
Expand Down
16 changes: 8 additions & 8 deletions lib/src/functions/selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import '../value.dart';

/// The global definitions of Sass selector functions.
final global = UnmodifiableListView([
_isSuperselector,
_simpleSelectors,
_parse.withName("selector-parse"),
_nest.withName("selector-nest"),
_append.withName("selector-append"),
_extend.withName("selector-extend"),
_replace.withName("selector-replace"),
_unify.withName("selector-unify")
_isSuperselector.withDeprecationWarning('selector'),
_simpleSelectors.withDeprecationWarning('selector'),
_parse.withDeprecationWarning('selector').withName("selector-parse"),
_nest.withDeprecationWarning('selector').withName("selector-nest"),
_append.withDeprecationWarning('selector').withName("selector-append"),
_extend.withDeprecationWarning('selector').withName("selector-extend"),
_replace.withDeprecationWarning('selector').withName("selector-replace"),
_unify.withDeprecationWarning('selector').withName("selector-unify")
]);

/// The Sass selector module.
Expand Down
14 changes: 9 additions & 5 deletions lib/src/functions/string.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ var _previousUniqueId = _random.nextInt(math.pow(36, 6) as int);

/// The global definitions of Sass string functions.
final global = UnmodifiableListView([
_unquote, _quote, _toUpperCase, _toLowerCase, _uniqueId, //
_length.withName("str-length"),
_insert.withName("str-insert"),
_index.withName("str-index"),
_slice.withName("str-slice")
_unquote.withDeprecationWarning('string'),
_quote.withDeprecationWarning('string'),
_toUpperCase.withDeprecationWarning('string'),
_toLowerCase.withDeprecationWarning('string'),
_uniqueId.withDeprecationWarning('string'),
_length.withDeprecationWarning('string').withName("str-length"),
_insert.withDeprecationWarning('string').withName("str-insert"),
_index.withDeprecationWarning('string').withName("str-index"),
_slice.withDeprecationWarning('string').withName("str-slice")
]);

/// The Sass string module.
Expand Down
7 changes: 4 additions & 3 deletions lib/src/parse/stylesheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1052,9 +1052,10 @@ abstract class StylesheetParser extends Parser {
if (argument is DynamicImport) {
logger.warnForDeprecation(
Deprecation.import,
'Sass @import rules will be deprecated in the future.\n'
'Remove the --future-deprecation=import flag to silence this '
'warning for now.',
'Sass @import rules are deprecated '
'and will be removed in Dart Sass 3.0.0.\n\n'
'More info and automated migrator: '
'https://sass-lang.com/d/import',
span: argument.span);
}
if ((_inControlDirective || _inMixin) && argument is DynamicImport) {
Expand Down
Loading