| OLD | NEW |
| 1 // Copyright (c) 2015, 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 /// Helper for debug JS nodes. | 5 /// Helper for debug JS nodes. |
| 6 | 6 |
| 7 library js.debug; | 7 library js.debug; |
| 8 | 8 |
| 9 import 'package:js_ast/js_ast.dart'; | 9 import 'package:js_ast/js_ast.dart'; |
| 10 import '../util/util.dart' show Indentation, Tagging; | 10 |
| 11 import '../io/code_output.dart' show |
| 12 BufferedCodeOutput; |
| 13 import '../util/util.dart' show |
| 14 Indentation, |
| 15 Tagging; |
| 11 | 16 |
| 12 /// Unparse the JavaScript [node]. | 17 /// Unparse the JavaScript [node]. |
| 13 String nodeToString(Node node) { | 18 String nodeToString(Node node) { |
| 14 JavaScriptPrintingOptions options = new JavaScriptPrintingOptions( | 19 JavaScriptPrintingOptions options = new JavaScriptPrintingOptions( |
| 15 shouldCompressOutput: true, | 20 shouldCompressOutput: true, |
| 16 preferSemicolonToNewlineInMinifiedOutput: true); | 21 preferSemicolonToNewlineInMinifiedOutput: true); |
| 17 LenientPrintingContext printingContext = | 22 LenientPrintingContext printingContext = |
| 18 new LenientPrintingContext(); | 23 new LenientPrintingContext(); |
| 19 new Printer(options, printingContext).visit(node); | 24 new Printer(options, printingContext).visit(node); |
| 20 return printingContext.getText(); | 25 return printingContext.getText(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 50 * Pretty-prints given node tree into string. | 55 * Pretty-prints given node tree into string. |
| 51 */ | 56 */ |
| 52 static String prettyPrint(Node node) { | 57 static String prettyPrint(Node node) { |
| 53 var p = new DebugPrinter(); | 58 var p = new DebugPrinter(); |
| 54 node.accept(p); | 59 node.accept(p); |
| 55 return p.sb.toString(); | 60 return p.sb.toString(); |
| 56 } | 61 } |
| 57 } | 62 } |
| 58 | 63 |
| 59 /// Simple printing context that doesn't throw on errors. | 64 /// Simple printing context that doesn't throw on errors. |
| 60 class LenientPrintingContext extends SimpleJavaScriptPrintingContext { | 65 class LenientPrintingContext extends SimpleJavaScriptPrintingContext |
| 66 implements BufferedCodeOutput { |
| 61 @override | 67 @override |
| 62 void error(String message) { | 68 void error(String message) { |
| 63 buffer.write('>>$message<<'); | 69 buffer.write('>>$message<<'); |
| 64 } | 70 } |
| 65 } | 71 } |
| OLD | NEW |