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

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: 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 8104a628f51c1dbc5fe6dfcd8ab8ebd0563e8fa0..bcd0eb579cd1309f234a6eda93ed9210064d511d 100644
--- a/lib/src/codegen/js_codegen.dart
+++ b/lib/src/codegen/js_codegen.dart
@@ -375,10 +375,10 @@ 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, _emitClassDeclaration(classExpr));
Jennifer Messerly 2016/02/01 23:59:55 The same fix is likely needed for ClassTypeAlias
ochafik 2016/02/03 19:41:33 Done.
}
JS.Statement _emitJsType(String dartClassName, DartObject jsName) {
@@ -669,6 +669,25 @@ 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;
+
+ JS.Statement _emitClassDeclaration(JS.ClassExpression cls) {
Jennifer Messerly 2016/02/01 23:59:55 from the naming convention, I would probably expec
ochafik 2016/02/03 19:41:33 Done.
+ var body = <JS.Statement>[];
Jennifer Messerly 2016/02/01 23:59:55 this can go inside the if: if (...) { return ne
ochafik 2016/02/03 19:41:33 Done.
+ if (options.closure &&
+ cls.heritage != null && !_isQualifiedPath(cls.heritage)) {
+ // Workaround for Closure: super classes must be qualified paths.
Jennifer Messerly 2016/02/01 23:59:55 After the method rename, this would be good as a d
ochafik 2016/02/03 19:41:33 Done.
+ var superVar = new JS.Identifier(cls.name.name + r'$super');
Jennifer Messerly 2016/02/01 23:59:55 This should be a temp. Use `new JS.TemporaryId`. T
ochafik 2016/02/03 19:41:33 Done.
+ body.add(js.statement('const # = #;', [superVar, cls.heritage]));
+ cls = new JS.ClassExpression(cls.name, superVar, cls.methods);
+ }
+ body.add(new JS.ClassDeclaration(cls));
+ return _statement(body);
+ }
+
/// 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.
@@ -696,7 +715,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ClosureAnnotator {
}
}
- body.add(new JS.ClassDeclaration(cls));
+ body.add(_emitClassDeclaration(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