Skip to content

Commit 21eeb4d

Browse files
authored
Parse Deprecation.forVersion on compiler side (#2248)
1 parent 1073c7b commit 21eeb4d

File tree

5 files changed

+43
-15
lines changed

5 files changed

+43
-15
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## 1.77.4
2+
3+
### Embedded Sass
4+
5+
* Support passing `Version` input for `fatalDeprecations` as string over
6+
embedded protocol.
7+
8+
* Fix a bug in the JS Embedded Host where `Version` could be incorrectly accepted
9+
as input for `silenceDeprecations` and `futureDeprecations` in pure JS.
10+
111
## 1.77.3
212

313
### Dart API

lib/src/embedded/compilation_dispatcher.dart

+26-12
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import 'dart:io';
77
import 'dart:isolate';
88
import 'dart:typed_data';
99

10-
import 'package:collection/collection.dart';
1110
import 'package:native_synchronization/mailbox.dart';
1211
import 'package:path/path.dart' as p;
1312
import 'package:protobuf/protobuf.dart';
13+
import 'package:pub_semver/pub_semver.dart';
1414
import 'package:sass/sass.dart' as sass;
1515
import 'package:sass/src/importer/node_package.dart' as npi;
1616

@@ -125,20 +125,34 @@ final class CompilationDispatcher {
125125
: EmbeddedLogger(this,
126126
color: request.alertColor, ascii: request.alertAscii);
127127

128-
sass.Deprecation? deprecationOrWarn(String id) {
129-
var deprecation = sass.Deprecation.fromId(id);
130-
if (deprecation == null) {
131-
logger.warn('Invalid deprecation "$id".');
132-
}
133-
return deprecation;
128+
Iterable<sass.Deprecation>? parseDeprecationsOrWarn(
129+
Iterable<String> deprecations,
130+
{bool supportVersions = false}) {
131+
return () sync* {
132+
for (var item in deprecations) {
133+
var deprecation = sass.Deprecation.fromId(item);
134+
if (deprecation == null) {
135+
if (supportVersions) {
136+
try {
137+
yield* sass.Deprecation.forVersion(Version.parse(item));
138+
} on FormatException {
139+
logger.warn('Invalid deprecation id or version "$item".');
140+
}
141+
} else {
142+
logger.warn('Invalid deprecation id "$item".');
143+
}
144+
} else {
145+
yield deprecation;
146+
}
147+
}
148+
}();
134149
}
135150

136-
var fatalDeprecations =
137-
request.fatalDeprecation.map(deprecationOrWarn).whereNotNull();
151+
var fatalDeprecations = parseDeprecationsOrWarn(request.fatalDeprecation,
152+
supportVersions: true);
138153
var silenceDeprecations =
139-
request.silenceDeprecation.map(deprecationOrWarn).whereNotNull();
140-
var futureDeprecations =
141-
request.futureDeprecation.map(deprecationOrWarn).whereNotNull();
154+
parseDeprecationsOrWarn(request.silenceDeprecation);
155+
var futureDeprecations = parseDeprecationsOrWarn(request.futureDeprecation);
142156

143157
try {
144158
var importers = request.importers.map((importer) =>

pkg/sass_api/CHANGELOG.md

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

37
* No user-visible changes.

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: 10.4.3
5+
version: 10.4.4
66
description: Additional APIs for Dart Sass.
77
homepage: https://github.com/sass/dart-sass
88

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

1212
dependencies:
13-
sass: 1.77.3
13+
sass: 1.77.4
1414

1515
dev_dependencies:
1616
dartdoc: ">=6.0.0 <9.0.0"

pubspec.yaml

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

0 commit comments

Comments
 (0)