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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR_BODY) { | 104 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR_BODY) { |
| 105 ConstructorBodyElement bodyElement = element; | 105 ConstructorBodyElement bodyElement = element; |
| 106 name = bodyElement.constructor.name; | 106 name = bodyElement.constructor.name; |
| 107 } | 107 } |
| 108 FunctionSignature signature = element.computeSignature(compiler); | 108 FunctionSignature signature = element.computeSignature(compiler); |
| 109 String methodName = | 109 String methodName = |
| 110 '${privateName(lib, name)}\$${signature.parameterCount}'; | 110 '${privateName(lib, name)}\$${signature.parameterCount}'; |
| 111 if (!signature.optionalParametersAreNamed) { | 111 if (!signature.optionalParametersAreNamed) { |
| 112 return methodName; | 112 return methodName; |
| 113 } else { | 113 } else { |
| 114 StringBuffer suffix = new StringBuffer(); | 114 List<String> optionalParameters = <String>[]; |
|
kasperl
2012/09/26 11:53:55
Maybe check if optionalParameters.isEmpty first an
ngeoffray
2012/09/26 12:28:47
Done.
| |
| 115 signature.forEachOptionalParameter((Element element) { | 115 signature.orderedOptionalParameters.forEach((Element element) { |
| 116 String jsName = JsNames.getValid(element.name.slowToString()); | 116 optionalParameters.add(JsNames.getValid(element.name.slowToString())); |
| 117 suffix.add('\$$jsName'); | |
| 118 }); | 117 }); |
| 118 String suffix = optionalParameters.isEmpty() | |
| 119 ? '' | |
| 120 : "\$${Strings.join(optionalParameters, '\$')}"; | |
| 119 return '$methodName$suffix'; | 121 return '$methodName$suffix'; |
| 120 } | 122 } |
| 121 } | 123 } |
| 122 | 124 |
| 123 String publicInstanceMethodNameByArity(SourceString name, int arity) { | 125 String publicInstanceMethodNameByArity(SourceString name, int arity) { |
| 124 assert(!name.isPrivate()); | 126 assert(!name.isPrivate()); |
| 125 return '${name.slowToString()}\$$arity'; | 127 return '${name.slowToString()}\$$arity'; |
| 126 } | 128 } |
| 127 | 129 |
| 128 String instanceMethodInvocationName(LibraryElement lib, SourceString name, | 130 String instanceMethodInvocationName(LibraryElement lib, SourceString name, |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 } | 305 } |
| 304 | 306 |
| 305 String safeName(String name) { | 307 String safeName(String name) { |
| 306 if (jsReserved.contains(name) || name.startsWith('\$')) { | 308 if (jsReserved.contains(name) || name.startsWith('\$')) { |
| 307 name = "\$$name"; | 309 name = "\$$name"; |
| 308 assert(!jsReserved.contains(name)); | 310 assert(!jsReserved.contains(name)); |
| 309 } | 311 } |
| 310 return name; | 312 return name; |
| 311 } | 313 } |
| 312 } | 314 } |
| OLD | NEW |