Files
sdk/pkg/compiler/test/sourcemaps/tools/translate_dart2js_stacktrace.dart
T
Nate Bosch 58e7e7eb26 Prepare for breaking change in package:http
The `url` argument is changing from `Object`, accepting either `String`
or `Uri` at runtime, to `Uri` for better static help.
https://github.com/dart-lang/http/pull/507

- Switch to using `Uri` for requests. Where sensible push this type into
  the signature of the surrounding method.
- Make some updated method private where they were unnecessarily public
  which makes it harder to have confidence when looking for usages.
  Rename a method with an unnecessary `get` name.

Change-Id: Ibf075741d6b9d292349b15f1dc84004981729aca
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/179368
Auto-Submit: Nate Bosch <nbosch@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
Reviewed-by: Jake Macdonald <jakemac@google.com>
2021-01-15 16:35:01 +00:00

92 lines
2.3 KiB
Dart

// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart = 2.7
import 'dart:io';
import 'package:args/args.dart';
import 'package:http/http.dart' as http;
import 'package:source_maps/source_maps.dart';
ArgParser parser = new ArgParser()
..addFlag('inline',
abbr: 'i',
negatable: true,
help: 'Inline untranslatable parts..',
defaultsTo: false);
main(List<String> arguments) async {
ArgResults options = parser.parse(arguments);
if (options.rest.length != 1) {
print('Usage: <script.dart> [<options>] <file or url for source map file>\n'
'Options:\n'
'${parser.usage}');
exit(2);
}
String url = options.rest[0];
String data;
if (url.startsWith("http://") || url.startsWith("https://")) {
data = (await http.get(Uri.parse(url))).body;
} else {
data = new File(url).readAsStringSync();
}
SingleMapping sourceMap = parse(data);
print("Now paste the stacktrace here. Finish with at least 3 empty lines...");
int emptyInARow = 0;
List<String> lines = [];
while (true) {
String line = stdin.readLineSync();
if (line == null) break;
if (line == "") {
++emptyInARow;
} else {
lines.add(line);
emptyInARow = 0;
}
if (emptyInARow >= 3) break;
}
List<String> tailMessages = [];
for (String line in lines) {
Iterable<Match> ms = new RegExp(r"(\d+):(\d+)").allMatches(line);
if (ms.isEmpty) {
if (options['inline']) {
print("----- (unparseable) -----");
} else {
tailMessages.add("Unparseable line: $line");
}
continue;
}
Match m = ms.first;
int l = int.parse(m.group(1));
int c = int.parse(m.group(2));
SourceMapSpan span = sourceMap.spanFor(l, c);
if (span?.start == null) {
if (options['inline']) {
print("----- (unparseable) -----");
} else {
tailMessages.add("No sourcemap entry for line line: $line");
}
continue;
}
print(span.start.toolString);
}
if (tailMessages.isNotEmpty) {
print("");
print("Messages:");
print("");
for (String line in tailMessages) {
print(line);
}
}
}