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

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

Issue 917033002: Redo "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 | « pkg/compiler/lib/src/js/characters.dart ('k') | pkg/compiler/lib/src/js/js_ast.dart » ('j') | no next file with comments »
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..a5bbec4244f1ea5c3ffa605e2a1c4010f1f6a322 100644
--- a/pkg/compiler/lib/src/js/js.dart
+++ b/pkg/compiler/lib/src/js/js.dart
@@ -1,23 +1,64 @@
-// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library js;
-import 'precedence.dart';
-import '../util/characters.dart' as charCodes;
-import '../util/util.dart';
+// TODO(sra): This will become a package import.
+import 'js_ast.dart';
+export 'js_ast.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;
-
-// TODO(floitsch): remove this dependency (currently necessary for the
-// CodeBuffer).
import '../dart2jslib.dart' as leg;
+import '../util/util.dart' show NO_LOCATION_SPANNABLE;
+import '../dump_info.dart' show DumpInfoTask;
+
+
+CodeBuffer prettyPrint(Node node, leg.Compiler compiler,
+ {DumpInfoTask monitor,
+ bool allowVariableMinification: true}) {
+ JavaScriptPrintingOptions options = new JavaScriptPrintingOptions(
+ shouldCompressOutput: compiler.enableMinification,
+ minifyLocalVariables: allowVariableMinification,
+ preferSemicolonToNewlineInMinifiedOutput: USE_NEW_EMITTER);
+ Dart2JSJavaScriptPrintingContext context =
+ new Dart2JSJavaScriptPrintingContext(compiler, monitor);
+ Printer printer = new Printer(options, context);
+ printer.visit(node);
+ return context.outBuffer;
+}
+
+class Dart2JSJavaScriptPrintingContext implements 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);
+ }
-import '../dump_info.dart';
+ void enterNode(Node node) {
+ SourceInformation sourceInformation = node.sourceInformation;
+ if (sourceInformation != null) {
+ sourceInformation.beginMapping(outBuffer);
+ }
+ if (monitor != null) monitor.enteringAst(node, outBuffer.length);
+ }
-part 'nodes.dart';
-part 'builder.dart';
-part 'printer.dart';
-part 'template.dart';
+ void exitNode(Node node) {
+ if (monitor != null) monitor.exitingAst(node, outBuffer.length);
+ SourceInformation sourceInformation = node.sourceInformation;
+ if (sourceInformation != null) {
+ sourceInformation.endMapping(outBuffer);
+ }
+ }
+}
« no previous file with comments | « pkg/compiler/lib/src/js/characters.dart ('k') | pkg/compiler/lib/src/js/js_ast.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698