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

Unified Diff: pkg/compiler/lib/src/js/js.dart

Issue 915533002: Steps towards making dart2js JS AST templates an indepentent library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js/nodes.dart » ('j') | pkg/compiler/lib/src/js/printer.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
+ }
+ }
+}
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js/nodes.dart » ('j') | pkg/compiler/lib/src/js/printer.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698