Skip to content
This repository was archived by the owner on May 15, 2023. It is now read-only.

Commit 5012b5c

Browse files
authored
Allow ImporterResponse.result to be null (#59)
1 parent 26127d8 commit 5012b5c

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
## 1.0.0-beta.15
22

3-
* Support version 1.0.0-beta.16 of the Sass embedded protocol:
3+
* Support version 1.0.0-beta.17 of the Sass embedded protocol:
4+
45
* Treat invalid host function signatures as function errors rather than
56
protocol errors.
67

8+
* Allow `ImportResponse.result` to be null.
9+
710
## 1.0.0-beta.14
811

912
* Support `FileImporter`s.

lib/src/importer/host.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class HostImporter extends ImporterBase {
4444
}());
4545
}
4646

47-
sass.ImporterResult load(Uri url) {
47+
sass.ImporterResult? load(Uri url) {
4848
return waitFor(() async {
4949
var response =
5050
await dispatcher.sendImportRequest(OutboundMessage_ImportRequest()
@@ -65,7 +65,7 @@ class HostImporter extends ImporterBase {
6565
throw response.error;
6666

6767
case InboundMessage_ImportResponse_Result.notSet:
68-
sendAndThrow(mandatoryError("ImportResponse.result"));
68+
return null;
6969
}
7070
}());
7171
}

test/importer_test.dart

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -217,21 +217,6 @@ void main() {
217217

218218
group("importing", () {
219219
group("emits a protocol error", () {
220-
test("for an unset import result", () async {
221-
process.inbound.add(compileString("@import 'other'", importers: [
222-
InboundMessage_CompileRequest_Importer()..importerId = 1
223-
]));
224-
await _canonicalize(process);
225-
226-
var import = getImportRequest(await process.outbound.next);
227-
process.inbound.add(InboundMessage()
228-
..importResponse = (InboundMessage_ImportResponse()..id = import.id));
229-
230-
await _expectImportParamsError(
231-
process, "Missing mandatory field ImportResponse.result");
232-
await process.kill();
233-
});
234-
235220
test("for an import result with a relative sourceMapUrl", () async {
236221
process.inbound.add(compileString("@import 'other'", importers: [
237222
InboundMessage_CompileRequest_Importer()..importerId = 1
@@ -289,6 +274,29 @@ void main() {
289274
});
290275
});
291276

277+
test("null results count as not found", () async {
278+
process.inbound.add(compileString("@import 'other'", importers: [
279+
InboundMessage_CompileRequest_Importer()..importerId = 1
280+
]));
281+
282+
var canonicalizeRequest =
283+
getCanonicalizeRequest(await process.outbound.next);
284+
process.inbound.add(InboundMessage()
285+
..canonicalizeResponse = (InboundMessage_CanonicalizeResponse()
286+
..id = canonicalizeRequest.id
287+
..url = "o:other"));
288+
289+
var importRequest = getImportRequest(await process.outbound.next);
290+
process.inbound.add(InboundMessage()
291+
..importResponse =
292+
(InboundMessage_ImportResponse()..id = importRequest.id));
293+
294+
var failure = getCompileFailure(await process.outbound.next);
295+
expect(failure.message, equals("Can't find stylesheet to import."));
296+
expect(failure.span.text, equals("'other'"));
297+
await process.kill();
298+
});
299+
292300
test("errors cause compilation to fail", () async {
293301
process.inbound.add(compileString("@import 'other'", importers: [
294302
InboundMessage_CompileRequest_Importer()..importerId = 1

0 commit comments

Comments
 (0)