| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 /** | 5 /** |
| 6 * Assigns JavaScript identifiers to Dart variables, class-names and members. | 6 * Assigns JavaScript identifiers to Dart variables, class-names and members. |
| 7 */ | 7 */ |
| 8 class Namer { | 8 class Namer { |
| 9 final Compiler compiler; | 9 final Compiler compiler; |
| 10 | 10 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 | 171 |
| 172 /** | 172 /** |
| 173 * Returns a preferred JS-id for the given top-level or static element. | 173 * Returns a preferred JS-id for the given top-level or static element. |
| 174 * The returned id is guaranteed to be a valid JS-id. | 174 * The returned id is guaranteed to be a valid JS-id. |
| 175 */ | 175 */ |
| 176 String _computeGuess(Element element) { | 176 String _computeGuess(Element element) { |
| 177 assert(!element.isInstanceMember()); | 177 assert(!element.isInstanceMember()); |
| 178 LibraryElement lib = element.getLibrary(); | 178 LibraryElement lib = element.getLibrary(); |
| 179 String name; | 179 String name; |
| 180 if (element.isGenerativeConstructor()) { | 180 if (element.isGenerativeConstructor()) { |
| 181 if (element.name == element.enclosingElement.name) { | 181 if (element.name == element.getEnclosingClass().name) { |
| 182 // Keep the class name for the class and not the factory. | 182 // Keep the class name for the class and not the factory. |
| 183 name = "${element.name.slowToString()}\$"; | 183 name = "${element.name.slowToString()}\$"; |
| 184 } else { | 184 } else { |
| 185 name = element.name.slowToString(); | 185 name = element.name.slowToString(); |
| 186 } | 186 } |
| 187 } else if (Elements.isStaticOrTopLevel(element)) { | 187 } else if (Elements.isStaticOrTopLevel(element)) { |
| 188 if (element.enclosingElement != null && | 188 if (element.isMember()) { |
| 189 element.enclosingElement.isClass()) { | 189 ClassElement enclosingClass = element.getEnclosingClass(); |
| 190 name = "${element.enclosingElement.name.slowToString()}_" | 190 name = "${enclosingClass.name.slowToString()}_" |
| 191 "${element.name.slowToString()}"; | 191 "${element.name.slowToString()}"; |
| 192 } else { | 192 } else { |
| 193 name = element.name.slowToString(); | 193 name = element.name.slowToString(); |
| 194 } | 194 } |
| 195 } else if (element.kind === ElementKind.LIBRARY) { | 195 } else if (element.kind === ElementKind.LIBRARY) { |
| 196 name = LIBRARY_PREFIX; | 196 name = LIBRARY_PREFIX; |
| 197 } else { | 197 } else { |
| 198 name = element.name.slowToString(); | 198 name = element.name.slowToString(); |
| 199 } | 199 } |
| 200 // Prefix the name with '$' if it is reserved. | 200 // Prefix the name with '$' if it is reserved. |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 } | 283 } |
| 284 | 284 |
| 285 String safeName(String name) { | 285 String safeName(String name) { |
| 286 if (jsReserved.contains(name) || name.startsWith('\$')) { | 286 if (jsReserved.contains(name) || name.startsWith('\$')) { |
| 287 name = "\$$name"; | 287 name = "\$$name"; |
| 288 assert(!jsReserved.contains(name)); | 288 assert(!jsReserved.contains(name)); |
| 289 } | 289 } |
| 290 return name; | 290 return name; |
| 291 } | 291 } |
| 292 } | 292 } |
| OLD | NEW |