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

Fix deprotofy SassCalculation.clamp #2043

Merged
merged 1 commit into from
Jul 21, 2023
Merged
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 1.64.1

### Embedded Sass

* Fix a bug where a valid `SassCalculation.clamp()` with less than 3 arguments
would throw an error.

## 1.64.0

* Comments that appear before or between `@use` and `@forward` rules are now
Expand Down
12 changes: 8 additions & 4 deletions lib/src/embedded/protofier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -350,16 +350,20 @@ class Protofier {
return SassCalculation.calc(
_deprotofyCalculationValue(calculation.arguments[0]));
} else if (calculation.name == "clamp") {
if (calculation.arguments.length != 3) {
if (calculation.arguments.isEmpty || calculation.arguments.length > 3) {
throw paramsError(
"Value.Calculation.arguments must have exactly 3 arguments for "
"Value.Calculation.arguments must have 1 to 3 arguments for "
"clamp().");
}

return SassCalculation.clamp(
_deprotofyCalculationValue(calculation.arguments[0]),
_deprotofyCalculationValue(calculation.arguments[1]),
_deprotofyCalculationValue(calculation.arguments[2]));
calculation.arguments.length > 1
? _deprotofyCalculationValue(calculation.arguments[1])
: null,
calculation.arguments.length > 2
? _deprotofyCalculationValue(calculation.arguments[2])
: null);
} else if (calculation.name == "min") {
if (calculation.arguments.isEmpty) {
throw paramsError(
Expand Down
2 changes: 1 addition & 1 deletion pkg/sass_api/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ environment:
sdk: ">=3.0.0 <4.0.0"

dependencies:
sass: 1.64.0
sass: 1.64.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.64.0
version: 1.64.1
description: A Sass implementation in Dart.
homepage: https://github.com/sass/dart-sass

Expand Down
12 changes: 3 additions & 9 deletions test/embedded/function_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1699,7 +1699,7 @@ void main() {
..number = (Value_Number()..value = 3.0))
..arguments.add(Value_Calculation_CalculationValue()
..number = (Value_Number()..value = 4.0))),
equals("Value.Calculation.arguments must have exactly 3 "
equals("Value.Calculation.arguments must have 1 to 3 "
"arguments for clamp()."));
});
});
Expand All @@ -1714,14 +1714,8 @@ void main() {

test("for clamp", () async {
await _expectDeprotofyError(
Value()
..calculation = (Value_Calculation()
..name = "clamp"
..arguments.add(Value_Calculation_CalculationValue()
..number = (Value_Number()..value = 1.0))
..arguments.add(Value_Calculation_CalculationValue()
..number = (Value_Number()..value = 2.0))),
equals("Value.Calculation.arguments must have exactly 3 "
Value()..calculation = (Value_Calculation()..name = "clamp"),
equals("Value.Calculation.arguments must have 1 to 3 "
"arguments for clamp()."));
});

Expand Down