| 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 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 var sdkLib = sdkRoot == null ? null : "$sdkRoot/lib"; | 44 var sdkLib = sdkRoot == null ? null : "$sdkRoot/lib"; |
| 45 | 45 |
| 46 var trace = new Trace.from(stackTrace); | 46 var trace = new Trace.from(stackTrace); |
| 47 return new Trace(trace.frames.map((frame) { | 47 return new Trace(trace.frames.map((frame) { |
| 48 // If there's no line information, there's no way to translate this frame. | 48 // If there's no line information, there's no way to translate this frame. |
| 49 // We could return it as-is, but these lines are usually not useful anyways. | 49 // We could return it as-is, but these lines are usually not useful anyways. |
| 50 if (frame.line == null) return null; | 50 if (frame.line == null) return null; |
| 51 | 51 |
| 52 // If there's no column, try using the first column of the line. | 52 // If there's no column, try using the first column of the line. |
| 53 var column = frame.column == null ? 0 : frame.column; | 53 var column = frame.column == null ? 0 : frame.column; |
| 54 var span = sourceMap.spanFor(frame.line, column); | 54 |
| 55 // Subtract 1 because stack traces use 1-indexed lines and columns and |
| 56 // source maps uses 0-indexed. |
| 57 var span = sourceMap.spanFor(frame.line - 1, column - 1); |
| 55 | 58 |
| 56 // If we can't find a source span, ignore the frame. It's probably something | 59 // If we can't find a source span, ignore the frame. It's probably something |
| 57 // internal that the user doesn't care about. | 60 // internal that the user doesn't care about. |
| 58 if (span == null) return null; | 61 if (span == null) return null; |
| 59 | 62 |
| 60 var sourceUrl = span.sourceUrl.toString(); | 63 var sourceUrl = span.sourceUrl.toString(); |
| 61 if (packageRoot != null && p.url.isWithin(packageRoot, sourceUrl)) { | 64 if (packageRoot != null && p.url.isWithin(packageRoot, sourceUrl)) { |
| 62 sourceUrl = "package:" + | 65 sourceUrl = "package:" + |
| 63 p.url.relative(sourceUrl, from: packageRoot); | 66 p.url.relative(sourceUrl, from: packageRoot); |
| 64 } else if (sdkRoot != null && p.url.isWithin(sdkLib, sourceUrl)) { | 67 } else if (sdkRoot != null && p.url.isWithin(sdkLib, sourceUrl)) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 .replaceAll(new RegExp(r"[a-zA-Z_0-9]+\$"), "") | 101 .replaceAll(new RegExp(r"[a-zA-Z_0-9]+\$"), "") |
| 99 // Get rid of the static method prefix. The class name also exists in the | 102 // 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. | 103 // invocation, so we're not getting rid of any information. |
| 101 .replaceAll(new RegExp(r"^[a-zA-Z_0-9]+.static."), "") | 104 .replaceAll(new RegExp(r"^[a-zA-Z_0-9]+.static."), "") |
| 102 // Convert underscores after identifiers to dots. This runs the risk of | 105 // Convert underscores after identifiers to dots. This runs the risk of |
| 103 // incorrectly converting members that contain underscores, but those are | 106 // incorrectly converting members that contain underscores, but those are |
| 104 // contrary to the style guide anyway. | 107 // contrary to the style guide anyway. |
| 105 .replaceAllMapped(new RegExp(r"([a-zA-Z0-9]+)_"), | 108 .replaceAllMapped(new RegExp(r"([a-zA-Z0-9]+)_"), |
| 106 (match) => match[1] + "."); | 109 (match) => match[1] + "."); |
| 107 } | 110 } |
| OLD | NEW |