Skip to content

Commit

Permalink
Deprecate user-defined functions with math function names
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 committed Aug 17, 2023
1 parent e70cd5a commit 34e1764
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 3 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,12 @@
## 1.66.1

* Deprecate user-defined Sass functions named `round()`, `mod()`, `rem()`,
`sin()`, `cos()`, `tan()`, `asin()`, `acos()`, `atan()`, `atan2()`, `pow()`,
`sqrt()`, `hypot()`, `log()`, `exp()`, `abs()`, and `sign()`. Defining
functions with these names will be an error in Dart Sass 2.0.0. In a more
immediate release, they will also be parsed as CSS calculations in ambiguous
cases.

## 1.66.0

* **Breaking change:** Drop support for the additional CSS calculations defined
Expand Down
5 changes: 5 additions & 0 deletions lib/src/deprecation.dart
Expand Up @@ -69,6 +69,11 @@ enum Deprecation {
deprecatedIn: '1.62.3',
description: 'Passing null as alpha in the ${isJS ? 'JS' : 'Dart'} API.'),

mathFunctionName('math-fn-name',
deprecatedIn: '1.66.1',
description:
'Defining a function with the same name as a CSS calculation.'),

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

Expand Down
31 changes: 31 additions & 0 deletions lib/src/parse/stylesheet.dart
Expand Up @@ -870,6 +870,37 @@ abstract class StylesheetParser extends Parser {
"not" ||
"clamp") {
error("Invalid function name.", scanner.spanFrom(start));
} else if (name
case "round" ||
"mod" ||
"rem" ||
"sin" ||
"cos" ||
"tan" ||
"asin" ||
"acos" ||
"atan" ||
"atan2" ||
"pow" ||
"sqrt" ||
"hypot" ||
"log" ||
"exp" ||
"abs" ||
"sign") {
var suggestion = switch (name) {
"sign" || "rem" || "mod" || "exp" => 'Please rename it.',
_ => 'Either rename it or use the math.$name() function.'
};

logger.warnForDeprecation(
Deprecation.mathFunctionName,
'Naming a Sass function "$name" is deprecated because it conflicts '
'with the new\n'
'CSS $name() syntax. $suggestion\n'
'\n'
'More info: https:/sass-lang.com/d/math-fn-name',
span: scanner.spanFrom(start));
}

whitespace();
Expand Down
4 changes: 4 additions & 0 deletions pkg/sass_api/CHANGELOG.md
@@ -1,3 +1,7 @@
## 8.2.1

* No user-visible changes.

## 8.2.0

* No user-visible changes.
Expand Down
4 changes: 2 additions & 2 deletions pkg/sass_api/pubspec.yaml
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: 8.2.0
version: 8.2.1
description: Additional APIs for Dart Sass.
homepage: https://github.com/sass/dart-sass

environment:
sdk: ">=3.0.0 <4.0.0"

dependencies:
sass: 1.66.0
sass: 1.66.1

dev_dependencies:
dartdoc: ^5.0.0
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
@@ -1,5 +1,5 @@
name: sass
version: 1.66.0
version: 1.66.1
description: A Sass implementation in Dart.
homepage: https://github.com/sass/dart-sass

Expand Down

0 comments on commit 34e1764

Please sign in to comment.