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 /** | 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 } | 69 } |
| 70 | 70 |
| 71 String setterName(LibraryElement lib, SourceString name) { | 71 String setterName(LibraryElement lib, SourceString name) { |
| 72 return 'set\$${privateName(lib, name)}'; | 72 return 'set\$${privateName(lib, name)}'; |
| 73 } | 73 } |
| 74 | 74 |
| 75 String getterName(LibraryElement lib, SourceString name) { | 75 String getterName(LibraryElement lib, SourceString name) { |
| 76 return 'get\$${privateName(lib, name)}'; | 76 return 'get\$${privateName(lib, name)}'; |
| 77 } | 77 } |
| 78 | 78 |
| 79 String getDynamicFieldSetterNamerFunction(String functionName) { | |
| 80 return 'function $functionName(fieldName) { return "set\$" + fieldName; }'; | |
|
kasperl
2012/05/09 07:53:15
Too much indentation. Wouldn't it look better with
ngeoffray
2012/05/09 08:50:28
Why not putting that in the JS blob instead?
floitsch
2012/05/09 13:58:36
Done.
| |
| 81 } | |
| 82 | |
| 83 String dynamicSetterName(String fieldName) => 'set\$$fieldName'; | |
| 84 | |
| 85 String getDynamicFieldGetterNamerFunction(String functionName) { | |
| 86 return 'function $functionName(fieldName) { return "get\$" + fieldName; }'; | |
| 87 } | |
| 88 | |
| 89 String dynamicGetterName(String fieldName) => 'get\$$fieldName'; | |
| 90 | |
| 79 String getFreshGlobalName(String proposedName) { | 91 String getFreshGlobalName(String proposedName) { |
| 80 int usedCount = usedGlobals[proposedName]; | 92 int usedCount = usedGlobals[proposedName]; |
| 81 if (usedCount === null) { | 93 if (usedCount === null) { |
| 82 // No element with this name has been used before. | 94 // No element with this name has been used before. |
| 83 usedGlobals[proposedName] = 1; | 95 usedGlobals[proposedName] = 1; |
| 84 return proposedName; | 96 return proposedName; |
| 85 } else { | 97 } else { |
| 86 // Not the first time we see this name. Append a number to make it unique. | 98 // Not the first time we see this name. Append a number to make it unique. |
| 87 String name; | 99 String name; |
| 88 do { | 100 do { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 } | 223 } |
| 212 | 224 |
| 213 String safeName(String name) { | 225 String safeName(String name) { |
| 214 if (jsReserved.contains(name) || name.startsWith('\$')) { | 226 if (jsReserved.contains(name) || name.startsWith('\$')) { |
| 215 name = "\$$name"; | 227 name = "\$$name"; |
| 216 assert(!jsReserved.contains(name)); | 228 assert(!jsReserved.contains(name)); |
| 217 } | 229 } |
| 218 return name; | 230 return name; |
| 219 } | 231 } |
| 220 } | 232 } |
| OLD | NEW |