| 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 library source_map_name_test; | 5 library source_map_name_test; |
| 6 | 6 |
| 7 import 'package:async_helper/async_helper.dart'; | 7 import 'package:async_helper/async_helper.dart'; |
| 8 import 'package:expect/expect.dart'; | 8 import 'package:expect/expect.dart'; |
| 9 import 'package:compiler/src/compiler.dart'; | 9 import 'package:compiler/src/compiler.dart'; |
| 10 import 'package:compiler/src/elements/elements.dart'; | 10 import 'package:compiler/src/elements/elements.dart'; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 c = new Class.named(); | 66 c = new Class.named(); |
| 67 c.instanceField = c.instanceMethod(); | 67 c.instanceField = c.instanceMethod(); |
| 68 c.instanceAnonymous(); | 68 c.instanceAnonymous(); |
| 69 c.instanceLocal(); | 69 c.instanceLocal(); |
| 70 c.instanceNestedLocal(); | 70 c.instanceNestedLocal(); |
| 71 } | 71 } |
| 72 '''; | 72 '''; |
| 73 | 73 |
| 74 check(Element element, String expectedName) { | 74 check(Element element, String expectedName) { |
| 75 String name = computeElementNameForSourceMaps(element); | 75 String name = computeElementNameForSourceMaps(element); |
| 76 Expect.equals( | 76 Expect.equals(expectedName, name, |
| 77 expectedName, | |
| 78 name, | |
| 79 "Unexpected name '$name' for $element, expected '$expectedName'."); | 77 "Unexpected name '$name' for $element, expected '$expectedName'."); |
| 80 } | 78 } |
| 81 | 79 |
| 82 main() { | 80 main() { |
| 83 asyncTest(() async { | 81 asyncTest(() async { |
| 84 CompilationResult result = | 82 CompilationResult result = |
| 85 await runCompiler(memorySourceFiles: {'main.dart': SOURCE}); | 83 await runCompiler(memorySourceFiles: {'main.dart': SOURCE}); |
| 86 Compiler compiler = result.compiler; | 84 Compiler compiler = result.compiler; |
| 87 | 85 |
| 88 Element lookup(String name) { | 86 Element lookup(String name) { |
| 89 Element element; | 87 Element element; |
| 90 int dotPosition = name.indexOf('.'); | 88 int dotPosition = name.indexOf('.'); |
| 91 if (dotPosition != -1) { | 89 if (dotPosition != -1) { |
| 92 String clsName = name.substring(0, dotPosition); | 90 String clsName = name.substring(0, dotPosition); |
| 93 ClassElement cls = compiler.mainApp.find(clsName); | 91 ClassElement cls = compiler.mainApp.find(clsName); |
| 94 Expect.isNotNull(cls, "Class '$clsName' not found."); | 92 Expect.isNotNull(cls, "Class '$clsName' not found."); |
| 95 element = cls.localLookup(name.substring(dotPosition + 1)); | 93 element = cls.localLookup(name.substring(dotPosition + 1)); |
| 96 } else { | 94 } else { |
| 97 element = compiler.mainApp.find(name); | 95 element = compiler.mainApp.find(name); |
| 98 } | 96 } |
| 99 Expect.isNotNull(element, "Element '$name' not found."); | 97 Expect.isNotNull(element, "Element '$name' not found."); |
| 100 return element; | 98 return element; |
| 101 } | 99 } |
| 102 | 100 |
| 103 void checkName(String expectedName, | 101 void checkName(String expectedName, |
| 104 [List<String> expectedClosureNames, | 102 [List<String> expectedClosureNames, String lookupName]) { |
| 105 String lookupName]) { | |
| 106 if (lookupName == null) { | 103 if (lookupName == null) { |
| 107 lookupName = expectedName; | 104 lookupName = expectedName; |
| 108 } | 105 } |
| 109 var element = lookup(lookupName); | 106 var element = lookup(lookupName); |
| 110 check(element, expectedName); | 107 check(element, expectedName); |
| 111 if (element.isConstructor) { | 108 if (element.isConstructor) { |
| 112 var constructorBody = | 109 var constructorBody = |
| 113 element.enclosingClass.lookupBackendMember(element.name); | 110 element.enclosingClass.lookupBackendMember(element.name); |
| 114 Expect.isNotNull(element, | 111 Expect.isNotNull( |
| 115 "Constructor body '${element.name}' not found."); | 112 element, "Constructor body '${element.name}' not found."); |
| 116 check(constructorBody, expectedName); | 113 check(constructorBody, expectedName); |
| 117 } | 114 } |
| 118 | 115 |
| 119 if (expectedClosureNames != null) { | 116 if (expectedClosureNames != null) { |
| 120 int index = 0; | 117 int index = 0; |
| 121 for (var closure in element.nestedClosures) { | 118 for (var closure in element.nestedClosures) { |
| 122 String expectedName = expectedClosureNames[index]; | 119 String expectedName = expectedClosureNames[index]; |
| 123 check(closure, expectedName); | 120 check(closure, expectedName); |
| 124 check(closure.expression, expectedName); | 121 check(closure.expression, expectedName); |
| 125 check(closure.enclosingClass, expectedName); | 122 check(closure.enclosingClass, expectedName); |
| 126 index++; | 123 index++; |
| 127 } | 124 } |
| 128 } | 125 } |
| 129 } | 126 } |
| 130 | 127 |
| 131 checkName('toplevelField'); | 128 checkName('toplevelField'); |
| 132 checkName('toplevelMethod'); | 129 checkName('toplevelMethod'); |
| 133 checkName('toplevelAnonymous', | 130 checkName('toplevelAnonymous', ['toplevelAnonymous.<anonymous function>']); |
| 134 ['toplevelAnonymous.<anonymous function>']); | 131 checkName('toplevelLocal', ['toplevelLocal.localMethod']); |
| 135 checkName('toplevelLocal', | |
| 136 ['toplevelLocal.localMethod']); | |
| 137 checkName('Class'); | 132 checkName('Class'); |
| 138 checkName('main'); | 133 checkName('main'); |
| 139 | 134 |
| 140 checkName('Class.staticField'); | 135 checkName('Class.staticField'); |
| 141 checkName('Class.staticMethod'); | 136 checkName('Class.staticMethod'); |
| 142 checkName('Class.staticAnonymous', | 137 checkName('Class.staticAnonymous', |
| 143 ['Class.staticAnonymous.<anonymous function>']); | 138 ['Class.staticAnonymous.<anonymous function>']); |
| 144 checkName('Class.staticLocal', | 139 checkName('Class.staticLocal', ['Class.staticLocal.localMethod']); |
| 145 ['Class.staticLocal.localMethod']); | |
| 146 | 140 |
| 147 checkName('Class', | 141 checkName('Class', ['Class.<anonymous function>'], 'Class.'); |
| 148 ['Class.<anonymous function>'], | 142 checkName('Class.named', ['Class.named.localMethod']); |
| 149 'Class.'); | |
| 150 checkName('Class.named', | |
| 151 ['Class.named.localMethod']); | |
| 152 | 143 |
| 153 checkName('Class.instanceField'); | 144 checkName('Class.instanceField'); |
| 154 checkName('Class.instanceMethod'); | 145 checkName('Class.instanceMethod'); |
| 155 checkName('Class.instanceAnonymous', | 146 checkName('Class.instanceAnonymous', |
| 156 ['Class.instanceAnonymous.<anonymous function>']); | 147 ['Class.instanceAnonymous.<anonymous function>']); |
| 157 checkName('Class.instanceLocal', | 148 checkName('Class.instanceLocal', ['Class.instanceLocal.localMethod']); |
| 158 ['Class.instanceLocal.localMethod']); | 149 checkName('Class.instanceNestedLocal', [ |
| 159 checkName('Class.instanceNestedLocal', | 150 'Class.instanceNestedLocal.localMethod', |
| 160 ['Class.instanceNestedLocal.localMethod', | 151 'Class.instanceNestedLocal.localMethod.<anonymous function>', |
| 161 'Class.instanceNestedLocal.localMethod.<anonymous function>', | 152 'Class.instanceNestedLocal.localMethod.nestedLocalMethod' |
| 162 'Class.instanceNestedLocal.localMethod.nestedLocalMethod']); | 153 ]); |
| 163 | |
| 164 | |
| 165 }); | 154 }); |
| 166 } | 155 } |
| OLD | NEW |