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 library js_backend.namer; | 5 library js_backend.namer; |
6 | 6 |
7 import 'dart:collection' show HashMap; | 7 import 'dart:collection' show HashMap; |
8 | 8 |
9 import 'package:js_runtime/shared/embedded_names.dart' show JsGetName; | 9 import 'package:js_runtime/shared/embedded_names.dart' show JsGetName; |
10 | 10 |
(...skipping 1268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1279 if (!name.contains(r'$')) { | 1279 if (!name.contains(r'$')) { |
1280 // Prepend $$. The result must not coincide with an annotated name. | 1280 // Prepend $$. The result must not coincide with an annotated name. |
1281 name = '\$\$$name'; | 1281 name = '\$\$$name'; |
1282 } | 1282 } |
1283 return name; | 1283 return name; |
1284 } | 1284 } |
1285 | 1285 |
1286 /// Returns a proposed name for the given typedef or class [element]. | 1286 /// Returns a proposed name for the given typedef or class [element]. |
1287 /// The returned id is guaranteed to be a valid JavaScript identifier. | 1287 /// The returned id is guaranteed to be a valid JavaScript identifier. |
1288 String _proposeNameForType(Entity element) { | 1288 String _proposeNameForType(Entity element) { |
1289 return element.name.replaceAll('+', '_'); | 1289 return element.name.replaceAll(_nonIdentifierRE, '_'); |
1290 } | 1290 } |
1291 | 1291 |
| 1292 static RegExp _nonIdentifierRE = new RegExp(r'[^A-Za-z0-9_$]'); |
| 1293 |
1292 /// Returns a proposed name for the given top-level or static member | 1294 /// Returns a proposed name for the given top-level or static member |
1293 /// [element]. The returned id is guaranteed to be a valid JavaScript | 1295 /// [element]. The returned id is guaranteed to be a valid JavaScript |
1294 /// identifier. | 1296 /// identifier. |
1295 String _proposeNameForMember(MemberEntity element) { | 1297 String _proposeNameForMember(MemberEntity element) { |
1296 if (element.isConstructor) { | 1298 if (element.isConstructor) { |
1297 return _proposeNameForConstructor(element); | 1299 return _proposeNameForConstructor(element); |
1298 } else if (element.enclosingClass != null) { | 1300 } else if (element.enclosingClass != null) { |
1299 ClassEntity enclosingClass = element.enclosingClass; | 1301 ClassEntity enclosingClass = element.enclosingClass; |
1300 return '${enclosingClass.name}_${element.name}'; | 1302 return '${enclosingClass.name}_${element.name}'; |
1301 } | 1303 } |
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2237 void addSuggestion(String original, String suggestion) { | 2239 void addSuggestion(String original, String suggestion) { |
2238 assert(!_suggestedNames.containsKey(original)); | 2240 assert(!_suggestedNames.containsKey(original)); |
2239 _suggestedNames[original] = suggestion; | 2241 _suggestedNames[original] = suggestion; |
2240 } | 2242 } |
2241 | 2243 |
2242 bool hasSuggestion(String original) => _suggestedNames.containsKey(original); | 2244 bool hasSuggestion(String original) => _suggestedNames.containsKey(original); |
2243 bool isSuggestion(String candidate) { | 2245 bool isSuggestion(String candidate) { |
2244 return _suggestedNames.containsValue(candidate); | 2246 return _suggestedNames.containsValue(candidate); |
2245 } | 2247 } |
2246 } | 2248 } |
OLD | NEW |