Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate user-defined functions with math function names #2068

Closed
wants to merge 1 commit into from
Closed
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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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',
Copy link
Member

Choose a reason for hiding this comment

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

The only nit is that this page is not live yet, but I understand it should go live soon

Copy link
Member

Choose a reason for hiding this comment

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

Oh actually on second look, there is a missing /

Suggested change
'More info: https:/sass-lang.com/d/math-fn-name',
'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
Original file line number Diff line number Diff line change
@@ -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
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: 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
Original file line number Diff line number Diff line change
@@ -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