diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..a2571cbb1 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.0.0-beta.8 + +* Internal changes only. diff --git a/bin/dart_sass_embedded.dart b/bin/dart_sass_embedded.dart index d431ac14a..d073441db 100644 --- a/bin/dart_sass_embedded.dart +++ b/bin/dart_sass_embedded.dart @@ -39,13 +39,12 @@ void main(List args) { request.style == InboundMessage_CompileRequest_OutputStyle.COMPRESSED ? sass.OutputStyle.compressed : sass.OutputStyle.expanded; - var color = request.alertColor ?? false; - var ascii = request.alertAscii ?? false; - var logger = Logger(dispatcher, request.id, color: color, ascii: ascii); + var logger = Logger(dispatcher, request.id, + color: request.alertColor, ascii: request.alertAscii); try { String result; - source_maps.SingleMapping sourceMap; + source_maps.SingleMapping? sourceMap; var sourceMapCallback = request.sourceMap ? (source_maps.SingleMapping map) => sourceMap = map : null; @@ -61,7 +60,7 @@ void main(List args) { case InboundMessage_CompileRequest_Input.string: var input = request.string; result = sass.compileString(input.source, - color: color, + color: request.alertColor, logger: logger, importers: importers, importer: _decodeImporter(dispatcher, request, input.importer), @@ -75,7 +74,7 @@ void main(List args) { case InboundMessage_CompileRequest_Input.path: try { result = sass.compile(request.path, - color: color, + color: request.alertColor, logger: logger, importers: importers, functions: globalFunctions, @@ -97,11 +96,13 @@ void main(List args) { var success = OutboundMessage_CompileResponse_CompileSuccess() ..css = result; if (sourceMap != null) { - success.sourceMap = json.encode(sourceMap.toJson()); + // dart-lang/language#1536 + success.sourceMap = json.encode(sourceMap!.toJson()); } return OutboundMessage_CompileResponse()..success = success; } on sass.SassException catch (error) { - var formatted = withGlyphs(() => error.toString(color: color), + var formatted = withGlyphs( + () => error.toString(color: request.alertColor), ascii: request.alertAscii); return OutboundMessage_CompileResponse() ..failure = (OutboundMessage_CompileResponse_CompileFailure() @@ -114,7 +115,7 @@ void main(List args) { } /// Converts [importer] into an [Importer]. -sass.Importer _decodeImporter( +sass.Importer? _decodeImporter( Dispatcher dispatcher, InboundMessage_CompileRequest request, InboundMessage_CompileRequest_Importer importer) { @@ -131,7 +132,4 @@ sass.Importer _decodeImporter( case InboundMessage_CompileRequest_Importer_Importer.notSet: return null; } - - // dart-lang/sdk#38790 - throw "Unknown Importer.importer $importer."; } diff --git a/lib/src/dispatcher.dart b/lib/src/dispatcher.dart index fcbd814bb..11e87c387 100644 --- a/lib/src/dispatcher.dart +++ b/lib/src/dispatcher.dart @@ -23,7 +23,7 @@ class Dispatcher { /// The completers are located at indexes in this list matching the request /// IDs. `null` elements indicate IDs whose requests have been responded to, /// and which are therefore free to re-use. - final _outstandingRequests = >[]; + final _outstandingRequests = ?>[]; /// Creates a [Dispatcher] that sends and receives encoded protocol buffers /// over [channel]. @@ -47,7 +47,7 @@ class Dispatcher { // for new input. await Future.value(); - InboundMessage message; + InboundMessage? message; try { try { message = InboundMessage.fromBuffer(binaryMessage); @@ -182,7 +182,7 @@ class Dispatcher { /// Returns the id for [message] if it it's a request, or `null` /// otherwise. - int _inboundId(InboundMessage message) { + int? _inboundId(InboundMessage? message) { if (message == null) return null; switch (message.whichMessage()) { case InboundMessage_Message.compileRequest: @@ -210,7 +210,7 @@ class Dispatcher { message.functionCallRequest.id = id; break; default: - return null; + break; } } } diff --git a/lib/src/function_registry.dart b/lib/src/function_registry.dart index 79b0cacce..1cfd69a05 100644 --- a/lib/src/function_registry.dart +++ b/lib/src/function_registry.dart @@ -29,5 +29,5 @@ class FunctionRegistry { /// Returns the compiler-side function associated with [id]. /// /// If no such function exists, returns `null`. - sass.SassFunction operator [](int id) => _functionsById[id]; + sass.SassFunction? operator [](int id) => _functionsById[id]; } diff --git a/lib/src/host_callable.dart b/lib/src/host_callable.dart index e3990aaf7..bb567d419 100644 --- a/lib/src/host_callable.dart +++ b/lib/src/host_callable.dart @@ -23,7 +23,7 @@ import 'value.dart'; /// Throws a [ProtocolError] if [signature] is invalid. sass.Callable hostCallable(Dispatcher dispatcher, FunctionRegistry functions, int compilationId, String signature, - {int id}) { + {int? id}) { var openParen = signature.indexOf('('); if (openParen == -1) { throw paramsError( @@ -38,7 +38,7 @@ sass.Callable hostCallable(Dispatcher dispatcher, FunctionRegistry functions, var name = signature.substring(0, openParen); try { - return sass.Callable( + return sass.Callable.function( name, signature.substring(openParen + 1, signature.length - 1), (arguments) { var request = OutboundMessage_FunctionCallRequest() @@ -66,9 +66,6 @@ sass.Callable hostCallable(Dispatcher dispatcher, FunctionRegistry functions, case InboundMessage_FunctionCallResponse_Result.notSet: throw mandatoryError('FunctionCallResponse.result'); } - - // dart-lang/sdk#38790 - throw "Unknown FunctionCallResponse.result $response."; } on ProtocolError catch (error) { error.id = errorId; stderr.writeln("Host caused ${error.type.name.toLowerCase()} error: " diff --git a/lib/src/importer.dart b/lib/src/importer.dart index 4b6d9d4ec..7e871482c 100644 --- a/lib/src/importer.dart +++ b/lib/src/importer.dart @@ -4,7 +4,6 @@ import 'dart:cli'; -import 'package:meta/meta.dart'; import 'package:sass/sass.dart' as sass; import 'dispatcher.dart'; @@ -24,7 +23,7 @@ class Importer extends sass.Importer { Importer(this._dispatcher, this._compilationId, this._importerId); - Uri canonicalize(Uri url) { + Uri? canonicalize(Uri url) { return waitFor(() async { var response = await _dispatcher .sendCanonicalizeRequest(OutboundMessage_CanonicalizeRequest() @@ -42,9 +41,6 @@ class Importer extends sass.Importer { case InboundMessage_CanonicalizeResponse_Result.notSet: return null; } - - // dart-lang/sdk#38790 - throw "Unknown CanonicalizeResponse.result $response."; }()); } @@ -70,11 +66,7 @@ class Importer extends sass.Importer { case InboundMessage_ImportResponse_Result.notSet: _sendAndThrow(mandatoryError("ImportResponse.result")); - break; // dart-lang/sdk#34048 } - - // dart-lang/sdk#38790 - throw "Unknown ImporterResponse.result $response."; }()); } @@ -96,8 +88,7 @@ class Importer extends sass.Importer { /// Sends [error] to the remote endpoint, and also throws it so that the Sass /// compilation fails. - @alwaysThrows - void _sendAndThrow(ProtocolError error) { + Never _sendAndThrow(ProtocolError error) { _dispatcher.sendError(error); throw "Protocol error: ${error.message}"; } diff --git a/lib/src/logger.dart b/lib/src/logger.dart index 06b82fb3f..566c0a2ab 100644 --- a/lib/src/logger.dart +++ b/lib/src/logger.dart @@ -47,9 +47,9 @@ class Logger implements sass.Logger { } void warn(String message, - {FileSpan span, Trace trace, bool deprecation = false}) { + {FileSpan? span, Trace? trace, bool deprecation = false}) { var formatted = withGlyphs(() { - var buffer = new StringBuffer(); + var buffer = StringBuffer(); if (_color) { buffer.write('\u001b[33m\u001b[1m'); if (deprecation) buffer.write('Deprecation '); diff --git a/lib/src/util/length_delimited_transformer.dart b/lib/src/util/length_delimited_transformer.dart index aba63ab7f..20bc33c98 100644 --- a/lib/src/util/length_delimited_transformer.dart +++ b/lib/src/util/length_delimited_transformer.dart @@ -23,7 +23,7 @@ final StreamChannelTransformer> lengthDelimited = final lengthDelimitedDecoder = StreamTransformer, Uint8List>.fromBind((stream) { // The number of bits we've consumed so far to fill out [nextMessageLength]. - int nextMessageLengthBits = 0; + var nextMessageLengthBits = 0; // The length of the next message, in bytes. // @@ -31,16 +31,16 @@ final lengthDelimitedDecoder = // initialized. // // [varint]: https://developers.google.com/protocol-buffers/docs/encoding#varints - int nextMessageLength = 0; + var nextMessageLength = 0; // The buffer into which the packet data itself is written. Initialized once // [nextMessageLength] is known. - Uint8List buffer; + Uint8List? buffer; // The index of the next byte to write to [buffer]. Once this is equal to // [buffer.length] (or equivalently [nextMessageLength]), the full packet is // available. - int bufferIndex; + var bufferIndex = 0; // It seems a little silly to use a nested [StreamTransformer] here, but we // need the outer one to establish a closure context so we can share state @@ -54,6 +54,8 @@ final lengthDelimitedDecoder = var i = 0; while (i < chunk.length) { + var buffer_ = buffer; // dart-lang/language#1536 + // We can be in one of two states here: // // * [buffer] is `null`, in which case we're adding data to @@ -63,7 +65,7 @@ final lengthDelimitedDecoder = // * [buffer] is not `null`, in which case we're waiting for [buffer] to // have [nextMessageLength] bytes in it before we send it to // [queue.local.sink] and start waiting for the next message. - if (buffer == null) { + if (buffer_ == null) { var byte = chunk[i]; // Varints encode data in the 7 lower bits of each byte, which we access @@ -79,7 +81,7 @@ final lengthDelimitedDecoder = // Otherwise, [nextMessageLength] is now finalized and we can allocate // the data buffer. - buffer = Uint8List(nextMessageLength); + buffer_ = buffer = Uint8List(nextMessageLength); bufferIndex = 0; } @@ -88,18 +90,17 @@ final lengthDelimitedDecoder = // message after the current one) or more than the chunk has available (if // the current message is split across multiple chunks). var bytesToWrite = - math.min(buffer.length - bufferIndex, chunk.length - i); - buffer.setRange(bufferIndex, bufferIndex + bytesToWrite, chunk, i); + math.min(buffer_.length - bufferIndex, chunk.length - i); + buffer_.setRange(bufferIndex, bufferIndex + bytesToWrite, chunk, i); i += bytesToWrite; bufferIndex += bytesToWrite; if (bufferIndex < nextMessageLength) return; // Once we've filled the buffer, emit it and reset our state. - sink.add(buffer); + sink.add(buffer_); nextMessageLength = 0; nextMessageLengthBits = 0; buffer = null; - bufferIndex = null; } })); }); diff --git a/lib/src/utils.dart b/lib/src/utils.dart index a74e19a9c..dbd547c8a 100644 --- a/lib/src/utils.dart +++ b/lib/src/utils.dart @@ -2,7 +2,6 @@ // MIT-style license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT. -import 'package:meta/meta.dart'; import 'package:sass/sass.dart' as sass; import 'package:source_span/source_span.dart'; import 'package:term_glyph/term_glyph.dart' as term_glyph; @@ -66,7 +65,7 @@ String indent(String string, int indentation) => /// Returns the result of running [callback] with the global ASCII config set /// to [ascii]. -T withGlyphs(T callback(), {@required bool ascii}) { +T withGlyphs(T callback(), {required bool ascii}) { var currentConfig = term_glyph.ascii; term_glyph.ascii = ascii; var result = callback(); diff --git a/lib/src/value.dart b/lib/src/value.dart index 065a2fcb8..6c286ecae 100644 --- a/lib/src/value.dart +++ b/lib/src/value.dart @@ -166,15 +166,10 @@ sass.Value deprotofyValue(Dispatcher dispatcher, FunctionRegistry functions, default: throw "Unknown Value.singleton ${value.singleton}"; } - // dart-lang/sdk#39304 - throw "Unreachable"; // ignore: dead_code case Value_Value.notSet: throw mandatoryError("Value.value"); } - - // dart-lang/sdk#38790 - throw "Unknown Value.value $value."; } /// Converts [separator] to its Sass representation. diff --git a/pubspec.yaml b/pubspec.yaml index 7202a2605..28765ef44 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,11 +1,11 @@ name: sass_embedded -version: 1.0.0-beta.7 +version: 1.0.0-dev description: An implementation of the Sass embedded protocol using Dart Sass. author: Sass Team homepage: https://github.com/sass/dart-sass-embedded environment: - sdk: '>=2.10.0 <3.0.0' + sdk: '>=2.12.0 <3.0.0' executables: dart-sass-embedded: dart_sass_embedded @@ -13,8 +13,8 @@ executables: dependencies: async: ">=1.13.0 <3.0.0" meta: ^1.1.0 - protobuf: ^1.0.0 - sass: ^1.21.0 + protobuf: ^2.0.0 + sass: ^1.25.0 source_maps: ^0.10.5 source_span: ^1.1.0 stack_trace: ^1.6.0 @@ -23,8 +23,8 @@ dependencies: dev_dependencies: cli_pkg: ^1.2.0 - grinder: ^0.8.0 - protoc_plugin: ^19.0.0 + grinder: ^0.9.0 + protoc_plugin: ^20.0.0 path: ^1.6.0 test: ^1.0.0 - test_descriptor: ^1.0.0 + test_descriptor: ^2.0.0 diff --git a/test/embedded_process.dart b/test/embedded_process.dart index 9919992e7..75ca7897f 100644 --- a/test/embedded_process.dart +++ b/test/embedded_process.dart @@ -26,11 +26,11 @@ class EmbeddedProcess { /// A [StreamQueue] that emits each outbound protocol buffer from the process. StreamQueue get outbound => _outbound; - StreamQueue _outbound; + late StreamQueue _outbound; /// A [StreamQueue] that emits each line of stderr from the process. StreamQueue get stderr => _stderr; - StreamQueue _stderr; + late StreamQueue _stderr; /// A splitter that can emit new copies of [outbound]. final StreamSplitter _outboundSplitter; @@ -49,7 +49,7 @@ class EmbeddedProcess { final _log = []; /// Whether [_log] has been passed to [printOnFailure] yet. - bool _loggedOutput = false; + var _loggedOutput = false; /// Returns a [Future] which completes to the exit code of the process, once /// it completes. @@ -60,8 +60,11 @@ class EmbeddedProcess { /// Completes to [_process]'s exit code if it's exited, otherwise completes to /// `null` immediately. - Future get _exitCodeOrNull async => - await exitCode.timeout(Duration.zero, onTimeout: () => null); + Future get _exitCodeOrNull async { + var exitCode = + await this.exitCode.timeout(Duration.zero, onTimeout: () => -1); + return exitCode == -1 ? null : exitCode; + } /// Starts a process. /// @@ -73,8 +76,8 @@ class EmbeddedProcess { /// [stderr] will be printed to the console as they appear. This is only /// intended to be set temporarily to help when debugging test failures. static Future start( - {String workingDirectory, - Map environment, + {String? workingDirectory, + Map? environment, bool includeParentEnvironment = true, bool runInShell = false, bool forwardOutput = false}) async { diff --git a/test/function_test.dart b/test/function_test.dart index fd5e3dd97..349352eae 100644 --- a/test/function_test.dart +++ b/test/function_test.dart @@ -14,7 +14,7 @@ final _true = Value()..singleton = Value_Singleton.TRUE; final _false = Value()..singleton = Value_Singleton.FALSE; final _null = Value()..singleton = Value_Singleton.NULL; -EmbeddedProcess _process; +late EmbeddedProcess _process; void main() { setUp(() async { @@ -67,7 +67,7 @@ void main() { group("includes in FunctionCallRequest", () { var compilationId = 1234; - OutboundMessage_FunctionCallRequest request; + late OutboundMessage_FunctionCallRequest request; setUp(() async { _process.inbound.add(compileString("a {b: foo()}", id: compilationId, functions: ["foo()"])); @@ -1232,7 +1232,7 @@ Future _deprotofy(Value value, {bool inspect = false}) async { var success = await getCompileSuccess(await _process.outbound.next); expect(_process.kill(), completes); - return RegExp(r" b: (.*);").firstMatch(success.css)[1]; + return RegExp(r" b: (.*);").firstMatch(success.css)![1]!; } /// Asserts that [value] causes a parameter error with a message matching diff --git a/test/importer_test.dart b/test/importer_test.dart index f60c7607b..42688095d 100644 --- a/test/importer_test.dart +++ b/test/importer_test.dart @@ -13,7 +13,7 @@ import 'embedded_process.dart'; import 'utils.dart'; void main() { - EmbeddedProcess process; + late EmbeddedProcess process; setUp(() async { process = await EmbeddedProcess.start(); }); @@ -101,7 +101,7 @@ void main() { group("includes in CanonicalizeRequest", () { var compilationId = 1234; var importerId = 5679; - OutboundMessage_CanonicalizeRequest request; + late OutboundMessage_CanonicalizeRequest request; setUp(() async { process.inbound.add(compileString("@import 'other'", id: compilationId, @@ -256,7 +256,7 @@ void main() { group("includes in ImportRequest", () { var compilationId = 1234; var importerId = 5678; - OutboundMessage_ImportRequest request; + late OutboundMessage_ImportRequest request; setUp(() async { process.inbound.add(compileString("@import 'other'", id: compilationId, diff --git a/test/length_delimited_test.dart b/test/length_delimited_test.dart index 1fc831821..38c247b8c 100644 --- a/test/length_delimited_test.dart +++ b/test/length_delimited_test.dart @@ -12,8 +12,8 @@ import 'package:test/test.dart'; void main() { group("encoder", () { - Sink> sink; - Stream> stream; + late Sink> sink; + late Stream> stream; setUp(() { var controller = StreamController>(); sink = controller.sink; @@ -52,8 +52,8 @@ void main() { }); group("decoder", () { - Sink> sink; - StreamQueue queue; + late Sink> sink; + late StreamQueue queue; setUp(() { var controller = StreamController>(); sink = controller.sink; diff --git a/test/protocol_test.dart b/test/protocol_test.dart index dd839b573..9b3ab4835 100644 --- a/test/protocol_test.dart +++ b/test/protocol_test.dart @@ -13,7 +13,7 @@ import 'embedded_process.dart'; import 'utils.dart'; void main() { - EmbeddedProcess process; + late EmbeddedProcess process; setUp(() async { process = await EmbeddedProcess.start(); }); @@ -119,7 +119,7 @@ void main() { process.outbound, emits(isSuccess("a { b: 3px; }", sourceMap: (map) { var mapping = source_maps.parse(map); - var span = mapping.spanFor(2, 5); + var span = mapping.spanFor(2, 5)!; expect(span.start.line, equals(0)); expect(span.start.column, equals(3)); expect(span.end, equals(span.start)); diff --git a/test/utils.dart b/test/utils.dart index 6a2823248..e3fe8e087 100644 --- a/test/utils.dart +++ b/test/utils.dart @@ -13,16 +13,16 @@ import 'embedded_process.dart'; /// Returns a [InboundMessage] that compiles the given plain CSS /// string. InboundMessage compileString(String css, - {int id, - bool alertColor, - bool alertAscii, - InboundMessage_Syntax syntax, - InboundMessage_CompileRequest_OutputStyle style, - String url, - bool sourceMap, - Iterable importers, - InboundMessage_CompileRequest_Importer importer, - Iterable functions}) { + {int? id, + bool? alertColor, + bool? alertAscii, + InboundMessage_Syntax? syntax, + InboundMessage_CompileRequest_OutputStyle? style, + String? url, + bool? sourceMap, + Iterable? importers, + InboundMessage_CompileRequest_Importer? importer, + Iterable? functions}) { var input = InboundMessage_CompileRequest_StringInput()..source = css; if (syntax != null) input.syntax = syntax; if (url != null) input.url = url; diff --git a/tool/grind.dart b/tool/grind.dart index 4cb59a20f..2247a2c55 100644 --- a/tool/grind.dart +++ b/tool/grind.dart @@ -10,7 +10,7 @@ import 'package:grinder/grinder.dart'; import 'utils.dart'; main(List args) { - pkg.githubBearerToken.value = Platform.environment["GH_BEARER_TOKEN"]; + pkg.githubBearerToken.fn = () => Platform.environment["GH_BEARER_TOKEN"]!; pkg.addGithubTasks(); grind(args); @@ -44,6 +44,6 @@ dart pub run protoc_plugin %* runOptions: RunOptions(environment: { "PATH": 'build' + (Platform.isWindows ? ";" : ":") + - Platform.environment["PATH"] + Platform.environment["PATH"]! })); }