| 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 import "package:compiler/src/js/js.dart"; | 6 import "package:compiler/src/js/js.dart"; |
| 7 import "package:compiler/src/js/rewrite_async.dart"; | 7 import "package:compiler/src/js/rewrite_async.dart"; |
| 8 | 8 |
| 9 import "backend_dart/dart_printer_test.dart" show PrintDiagnosticListener; | 9 import "backend_dart/dart_printer_test.dart" show PrintDiagnosticListener; |
| 10 | 10 |
| 11 void testTransform(String source, String expected) { | 11 void testTransform(String source, String expected) { |
| 12 Fun fun = js(source); | 12 Fun fun = js(source); |
| 13 Fun rewritten = new AsyncRewriter( | 13 Fun rewritten = new AsyncRewriter( |
| 14 null, // The diagnostic helper should not be used in these tests. | 14 null, // The diagnostic helper should not be used in these tests. |
| 15 null, | 15 null, |
| 16 thenHelper: new VariableUse("thenHelper"), | 16 thenHelper: new VariableUse("thenHelper"), |
| 17 newCompleter: new VariableUse("Completer"), | 17 newCompleter: new VariableUse("Completer"), |
| 18 endOfIteration: new VariableUse("endOfIteration"), | 18 endOfIteration: new VariableUse("endOfIteration"), |
| 19 newIterable: new VariableUse("Iterator"), | 19 newIterable: new VariableUse("Iterator"), |
| 20 safeVariableName: (String name) => "__$name").rewrite(fun); | 20 safeVariableName: (String name) => "__$name").rewrite(fun); |
| 21 Printer printer = new Printer(new PrintDiagnosticListener(), null); | 21 |
| 22 JavaScriptPrintingOptions options = new JavaScriptPrintingOptions(); |
| 23 JavaScriptPrintingContext context = new SimpleJavaScriptPrintingContext(); |
| 24 Printer printer = new Printer(options, context); |
| 22 printer.visit(rewritten); | 25 printer.visit(rewritten); |
| 23 Expect.stringEquals(expected, printer.outBuffer.getText()); | 26 Expect.stringEquals(expected, context.getText()); |
| 24 } | 27 } |
| 25 | 28 |
| 26 main() { | 29 main() { |
| 27 testTransform(""" | 30 testTransform(""" |
| 28 function() async { | 31 function() async { |
| 29 print(this.x); // Ensure `this` is translated in the helper function. | 32 print(this.x); // Ensure `this` is translated in the helper function. |
| 30 await foo(); | 33 await foo(); |
| 31 }""", """ | 34 }""", """ |
| 32 function() { | 35 function() { |
| 33 var __goto = 0, __completer = new Completer(), __self = this; | 36 var __goto = 0, __completer = new Completer(), __self = this; |
| (...skipping 902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 break; | 939 break; |
| 937 case 3: | 940 case 3: |
| 938 // after while | 941 // after while |
| 939 case 1: | 942 case 1: |
| 940 // return | 943 // return |
| 941 return thenHelper(__returnValue, null, __completer, null); | 944 return thenHelper(__returnValue, null, __completer, null); |
| 942 } | 945 } |
| 943 } | 946 } |
| 944 return thenHelper(null, __helper, __completer, null); | 947 return thenHelper(null, __helper, __completer, null); |
| 945 }"""); | 948 }"""); |
| 946 } | 949 } |
| OLD | NEW |