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

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

Issue 1088663002: fix sunflower -- dom types were not resolving (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/runtime/dart_runtime.js ('k') | test/codegen/expect/sunflower/dom.js » ('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 3a4194c6676b2869e25715dae14c4db78679f8ac..654073628fd7a4eac6fa94b93fed8145f6390bf1 100644
--- a/lib/src/codegen/js_codegen.dart
+++ b/lib/src/codegen/js_codegen.dart
@@ -333,12 +333,29 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
return _finishClassDef(type, classDecl);
}
+ JS.Statement _emitJsType(ClassDeclaration node, Annotation jsName) {
+ var dartName = node.name.name;
+ var jsTypeName = _getLiteralStringNamedArg(jsName, 'name');
+
+ if (jsTypeName != null && jsTypeName != dartName) {
+ // We export the JS type as if it was a Dart type. For example this allows
+ // `dom.InputElement` to actually be HTMLInputElement.
+ // TODO(jmesserly): if we had the JsName on the Element, we could just
+ // generate it correctly when we refer to it.
+ if (isPublic(dartName)) _addExport(dartName);
+ return js.statement('let # = #;', [dartName, jsTypeName]);
+ }
+ return null;
+ }
+
@override
JS.Statement visitClassDeclaration(ClassDeclaration node) {
// If we've already emitted this class, skip it.
var type = node.element.type;
if (_pendingClasses.remove(node.element) == null) return null;
- if (_getJsNameAnnotation(node) != null) return null;
+
+ var jsName = _getJsNameAnnotation(node);
+ if (jsName != null) return _emitJsType(node, jsName);
currentClass = node;
@@ -2576,3 +2593,17 @@ class _AssignmentFinder extends RecursiveAstVisitor {
}
}
}
+
+String _getLiteralStringNamedArg(Annotation annotation, String argName) {
+ if (annotation.arguments != null) {
+ var args = annotation.arguments.arguments;
+ if (args.isNotEmpty && args[0] is NamedExpression) {
+ NamedExpression named = args[0];
+ if (named.name.label.name == argName &&
+ named.expression is StringLiteral) {
+ return (named.expression as StringLiteral).stringValue;
+ }
+ }
+ }
+ return null;
+}
« no previous file with comments | « lib/runtime/dart_runtime.js ('k') | test/codegen/expect/sunflower/dom.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698