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 import 'package:package_resolver/package_resolver.dart'; | 5 import 'package:package_resolver/package_resolver.dart'; |
6 import 'package:path/path.dart' as p; | 6 import 'package:path/path.dart' as p; |
7 import 'package:source_maps/source_maps.dart'; | 7 import 'package:source_maps/source_maps.dart'; |
8 import 'package:stack_trace/stack_trace.dart'; | 8 import 'package:stack_trace/stack_trace.dart'; |
9 | 9 |
10 /// Convert [stackTrace], a stack trace generated by dart2js-compiled | 10 /// Convert [stackTrace], a stack trace generated by dart2js-compiled |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 return new Trace(trace.frames.map((frame) { | 55 return new Trace(trace.frames.map((frame) { |
56 // If there's no line information, there's no way to translate this frame. | 56 // If there's no line information, there's no way to translate this frame. |
57 // We could return it as-is, but these lines are usually not useful anyways. | 57 // We could return it as-is, but these lines are usually not useful anyways. |
58 if (frame.line == null) return null; | 58 if (frame.line == null) return null; |
59 | 59 |
60 // If there's no column, try using the first column of the line. | 60 // If there's no column, try using the first column of the line. |
61 var column = frame.column == null ? 0 : frame.column; | 61 var column = frame.column == null ? 0 : frame.column; |
62 | 62 |
63 // Subtract 1 because stack traces use 1-indexed lines and columns and | 63 // Subtract 1 because stack traces use 1-indexed lines and columns and |
64 // source maps uses 0-indexed. | 64 // 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()); |
66 | 67 |
67 // If we can't find a source span, ignore the frame. It's probably something | 68 // If we can't find a source span, ignore the frame. It's probably something |
68 // internal that the user doesn't care about. | 69 // internal that the user doesn't care about. |
69 if (span == null) return null; | 70 if (span == null) return null; |
70 | 71 |
71 var sourceUrl = span.sourceUrl.toString(); | 72 var sourceUrl = span.sourceUrl.toString(); |
72 if (sdkRoot != null && p.url.isWithin(sdkLib, sourceUrl)) { | 73 if (sdkRoot != null && p.url.isWithin(sdkLib, sourceUrl)) { |
73 sourceUrl = "dart:" + p.url.relative(sourceUrl, from: sdkLib); | 74 sourceUrl = "dart:" + p.url.relative(sourceUrl, from: sdkLib); |
74 } else if (packageResolver != null) { | 75 } else if (packageResolver != null) { |
75 if (packageResolver.packageRoot != null && | 76 if (packageResolver.packageRoot != null && |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 .replaceAll(new RegExp(r"[a-zA-Z_0-9]+\$"), "") | 122 .replaceAll(new RegExp(r"[a-zA-Z_0-9]+\$"), "") |
122 // Get rid of the static method prefix. The class name also exists in the | 123 // Get rid of the static method prefix. The class name also exists in the |
123 // invocation, so we're not getting rid of any information. | 124 // invocation, so we're not getting rid of any information. |
124 .replaceAll(new RegExp(r"^[a-zA-Z_0-9]+.(static|dart)."), "") | 125 .replaceAll(new RegExp(r"^[a-zA-Z_0-9]+.(static|dart)."), "") |
125 // Convert underscores after identifiers to dots. This runs the risk of | 126 // Convert underscores after identifiers to dots. This runs the risk of |
126 // incorrectly converting members that contain underscores, but those are | 127 // incorrectly converting members that contain underscores, but those are |
127 // contrary to the style guide anyway. | 128 // contrary to the style guide anyway. |
128 .replaceAllMapped(new RegExp(r"([a-zA-Z0-9]+)_"), | 129 .replaceAllMapped(new RegExp(r"([a-zA-Z0-9]+)_"), |
129 (match) => match[1] + "."); | 130 (match) => match[1] + "."); |
130 } | 131 } |
OLD | NEW |