Support extended source maps.
Pass stack frame uris to source map `Mapping` fixing bug where source
map lookups occurred using the wrong file when using a extended source map
bundle that specified file information.
R=nweiz@google.com
Review URL: https://codereview.chromium.org//2555223004 .
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 60bfd72..554bcf2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+## 1.1.4
+
+* Support source maps that depend on the uri of the location to resolve spans
+ correctly.
+
## 1.1.3
* Add a missing dependency on `path`.
diff --git a/lib/source_map_stack_trace.dart b/lib/source_map_stack_trace.dart
index ae2f124..c9e49f2 100644
--- a/lib/source_map_stack_trace.dart
+++ b/lib/source_map_stack_trace.dart
@@ -62,7 +62,8 @@
// Subtract 1 because stack traces use 1-indexed lines and columns and
// source maps uses 0-indexed.
- var span = sourceMap.spanFor(frame.line - 1, column - 1);
+ var span = sourceMap.spanFor(frame.line - 1, column - 1,
+ uri: frame.uri?.toString());
// If we can't find a source span, ignore the frame. It's probably something
// internal that the user doesn't care about.
diff --git a/pubspec.yaml b/pubspec.yaml
index 4e32d11..f890ed7 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: source_map_stack_trace
-version: 1.1.3
+version: 1.1.4
description: >
A package for applying source maps to stack traces.
author: Dart Team <misc@dartlang.org>
@@ -9,7 +9,7 @@
package_resolver: "^1.0.0"
path: "^1.0.0"
stack_trace: "^1.0.0"
- source_maps: "^0.10.0"
+ source_maps: "^0.10.2"
dev_dependencies:
test: "^0.12.0"
diff --git a/test/source_map_stack_trace_test.dart b/test/source_map_stack_trace_test.dart
index 64145a6..14ec86b 100644
--- a/test/source_map_stack_trace_test.dart
+++ b/test/source_map_stack_trace_test.dart
@@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:package_resolver/package_resolver.dart';
+import 'package:path/path.dart' as p;
import 'package:source_maps/source_maps.dart';
import 'package:source_span/source_span.dart';
import 'package:stack_trace/stack_trace.dart';
@@ -62,6 +63,58 @@
expect(frames.last.member, equals("baz"));
});
+ test("include frames from JS files not covered by the source map bundle",
+ () {
+ var trace = new Trace.parse("""
+foo.dart.js 10:11 foo
+jquery.js 10:1 foo
+bar.dart.js 10:11 foo
+""");
+ var builder = new SourceMapBuilder()
+ ..addSpan(
+ new SourceMapSpan.identifier(
+ new SourceLocation(1,
+ line: 1, column: 3, sourceUrl: "packages/foo/foo.dart"),
+ "qux"),
+ new SourceSpan(new SourceLocation(8, line: 5, column: 0),
+ new SourceLocation(12, line: 9, column: 1), "\n" * 4));
+ var sourceMapJson1 = builder.build("foo.dart.js.map");
+ sourceMapJson1['file'] = "foo.dart.js";
+
+ builder = new SourceMapBuilder()
+ ..addSpan(
+ new SourceMapSpan.identifier(
+ new SourceLocation(1,
+ line: 1, column: 3, sourceUrl: "packages/bar/bar.dart"),
+ "qux"),
+ new SourceSpan(new SourceLocation(8, line: 5, column: 0),
+ new SourceLocation(12, line: 9, column: 1), "\n" * 4));
+ var sourceMapJson2 = builder.build("bar.dart.js.map");
+ sourceMapJson2['file'] = "bar.dart.js";
+
+ var bundle = [sourceMapJson1, sourceMapJson2];
+ var mapping = parseJsonExtended(bundle);
+ var frames = _mapTrace(mapping, trace,
+ packageResolver: new SyncPackageResolver.root("packages/"))
+ .frames;
+
+ expect(frames.length, equals(3));
+
+ var frame = frames[0];
+ expect(frame.uri, equals(Uri.parse("package:foo/foo.dart")));
+ expect(frame.line, equals(2));
+ expect(frame.column, equals(4));
+
+ frame = frames[1];
+ expect(p.basename(frame.uri.toString()), equals("jquery.js"));
+ expect(frame.line, equals(10));
+
+ frame = frames[2];
+ expect(frame.uri, equals(Uri.parse("package:bar/bar.dart")));
+ expect(frame.line, equals(2));
+ expect(frame.column, equals(4));
+ });
+
test("falls back to column 0 for unlisted column", () {
var trace = new Trace.parse("foo.dart.js 10 foo");
var builder = new SourceMapBuilder()