Skip to content

Commit 6a9e9e3

Browse files
committed
Merge pull request #387 from dart-lang/pretty_print_maps
pretty print source maps
2 parents e37cdb4 + 0cbc2ff commit 6a9e9e3

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

pkg/dev_compiler/lib/src/codegen/js_printer.dart

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
library dev_compiler.src.codegen.js_printer;
66

7+
import 'dart:convert' show JSON, JsonEncoder;
78
import 'dart:io' show Directory, File, Platform, Process;
89

910
import 'package:analyzer/src/generated/ast.dart';
@@ -40,10 +41,21 @@ String writeJsLibrary(JS.Program jsTree, String outputPath,
4041
String text;
4142
if (context is SourceMapPrintingContext) {
4243
var printer = context.printer;
43-
printer.add('//# sourceMappingURL=$outFilename.map');
44+
printer.add('//# sourceMappingURL=$outFilename.map\n');
4445
// Write output file and source map
4546
text = printer.text;
46-
new File('$outputPath.map').writeAsStringSync(printer.map);
47+
var sourceMap = JSON.decode(printer.map);
48+
var sourceMapText = new JsonEncoder.withIndent(' ').convert(sourceMap);
49+
// Convert:
50+
// "names": [
51+
// "state",
52+
// "print"
53+
// ]
54+
// to:
55+
// "names": ["state","print"]
56+
sourceMapText =
57+
sourceMapText.replaceAll('\n ', '').replaceAll('\n ]', ']');
58+
new File('$outputPath.map').writeAsStringSync('$sourceMapText\n');
4759
} else {
4860
text = (context as JS.SimpleJavaScriptPrintingContext).getText();
4961
}

0 commit comments

Comments
 (0)