Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: tests/compiler/dart2js/sourcemaps/load.dart

Issue 2431223006: Add stacktrace_test (Closed)
Patch Set: Updated cf. comments. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
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.
4
5 /// Loads a source map file and outputs a human-readable version of it.
6
7 library load;
8
9 import 'dart:convert';
10 import 'dart:io';
11 import 'package:source_maps/source_maps.dart';
12
13 void main(List<String> args) {
14 if (args.isEmpty) {
15 print('''
16 Usage: load <dir-containing 'out.js.map'>
17 or: load <source-map-file> [<human-readable-source-map-file>]''');
18 exit(1);
19 }
20
21 File humanReadableSourceMapFile;
22 File sourceMapFile;
23 if (args.length == 1 && new Directory(args[0]).existsSync()) {
24 humanReadableSourceMapFile = new File('${args[0]}/out.js.map2');
25 sourceMapFile = new File('${args[0]}/out.js.map');
26 } else {
27 sourceMapFile = new File(args[0]);
28 if (args.length > 1) {
29 humanReadableSourceMapFile = new File(args[1]);
30 }
31 }
32 mainInternal(sourceMapFile, humanReadableSourceMapFile);
33 }
34
35 void mainInternal(File sourceMapFile, File humanReadableSourceMapFile) {
36 SingleMapping sourceMap =
37 new SingleMapping.fromJson(JSON.decode(sourceMapFile.readAsStringSync()));
38 String humanReadableSourceMap = convertToHumanReadableSourceMap(sourceMap);
39 if (humanReadableSourceMapFile != null) {
40 humanReadableSourceMapFile.writeAsStringSync(humanReadableSourceMap);
41 } else {
42 print(humanReadableSourceMap);
43 }
44 }
45
46 String convertToHumanReadableSourceMap(SingleMapping sourceMap) {
47 StringBuffer sb = new StringBuffer();
48 sb.write('{\n');
49 sb.write(' "file": "${sourceMap.targetUrl}",\n');
50 sb.write(' "sourceRoot": "${sourceMap.sourceRoot}",\n');
51 sb.write(' "sources": {\n');
52 for (int index = 0; index < sourceMap.urls.length; index++) {
53 if (index > 0) {
54 sb.write(',\n');
55 }
56 sb.write(' "$index": "${sourceMap.urls[index]}"');
57 }
58 sb.write('\n },\n');
59 sb.write(' "lines": [\n');
60 bool needsComma = false;
61 for (int lineIndex = 0; lineIndex < sourceMap.lines.length; lineIndex++) {
62 TargetLineEntry lineEntry = sourceMap.lines[lineIndex];
63 int line = lineEntry.line + 1;
64 for (int entryIndex = 0;
65 entryIndex < lineEntry.entries.length;
66 entryIndex++) {
67 TargetEntry entry = lineEntry.entries[entryIndex];
68 int columnStart = entry.column + 1;
69 int columnEnd;
70 String position;
71 if (entryIndex + 1 < lineEntry.entries.length) {
72 columnEnd = lineEntry.entries[entryIndex + 1].column + 1;
73 position = '$line,$columnStart-$columnEnd';
74 } else {
75 position = '$line,$columnStart-';
76 }
77 if (entry.sourceUrlId != null) {
78 int sourceUrlId = entry.sourceUrlId;
79 int sourceLine = entry.sourceLine + 1;
80 int sourceColumn = entry.sourceColumn + 1;
81 if (needsComma) {
82 sb.write(',\n');
83 }
84 sb.write(' {"target": "$position"');
85 sb.write(', "source": "$sourceUrlId:$sourceLine,$sourceColumn"');
86 if (entry.sourceNameId != null) {
87 sb.write(', "name": "${sourceMap.names[entry.sourceNameId]}"');
88 }
89 sb.write('}');
90 needsComma = true;
91 }
92 }
93 }
94 sb.write('\n ]\n');
95 sb.write('}');
96 return sb.toString();
97 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/sourcemaps/lax_json_test.dart ('k') | tests/compiler/dart2js/sourcemaps/load_save_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698