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

Side by Side Diff: lib/src/compiler/js_interop.dart

Issue 1920473003: Use correct annotation for JS names (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Address comments Created 4 years, 8 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/runtime/dart_sdk.js ('k') | no next file » | 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 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
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
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 }
OLDNEW
« no previous file with comments | « lib/runtime/dart_sdk.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698