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

Unified Diff: pkg/dev_compiler/lib/src/compiler/code_generator.dart

Issue 2783443002: Fix for #29003 (Closed)
Patch Set: Created 3 years, 9 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 | « no previous file | pkg/dev_compiler/test/browser/language_tests.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/dev_compiler/lib/src/compiler/code_generator.dart
diff --git a/pkg/dev_compiler/lib/src/compiler/code_generator.dart b/pkg/dev_compiler/lib/src/compiler/code_generator.dart
index 50d6c19e5535a112484041abfd2cd437bdcaf34b..bbd78a7630e884b1f5022e78f6e11536f05a087a 100644
--- a/pkg/dev_compiler/lib/src/compiler/code_generator.dart
+++ b/pkg/dev_compiler/lib/src/compiler/code_generator.dart
@@ -716,11 +716,10 @@ class CodeGenerator extends GeneralizingAstVisitor
@override
JS.Statement visitClassTypeAlias(ClassTypeAlias node) {
ClassElement element = node.element;
+ var supertype = element.supertype;
// Forward all generative constructors from the base class.
var methods = <JS.Method>[];
-
- var supertype = element.supertype;
if (!supertype.isObject) {
for (var ctor in element.constructors) {
var parentCtor = supertype.lookUpConstructor(ctor.name, ctor.library);
@@ -740,14 +739,45 @@ class CodeGenerator extends GeneralizingAstVisitor
}
}
- var classExpr = _emitClassExpression(element, methods);
-
var typeFormals = element.typeParameters;
- if (typeFormals.isNotEmpty) {
+ var isGeneric = typeFormals.isNotEmpty;
+ var className = isGeneric ? element.name : _emitTopLevelName(element);
+ JS.Statement declareInterfaces(JS.Statement decl) {
+ if (element.interfaces.isNotEmpty) {
+ var body = [decl]
+ ..add(js.statement('#[#.implements] = () => #;', [
+ className,
+ _runtimeModule,
+ new JS.ArrayInitializer(
+ new List<JS.Expression>.from(element.interfaces.map(_emitType)))
+ ]));
+ decl = _statement(body);
+ }
+ return decl;
+ }
+
+ if (supertype.isObject && element.mixins.length == 1) {
+ // Special case where supertype is Object, and we mixin a single class.
+ // The resulting 'class' is a mixable class in this case.
+ var classExpr = _emitClassHeritage(element);
+ if (isGeneric) {
+ var classStmt = js.statement('const # = #;', [className, classExpr]);
+ return _defineClassTypeArguments(
+ element, typeFormals, declareInterfaces(classStmt));
+ } else {
+ var classStmt = js.statement('# = #;', [className, classExpr]);
+ return declareInterfaces(classStmt);
+ }
+ }
+
+ var classExpr = _emitClassExpression(element, methods);
+ if (isGeneric) {
+ var classStmt = new JS.ClassDeclaration(classExpr);
return _defineClassTypeArguments(
- element, typeFormals, new JS.ClassDeclaration(classExpr));
+ element, typeFormals, declareInterfaces(classStmt));
} else {
- return js.statement('# = #;', [_emitTopLevelName(element), classExpr]);
+ var classStmt = js.statement('# = #;', [className, classExpr]);
+ return declareInterfaces(classStmt);
}
}
« no previous file with comments | « no previous file | pkg/dev_compiler/test/browser/language_tests.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698