Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(424)

Unified Diff: lib/src/codegen/js_interop.dart

Issue 1580413002: Add a `@JSExportName` annotation for internal use in the runtime (use it to export dart.assert inst… (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: made _emitTopLevelName.suffix a named arg Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/codegen/js_codegen.dart ('k') | tool/input_sdk/private/foreign_helper.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/codegen/js_interop.dart
diff --git a/lib/src/codegen/js_interop.dart b/lib/src/codegen/js_interop.dart
index 1e6dff69bcbaa90cd632c7b5ae37d12a6e94c3ed..777a0097bde7e47720d2dd05638683a0c11c2baf 100644
--- a/lib/src/codegen/js_interop.dart
+++ b/lib/src/codegen/js_interop.dart
@@ -11,21 +11,40 @@ import 'package:analyzer/src/generated/constant.dart';
bool _isJsLibType(String expectedName, Element e) =>
e?.name == expectedName && _isJsLib(e.library);
+/// Returns true if [e] represents any library from `package:js` or is the
+/// internal `dart:_js_helper` library.
bool _isJsLib(LibraryElement e) {
- var libName = e?.name;
- return libName == 'js' ||
- libName == 'js.varargs' ||
- libName == 'dart._js_helper';
+ if (e == null) return false;
+ var uri = e.source.uri;
+ if (uri.scheme == 'package' && uri.path.startsWith('js/')) return true;
+ if (uri.scheme == 'dart') {
+ return uri.path == '_js_helper' || uri.path == '_foreign_helper';
+ }
+ return false;
}
+/// Whether [value] is a `@rest` annotation (to be used on function parameters
+/// to have them compiled as `...` rest params in ES6 outputs).
bool isJsRestAnnotation(DartObjectImpl value) =>
_isJsLibType('_Rest', value.type.element);
+/// Whether [i] is a `spread` invocation (to be used on function arguments
+/// to have them compiled as `...` spread args in ES6 outputs).
bool isJsSpreadInvocation(MethodInvocation i) =>
_isJsLibType('spread', i.methodName?.bestElement);
// TODO(jmesserly): Move JsPeerInterface to package:js (see issue #135).
-bool isJSAnnotation(DartObjectImpl value) => value.type.name == 'JS';
+bool isJSAnnotation(DartObjectImpl value) =>
+ _isJsLibType('JS', value.type.element);
+
+/// Whether [value] is a `@JSExportName` (internal annotation used in SDK
+/// instead of `@JS` from `package:js`).
+bool isJSExportNameAnnotation(DartObjectImpl value) {
+ var e = value?.type?.element;
+ if (e?.name != 'JSExportName') return false;
+ var uri = e.source.uri;
+ return uri.scheme == 'dart' && uri.path == '_foreign_helper';
+}
bool isJsPeerInterface(DartObjectImpl value) =>
value.type.name == 'JsPeerInterface';
« no previous file with comments | « lib/src/codegen/js_codegen.dart ('k') | tool/input_sdk/private/foreign_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698