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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library js; 5 library js;
6 6
7 import 'precedence.dart'; 7 // TODO(sra): This will become a package import.
8 import '../util/characters.dart' as charCodes; 8 import 'js_ast.dart';
9 import '../util/util.dart'; 9 export 'js_ast.dart';
10
10 import '../io/code_output.dart' show CodeBuffer; 11 import '../io/code_output.dart' show CodeBuffer;
11 import '../io/source_information.dart' show SourceInformation; 12 import '../io/source_information.dart' show SourceInformation;
12 import '../js_emitter/js_emitter.dart' show USE_NEW_EMITTER; 13 import '../js_emitter/js_emitter.dart' show USE_NEW_EMITTER;
14 import '../dart2jslib.dart' as leg;
15 import '../util/util.dart' show NO_LOCATION_SPANNABLE;
16 import '../dump_info.dart' show DumpInfoTask;
13 17
14 // TODO(floitsch): remove this dependency (currently necessary for the
15 // CodeBuffer).
16 import '../dart2jslib.dart' as leg;
17 18
18 import '../dump_info.dart'; 19 CodeBuffer prettyPrint(Node node, leg.Compiler compiler,
20 {DumpInfoTask monitor,
21 bool allowVariableMinification: true}) {
22 JavaScriptPrintingOptions options = new JavaScriptPrintingOptions(
23 shouldCompressOutput: compiler.enableMinification,
24 minifyLocalVariables: allowVariableMinification,
25 preferSemicolonToNewlineInMinifiedOutput: USE_NEW_EMITTER);
26 Dart2JSJavaScriptPrintingContext context =
27 new Dart2JSJavaScriptPrintingContext(compiler, monitor);
28 Printer printer = new Printer(options, context);
29 printer.visit(node);
30 return context.outBuffer;
31 }
19 32
20 part 'nodes.dart'; 33 class Dart2JSJavaScriptPrintingContext implements JavaScriptPrintingContext {
21 part 'builder.dart'; 34 final leg.Compiler compiler;
22 part 'printer.dart'; 35 final DumpInfoTask monitor;
23 part 'template.dart'; 36 final CodeBuffer outBuffer = new CodeBuffer();
37
38 Dart2JSJavaScriptPrintingContext(leg.Compiler this.compiler,
39 DumpInfoTask this.monitor);
40
41 void error(String message) {
42 compiler.internalError(NO_LOCATION_SPANNABLE, message);
43 }
44
45 void emit(String string) {
46 outBuffer.add(string);
47 }
48
49 void enterNode(Node node) {
50 SourceInformation sourceInformation = node.sourceInformation;
51 if (sourceInformation != null) {
52 sourceInformation.beginMapping(outBuffer);
53 }
54 if (monitor != null) monitor.enteringAst(node, outBuffer.length);
55 }
56
57 void exitNode(Node node) {
58 if (monitor != null) monitor.exitingAst(node, outBuffer.length);
59 SourceInformation sourceInformation = node.sourceInformation;
60 if (sourceInformation != null) {
61 sourceInformation.endMapping(outBuffer);
62 }
63 }
64 }
OLDNEW
« 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