Skip to content

Commit

Permalink
Merge branch 'main' into watch-reliability
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 authored Dec 3, 2024
2 parents 88a7417 + 63ebf16 commit 4e74fe6
Show file tree
Hide file tree
Showing 35 changed files with 2,794 additions and 179 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
## 1.81.1
## 1.82.0

### Command-Line Interface

* Improve `--watch` mode reliability when making multiple changes at once, such
as checking out a different Git branch.

* Parse the `calc-size()` function as a calculation now that it's supported in
some browsers.

### Dart API

* Add a `SassCalculation.calcSize()` function.

## 1.81.1

* No user-visible changes.

## 1.81.0

* Fix a few cases where deprecation warnings weren't being emitted for global
Expand Down
6 changes: 6 additions & 0 deletions lib/src/js/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ void _updateAstPrototypes() {
'accept',
(Expression self, ExpressionVisitor<Object?> visitor) =>
self.accept(visitor));
var arguments = ArgumentDeclaration([], bogusSpan);
getJSClass(arguments)
.defineGetter('arguments', (ArgumentDeclaration self) => self.arguments);
var function = FunctionRule('a', arguments, [], bogusSpan);
getJSClass(function)
.defineGetter('arguments', (FunctionRule self) => self.arguments);

_addSupportsConditionToInterpolation();

Expand Down
15 changes: 15 additions & 0 deletions lib/src/value/calculation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,21 @@ final class SassCalculation extends Value {
}
}

/// Creates an `calc-size()` calculation with the given [basis] and [value].
///
/// The [basis] and [value] must be either a [SassNumber], a
/// [SassCalculation], an unquoted [SassString], or a [CalculationOperation].
///
/// This automatically simplifies the calculation. It throws an exception if
/// it can determine that the calculation will definitely produce invalid CSS.
static SassCalculation calcSize(Object basis, Object? value) {
var args = [basis, if (value != null) value];
_verifyLength(args, 2);
basis = _simplify(basis);
value = value.andThen(_simplify);
return SassCalculation._("calc-size", [basis, if (value != null) value]);
}

/// Creates and simplifies a [CalculationOperation] with the given [operator],
/// [left], and [right].
///
Expand Down
10 changes: 7 additions & 3 deletions lib/src/visitor/async_evaluate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2456,7 +2456,8 @@ final class _EvaluateVisitor
(node.namespace == null &&
const {
"calc", "clamp", "hypot", "sin", "cos", "tan", "asin", "acos", //
"atan", "sqrt", "exp", "sign", "mod", "rem", "atan2", "pow", "log"
"atan", "sqrt", "exp", "sign", "mod", "rem", "atan2", "pow", //
"log", "calc-size"
}.contains(node.name.toLowerCase()) &&
_environment.getFunction(node.name) == null);

Expand Down Expand Up @@ -2578,7 +2579,8 @@ final class _EvaluateVisitor
"rem" ||
"atan2" ||
"pow" ||
"log":
"log" ||
"calc-size":
return await _visitCalculation(node);
}

Expand Down Expand Up @@ -2671,6 +2673,8 @@ final class _EvaluateVisitor
_warn(message, node.span, deprecation)),
"clamp" => SassCalculation.clamp(arguments[0],
arguments.elementAtOrNull(1), arguments.elementAtOrNull(2)),
"calc-size" =>
SassCalculation.calcSize(arguments[0], arguments.elementAtOrNull(1)),
_ => throw UnsupportedError('Unknown calculation name "${node.name}".')
};
} on SassScriptException catch (error, stackTrace) {
Expand Down Expand Up @@ -2718,7 +2722,7 @@ final class _EvaluateVisitor
check(1);
case "min" || "max" || "hypot":
check();
case "pow" || "atan2" || "log" || "mod" || "rem":
case "pow" || "atan2" || "log" || "mod" || "rem" || "calc-size":
check(2);
case "round" || "clamp":
check(3);
Expand Down
12 changes: 8 additions & 4 deletions lib/src/visitor/evaluate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// DO NOT EDIT. This file was generated from async_evaluate.dart.
// See tool/grind/synchronize.dart for details.
//
// Checksum: fbffa0dbe5a1af846dc83752457d39fb2984d280
// Checksum: afc541c7e8bbec53a7a076341b1afff290cb0e45
//
// ignore_for_file: unused_import

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

Expand Down Expand Up @@ -2556,7 +2557,8 @@ final class _EvaluateVisitor
"rem" ||
"atan2" ||
"pow" ||
"log":
"log" ||
"calc-size":
return _visitCalculation(node);
}

Expand Down Expand Up @@ -2649,6 +2651,8 @@ final class _EvaluateVisitor
_warn(message, node.span, deprecation)),
"clamp" => SassCalculation.clamp(arguments[0],
arguments.elementAtOrNull(1), arguments.elementAtOrNull(2)),
"calc-size" =>
SassCalculation.calcSize(arguments[0], arguments.elementAtOrNull(1)),
_ => throw UnsupportedError('Unknown calculation name "${node.name}".')
};
} on SassScriptException catch (error, stackTrace) {
Expand Down Expand Up @@ -2696,7 +2700,7 @@ final class _EvaluateVisitor
check(1);
case "min" || "max" || "hypot":
check();
case "pow" || "atan2" || "log" || "mod" || "rem":
case "pow" || "atan2" || "log" || "mod" || "rem" || "calc-size":
check(2);
case "round" || "clamp":
check(3);
Expand Down
4 changes: 4 additions & 0 deletions pkg/sass-parser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.4.7-dev

* No user-visible changes.

## 0.4.6

* No user-visible changes.
Expand Down
20 changes: 20 additions & 0 deletions pkg/sass-parser/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export {
ConfiguredVariableProps,
ConfiguredVariableRaws,
} from './src/configured-variable';
export {Container} from './src/container';
export {AnyNode, Node, NodeProps, NodeType} from './src/node';
export {RawWithValue} from './src/raw-with-value';
export {
Expand Down Expand Up @@ -55,6 +56,20 @@ export {
InterpolationRaws,
NewNodeForInterpolation,
} from './src/interpolation';
export {
NewParameters,
ParameterListObjectProps,
ParameterListProps,
ParameterListRaws,
ParameterList,
} from './src/parameter-list';
export {
ParameterObjectProps,
ParameterRaws,
ParameterExpressionProps,
ParameterProps,
Parameter,
} from './src/parameter';
export {
CssComment,
CssCommentProps,
Expand All @@ -79,6 +94,11 @@ export {
ForwardRuleProps,
ForwardRuleRaws,
} from './src/statement/forward-rule';
export {
FunctionRuleRaws,
FunctionRuleProps,
FunctionRule,
} from './src/statement/function-rule';
export {
GenericAtRule,
GenericAtRuleProps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ exports[`a configured variable toJSON 1`] = `
"id": "<input css _____>",
},
],
"name": "baz",
"raws": {},
"sassType": "configured-variable",
"source": <1:18-1:29 in 0>,
"variableName": "baz",
}
`;
20 changes: 20 additions & 0 deletions pkg/sass-parser/lib/src/__snapshots__/parameter-list.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`a parameter list toJSON 1`] = `
{
"inputs": [
{
"css": "@function x($foo, $bar...) {}",
"hasBOM": false,
"id": "<input css _____>",
},
],
"nodes": [
<$foo>,
],
"raws": {},
"restParameter": "bar",
"sassType": "parameter-list",
"source": <1:12-1:27 in 0>,
}
`;
34 changes: 34 additions & 0 deletions pkg/sass-parser/lib/src/__snapshots__/parameter.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`a parameter toJSON with a default 1`] = `
{
"defaultValue": <"qux">,
"inputs": [
{
"css": "@function x($baz: "qux") {}",
"hasBOM": false,
"id": "<input css _____>",
},
],
"name": "baz",
"raws": {},
"sassType": "parameter",
"source": <1:13-1:24 in 0>,
}
`;

exports[`a parameter toJSON with no default 1`] = `
{
"inputs": [
{
"css": "@function x($baz) {}",
"hasBOM": false,
"id": "<input css _____>",
},
],
"name": "baz",
"raws": {},
"sassType": "parameter",
"source": <1:13-1:17 in 0>,
}
`;
Loading

0 comments on commit 4e74fe6

Please sign in to comment.