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

Unified Diff: lib/src/codegen/js_codegen.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/runtime/dart/_utils.js ('k') | lib/src/codegen/js_interop.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/codegen/js_codegen.dart
diff --git a/lib/src/codegen/js_codegen.dart b/lib/src/codegen/js_codegen.dart
index dc64c5bb8d44c6ac9f0f03f52a83d044e09f708f..2f0a0b8ed3b5ef0fa9fb31d0fa4e8b78a07797da 100644
--- a/lib/src/codegen/js_codegen.dart
+++ b/lib/src/codegen/js_codegen.dart
@@ -1294,6 +1294,17 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ClosureAnnotator {
node.element);
}
+ /// Returns the name value of the `JSExportName` annotation (when compiling
+ /// the SDK), or `null` if there's none. This is used to control the name
+ /// under which functions are compiled and exported.
+ String _getJSExportName(Element e) {
+ if (e is! FunctionElement || !currentLibrary.source.isInSystemLibrary) {
+ return null;
+ }
+ var jsName = findAnnotation(e, isJSExportNameAnnotation);
+ return getConstantField(jsName, 'name', types.stringType)?.toStringValue();
+ }
+
@override
JS.Statement visitFunctionDeclaration(FunctionDeclaration node) {
assert(node.parent is CompilationUnit);
@@ -1309,7 +1320,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ClosureAnnotator {
var body = <JS.Statement>[];
_flushLibraryProperties(body);
- var name = node.name.name;
+ var name = _getJSExportName(node.element) ?? node.name.name;
var fn = _visit(node.functionExpression);
bool needsTagging = true;
@@ -1575,8 +1586,6 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ClosureAnnotator {
_loader.declareBeforeUse(element);
- var name = element.name;
-
// type literal
if (element is ClassElement ||
element is DynamicElementImpl ||
@@ -1587,9 +1596,11 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ClosureAnnotator {
// library member
if (element.enclosingElement is CompilationUnitElement) {
- return _maybeQualifiedName(element);
+ return _emitTopLevelName(element);
}
+ var name = element.name;
+
// Unqualified class member. This could mean implicit-this, or implicit
// call to a static from the same class.
if (element is ClassMemberElement && element is! ConstructorElement) {
@@ -1757,17 +1768,17 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ClosureAnnotator {
jsArgs = [];
}
if (jsArgs != null) {
- var genericName = _maybeQualifiedName(element, '$name\$');
+ var genericName = _emitTopLevelName(element, suffix: '\$');
return js.call('#(#)', [genericName, jsArgs]);
}
}
- return _maybeQualifiedName(element);
+ return _emitTopLevelName(element);
}
- JS.Expression _maybeQualifiedName(Element e, [String name]) {
+ JS.Expression _emitTopLevelName(Element e, {String suffix : ''}) {
var libName = _libraryName(e.library);
- var nameExpr = _propertyName(name ?? e.name);
+ var nameExpr = _propertyName((_getJSExportName(e) ?? e.name) + suffix);
// Always qualify:
// * mutable top-level fields
@@ -2231,6 +2242,9 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ClosureAnnotator {
if (isJSTopLevel) eagerInit = true;
var fieldName = field.name.name;
+ if (element is TopLevelVariableElement) {
+ fieldName = _getJSExportName(element) ?? fieldName;
+ }
if ((field.isConst && eagerInit && element is TopLevelVariableElement) ||
isJSTopLevel) {
// constant fields don't change, so we can generate them as `let`
« no previous file with comments | « lib/runtime/dart/_utils.js ('k') | lib/src/codegen/js_interop.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698