Skip to content
This repository was archived by the owner on Aug 26, 2024. It is now read-only.

Commit f4bbbda

Browse files
committed
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 .
1 parent 662aa1a commit f4bbbda

File tree

4 files changed

+62
-3
lines changed

4 files changed

+62
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 1.1.4
2+
3+
* Support source maps that depend on the uri of the location to resolve spans
4+
correctly.
5+
16
## 1.1.3
27

38
* Add a missing dependency on `path`.

lib/source_map_stack_trace.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ StackTrace mapStackTrace(Mapping sourceMap, StackTrace stackTrace,
6262

6363
// Subtract 1 because stack traces use 1-indexed lines and columns and
6464
// source maps uses 0-indexed.
65-
var span = sourceMap.spanFor(frame.line - 1, column - 1);
65+
var span = sourceMap.spanFor(frame.line - 1, column - 1,
66+
uri: frame.uri?.toString());
6667

6768
// If we can't find a source span, ignore the frame. It's probably something
6869
// internal that the user doesn't care about.

pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: source_map_stack_trace
2-
version: 1.1.3
2+
version: 1.1.4
33
description: >
44
A package for applying source maps to stack traces.
55
author: Dart Team <misc@dartlang.org>
@@ -9,7 +9,7 @@ dependencies:
99
package_resolver: "^1.0.0"
1010
path: "^1.0.0"
1111
stack_trace: "^1.0.0"
12-
source_maps: "^0.10.0"
12+
source_maps: "^0.10.2"
1313

1414
dev_dependencies:
1515
test: "^0.12.0"

test/source_map_stack_trace_test.dart

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:package_resolver/package_resolver.dart';
6+
import 'package:path/path.dart' as p;
67
import 'package:source_maps/source_maps.dart';
78
import 'package:source_span/source_span.dart';
89
import 'package:stack_trace/stack_trace.dart';
@@ -62,6 +63,58 @@ foo.dart.js 10:11 baz
6263
expect(frames.last.member, equals("baz"));
6364
});
6465

66+
test("include frames from JS files not covered by the source map bundle",
67+
() {
68+
var trace = new Trace.parse("""
69+
foo.dart.js 10:11 foo
70+
jquery.js 10:1 foo
71+
bar.dart.js 10:11 foo
72+
""");
73+
var builder = new SourceMapBuilder()
74+
..addSpan(
75+
new SourceMapSpan.identifier(
76+
new SourceLocation(1,
77+
line: 1, column: 3, sourceUrl: "packages/foo/foo.dart"),
78+
"qux"),
79+
new SourceSpan(new SourceLocation(8, line: 5, column: 0),
80+
new SourceLocation(12, line: 9, column: 1), "\n" * 4));
81+
var sourceMapJson1 = builder.build("foo.dart.js.map");
82+
sourceMapJson1['file'] = "foo.dart.js";
83+
84+
builder = new SourceMapBuilder()
85+
..addSpan(
86+
new SourceMapSpan.identifier(
87+
new SourceLocation(1,
88+
line: 1, column: 3, sourceUrl: "packages/bar/bar.dart"),
89+
"qux"),
90+
new SourceSpan(new SourceLocation(8, line: 5, column: 0),
91+
new SourceLocation(12, line: 9, column: 1), "\n" * 4));
92+
var sourceMapJson2 = builder.build("bar.dart.js.map");
93+
sourceMapJson2['file'] = "bar.dart.js";
94+
95+
var bundle = [sourceMapJson1, sourceMapJson2];
96+
var mapping = parseJsonExtended(bundle);
97+
var frames = _mapTrace(mapping, trace,
98+
packageResolver: new SyncPackageResolver.root("packages/"))
99+
.frames;
100+
101+
expect(frames.length, equals(3));
102+
103+
var frame = frames[0];
104+
expect(frame.uri, equals(Uri.parse("package:foo/foo.dart")));
105+
expect(frame.line, equals(2));
106+
expect(frame.column, equals(4));
107+
108+
frame = frames[1];
109+
expect(p.basename(frame.uri.toString()), equals("jquery.js"));
110+
expect(frame.line, equals(10));
111+
112+
frame = frames[2];
113+
expect(frame.uri, equals(Uri.parse("package:bar/bar.dart")));
114+
expect(frame.line, equals(2));
115+
expect(frame.column, equals(4));
116+
});
117+
65118
test("falls back to column 0 for unlisted column", () {
66119
var trace = new Trace.parse("foo.dart.js 10 foo");
67120
var builder = new SourceMapBuilder()

0 commit comments

Comments
 (0)