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

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

Issue 1977893002: implement @JS classes (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: enable more tests Created 4 years, 7 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 | lib/src/compiler/js_interop.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/compiler/code_generator.dart
diff --git a/lib/src/compiler/code_generator.dart b/lib/src/compiler/code_generator.dart
index 23e36750e5d2f921c9d29526d888b309ccd2db0f..d07bfb06619611d3aa7cb7238e7f19185343f0e9 100644
--- a/lib/src/compiler/code_generator.dart
+++ b/lib/src/compiler/code_generator.dart
@@ -598,6 +598,9 @@ class CodeGenerator extends GeneralizingAstVisitor
JS.Statement visitClassDeclaration(ClassDeclaration node) {
var classElem = node.element;
+ // If this class is annotated with `@JS`, then there is nothing to emit.
+ if (findAnnotation(classElem, isPublicJSAnnotation) != null) return null;
+
// If this is a JavaScript type, emit it now and then exit.
var jsTypeDef = _emitJsType(classElem);
if (jsTypeDef != null) return jsTypeDef;
@@ -3020,6 +3023,12 @@ class CodeGenerator extends GeneralizingAstVisitor
JS.Expression _emitConstructorName(
ConstructorElement element, DartType type, SimpleIdentifier name) {
+ var classElem = element.enclosingElement;
+ if (findAnnotation(classElem, isPublicJSAnnotation) != null) {
+ var annotationName = getAnnotationName(classElem, isPublicJSAnnotation);
+ var typeName = js.string(annotationName ?? classElem.name);
+ return new JS.PropertyAccess(new JS.Identifier('self'), typeName);
+ }
var typeName = _emitType(type);
if (name != null || element.isFactory) {
var namedCtor = _constructorName(element);
@@ -3057,10 +3066,27 @@ class CodeGenerator extends GeneralizingAstVisitor
var args = _visit(argumentList) as List<JS.Expression>;
return isFactory ? new JS.Call(ctor, args) : new JS.New(ctor, args);
}
+ if (_isObjectLiteral(element.enclosingElement)) {
+ return _emitObjectLiteral(argumentList);
+ }
if (isConst) return _emitConst(emitNew);
return emitNew();
}
+ bool _isObjectLiteral(ClassElement classElem) {
+ return findAnnotation(classElem, isPublicJSAnnotation) != null &&
+ findAnnotation(classElem, isJSAnonymousAnnotation) != null;
+ }
+
+ JS.Expression _emitObjectLiteral(ArgumentList argumentList) {
+ var args = _visit(argumentList) as List<JS.Expression>;
+ if (args.isEmpty) {
+ return js.call('{}');
+ }
+ assert(args.single is JS.ObjectInitializer);
+ return args.single;
+ }
+
@override
visitInstanceCreationExpression(InstanceCreationExpression node) {
var element = node.staticElement;
« no previous file with comments | « no previous file | lib/src/compiler/js_interop.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698