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

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

Issue 1638533004: Create local alias for super class in --closure mode (issue #312) (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: fix test 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/_runtime.js ('k') | test/codegen/expect/closure.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 88215c42ea58829381a016fc23d2cd62657d85fc..2b3fddff52f27b3870c7802ab85220cabf934bfb 100644
--- a/lib/src/codegen/js_codegen.dart
+++ b/lib/src/codegen/js_codegen.dart
@@ -379,10 +379,11 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ClosureAnnotator {
}
}
- var classDecl = new JS.ClassDeclaration(new JS.ClassExpression(
- new JS.Identifier(element.name), _classHeritage(element), body));
+ var classExpr = new JS.ClassExpression(
+ new JS.Identifier(element.name), _classHeritage(element), body);
- return _finishClassDef(element.type, classDecl);
+ return _finishClassDef(
+ element.type, _emitClassHeritageWorkaround(classExpr));
}
JS.Statement _emitJsType(String dartClassName, DartObject jsName) {
@@ -674,6 +675,27 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ClosureAnnotator {
}
}
+ _isQualifiedPath(JS.Expression node) =>
+ node is JS.Identifier ||
+ node is JS.PropertyAccess &&
+ _isQualifiedPath(node.receiver) &&
+ node.selector is JS.LiteralString;
+
+ /// Workaround for Closure: super classes must be qualified paths.
+ JS.Statement _emitClassHeritageWorkaround(JS.ClassExpression cls) {
+ if (options.closure &&
+ cls.heritage != null &&
+ !_isQualifiedPath(cls.heritage)) {
+ var superVar = new JS.TemporaryId(cls.name.name + r'$super');
+ return _statement([
+ js.statement('const # = #;', [superVar, cls.heritage]),
+ new JS.ClassDeclaration(
+ new JS.ClassExpression(cls.name, superVar, cls.methods))
+ ]);
+ }
+ return new JS.ClassDeclaration(cls);
+ }
+
/// Emit class members that need to come after the class declaration, such
/// as static fields. See [_emitClassMethods] for things that are emitted
/// inside the ES6 `class { ... }` node.
@@ -702,7 +724,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ClosureAnnotator {
}
}
- body.add(new JS.ClassDeclaration(cls));
+ body.add(_emitClassHeritageWorkaround(cls));
// TODO(jmesserly): we should really just extend native Array.
if (jsPeerName != null && classElem.typeParameters.isNotEmpty) {
« no previous file with comments | « lib/runtime/dart/_runtime.js ('k') | test/codegen/expect/closure.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698