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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 /// Returns true if [e] represents any library from `package:js` or is the
15 /// internal `dart:_js_helper` library.
14 bool _isJsLib(LibraryElement e) { 16 bool _isJsLib(LibraryElement e) {
15 var libName = e?.name; 17 if (e == null) return false;
16 return libName == 'js' || 18 var uri = e.source.uri;
17 libName == 'js.varargs' || 19 if (uri.scheme == 'package' && uri.path.startsWith('js/')) return true;
18 libName == 'dart._js_helper'; 20 if (uri.scheme == 'dart') {
21 return uri.path == '_js_helper' || uri.path == '_foreign_helper';
22 }
23 return false;
19 } 24 }
20 25
26 /// Whether [value] is a `@rest` annotation (to be used on function parameters
27 /// to have them compiled as `...` rest params in ES6 outputs).
21 bool isJsRestAnnotation(DartObjectImpl value) => 28 bool isJsRestAnnotation(DartObjectImpl value) =>
22 _isJsLibType('_Rest', value.type.element); 29 _isJsLibType('_Rest', value.type.element);
23 30
31 /// Whether [i] is a `spread` invocation (to be used on function arguments
32 /// to have them compiled as `...` spread args in ES6 outputs).
24 bool isJsSpreadInvocation(MethodInvocation i) => 33 bool isJsSpreadInvocation(MethodInvocation i) =>
25 _isJsLibType('spread', i.methodName?.bestElement); 34 _isJsLibType('spread', i.methodName?.bestElement);
26 35
27 // TODO(jmesserly): Move JsPeerInterface to package:js (see issue #135). 36 // TODO(jmesserly): Move JsPeerInterface to package:js (see issue #135).
28 bool isJSAnnotation(DartObjectImpl value) => value.type.name == 'JS'; 37 bool isJSAnnotation(DartObjectImpl value) =>
38 _isJsLibType('JS', value.type.element);
39
40 /// Whether [value] is a `@JSExportName` (internal annotation used in SDK
41 /// instead of `@JS` from `package:js`).
42 bool isJSExportNameAnnotation(DartObjectImpl value) {
43 var e = value?.type?.element;
44 if (e?.name != 'JSExportName') return false;
45 var uri = e.source.uri;
46 return uri.scheme == 'dart' && uri.path == '_foreign_helper';
47 }
29 48
30 bool isJsPeerInterface(DartObjectImpl value) => 49 bool isJsPeerInterface(DartObjectImpl value) =>
31 value.type.name == 'JsPeerInterface'; 50 value.type.name == 'JsPeerInterface';
OLDNEW
« 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