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

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
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..b111fab4bb00ad352a52d867565940f7ea6dfd8f 100644
--- a/lib/src/codegen/js_codegen.dart
+++ b/lib/src/codegen/js_codegen.dart
@@ -333,12 +333,40 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
return _finishClassDef(type, classDecl);
}
+ JS.Statement _emitJsType(ClassDeclaration node, Annotation jsName) {
+ var dartName = node.name.name;
+ String jsTypeName = null;
+
+ if (jsName.arguments != null) {
+ var args = jsName.arguments.arguments;
+ if (args.isNotEmpty && args[0] is NamedExpression) {
+ NamedExpression named = args[0];
Jacob 2015/04/13 19:27:14 seems like we should add a helper method to extrac
Jennifer Messerly 2015/04/13 20:02:10 Sure thing. Ultimately we need these in analyzer t
+ if (named.name.label.name == 'name' &&
+ named.expression is StringLiteral) {
+ jsTypeName = (named.expression as StringLiteral).stringValue;
+ }
+ }
+ }
+
+ // 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 JS name on the Element, we could
+ if (isPublic(dartName)) _addExport(dartName);
+
+ if (jsTypeName != null && jsTypeName != 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;

Powered by Google App Engine
This is Rietveld 408576698