| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'package:expect/expect.dart'; | 6 import 'package:expect/expect.dart'; |
| 7 import 'package:async_helper/async_helper.dart'; | 7 import 'package:async_helper/async_helper.dart'; |
| 8 import 'mock_compiler.dart'; | 8 import 'mock_compiler.dart'; |
| 9 import 'package:compiler/src/js/js.dart' as jsAst; | 9 import 'package:compiler/src/js/js.dart' as jsAst; |
| 10 import 'package:compiler/src/js/js.dart' show js; | 10 import 'package:compiler/src/js/js.dart' show js; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 function foo() { | 69 function foo() { |
| 70 /a/; | 70 /a/; |
| 71 1; | 71 1; |
| 72 2; | 72 2; |
| 73 }'''; | 73 }'''; |
| 74 | 74 |
| 75 | 75 |
| 76 void main() { | 76 void main() { |
| 77 | 77 |
| 78 var eOne = js('1'); | 78 var eOne = js('1'); |
| 79 var eTwo = js('2'); |
| 79 var eTrue = js('true'); | 80 var eTrue = js('true'); |
| 80 var eVar = js('x'); | 81 var eVar = js('x'); |
| 81 var block12 = js.statement('{ 1; 2; }'); | 82 var block12 = js.statement('{ 1; 2; }'); |
| 83 var stm = js.statement('foo();'); |
| 82 var seq1 = js('1, 2, 3'); | 84 var seq1 = js('1, 2, 3'); |
| 83 | 85 |
| 84 Expect.isTrue(eOne is jsAst.LiteralNumber); | 86 Expect.isTrue(eOne is jsAst.LiteralNumber); |
| 85 Expect.isTrue(eTrue is jsAst.LiteralBool); | 87 Expect.isTrue(eTrue is jsAst.LiteralBool); |
| 86 Expect.isTrue(block12 is jsAst.Block); | 88 Expect.isTrue(block12 is jsAst.Block); |
| 87 | 89 |
| 88 asyncTest(() => Future.wait([ | 90 asyncTest(() => Future.wait([ |
| 89 // Interpolated Expressions are upgraded to ExpressionStatements. | 91 // Interpolated Expressions are upgraded to ExpressionStatements. |
| 90 testStatement('{ #; #; }', [eOne, eOne], '{\n 1;\n 1;\n}'), | 92 testStatement('{ #; #; }', [eOne, eOne], '{\n 1;\n 1;\n}'), |
| 91 testStatement('{ #a; #b; }', {'a': eOne, 'b': eOne}, '{\n 1;\n 1;\n}'), | 93 testStatement('{ #a; #b; }', {'a': eOne, 'b': eOne}, '{\n 1;\n 1;\n}'), |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 testStatement('if (#a) #b;', | 126 testStatement('if (#a) #b;', |
| 125 {'a': false, 'b': block12}, | 127 {'a': false, 'b': block12}, |
| 126 ';'), | 128 ';'), |
| 127 testStatement('if (#a) 3; else #b;', | 129 testStatement('if (#a) 3; else #b;', |
| 128 {'a': true, 'b': block12}, | 130 {'a': true, 'b': block12}, |
| 129 '3;'), | 131 '3;'), |
| 130 testStatement('if (#a) 3; else #b;', | 132 testStatement('if (#a) 3; else #b;', |
| 131 {'a': false, 'b': block12}, | 133 {'a': false, 'b': block12}, |
| 132 '{\n 1;\n 2;\n}'), | 134 '{\n 1;\n 2;\n}'), |
| 133 | 135 |
| 136 testStatement('while (#) #', [eOne, block12], 'while (1) {\n 1;\n 2;\n}'), |
| 137 testStatement('while (#) #;', [eTrue, block12], |
| 138 'while (true) {\n 1;\n 2;\n}'), |
| 139 testStatement('while (#) #;', [eVar, block12], |
| 140 'while (x) {\n 1;\n 2;\n}'), |
| 141 testStatement('while (#) #;', ['a', block12], |
| 142 'while (a) {\n 1;\n 2;\n}'), |
| 143 testStatement('while (#) #;', ['a', stm], |
| 144 'while (a)\n foo();'), |
| 145 |
| 146 testStatement( |
| 147 'do { {print(1);} do while(true); while (false) } while ( true )', [], |
| 148 ''' |
| 149 do { |
| 150 print(1); |
| 151 do |
| 152 while (true) |
| 153 ; |
| 154 while (false); |
| 155 } while (true); |
| 156 '''), |
| 157 testStatement('do #; while ( # )', [block12, eOne], |
| 158 'do {\n 1;\n 2;\n} while (1); '), |
| 159 testStatement('do #; while ( # )', [block12, eTrue], |
| 160 'do {\n 1;\n 2;\n} while (true); '), |
| 161 testStatement('do #; while ( # );', [block12, eVar], |
| 162 'do {\n 1;\n 2;\n} while (x);'), |
| 163 testStatement('do { # } while ( # )', [block12, 'a'], |
| 164 'do {\n 1;\n 2;\n} while (a);'), |
| 165 testStatement('do #; while ( # )', [stm, 'a'], |
| 166 'do\n foo();\nwhile (a);'), |
| 167 |
| 168 testStatement('switch (#) {}', [eOne], 'switch (1) {\n}'), |
| 169 testStatement(''' |
| 170 switch (#) { |
| 171 case #: { # } |
| 172 }''', [eTrue, eOne, block12], |
| 173 'switch (true) {\n case 1:\n 1;\n 2;\n}'), |
| 174 testStatement(''' |
| 175 switch (#) { |
| 176 case #: { # } |
| 177 break; |
| 178 case #: { # } |
| 179 default: { # } |
| 180 }''', [eTrue, eOne, block12, eTwo, block12, stm], ''' |
| 181 switch (true) { |
| 182 case 1: |
| 183 1; |
| 184 2; |
| 185 break; |
| 186 case 2: |
| 187 1; |
| 188 2; |
| 189 default: |
| 190 foo(); |
| 191 }'''), |
| 134 | 192 |
| 135 testStatement(NAMED_FUNCTION_1, [eOne], NAMED_FUNCTION_1_ONE), | 193 testStatement(NAMED_FUNCTION_1, [eOne], NAMED_FUNCTION_1_ONE), |
| 136 testStatement(NAMED_FUNCTION_1_NAMED_HOLE, | 194 testStatement(NAMED_FUNCTION_1_NAMED_HOLE, |
| 137 {'hole': eOne}, | 195 {'hole': eOne}, |
| 138 NAMED_FUNCTION_1_ONE), | 196 NAMED_FUNCTION_1_ONE), |
| 139 | 197 |
| 140 testStatement(MISC_1, [block12], MISC_1_1), | 198 testStatement(MISC_1, [block12], MISC_1_1), |
| 141 testStatement(MISC_1_NAMED_HOLE, {'hole': block12}, MISC_1_1), | 199 testStatement(MISC_1_NAMED_HOLE, {'hole': block12}, MISC_1_1), |
| 142 | 200 |
| 143 // Argument list splicing. | 201 // Argument list splicing. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 testStatement('function foo(#){}', [['x', 'y']], 'function foo(x, y) {\n}'), | 251 testStatement('function foo(#){}', [['x', 'y']], 'function foo(x, y) {\n}'), |
| 194 testStatement('function foo(#a){}', {'a': new jsAst.Parameter('x')}, | 252 testStatement('function foo(#a){}', {'a': new jsAst.Parameter('x')}, |
| 195 'function foo(x) {\n}'), | 253 'function foo(x) {\n}'), |
| 196 testStatement('function foo(#a){}', {'a': 'x'}, 'function foo(x) {\n}'), | 254 testStatement('function foo(#a){}', {'a': 'x'}, 'function foo(x) {\n}'), |
| 197 testStatement('function foo(#a){}', {'a': []}, 'function foo() {\n}'), | 255 testStatement('function foo(#a){}', {'a': []}, 'function foo() {\n}'), |
| 198 testStatement('function foo(#a){}', {'a': ['x']}, 'function foo(x) {\n}'), | 256 testStatement('function foo(#a){}', {'a': ['x']}, 'function foo(x) {\n}'), |
| 199 testStatement('function foo(#a){}', | 257 testStatement('function foo(#a){}', |
| 200 {'a': ['x', 'y']}, | 258 {'a': ['x', 'y']}, |
| 201 'function foo(x, y) {\n}'), | 259 'function foo(x, y) {\n}'), |
| 202 | 260 |
| 261 testStatement('function foo() async {}', [], 'function foo() async {\n}'), |
| 262 testStatement('function foo() sync* {}', [], 'function foo() sync* {\n}'), |
| 263 testStatement('function foo() async* {}', [], 'function foo() async* {\n}'), |
| 264 |
| 203 testStatement('a = #.#', [eVar,eOne], 'a = x[1];'), | 265 testStatement('a = #.#', [eVar,eOne], 'a = x[1];'), |
| 204 testStatement('a = #.#', [eVar,'foo'], 'a = x.foo;'), | 266 testStatement('a = #.#', [eVar,'foo'], 'a = x.foo;'), |
| 205 testStatement('a = #a.#b', {'a': eVar, 'b': eOne}, 'a = x[1];'), | 267 testStatement('a = #a.#b', {'a': eVar, 'b': eOne}, 'a = x[1];'), |
| 206 testStatement('a = #a.#b', {'a': eVar, 'b': 'foo'}, 'a = x.foo;'), | 268 testStatement('a = #a.#b', {'a': eVar, 'b': 'foo'}, 'a = x.foo;'), |
| 207 | 269 |
| 208 testStatement('function f(#) { return #.#; }', ['x', eVar,'foo'], | 270 testStatement('function f(#) { return #.#; }', ['x', eVar,'foo'], |
| 209 'function f(x) {\n return x.foo;\n}'), | 271 'function f(x) {\n return x.foo;\n}'), |
| 210 testStatement('function f(#a) { return #b.#c; }', | 272 testStatement('function f(#a) { return #b.#c; }', |
| 211 {'a': 'x', 'b': eVar, 'c': 'foo'}, | 273 {'a': 'x', 'b': eVar, 'c': 'foo'}, |
| 212 'function f(x) {\n return x.foo;\n}'), | 274 'function f(x) {\n return x.foo;\n}'), |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 | 315 |
| 254 // Use the same name several times. | 316 // Use the same name several times. |
| 255 testStatement('#a.prototype.#a = function(#b) { return #c.#c };', | 317 testStatement('#a.prototype.#a = function(#b) { return #c.#c };', |
| 256 {'a': 'name1_2', | 318 {'a': 'name1_2', |
| 257 'b': ['r', 'y'], | 319 'b': ['r', 'y'], |
| 258 'c': 'name4_5'}, | 320 'c': 'name4_5'}, |
| 259 'name1_2.prototype.name1_2 = function(r, y) {\n' | 321 'name1_2.prototype.name1_2 = function(r, y) {\n' |
| 260 ' return name4_5.name4_5;\n' | 322 ' return name4_5.name4_5;\n' |
| 261 '};'), | 323 '};'), |
| 262 | 324 |
| 325 testStatement('label: while (a) { label2: break label;}', [], |
| 326 'label:\n while (a) {\n label2:\n break label;\n }'), |
| 327 |
| 263 ])); | 328 ])); |
| 264 } | 329 } |
| OLD | NEW |