| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 // Test that parameters keep their names in the output. | |
| 5 | |
| 6 #import("compiler_helper.dart"); | |
| 7 #import("parser_helper.dart"); | |
| 8 | |
| 9 final String TEST_ONE = @""" | |
| 10 class A { foo() => 499; } | |
| 11 class B { bar() => 42; } | |
| 12 | |
| 13 main() { | |
| 14 new A().foo(); | |
| 15 new B().bar(); | |
| 16 } | |
| 17 """; | |
| 18 | |
| 19 final String TEST_TWO = @""" | |
| 20 class A { | |
| 21 foo() => 499; | |
| 22 bar() => 42; | |
| 23 } | |
| 24 | |
| 25 main() { | |
| 26 new A().foo(); | |
| 27 new A().bar(); | |
| 28 } | |
| 29 """; | |
| 30 | |
| 31 final String TEST_THREE = @""" | |
| 32 class A { | |
| 33 foo() => 499; | |
| 34 bar() => 42; | |
| 35 } | |
| 36 | |
| 37 class B extends A { | |
| 38 foo() => -499; | |
| 39 bar() => -42; | |
| 40 } | |
| 41 | |
| 42 var y; | |
| 43 foo(i) { | |
| 44 if (0 != i) { | |
| 45 y--; | |
| 46 foo(i - 1); | |
| 47 y++; | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 makeStaticInliningHard() { | |
| 52 y = 0; | |
| 53 foo(10); | |
| 54 return 0 == y; | |
| 55 } | |
| 56 | |
| 57 | |
| 58 // id returns [x] in a way that should be difficult to predict statically. | |
| 59 id(x) { | |
| 60 y = x; | |
| 61 foo(10); | |
| 62 return y; | |
| 63 } | |
| 64 | |
| 65 main() { | |
| 66 var a = new A(); | |
| 67 var b = new B(); | |
| 68 var x = a; | |
| 69 if (makeStaticInliningHard()) x = b; | |
| 70 x.foo(); | |
| 71 x.bar(); | |
| 72 } | |
| 73 """; | |
| 74 | |
| 75 final String TEST_FOUR = @""" | |
| 76 class A { foo() => 499; } | |
| 77 | |
| 78 foo(f) { f(); } | |
| 79 | |
| 80 main() { | |
| 81 foo(new A().foo); | |
| 82 } | |
| 83 """; | |
| 84 | |
| 85 main() { | |
| 86 // At some point Dart2js generated bad object literals with dangling commas: | |
| 87 // { a: true, }. Make sure this doesn't happen again. | |
| 88 RegExp danglingComma = const RegExp(@',[ \n]*}'); | |
| 89 String generated = compileAll(TEST_ONE); | |
| 90 Expect.isFalse(danglingComma.hasMatch(generated)); | |
| 91 | |
| 92 generated = compileAll(TEST_TWO); | |
| 93 Expect.isFalse(danglingComma.hasMatch(generated)); | |
| 94 | |
| 95 generated = compileAll(TEST_THREE); | |
| 96 Expect.isFalse(danglingComma.hasMatch(generated)); | |
| 97 | |
| 98 generated = compileAll(TEST_FOUR); | |
| 99 Expect.isFalse(danglingComma.hasMatch(generated)); | |
| 100 } | |
| OLD | NEW |