OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library source_map_stack_trace; | 5 library source_map_stack_trace; |
6 | 6 |
7 import 'package:path/path.dart' as p; | 7 import 'package:path/path.dart' as p; |
8 import 'package:source_maps/source_maps.dart'; | 8 import 'package:source_maps/source_maps.dart'; |
9 import 'package:stack_trace/stack_trace.dart'; | 9 import 'package:stack_trace/stack_trace.dart'; |
10 | 10 |
11 /// Convert [stackTrace], a stack trace generated by dart2js-compiled | 11 /// Convert [stackTrace], a stack trace generated by dart2js-compiled |
12 /// JavaScript, to a native-looking stack trace using [sourceMap]. | 12 /// JavaScript, to a native-looking stack trace using [sourceMap]. |
13 /// | 13 /// |
14 /// [minified] indicates whether or not the dart2js code was minified. If it | 14 /// [minified] indicates whether or not the dart2js code was minified. If it |
15 /// hasn't, this tries to clean up the stack frame member names. | 15 /// hasn't, this tries to clean up the stack frame member names. |
16 /// | 16 /// |
17 /// [packageRoot] is the URI (usually a `file:` URI) for the package root that | 17 /// [packageRoot] is the URI (usually a `file:` URI) for the package root that |
18 /// was used by dart2js. It can be a [String] or a [Uri]. If it's passed, stack | 18 /// was used by dart2js. It can be a [String] or a [Uri]. If it's passed, stack |
19 /// frames from packages will use `package:` URLs. | 19 /// frames from packages will use `package:` URLs. |
20 /// | 20 /// |
21 /// [sdkRoot] is the URI (usually a `file:` URI) for the SDK containing dart2js. | 21 /// [sdkRoot] is the URI (usually a `file:` URI) for the SDK containing dart2js. |
22 /// It can be a [String] or a [Uri]. If it's passed, stack frames from the SDK | 22 /// It can be a [String] or a [Uri]. If it's passed, stack frames from the SDK |
23 /// will have `dart:` URLs. | 23 /// will have `dart:` URLs. |
24 StackTrace mapStackTrace(Mapping sourceMap, StackTrace stackTrace, | 24 StackTrace mapStackTrace(Mapping sourceMap, StackTrace stackTrace, |
25 {bool minified: false, packageRoot, sdkRoot}) { | 25 {bool minified: false, packageRoot, sdkRoot}) { |
26 if (stackTrace is Chain) { | 26 if (stackTrace is Chain) { |
27 return new Chain(stackTrace.traces.map((trace) { | 27 return new Chain(stackTrace.traces.map((trace) { |
28 return mapStackTrace(trace, sourceMap, | 28 return new Trace.from(mapStackTrace(sourceMap, trace, |
29 minified: minified, packageRoot: packageRoot, sdkRoot: sdkRoot); | 29 minified: minified, packageRoot: packageRoot, sdkRoot: sdkRoot)); |
30 })); | 30 })); |
31 } | 31 } |
32 | 32 |
33 if (packageRoot != null && packageRoot is! String && packageRoot is! Uri) { | 33 if (packageRoot != null && packageRoot is! String && packageRoot is! Uri) { |
34 throw new ArgumentError( | 34 throw new ArgumentError( |
35 'packageRoot must be a String or a Uri, was "$packageRoot".'); | 35 'packageRoot must be a String or a Uri, was "$packageRoot".'); |
36 } | 36 } |
37 | 37 |
38 if (sdkRoot != null && sdkRoot is! String && sdkRoot is! Uri) { | 38 if (sdkRoot != null && sdkRoot is! String && sdkRoot is! Uri) { |
39 throw new ArgumentError( | 39 throw new ArgumentError( |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 .replaceAll(new RegExp(r"[a-zA-Z_0-9]+\$"), "") | 98 .replaceAll(new RegExp(r"[a-zA-Z_0-9]+\$"), "") |
99 // Get rid of the static method prefix. The class name also exists in the | 99 // Get rid of the static method prefix. The class name also exists in the |
100 // invocation, so we're not getting rid of any information. | 100 // invocation, so we're not getting rid of any information. |
101 .replaceAll(new RegExp(r"^[a-zA-Z_0-9]+.static."), "") | 101 .replaceAll(new RegExp(r"^[a-zA-Z_0-9]+.static."), "") |
102 // Convert underscores after identifiers to dots. This runs the risk of | 102 // Convert underscores after identifiers to dots. This runs the risk of |
103 // incorrectly converting members that contain underscores, but those are | 103 // incorrectly converting members that contain underscores, but those are |
104 // contrary to the style guide anyway. | 104 // contrary to the style guide anyway. |
105 .replaceAllMapped(new RegExp(r"([a-zA-Z0-9]+)_"), | 105 .replaceAllMapped(new RegExp(r"([a-zA-Z0-9]+)_"), |
106 (match) => match[1] + "."); | 106 (match) => match[1] + "."); |
107 } | 107 } |
OLD | NEW |