| 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 fac460db21e1eb06b98edb6564ef455db4cc36a8..87a346837e22b0fe9319996bbdf46e3b9fc80b21 100644
|
| --- a/pkg/compiler/lib/src/js/js.dart
|
| +++ b/pkg/compiler/lib/src/js/js.dart
|
| @@ -5,19 +5,66 @@
|
| library js;
|
|
|
| import 'precedence.dart';
|
| -import '../util/characters.dart' as charCodes;
|
| -import '../util/util.dart';
|
| -import '../io/code_output.dart' show CodeBuffer;
|
| -import '../io/source_information.dart' show SourceInformation;
|
| -import '../js_emitter/js_emitter.dart' show USE_NEW_EMITTER;
|
| +import '../util/characters.dart' as charCodes; // TODO(sra): Local copy of used constants.
|
| +import '../io/code_output.dart' show CodeBuffer; // TODO(sra): Remove.
|
| +import '../io/source_information.dart' show SourceInformation; // TODO(sra): Remove.
|
| +import '../js_emitter/js_emitter.dart' show USE_NEW_EMITTER; // TODO(sra): Turn into an option.
|
|
|
| // TODO(floitsch): remove this dependency (currently necessary for the
|
| // CodeBuffer).
|
| -import '../dart2jslib.dart' as leg;
|
| +import '../dart2jslib.dart' as leg; // TODO(sra): Remove.
|
|
|
| -import '../dump_info.dart';
|
| +import '../dump_info.dart' show DumpInfoTask; // TODO(sra): Remove.
|
|
|
| part 'nodes.dart';
|
| part 'builder.dart';
|
| part 'printer.dart';
|
| part 'template.dart';
|
| +
|
| +
|
| +// The following code will be moved out of this library into js_backend. When
|
| +// this happens, most of the imports can be removed.
|
| +
|
| +CodeBuffer prettyPrint(Node node, leg.Compiler compiler,
|
| + {DumpInfoTask monitor,
|
| + bool allowVariableMinification: true}) {
|
| + JavaScriptPrintingOptions options = new JavaScriptPrintingOptions(
|
| + shouldCompressOutput: compiler.enableMinification,
|
| + minifyLocalVariables: allowVariableMinification);
|
| + Dart2JSJavaScriptPrintingContext context =
|
| + new Dart2JSJavaScriptPrintingContext(compiler, monitor);
|
| + Printer printer = new Printer(options, context);
|
| + printer.visit(node);
|
| + return context.outBuffer;
|
| +}
|
| +
|
| +class Dart2JSJavaScriptPrintingContext extends JavaScriptPrintingContext {
|
| + final leg.Compiler compiler;
|
| + final DumpInfoTask monitor;
|
| + final CodeBuffer outBuffer = new CodeBuffer();
|
| +
|
| + Dart2JSJavaScriptPrintingContext(leg.Compiler this.compiler,
|
| + DumpInfoTask this.monitor);
|
| +
|
| + void error(String message) {
|
| + compiler.internalError(NO_LOCATION_SPANNABLE, message);
|
| + }
|
| +
|
| + void emit(String string) {
|
| + outBuffer.add(string);
|
| + }
|
| +
|
| + void enterNode(Node node) {
|
| + if (node.sourceInformation != null) {
|
| + node.sourceInformation.beginMapping(outBuffer);
|
| + }
|
| + if (monitor != null) monitor.enteringAst(node, outBuffer.length);
|
| + }
|
| +
|
| + void exitNode(Node node) {
|
| + if (monitor != null) monitor.exitingAst(node, outBuffer.length);
|
| + if (node.sourceInformation != null) {
|
| + node.sourceInformation.endMapping(outBuffer);
|
| + }
|
| + }
|
| +}
|
|
|