OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 // TODO(sra): This will become a package import. | 7 import 'precedence.dart'; |
8 import 'js_ast.dart'; | 8 import '../util/characters.dart' as charCodes; |
9 export 'js_ast.dart'; | 9 import '../util/util.dart'; |
10 | |
11 import '../io/code_output.dart' show CodeBuffer; | 10 import '../io/code_output.dart' show CodeBuffer; |
12 import '../io/source_information.dart' show SourceInformation; | 11 import '../io/source_information.dart' show SourceInformation; |
13 import '../js_emitter/js_emitter.dart' show USE_NEW_EMITTER; | 12 import '../js_emitter/js_emitter.dart' show USE_NEW_EMITTER; |
| 13 |
| 14 // TODO(floitsch): remove this dependency (currently necessary for the |
| 15 // CodeBuffer). |
14 import '../dart2jslib.dart' as leg; | 16 import '../dart2jslib.dart' as leg; |
15 import '../util/util.dart' show NO_LOCATION_SPANNABLE; | |
16 import '../dump_info.dart' show DumpInfoTask; | |
17 | 17 |
| 18 import '../dump_info.dart'; |
18 | 19 |
19 CodeBuffer prettyPrint(Node node, leg.Compiler compiler, | 20 part 'nodes.dart'; |
20 {DumpInfoTask monitor, | 21 part 'builder.dart'; |
21 bool allowVariableMinification: true}) { | 22 part 'printer.dart'; |
22 JavaScriptPrintingOptions options = new JavaScriptPrintingOptions( | 23 part 'template.dart'; |
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 } | |
32 | |
33 class Dart2JSJavaScriptPrintingContext implements JavaScriptPrintingContext { | |
34 final leg.Compiler compiler; | |
35 final DumpInfoTask monitor; | |
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 } | |
OLD | NEW |