Skip to content

Commit 63ebf16

Browse files
authored
Add support for calc-size() (#2446)
See sass/sass#3989
1 parent 5163644 commit 63ebf16

File tree

9 files changed

+51
-11
lines changed

9 files changed

+51
-11
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## 1.82.0-dev
2+
3+
* Parse the `calc-size()` function as a calculation now that it's supported in
4+
some browsers.
5+
6+
### Dart API
7+
8+
* Add a `SassCalculation.calcSize()` function.
9+
110
## 1.81.1
211

312
* No user-visible changes.

lib/src/value/calculation.dart

+15
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,21 @@ final class SassCalculation extends Value {
604604
}
605605
}
606606

607+
/// Creates an `calc-size()` calculation with the given [basis] and [value].
608+
///
609+
/// The [basis] and [value] must be either a [SassNumber], a
610+
/// [SassCalculation], an unquoted [SassString], or a [CalculationOperation].
611+
///
612+
/// This automatically simplifies the calculation. It throws an exception if
613+
/// it can determine that the calculation will definitely produce invalid CSS.
614+
static SassCalculation calcSize(Object basis, Object? value) {
615+
var args = [basis, if (value != null) value];
616+
_verifyLength(args, 2);
617+
basis = _simplify(basis);
618+
value = value.andThen(_simplify);
619+
return SassCalculation._("calc-size", [basis, if (value != null) value]);
620+
}
621+
607622
/// Creates and simplifies a [CalculationOperation] with the given [operator],
608623
/// [left], and [right].
609624
///

lib/src/visitor/async_evaluate.dart

+7-3
Original file line numberDiff line numberDiff line change
@@ -2456,7 +2456,8 @@ final class _EvaluateVisitor
24562456
(node.namespace == null &&
24572457
const {
24582458
"calc", "clamp", "hypot", "sin", "cos", "tan", "asin", "acos", //
2459-
"atan", "sqrt", "exp", "sign", "mod", "rem", "atan2", "pow", "log"
2459+
"atan", "sqrt", "exp", "sign", "mod", "rem", "atan2", "pow", //
2460+
"log", "calc-size"
24602461
}.contains(node.name.toLowerCase()) &&
24612462
_environment.getFunction(node.name) == null);
24622463

@@ -2578,7 +2579,8 @@ final class _EvaluateVisitor
25782579
"rem" ||
25792580
"atan2" ||
25802581
"pow" ||
2581-
"log":
2582+
"log" ||
2583+
"calc-size":
25822584
return await _visitCalculation(node);
25832585
}
25842586

@@ -2671,6 +2673,8 @@ final class _EvaluateVisitor
26712673
_warn(message, node.span, deprecation)),
26722674
"clamp" => SassCalculation.clamp(arguments[0],
26732675
arguments.elementAtOrNull(1), arguments.elementAtOrNull(2)),
2676+
"calc-size" =>
2677+
SassCalculation.calcSize(arguments[0], arguments.elementAtOrNull(1)),
26742678
_ => throw UnsupportedError('Unknown calculation name "${node.name}".')
26752679
};
26762680
} on SassScriptException catch (error, stackTrace) {
@@ -2718,7 +2722,7 @@ final class _EvaluateVisitor
27182722
check(1);
27192723
case "min" || "max" || "hypot":
27202724
check();
2721-
case "pow" || "atan2" || "log" || "mod" || "rem":
2725+
case "pow" || "atan2" || "log" || "mod" || "rem" || "calc-size":
27222726
check(2);
27232727
case "round" || "clamp":
27242728
check(3);

lib/src/visitor/evaluate.dart

+8-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// DO NOT EDIT. This file was generated from async_evaluate.dart.
66
// See tool/grind/synchronize.dart for details.
77
//
8-
// Checksum: fbffa0dbe5a1af846dc83752457d39fb2984d280
8+
// Checksum: afc541c7e8bbec53a7a076341b1afff290cb0e45
99
//
1010
// ignore_for_file: unused_import
1111

@@ -2437,7 +2437,8 @@ final class _EvaluateVisitor
24372437
(node.namespace == null &&
24382438
const {
24392439
"calc", "clamp", "hypot", "sin", "cos", "tan", "asin", "acos", //
2440-
"atan", "sqrt", "exp", "sign", "mod", "rem", "atan2", "pow", "log"
2440+
"atan", "sqrt", "exp", "sign", "mod", "rem", "atan2", "pow", //
2441+
"log", "calc-size"
24412442
}.contains(node.name.toLowerCase()) &&
24422443
_environment.getFunction(node.name) == null);
24432444

@@ -2556,7 +2557,8 @@ final class _EvaluateVisitor
25562557
"rem" ||
25572558
"atan2" ||
25582559
"pow" ||
2559-
"log":
2560+
"log" ||
2561+
"calc-size":
25602562
return _visitCalculation(node);
25612563
}
25622564

@@ -2649,6 +2651,8 @@ final class _EvaluateVisitor
26492651
_warn(message, node.span, deprecation)),
26502652
"clamp" => SassCalculation.clamp(arguments[0],
26512653
arguments.elementAtOrNull(1), arguments.elementAtOrNull(2)),
2654+
"calc-size" =>
2655+
SassCalculation.calcSize(arguments[0], arguments.elementAtOrNull(1)),
26522656
_ => throw UnsupportedError('Unknown calculation name "${node.name}".')
26532657
};
26542658
} on SassScriptException catch (error, stackTrace) {
@@ -2696,7 +2700,7 @@ final class _EvaluateVisitor
26962700
check(1);
26972701
case "min" || "max" || "hypot":
26982702
check();
2699-
case "pow" || "atan2" || "log" || "mod" || "rem":
2703+
case "pow" || "atan2" || "log" || "mod" || "rem" || "calc-size":
27002704
check(2);
27012705
case "round" || "clamp":
27022706
check(3);

pkg/sass-parser/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.4.7-dev
2+
3+
* No user-visible changes.
4+
15
## 0.4.6
26

37
* No user-visible changes.

pkg/sass-parser/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sass-parser",
3-
"version": "0.4.6",
3+
"version": "0.4.7-dev",
44
"description": "A PostCSS-compatible wrapper of the official Sass parser",
55
"repository": "sass/sass",
66
"author": "Google Inc.",

pkg/sass_api/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 14.4.0-dev
2+
3+
* No user-visible changes.
4+
15
## 14.3.0
26

37
* Add `NodePackageImporter`, which loads `pkg:` URLs from `node_modules` within

pkg/sass_api/pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ name: sass_api
22
# Note: Every time we add a new Sass AST node, we need to bump the *major*
33
# version because it's a breaking change for anyone who's implementing the
44
# visitor interface(s).
5-
version: 14.3.0
5+
version: 14.4.0-dev
66
description: Additional APIs for Dart Sass.
77
homepage: https://github.com/sass/dart-sass
88

99
environment:
1010
sdk: ">=3.3.0 <4.0.0"
1111

1212
dependencies:
13-
sass: 1.81.1
13+
sass: 1.82.0
1414

1515
dev_dependencies:
1616
dartdoc: ^8.0.14

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: sass
2-
version: 1.81.1
2+
version: 1.82.0-dev
33
description: A Sass implementation in Dart.
44
homepage: https://github.com/sass/dart-sass
55

0 commit comments

Comments
 (0)