@@ -379,10 +379,11 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ClosureAnnotator {
379
379
}
380
380
}
381
381
382
- var classDecl = new JS . ClassDeclaration ( new JS .ClassExpression (
383
- new JS .Identifier (element.name), _classHeritage (element), body)) ;
382
+ var classExpr = new JS .ClassExpression (
383
+ new JS .Identifier (element.name), _classHeritage (element), body);
384
384
385
- return _finishClassDef (element.type, classDecl);
385
+ return _finishClassDef (
386
+ element.type, _emitClassHeritageWorkaround (classExpr));
386
387
}
387
388
388
389
JS .Statement _emitJsType (String dartClassName, DartObject jsName) {
@@ -674,6 +675,27 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ClosureAnnotator {
674
675
}
675
676
}
676
677
678
+ _isQualifiedPath (JS .Expression node) =>
679
+ node is JS .Identifier ||
680
+ node is JS .PropertyAccess &&
681
+ _isQualifiedPath (node.receiver) &&
682
+ node.selector is JS .LiteralString ;
683
+
684
+ /// Workaround for Closure: super classes must be qualified paths.
685
+ JS .Statement _emitClassHeritageWorkaround (JS .ClassExpression cls) {
686
+ if (options.closure &&
687
+ cls.heritage != null &&
688
+ ! _isQualifiedPath (cls.heritage)) {
689
+ var superVar = new JS .TemporaryId (cls.name.name + r'$super' );
690
+ return _statement ([
691
+ js.statement ('const # = #;' , [superVar, cls.heritage]),
692
+ new JS .ClassDeclaration (
693
+ new JS .ClassExpression (cls.name, superVar, cls.methods))
694
+ ]);
695
+ }
696
+ return new JS .ClassDeclaration (cls);
697
+ }
698
+
677
699
/// Emit class members that need to come after the class declaration, such
678
700
/// as static fields. See [_emitClassMethods] for things that are emitted
679
701
/// inside the ES6 `class { ... }` node.
@@ -702,7 +724,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ClosureAnnotator {
702
724
}
703
725
}
704
726
705
- body.add (new JS . ClassDeclaration (cls));
727
+ body.add (_emitClassHeritageWorkaround (cls));
706
728
707
729
// TODO(jmesserly): we should really just extend native Array.
708
730
if (jsPeerName != null && classElem.typeParameters.isNotEmpty) {
0 commit comments