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 | 21 Printer printer = new Printer(new PrintDiagnosticListener(), null); |
22 JavaScriptPrintingOptions options = new JavaScriptPrintingOptions(); | |
23 JavaScriptPrintingContext context = new SimpleJavaScriptPrintingContext(); | |
24 Printer printer = new Printer(options, context); | |
25 printer.visit(rewritten); | 22 printer.visit(rewritten); |
26 Expect.stringEquals(expected, context.getText()); | 23 Expect.stringEquals(expected, printer.outBuffer.getText()); |
27 } | 24 } |
28 | 25 |
29 main() { | 26 main() { |
30 testTransform(""" | 27 testTransform(""" |
31 function() async { | 28 function() async { |
32 print(this.x); // Ensure `this` is translated in the helper function. | 29 print(this.x); // Ensure `this` is translated in the helper function. |
33 await foo(); | 30 await foo(); |
34 }""", """ | 31 }""", """ |
35 function() { | 32 function() { |
36 var __goto = 0, __completer = new Completer(), __self = this; | 33 var __goto = 0, __completer = new Completer(), __self = this; |
(...skipping 902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 break; | 936 break; |
940 case 3: | 937 case 3: |
941 // after while | 938 // after while |
942 case 1: | 939 case 1: |
943 // return | 940 // return |
944 return thenHelper(__returnValue, null, __completer, null); | 941 return thenHelper(__returnValue, null, __completer, null); |
945 } | 942 } |
946 } | 943 } |
947 return thenHelper(null, __helper, __completer, null); | 944 return thenHelper(null, __helper, __completer, null); |
948 }"""); | 945 }"""); |
949 } | 946 } |
OLD | NEW |