| Index: pkg/compiler/lib/src/js/js.dart
|
| diff --git a/pkg/compiler/lib/src/js/js.dart b/pkg/compiler/lib/src/js/js.dart
|
| index 2d208a6940a14714429d5c817bc0c1c5c5d0731e..04eb3067087b8c80a8d683bec26134e1aa316aa9 100644
|
| --- a/pkg/compiler/lib/src/js/js.dart
|
| +++ b/pkg/compiler/lib/src/js/js.dart
|
| @@ -7,35 +7,47 @@ library js;
|
| import 'package:js_ast/js_ast.dart';
|
| export 'package:js_ast/js_ast.dart';
|
|
|
| -import '../io/code_output.dart' show CodeBuffer;
|
| -import '../io/source_information.dart' show SourceInformation;
|
| +import '../io/code_output.dart' show CodeOutput, CodeBuffer;
|
| import '../js_emitter/js_emitter.dart' show USE_NEW_EMITTER;
|
| import '../dart2jslib.dart' as leg;
|
| -import '../util/util.dart' show NO_LOCATION_SPANNABLE;
|
| +import '../util/util.dart' show NO_LOCATION_SPANNABLE, Indentation, Tagging;
|
| import '../dump_info.dart' show DumpInfoTask;
|
| +import 'js_source_mapping.dart';
|
|
|
| -CodeBuffer prettyPrint(Node node, leg.Compiler compiler,
|
| +CodeBuffer prettyPrint(Node node,
|
| + leg.Compiler compiler,
|
| {DumpInfoTask monitor,
|
| bool allowVariableMinification: true}) {
|
| + JavaScriptSourceInformationStrategy sourceInformationFactory =
|
| + compiler.backend.sourceInformationStrategy;
|
| JavaScriptPrintingOptions options = new JavaScriptPrintingOptions(
|
| shouldCompressOutput: compiler.enableMinification,
|
| minifyLocalVariables: allowVariableMinification,
|
| preferSemicolonToNewlineInMinifiedOutput: USE_NEW_EMITTER);
|
| + CodeBuffer outBuffer = new CodeBuffer();
|
| + SourceInformationProcessor sourceInformationProcessor =
|
| + sourceInformationFactory.createProcessor(
|
| + new SourceLocationsMapper(outBuffer));
|
| Dart2JSJavaScriptPrintingContext context =
|
| - new Dart2JSJavaScriptPrintingContext(compiler, monitor);
|
| + new Dart2JSJavaScriptPrintingContext(
|
| + compiler, monitor, outBuffer, sourceInformationProcessor);
|
| Printer printer = new Printer(options, context);
|
| printer.visit(node);
|
| - return context.outBuffer;
|
| + sourceInformationProcessor.process(node);
|
| + return outBuffer;
|
| }
|
|
|
| class Dart2JSJavaScriptPrintingContext implements JavaScriptPrintingContext {
|
| final leg.Compiler compiler;
|
| final DumpInfoTask monitor;
|
| - final CodeBuffer outBuffer = new CodeBuffer();
|
| - Node rootNode;
|
| + final CodeBuffer outBuffer;
|
| + final CodePositionListener codePositionListener;
|
|
|
| - Dart2JSJavaScriptPrintingContext(leg.Compiler this.compiler,
|
| - DumpInfoTask this.monitor);
|
| + Dart2JSJavaScriptPrintingContext(
|
| + this.compiler,
|
| + this.monitor,
|
| + this.outBuffer,
|
| + this.codePositionListener);
|
|
|
| @override
|
| void error(String message) {
|
| @@ -48,40 +60,17 @@ class Dart2JSJavaScriptPrintingContext implements JavaScriptPrintingContext {
|
| }
|
|
|
| @override
|
| - void enterNode(Node node, int startPosition) {
|
| - SourceInformation sourceInformation = node.sourceInformation;
|
| - if (sourceInformation != null) {
|
| - if (rootNode == null) {
|
| - rootNode = node;
|
| - }
|
| - if (sourceInformation.startPosition != null) {
|
| - outBuffer.addSourceLocation(
|
| - startPosition, sourceInformation.startPosition);
|
| - }
|
| - }
|
| - }
|
| + void enterNode(Node, int startPosition) {}
|
|
|
| + @override
|
| void exitNode(Node node,
|
| int startPosition,
|
| int endPosition,
|
| int closingPosition) {
|
| - SourceInformation sourceInformation = node.sourceInformation;
|
| - if (sourceInformation != null) {
|
| - if (closingPosition != null &&
|
| - sourceInformation.closingPosition != null) {
|
| - outBuffer.addSourceLocation(
|
| - closingPosition, sourceInformation.closingPosition);
|
| - }
|
| - if (sourceInformation.endPosition != null) {
|
| - outBuffer.addSourceLocation(endPosition, sourceInformation.endPosition);
|
| - }
|
| - if (rootNode == node) {
|
| - outBuffer.addSourceLocation(endPosition, null);
|
| - rootNode = null;
|
| - }
|
| - }
|
| if (monitor != null) {
|
| monitor.recordAstSize(node, endPosition - startPosition);
|
| }
|
| + codePositionListener.onPositions(
|
| + node, startPosition, endPosition, closingPosition);
|
| }
|
| }
|
|
|