Skip to content

Commit

Permalink
Merge pull request #387 from dart-lang/pretty_print_maps
Browse files Browse the repository at this point in the history
pretty print source maps
  • Loading branch information
vsmenon committed Nov 20, 2015
2 parents e37cdb4 + 0cbc2ff commit 6a9e9e3
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions pkg/dev_compiler/lib/src/codegen/js_printer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

library dev_compiler.src.codegen.js_printer;

import 'dart:convert' show JSON, JsonEncoder;
import 'dart:io' show Directory, File, Platform, Process;

import 'package:analyzer/src/generated/ast.dart';
Expand Down Expand Up @@ -40,10 +41,21 @@ String writeJsLibrary(JS.Program jsTree, String outputPath,
String text;
if (context is SourceMapPrintingContext) {
var printer = context.printer;
printer.add('//# sourceMappingURL=$outFilename.map');
printer.add('//# sourceMappingURL=$outFilename.map\n');
// Write output file and source map
text = printer.text;
new File('$outputPath.map').writeAsStringSync(printer.map);
var sourceMap = JSON.decode(printer.map);
var sourceMapText = new JsonEncoder.withIndent(' ').convert(sourceMap);
// Convert:
// "names": [
// "state",
// "print"
// ]
// to:
// "names": ["state","print"]
sourceMapText =
sourceMapText.replaceAll('\n ', '').replaceAll('\n ]', ']');
new File('$outputPath.map').writeAsStringSync('$sourceMapText\n');
} else {
text = (context as JS.SimpleJavaScriptPrintingContext).getText();
}
Expand Down

0 comments on commit 6a9e9e3

Please sign in to comment.