Chromium Code Reviews| 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 part of js_backend; | 5 part of js_backend; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Assigns JavaScript identifiers to Dart variables, class-names and members. | 8 * Assigns JavaScript identifiers to Dart variables, class-names and members. |
| 9 */ | 9 */ |
| 10 class Namer implements ClosureNamer { | 10 class Namer implements ClosureNamer { |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 /** | 352 /** |
| 353 * If the [name] is not private returns [:name:]. Otherwise | 353 * If the [name] is not private returns [:name:]. Otherwise |
| 354 * mangles the [name] so that each library has a unique name. | 354 * mangles the [name] so that each library has a unique name. |
| 355 */ | 355 */ |
| 356 String privateName(LibraryElement library, String name) { | 356 String privateName(LibraryElement library, String name) { |
| 357 // Public names are easy. | 357 // Public names are easy. |
| 358 String nameString = name; | 358 String nameString = name; |
| 359 if (!isPrivateName(name)) return nameString; | 359 if (!isPrivateName(name)) return nameString; |
| 360 | 360 |
| 361 // The first library asking for a short private name wins. | 361 // The first library asking for a short private name wins. |
| 362 LibraryElement owner = shouldMinify | 362 LibraryElement owner = |
| 363 ? library | 363 shortPrivateNameOwners.putIfAbsent(nameString, () => library); |
| 364 : shortPrivateNameOwners.putIfAbsent(nameString, () => library); | |
| 365 | 364 |
| 366 if (owner == library && !shouldMinify && !nameString.contains('\$')) { | 365 if (owner == library && !nameString.contains('\$')) { |
| 367 // Since the name doesn't contain $ it doesn't clash with any | 366 // Since the name doesn't contain $ it doesn't clash with any |
| 368 // of the private names that have the library name as the prefix. | 367 // of the private names that have the library name as the prefix. |
| 369 return nameString; | 368 return nameString; |
| 370 } else { | 369 } else { |
| 371 // Make sure to return a private name that starts with _ so it | 370 // Make sure to return a private name that starts with _ so it |
| 372 // cannot clash with any public names. | 371 // cannot clash with any public names. |
| 373 String libraryName = getNameOfLibrary(library); | 372 String libraryName = getNameOfLibrary(library); |
| 374 return '_$libraryName\$$nameString'; | 373 return '_$libraryName\$$nameString'; |
|
floitsch
2014/07/29 14:22:39
Is the libraryName the unminified name of the libr
herhut
2014/07/29 14:31:55
It is the minified name. However, we do not minify
| |
| 375 } | 374 } |
| 376 } | 375 } |
| 377 | 376 |
| 378 String instanceMethodName(FunctionElement element) { | 377 String instanceMethodName(FunctionElement element) { |
| 379 // TODO(ahe): Could this be: return invocationName(new | 378 // TODO(ahe): Could this be: return invocationName(new |
| 380 // Selector.fromElement(element))? | 379 // Selector.fromElement(element))? |
| 381 String elementName = element.name; | 380 String elementName = element.name; |
| 382 String name = operatorNameToIdentifier(elementName); | 381 String name = operatorNameToIdentifier(elementName); |
| 383 if (name != elementName) return getMappedOperatorName(name); | 382 if (name != elementName) return getMappedOperatorName(name); |
| 384 | 383 |
| (...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1371 if (!first) { | 1370 if (!first) { |
| 1372 sb.write('_'); | 1371 sb.write('_'); |
| 1373 } | 1372 } |
| 1374 sb.write('_'); | 1373 sb.write('_'); |
| 1375 visit(parameter); | 1374 visit(parameter); |
| 1376 first = true; | 1375 first = true; |
| 1377 } | 1376 } |
| 1378 } | 1377 } |
| 1379 } | 1378 } |
| 1380 } | 1379 } |
| OLD | NEW |