| 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/dart/ast/ast.dart'; | 5 import 'package:analyzer/dart/ast/ast.dart'; |
| 6 import 'package:analyzer/src/generated/constant.dart'; | 6 import 'package:analyzer/src/generated/constant.dart'; |
| 7 import 'package:analyzer/dart/element/element.dart'; | 7 import 'package:analyzer/dart/element/element.dart'; |
| 8 | 8 |
| 9 import 'element_helpers.dart'; | 9 import 'element_helpers.dart'; |
| 10 | 10 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 bool isJsSpreadInvocation(MethodInvocation i) => | 33 bool isJsSpreadInvocation(MethodInvocation i) => |
| 34 _isJsLibType('spread', i.methodName?.bestElement); | 34 _isJsLibType('spread', i.methodName?.bestElement); |
| 35 | 35 |
| 36 // TODO(jmesserly): Move JsPeerInterface to package:js (see issue #135). | 36 // TODO(jmesserly): Move JsPeerInterface to package:js (see issue #135). |
| 37 // TODO(jacobr): The 'JS' annotation is the new, publically accessible one. | 37 // TODO(jacobr): The 'JS' annotation is the new, publically accessible one. |
| 38 // The 'JsName' annotation is the old one using internally by dart2js and | 38 // The 'JsName' annotation is the old one using internally by dart2js and |
| 39 // html libraries. These two concepts will probably merge eventually. | 39 // html libraries. These two concepts will probably merge eventually. |
| 40 bool isJSAnnotation(DartObjectImpl value) => | 40 bool isJSAnnotation(DartObjectImpl value) => |
| 41 _isJsLibType('JS', value.type.element) || isJsName(value); | 41 _isJsLibType('JS', value.type.element) || isJsName(value); |
| 42 | 42 |
| 43 /// Returns [true] if [e] is the `JS` annotation from `package:js`. |
| 44 bool isPublicJSAnnotation(DartObjectImpl value) => |
| 45 _isJsLibType('JS', value.type.element); |
| 46 |
| 47 bool isJSAnonymousAnnotation(DartObjectImpl value) => |
| 48 _isJsLibType('_Anonymous', value.type.element); |
| 49 |
| 43 bool _isBuiltinAnnotation( | 50 bool _isBuiltinAnnotation( |
| 44 DartObjectImpl value, String libraryName, String annotationName) { | 51 DartObjectImpl value, String libraryName, String annotationName) { |
| 45 var e = value?.type?.element; | 52 var e = value?.type?.element; |
| 46 if (e?.name != annotationName) return false; | 53 if (e?.name != annotationName) return false; |
| 47 var uri = e.source.uri; | 54 var uri = e.source.uri; |
| 48 var path = uri.pathSegments[0]; | 55 var path = uri.pathSegments[0]; |
| 49 return uri.scheme == 'dart' && path == libraryName; | 56 return uri.scheme == 'dart' && path == libraryName; |
| 50 } | 57 } |
| 51 | 58 |
| 52 /// Whether [value] is a `@JSExportName` (internal annotation used in SDK | 59 /// Whether [value] is a `@JSExportName` (internal annotation used in SDK |
| (...skipping 12 matching lines...) Expand all Loading... |
| 65 | 72 |
| 66 /// Returns the name value of the `JSExportName` annotation (when compiling | 73 /// Returns the name value of the `JSExportName` annotation (when compiling |
| 67 /// the SDK), or `null` if there's none. This is used to control the name | 74 /// the SDK), or `null` if there's none. This is used to control the name |
| 68 /// under which functions are compiled and exported. | 75 /// under which functions are compiled and exported. |
| 69 String getJSExportName(Element e) { | 76 String getJSExportName(Element e) { |
| 70 if (e.source.isInSystemLibrary) { | 77 if (e.source.isInSystemLibrary) { |
| 71 return getAnnotationName(e, isJSExportNameAnnotation) ?? e.name; | 78 return getAnnotationName(e, isJSExportNameAnnotation) ?? e.name; |
| 72 } | 79 } |
| 73 return e.name; | 80 return e.name; |
| 74 } | 81 } |
| OLD | NEW |