Skip to content

Commit

Permalink
Parse Deprecation.forVersion on compiler side (#2248)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntkme committed May 30, 2024
1 parent 1073c7b commit 21eeb4d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 15 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 1.77.4

### Embedded Sass

* Support passing `Version` input for `fatalDeprecations` as string over
embedded protocol.

* Fix a bug in the JS Embedded Host where `Version` could be incorrectly accepted
as input for `silenceDeprecations` and `futureDeprecations` in pure JS.

## 1.77.3

### Dart API
Expand Down
38 changes: 26 additions & 12 deletions lib/src/embedded/compilation_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import 'dart:io';
import 'dart:isolate';
import 'dart:typed_data';

import 'package:collection/collection.dart';
import 'package:native_synchronization/mailbox.dart';
import 'package:path/path.dart' as p;
import 'package:protobuf/protobuf.dart';
import 'package:pub_semver/pub_semver.dart';
import 'package:sass/sass.dart' as sass;
import 'package:sass/src/importer/node_package.dart' as npi;

Expand Down Expand Up @@ -125,20 +125,34 @@ final class CompilationDispatcher {
: EmbeddedLogger(this,
color: request.alertColor, ascii: request.alertAscii);

sass.Deprecation? deprecationOrWarn(String id) {
var deprecation = sass.Deprecation.fromId(id);
if (deprecation == null) {
logger.warn('Invalid deprecation "$id".');
}
return deprecation;
Iterable<sass.Deprecation>? parseDeprecationsOrWarn(
Iterable<String> deprecations,
{bool supportVersions = false}) {
return () sync* {
for (var item in deprecations) {
var deprecation = sass.Deprecation.fromId(item);
if (deprecation == null) {
if (supportVersions) {
try {
yield* sass.Deprecation.forVersion(Version.parse(item));
} on FormatException {
logger.warn('Invalid deprecation id or version "$item".');
}
} else {
logger.warn('Invalid deprecation id "$item".');
}
} else {
yield deprecation;
}
}
}();
}

var fatalDeprecations =
request.fatalDeprecation.map(deprecationOrWarn).whereNotNull();
var fatalDeprecations = parseDeprecationsOrWarn(request.fatalDeprecation,
supportVersions: true);
var silenceDeprecations =
request.silenceDeprecation.map(deprecationOrWarn).whereNotNull();
var futureDeprecations =
request.futureDeprecation.map(deprecationOrWarn).whereNotNull();
parseDeprecationsOrWarn(request.silenceDeprecation);
var futureDeprecations = parseDeprecationsOrWarn(request.futureDeprecation);

try {
var importers = request.importers.map((importer) =>
Expand Down
4 changes: 4 additions & 0 deletions pkg/sass_api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 10.4.4

* No user-visible changes.

## 10.4.3

* No user-visible changes.
Expand Down
4 changes: 2 additions & 2 deletions pkg/sass_api/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ name: sass_api
# Note: Every time we add a new Sass AST node, we need to bump the *major*
# version because it's a breaking change for anyone who's implementing the
# visitor interface(s).
version: 10.4.3
version: 10.4.4
description: Additional APIs for Dart Sass.
homepage: https://github.com/sass/dart-sass

environment:
sdk: ">=3.0.0 <4.0.0"

dependencies:
sass: 1.77.3
sass: 1.77.4

dev_dependencies:
dartdoc: ">=6.0.0 <9.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.77.3
version: 1.77.4
description: A Sass implementation in Dart.
homepage: https://github.com/sass/dart-sass

Expand Down

0 comments on commit 21eeb4d

Please sign in to comment.