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 library dev_compiler.src.js_interop; | 5 library dev_compiler.src.js_interop; |
6 | 6 |
7 import 'package:analyzer/src/generated/ast.dart'; | 7 import 'package:analyzer/src/generated/ast.dart'; |
8 import 'package:analyzer/src/generated/element.dart'; | 8 import 'package:analyzer/src/generated/element.dart'; |
9 import 'package:analyzer/src/generated/constant.dart'; | 9 import 'package:analyzer/src/generated/constant.dart'; |
10 | 10 |
11 bool _isJsLibType(String expectedName, Element e) => | 11 bool _isJsLibType(String expectedName, Element e) => |
12 e?.name == expectedName && _isJsLib(e.library); | 12 e?.name == expectedName && _isJsLib(e.library); |
13 | 13 |
14 bool _isJsLib(LibraryElement e) { | 14 bool _isJsLib(LibraryElement e) { |
15 var libName = e?.name; | 15 var libName = e?.name; |
16 return libName == 'js' || | 16 return libName == 'js' || |
17 libName == 'js.varargs' || | 17 libName == 'js.varargs' || |
18 libName == 'dart._js_helper'; | 18 libName == 'dart._js_helper' || |
| 19 libName == 'dart._foreign_helper'; |
19 } | 20 } |
20 | 21 |
21 bool isJsRestAnnotation(DartObjectImpl value) => | 22 bool isJsRestAnnotation(DartObjectImpl value) => |
22 _isJsLibType('_Rest', value.type.element); | 23 _isJsLibType('_Rest', value.type.element); |
23 | 24 |
24 bool isJsSpreadInvocation(MethodInvocation i) => | 25 bool isJsSpreadInvocation(MethodInvocation i) => |
25 _isJsLibType('spread', i.methodName?.bestElement); | 26 _isJsLibType('spread', i.methodName?.bestElement); |
26 | 27 |
| 28 bool isGenericTypeConstructorInvocation(MethodInvocation i) => |
| 29 _isJsLibType('genericTypeConstructor', i.methodName?.bestElement); |
| 30 |
27 // TODO(jmesserly): Move JsPeerInterface to package:js (see issue #135). | 31 // TODO(jmesserly): Move JsPeerInterface to package:js (see issue #135). |
28 bool isJSAnnotation(DartObjectImpl value) => value.type.name == 'JS'; | 32 bool isJSAnnotation(DartObjectImpl value) => |
| 33 value.type.name == 'JS' || isJsNameAnnotation(value); |
| 34 |
| 35 bool isJsNameAnnotation(DartObjectImpl value) { |
| 36 var e = value.type.element; |
| 37 return e?.name == 'JsName' && e.library.name == 'dart._foreign_helper'; |
| 38 } |
29 | 39 |
30 bool isJsPeerInterface(DartObjectImpl value) => | 40 bool isJsPeerInterface(DartObjectImpl value) => |
31 value.type.name == 'JsPeerInterface'; | 41 value.type.name == 'JsPeerInterface'; |
OLD | NEW |