Skip to content

Commit c6b2163

Browse files
authored
Merge pull request #2572 from sass/empty-custom-prop
Support empty custom properties
2 parents 7f54226 + 6edc11e commit c6b2163

File tree

10 files changed

+29
-26
lines changed

10 files changed

+29
-26
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
## 1.88.0-dev
1+
## 1.88.0
2+
3+
* Allow custom properties with empty values (such as `--var:;`).
24

35
* Fix a bug when calculating source spans for interpolations.
46

lib/src/parse/stylesheet.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,9 @@ abstract class StylesheetParser extends Parser {
412412
var name = nameBuffer.interpolation(scanner.spanFrom(start, beforeColon));
413413
if (name.initialPlain.startsWith('--')) {
414414
var value = StringExpression(
415-
_interpolatedDeclarationValue(silentComments: false),
415+
atEndOfStatement()
416+
? Interpolation(const [], const [], scanner.emptySpan)
417+
: _interpolatedDeclarationValue(silentComments: false),
416418
);
417419
expectStatementSeparator("custom property");
418420
return Declaration(name, value, scanner.spanFrom(start));

lib/src/visitor/async_evaluate.dart

+6-8
Original file line numberDiff line numberDiff line change
@@ -1381,9 +1381,12 @@ final class _EvaluateVisitor
13811381

13821382
if (node.value case var expression?) {
13831383
var value = await expression.accept(this);
1384-
// If the value is an empty list, preserve it, because converting it to CSS
1385-
// will throw an error that we want the user to see.
1386-
if (!value.isBlank || _isEmptyList(value)) {
1384+
if (!value.isBlank ||
1385+
// If the value is an empty list, preserve it, because converting it
1386+
// to CSS will throw an error that we want the user to see.
1387+
_isEmptyList(value) ||
1388+
// Custom properties are allowed to have empty values, per spec.
1389+
name.value.startsWith('--')) {
13871390
_parent.addChild(
13881391
ModifiableCssDeclaration(
13891392
name,
@@ -1396,11 +1399,6 @@ final class _EvaluateVisitor
13961399
_sourceMap ? node.value.andThen(_expressionNode)?.span : null,
13971400
),
13981401
);
1399-
} else if (name.value.startsWith('--')) {
1400-
throw _exception(
1401-
"Custom property values may not be empty.",
1402-
expression.span,
1403-
);
14041402
}
14051403
}
14061404

lib/src/visitor/evaluate.dart

+7-9
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: 6e5710daa106ed0b9b684af8bc61ce9cc233a10b
8+
// Checksum: a3068d04660dd2bed34b884aa6e1a21d423dc4e5
99
//
1010
// ignore_for_file: unused_import
1111

@@ -1389,9 +1389,12 @@ final class _EvaluateVisitor
13891389

13901390
if (node.value case var expression?) {
13911391
var value = expression.accept(this);
1392-
// If the value is an empty list, preserve it, because converting it to CSS
1393-
// will throw an error that we want the user to see.
1394-
if (!value.isBlank || _isEmptyList(value)) {
1392+
if (!value.isBlank ||
1393+
// If the value is an empty list, preserve it, because converting it
1394+
// to CSS will throw an error that we want the user to see.
1395+
_isEmptyList(value) ||
1396+
// Custom properties are allowed to have empty values, per spec.
1397+
name.value.startsWith('--')) {
13951398
_parent.addChild(
13961399
ModifiableCssDeclaration(
13971400
name,
@@ -1404,11 +1407,6 @@ final class _EvaluateVisitor
14041407
_sourceMap ? node.value.andThen(_expressionNode)?.span : null,
14051408
),
14061409
);
1407-
} else if (name.value.startsWith('--')) {
1408-
throw _exception(
1409-
"Custom property values may not be empty.",
1410-
expression.span,
1411-
);
14121410
}
14131411
}
14141412

pkg/sass-parser/CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 0.4.21-dev
1+
## 0.4.21
22

33
* No user-visible changes.
44

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.21-dev",
3+
"version": "0.4.21",
44
"description": "A PostCSS-compatible wrapper of the official Sass parser",
55
"repository": "sass/sass",
66
"author": "Google Inc.",

pkg/sass_api/CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 15.5.0-dev
1+
## 15.5.0
22

33
* No user-visible changes.
44

pkg/sass_api/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ 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: 15.5.0-dev
5+
version: 15.5.0
66
description: Additional APIs for Dart Sass.
77
homepage: https://github.com/sass/dart-sass
88

pubspec.yaml

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

tool/grind/bump_version.dart

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ final _pubspecVersionRegExp = RegExp(r'^version: (.*)$', multiLine: true);
1717
/// A regular expression that matches a Sass dependency version in a pubspec.
1818
final _sassVersionRegExp = RegExp(r'^( +)sass: (\d.*)$', multiLine: true);
1919

20+
/// A regular expression that matches a CHANGELOG header for a dev version
21+
final _changelogDevHeaderRegExp = RegExp(r'^## .*-dev$', multiLine: true);
22+
2023
/// Adds grinder tasks for bumping package versions.
2124
void addBumpVersionTasks() {
2225
for (var patch in [false, true]) {
@@ -65,9 +68,9 @@ void _bumpVersion(bool patch, bool dev) {
6568
void addChangelogEntry(String dir, Version version) {
6669
var path = p.join(dir, "CHANGELOG.md");
6770
var text = File(path).readAsStringSync();
68-
if (!dev && text.startsWith("## $version-dev\n")) {
71+
if (!dev && text.startsWith(_changelogDevHeaderRegExp)) {
6972
File(path).writeAsStringSync(
70-
text.replaceFirst("## $version-dev\n", "## $version\n"),
73+
text.replaceFirst(_changelogDevHeaderRegExp, "## $version"),
7174
);
7275
} else if (text.startsWith("## $version\n")) {
7376
return;

0 commit comments

Comments
 (0)