| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 import 'package:analyzer/src/generated/ast.dart'; | 5 import 'package:analyzer/src/generated/ast.dart'; |
| 6 import 'package:analyzer/src/generated/constant.dart'; |
| 6 import 'package:analyzer/src/generated/element.dart'; | 7 import 'package:analyzer/src/generated/element.dart'; |
| 7 import 'package:analyzer/src/generated/constant.dart'; | 8 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; |
| 9 |
| 10 import '../utils.dart'; |
| 8 | 11 |
| 9 bool _isJsLibType(String expectedName, Element e) => | 12 bool _isJsLibType(String expectedName, Element e) => |
| 10 e?.name == expectedName && _isJsLib(e.library); | 13 e?.name == expectedName && _isJsLib(e.library); |
| 11 | 14 |
| 12 /// Returns true if [e] represents any library from `package:js` or is the | 15 /// Returns true if [e] represents any library from `package:js` or is the |
| 13 /// internal `dart:_js_helper` library. | 16 /// internal `dart:_js_helper` library. |
| 14 bool _isJsLib(LibraryElement e) { | 17 bool _isJsLib(LibraryElement e) { |
| 15 if (e == null) return false; | 18 if (e == null) return false; |
| 16 var uri = e.source.uri; | 19 var uri = e.source.uri; |
| 17 if (uri.scheme == 'package' && uri.path.startsWith('js/')) return true; | 20 if (uri.scheme == 'package' && uri.path.startsWith('js/')) return true; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 _isBuiltinAnnotation(value, '_foreign_helper', 'JSExportName'); | 53 _isBuiltinAnnotation(value, '_foreign_helper', 'JSExportName'); |
| 51 | 54 |
| 52 bool isJsName(DartObjectImpl value) => | 55 bool isJsName(DartObjectImpl value) => |
| 53 _isBuiltinAnnotation(value, '_js_helper', 'JSName'); | 56 _isBuiltinAnnotation(value, '_js_helper', 'JSName'); |
| 54 | 57 |
| 55 bool isJsPeerInterface(DartObjectImpl value) => | 58 bool isJsPeerInterface(DartObjectImpl value) => |
| 56 _isBuiltinAnnotation(value, '_js_helper', 'JsPeerInterface'); | 59 _isBuiltinAnnotation(value, '_js_helper', 'JsPeerInterface'); |
| 57 | 60 |
| 58 bool isNativeAnnotation(DartObjectImpl value) => | 61 bool isNativeAnnotation(DartObjectImpl value) => |
| 59 _isBuiltinAnnotation(value, '_js_helper', 'Native'); | 62 _isBuiltinAnnotation(value, '_js_helper', 'Native'); |
| 63 |
| 64 /// Returns the name value of the `JSExportName` annotation (when compiling |
| 65 /// the SDK), or `null` if there's none. This is used to control the name |
| 66 /// under which functions are compiled and exported. |
| 67 String getJSExportName(Element e, TypeProvider types) { |
| 68 if (!e.source.isInSystemLibrary) { |
| 69 return null; |
| 70 } |
| 71 var jsName = findAnnotation(e, isJSExportNameAnnotation); |
| 72 return getConstantField(jsName, 'name', types.stringType)?.toStringValue(); |
| 73 } |
| OLD | NEW |