Skip to content

Commit 99f61c2

Browse files
committed
Use the canonical URL instead of a data: URL for sourceMapUrl fallback
1 parent 62ec662 commit 99f61c2

File tree

3 files changed

+9
-22
lines changed

3 files changed

+9
-22
lines changed

lib/src/importer/result.dart

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// MIT-style license that can be found in the LICENSE file or at
33
// https://opensource.org/licenses/MIT.
44

5-
import 'dart:convert';
6-
75
import 'package:meta/meta.dart';
86

97
import '../importer.dart';
@@ -17,15 +15,8 @@ class ImporterResult {
1715
/// The contents of the stylesheet.
1816
final String contents;
1917

20-
/// An absolute, browser-accessible URL indicating the resolved location of
21-
/// the imported stylesheet.
22-
///
23-
/// This should be a `file:` URL if one is available, but an `http:` URL is
24-
/// acceptable as well. If no URL is supplied, a `data:` URL is generated
25-
/// automatically from [contents].
26-
Uri get sourceMapUrl =>
27-
_sourceMapUrl ?? Uri.dataFromString(contents, encoding: utf8);
28-
final Uri? _sourceMapUrl;
18+
/// An absolute URL indicating the resolved location of the imported stylesheet.
19+
final Uri? sourceMapUrl;
2920

3021
/// The syntax to use to parse the stylesheet.
3122
final Syntax syntax;
@@ -40,11 +31,10 @@ class ImporterResult {
4031
/// parameter instead.
4132
ImporterResult(
4233
this.contents, {
43-
Uri? sourceMapUrl,
34+
this.sourceMapUrl,
4435
Syntax? syntax,
4536
@Deprecated("Use the syntax parameter instead.") bool? indented,
46-
}) : _sourceMapUrl = sourceMapUrl,
47-
syntax = syntax ?? (indented == true ? Syntax.sass : Syntax.scss) {
37+
}) : syntax = syntax ?? (indented == true ? Syntax.sass : Syntax.scss) {
4838
if (sourceMapUrl?.scheme == '') {
4939
throw ArgumentError.value(
5040
sourceMapUrl,

test/dart_api/importer_test.dart

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
@TestOn('vm')
66
library;
77

8-
import 'dart:convert';
98

109
import 'package:test/test.dart';
1110

@@ -305,7 +304,7 @@ void main() {
305304
expect(result.sourceMap!.urls, contains("u:blue"));
306305
});
307306

308-
test("uses a data: source map URL if the importer doesn't provide one", () {
307+
test("uses the canonical URL if the importer doesn't provide one", () {
309308
var result = compileStringToResult(
310309
'@use "orange";',
311310
importers: [
@@ -320,10 +319,7 @@ void main() {
320319
expect(
321320
result.sourceMap!.urls,
322321
contains(
323-
Uri.dataFromString(
324-
".orange {color: orange}",
325-
encoding: utf8,
326-
).toString(),
322+
"u:orange",
327323
),
328324
);
329325
});

test/embedded/importer_test.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,8 @@ void main() {
648648
await process.close();
649649
});
650650

651-
test("uses a data: URL rather than an empty source map URL", () async {
651+
test("uses the canonical URL rather than an empty source map URL",
652+
() async {
652653
process.send(
653654
compileString(
654655
"@use 'other'",
@@ -673,7 +674,7 @@ void main() {
673674
"a { b: c; }",
674675
sourceMap: (String map) {
675676
var mapping = source_maps.parse(map) as source_maps.SingleMapping;
676-
expect(mapping.urls, [startsWith("data:")]);
677+
expect(mapping.urls, contains("custom:other"));
677678
},
678679
);
679680
await process.close();

0 commit comments

Comments
 (0)