1ef4399df0
This uses optional new/const and `=` in named argument defaults. All changes are automated, except for: - utils/dartdevc/BUILD.gn: run DDC build scripts with --preview-dart-2 - pkg/dev_compiler/tool/patch_sdk.dart: add a TODO that Analyzer doesn't supporting implicit const in libraries.dart - pkg/dev_compiler/tool/input_sdk/libraries.dart: was not formatted due to the aforementioned Analyzer bug - tools/bots/test_matrix.json: run DDC sourcemap suite in Dart 2 mode - pkg/pkg.status: skip pkg/dev_compiler if running in Dart 1 mode Change-Id: I9b80ccba0c2cc7b66efc662a0b16562e3660aee3 Reviewed-on: https://dart-review.googlesource.com/60402 Commit-Queue: Jenny Messerly <jmesserly@google.com> Reviewed-by: Bob Nystrom <rnystrom@google.com>
80 lines
3.0 KiB
Dart
80 lines
3.0 KiB
Dart
// Copyright (c) 2017, 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.
|
|
|
|
import 'package:path/path.dart' as p;
|
|
import 'package:source_maps/source_maps.dart';
|
|
import 'package:stack_trace/stack_trace.dart';
|
|
|
|
/// This is a fork of package:source_map_stack_trace, a tool for
|
|
/// dart2js-compiled code, reworked for DDC.
|
|
|
|
/// Convert [stackTrace], a stack trace generated by DDC-compiled
|
|
/// JavaScript, to a native-looking stack trace using [sourceMap].
|
|
///
|
|
/// [roots] are the paths (usually `http:` URI strings) that DDC applications
|
|
/// are served from. This is used to identify sdk and package URIs.
|
|
StackTrace mapStackTrace(Mapping sourceMap, StackTrace stackTrace,
|
|
{List<String> roots}) {
|
|
if (stackTrace is Chain) {
|
|
return Chain(stackTrace.traces.map((trace) {
|
|
return Trace.from(mapStackTrace(sourceMap, trace, roots: roots));
|
|
}));
|
|
}
|
|
|
|
var trace = Trace.from(stackTrace);
|
|
return Trace(trace.frames.map((frame) {
|
|
// If there's no line information, there's no way to translate this frame.
|
|
// We could return it as-is, but these lines are usually not useful anyways.
|
|
if (frame.line == null) return null;
|
|
|
|
// If there's no column, try using the first column of the line.
|
|
var column = frame.column == null ? 0 : frame.column;
|
|
|
|
// Subtract 1 because stack traces use 1-indexed lines and columns and
|
|
// source maps uses 0-indexed.
|
|
var span = sourceMap.spanFor(frame.line - 1, column - 1,
|
|
uri: frame.uri?.toString());
|
|
|
|
// If we can't find a source span, ignore the frame. It's probably something
|
|
// internal that the user doesn't care about.
|
|
if (span == null) return null;
|
|
|
|
var sourceUrl = span.sourceUrl.toString();
|
|
for (var root in roots) {
|
|
if (root != null && p.url.isWithin(root, sourceUrl)) {
|
|
var relative = p.url.relative(sourceUrl, from: root);
|
|
if (relative.contains('dart:')) {
|
|
sourceUrl = relative.substring(relative.indexOf('dart:'));
|
|
break;
|
|
}
|
|
var packageRoot = '$root/packages';
|
|
if (p.url.isWithin(packageRoot, sourceUrl)) {
|
|
sourceUrl = "package:" + p.url.relative(sourceUrl, from: packageRoot);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!sourceUrl.startsWith('dart:') &&
|
|
!sourceUrl.startsWith('package:') &&
|
|
sourceUrl.contains('dart_sdk.js')) {
|
|
// This compresses the long dart_sdk URLs if SDK source maps are missing.
|
|
// It's no longer linkable, but neither are the properly mapped ones
|
|
// above.
|
|
sourceUrl = 'dart:sdk_internal';
|
|
}
|
|
|
|
return Frame(Uri.parse(sourceUrl), span.start.line + 1,
|
|
span.start.column + 1, _prettifyMember(frame.member));
|
|
}).where((frame) => frame != null));
|
|
}
|
|
|
|
/// Reformats a JS member name to make it look more Dart-like.
|
|
String _prettifyMember(String member) {
|
|
var last = member.lastIndexOf('.');
|
|
if (last < 0) return member;
|
|
var suffix = member.substring(last + 1);
|
|
return suffix == 'fn' ? member : suffix;
|
|
}
|