| 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 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 } | 764 } |
| 765 | 765 |
| 766 /// Annotated name for [method] encoding arity and named parameters. | 766 /// Annotated name for [method] encoding arity and named parameters. |
| 767 jsAst.Name instanceMethodName(MethodElement method) { | 767 jsAst.Name instanceMethodName(MethodElement method) { |
| 768 if (method.isGenerativeConstructorBody) { | 768 if (method.isGenerativeConstructorBody) { |
| 769 return constructorBodyName(method); | 769 return constructorBodyName(method); |
| 770 } | 770 } |
| 771 return invocationName(new Selector.fromElement(method)); | 771 return invocationName(new Selector.fromElement(method)); |
| 772 } | 772 } |
| 773 | 773 |
| 774 String _jsNameHelper(Element e) { | |
| 775 String jsInteropName = _nativeData.getJsInteropName(e); | |
| 776 if (jsInteropName != null && jsInteropName.isNotEmpty) return jsInteropName; | |
| 777 return e.isLibrary ? 'self' : _nativeData.getUnescapedJSInteropName(e.name); | |
| 778 } | |
| 779 | |
| 780 /// Returns a JavaScript path specifying the context in which | |
| 781 /// [element.fixedBackendName] should be evaluated. Only applicable for | |
| 782 /// elements using typed JavaScript interop. | |
| 783 /// For example: fixedBackendPath for the static method createMap in the | |
| 784 /// Map class of the goog.map JavaScript library would have path | |
| 785 /// "goog.maps.Map". | |
| 786 String fixedBackendMethodPath(MethodElement element) { | |
| 787 return _fixedBackendPath(element); | |
| 788 } | |
| 789 | |
| 790 String _fixedBackendPath(Element element) { | |
| 791 if (!_nativeData.isJsInterop(element)) return null; | |
| 792 if (element.isInstanceMember) return 'this'; | |
| 793 if (element.isConstructor) return _fixedBackendPath(element.enclosingClass); | |
| 794 if (element.isLibrary) return 'self'; | |
| 795 var sb = new StringBuffer(); | |
| 796 sb..write(_jsNameHelper(element.library)); | |
| 797 | |
| 798 if (element.enclosingClass != null && element.enclosingClass != element) { | |
| 799 sb..write('.')..write(_jsNameHelper(element.enclosingClass)); | |
| 800 } | |
| 801 return sb.toString(); | |
| 802 } | |
| 803 | |
| 804 /// Returns the annotated name for a variant of `call`. | 774 /// Returns the annotated name for a variant of `call`. |
| 805 /// The result has the form: | 775 /// The result has the form: |
| 806 /// | 776 /// |
| 807 /// call$<N>$namedParam1...$namedParam<M> | 777 /// call$<N>$namedParam1...$namedParam<M> |
| 808 /// | 778 /// |
| 809 /// This name cannot be minified because it is generated by string | 779 /// This name cannot be minified because it is generated by string |
| 810 /// concatenation at runtime, by applyFunction in js_helper.dart. | 780 /// concatenation at runtime, by applyFunction in js_helper.dart. |
| 811 jsAst.Name deriveCallMethodName(List<String> suffix) { | 781 jsAst.Name deriveCallMethodName(List<String> suffix) { |
| 812 // TODO(asgerf): Avoid clashes when named parameters contain $ symbols. | 782 // TODO(asgerf): Avoid clashes when named parameters contain $ symbols. |
| 813 return new StringBackedName('$callPrefix\$${suffix.join(r'$')}'); | 783 return new StringBackedName('$callPrefix\$${suffix.join(r'$')}'); |
| (...skipping 1378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2192 void addSuggestion(String original, String suggestion) { | 2162 void addSuggestion(String original, String suggestion) { |
| 2193 assert(!_suggestedNames.containsKey(original)); | 2163 assert(!_suggestedNames.containsKey(original)); |
| 2194 _suggestedNames[original] = suggestion; | 2164 _suggestedNames[original] = suggestion; |
| 2195 } | 2165 } |
| 2196 | 2166 |
| 2197 bool hasSuggestion(String original) => _suggestedNames.containsKey(original); | 2167 bool hasSuggestion(String original) => _suggestedNames.containsKey(original); |
| 2198 bool isSuggestion(String candidate) { | 2168 bool isSuggestion(String candidate) { |
| 2199 return _suggestedNames.containsValue(candidate); | 2169 return _suggestedNames.containsValue(candidate); |
| 2200 } | 2170 } |
| 2201 } | 2171 } |
| OLD | NEW |