Skip to content

Commit 1c0a984

Browse files
sigmundchrakudrama
authored andcommitted
Preserve source-map extensions in SingleMapping (dart-archive/source_maps#31)
* Preserve source-map extensions in SingleMapping * include test that extensions are preserved
1 parent e3efcb3 commit 1c0a984

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

pkgs/source_maps/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.10.8
2+
3+
* Preserve source-map extensions in `SingleMapping`. Extensions are keys in the
4+
json map that start with `"x_"`.
5+
16
## 0.10.7
27

38
* Set max SDK version to `<3.0.0`, and adjust other dependencies.

pkgs/source_maps/lib/parser.dart

+11-2
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,11 @@ class SingleMapping extends Mapping {
278278

279279
final Uri _mapUrl;
280280

281+
final Map<String, dynamic> extensions;
282+
281283
SingleMapping._(this.targetUrl, this.files, this.urls, this.names, this.lines)
282-
: _mapUrl = null;
284+
: _mapUrl = null,
285+
extensions = {};
283286

284287
factory SingleMapping.fromEntries(Iterable<builder.Entry> entries,
285288
[String fileUrl]) {
@@ -341,7 +344,8 @@ class SingleMapping extends Mapping {
341344
files = new List(map['sources'].length),
342345
sourceRoot = map['sourceRoot'],
343346
lines = <TargetLineEntry>[],
344-
_mapUrl = mapUrl is String ? Uri.parse(mapUrl) : mapUrl {
347+
_mapUrl = mapUrl is String ? Uri.parse(mapUrl) : mapUrl,
348+
extensions = {} {
345349
var sourcesContent = map['sourcesContent'] == null
346350
? const []
347351
: new List<String>.from(map['sourcesContent']);
@@ -414,6 +418,10 @@ class SingleMapping extends Mapping {
414418
if (!entries.isEmpty) {
415419
lines.add(new TargetLineEntry(line, entries));
416420
}
421+
422+
map.forEach((name, value) {
423+
if (name.startsWith("x_")) extensions[name] = value;
424+
});
417425
}
418426

419427
/// Encodes the Mapping mappings as a json map.
@@ -471,6 +479,7 @@ class SingleMapping extends Mapping {
471479
if (includeSourceContents) {
472480
result['sourcesContent'] = files.map((file) => file?.getText(0)).toList();
473481
}
482+
extensions.forEach((name, value) => result[name] = value);
474483

475484
return result;
476485
}

pkgs/source_maps/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: source_maps
2-
version: 0.10.7
2+
version: 0.10.8
33

44
description: Library to programmatically manipulate source map files.
55
author: Dart Team <[email protected]>

pkgs/source_maps/test/parser_test.dart

+10
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,16 @@ main() {
342342
expect(mapping.toJson(), equals(SOURCE_MAP_BUNDLE));
343343
});
344344

345+
test('parse extensions', () {
346+
var map = new Map.from(EXPECTED_MAP);
347+
map["x_foo"] = "a";
348+
map["x_bar"] = [3];
349+
SingleMapping mapping = parseJson(map);
350+
expect(mapping.toJson(), equals(map));
351+
expect(mapping.extensions["x_foo"], equals("a"));
352+
expect(mapping.extensions["x_bar"].first, equals(3));
353+
});
354+
345355
group("source files", () {
346356
group("from fromEntries()", () {
347357
test("are null for non-FileLocations", () {

0 commit comments

Comments
 (0)