| 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 16 matching lines...) Expand all Loading... |
| 27 /// to have them compiled as `...` rest params in ES6 outputs). | 27 /// to have them compiled as `...` rest params in ES6 outputs). |
| 28 bool isJsRestAnnotation(DartObjectImpl value) => | 28 bool isJsRestAnnotation(DartObjectImpl value) => |
| 29 _isJsLibType('_Rest', value.type.element); | 29 _isJsLibType('_Rest', value.type.element); |
| 30 | 30 |
| 31 /// Whether [i] is a `spread` invocation (to be used on function arguments | 31 /// Whether [i] is a `spread` invocation (to be used on function arguments |
| 32 /// to have them compiled as `...` spread args in ES6 outputs). | 32 /// to have them compiled as `...` spread args in ES6 outputs). |
| 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. |
| 38 // The 'JsName' annotation is the old one using internally by dart2js and |
| 39 // html libraries. These two concepts will probably merge eventually. |
| 37 bool isJSAnnotation(DartObjectImpl value) => | 40 bool isJSAnnotation(DartObjectImpl value) => |
| 38 _isJsLibType('JS', value.type.element); | 41 _isJsLibType('JS', value.type.element) || isJsName(value); |
| 39 | 42 |
| 40 bool _isBuiltinAnnotation( | 43 bool _isBuiltinAnnotation( |
| 41 DartObjectImpl value, String libraryName, String annotationName) { | 44 DartObjectImpl value, String libraryName, String annotationName) { |
| 42 var e = value?.type?.element; | 45 var e = value?.type?.element; |
| 43 if (e?.name != annotationName) return false; | 46 if (e?.name != annotationName) return false; |
| 44 var uri = e.source.uri; | 47 var uri = e.source.uri; |
| 45 var path = uri.pathSegments[0]; | 48 var path = uri.pathSegments[0]; |
| 46 return uri.scheme == 'dart' && path == libraryName; | 49 return uri.scheme == 'dart' && path == libraryName; |
| 47 } | 50 } |
| 48 | 51 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 62 | 65 |
| 63 /// Returns the name value of the `JSExportName` annotation (when compiling | 66 /// Returns the name value of the `JSExportName` annotation (when compiling |
| 64 /// the SDK), or `null` if there's none. This is used to control the name | 67 /// the SDK), or `null` if there's none. This is used to control the name |
| 65 /// under which functions are compiled and exported. | 68 /// under which functions are compiled and exported. |
| 66 String getJSExportName(Element e) { | 69 String getJSExportName(Element e) { |
| 67 if (e.source.isInSystemLibrary) { | 70 if (e.source.isInSystemLibrary) { |
| 68 return getAnnotationName(e, isJSExportNameAnnotation) ?? e.name; | 71 return getAnnotationName(e, isJSExportNameAnnotation) ?? e.name; |
| 69 } | 72 } |
| 70 return e.name; | 73 return e.name; |
| 71 } | 74 } |
| OLD | NEW |