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