Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit 6783522

Browse files
committed
Improve handling of locations not from the uris the source map is for.
Make `MappingBundle` distinguish between locations from a file with source maps that do not have a source map entry and locations that are from a file that does not have a source map. This enables more graceful generation of stack traces with mixed Dart and JS stack frames. Support a new source map bundle format useful for the Dart Dev Compiler. A source map bundle is a JSON array where each entry is a source map. BUG= R=sigmund@google.com Review URL: https://codereview.chromium.org//2564683003 .
1 parent 453723b commit 6783522

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.10.1+4
2+
3+
* Extend `MappingBundle.spanFor` to accept requests for output files that
4+
don't have source maps.
5+
16
## 0.10.1+3
27

38
* Add `MappingBundle` class that handles extended source map format that

lib/parser.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,17 @@ class MappingBundle extends Mapping {
213213
if (_mappings.containsKey(name)) {
214214
return _mappings[name].spanFor(line, column, files: files, uri: name);
215215
}
216-
return null;
216+
217+
// Note: when there is no source map for an uri, this behaves like an
218+
// identity function, returning the requested location as the result.
219+
220+
// Create a mock offset for the output location. We compute it in terms
221+
// of the input line and column to minimize the chances that two different
222+
// line and column locations are mapped to the same offset.
223+
var offset = line * 1000000 + column;
224+
var location = new SourceLocation(offset,
225+
line: line, column: column, sourceUrl: Uri.parse(uri));
226+
return new SourceMapSpan(location, location, "");
217227
}
218228
}
219229

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: source_maps
2-
version: 0.10.1+3
2+
version: 0.10.1+4
33
author: Dart Team <misc@dartlang.org>
44
description: Library to programmatically manipulate source map files.
55
homepage: http://github.com/dart-lang/source_maps

test/parser_test.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,15 @@ main() {
178178
});
179179

180180
test('unmapped path', () {
181-
expect(mapping.spanFor(0, 0, uri: "unmapped_output.dart"), isNull);
181+
var span = mapping.spanFor(0, 0, uri: "unmapped_output.dart");
182+
expect(span.sourceUrl, Uri.parse("unmapped_output.dart"));
183+
expect(span.start.line, equals(0));
184+
expect(span.start.column, equals(0));
185+
186+
span = mapping.spanFor(10, 5, uri: "unmapped_output.dart");
187+
expect(span.sourceUrl, Uri.parse("unmapped_output.dart"));
188+
expect(span.start.line, equals(10));
189+
expect(span.start.column, equals(5));
182190
});
183191

184192
test('missing path', () {

0 commit comments

Comments
 (0)