Chromium Code Reviews| Index: lib/src/codegen/js_codegen.dart |
| diff --git a/lib/src/codegen/js_codegen.dart b/lib/src/codegen/js_codegen.dart |
| index 264cccc42e23de10153334825d9e0422fa09896f..b273673cf69ccbee9a9d9f909f27e141d31d8105 100644 |
| --- a/lib/src/codegen/js_codegen.dart |
| +++ b/lib/src/codegen/js_codegen.dart |
| @@ -68,6 +68,8 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor { |
| ConstantEvaluator _constEvaluator; |
| + InterfaceType _currentClass = null; |
| + |
| /// Imported libraries, and the temporaries used to refer to them. |
| final _imports = new Map<LibraryElement, JS.TemporaryId>(); |
| final _exports = new Set<String>(); |
| @@ -332,6 +334,10 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor { |
| if (jsName != null) return _emitJsType(node.name.name, jsName); |
| + // Set current class |
| + assert(_currentClass == null); |
| + _currentClass = type; |
|
Jennifer Messerly
2015/05/11 16:35:08
suggestion: maybe save the Element here, not the t
vsm
2015/05/11 17:51:09
Done.
|
| + |
| var ctors = <ConstructorDeclaration>[]; |
| var fields = <FieldDeclaration>[]; |
| var staticFields = <FieldDeclaration>[]; |
| @@ -355,6 +361,10 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor { |
| var body = _finishClassMembers( |
| classElem, classExpr, ctors, fields, staticFields, jsPeerName); |
| + // Unset current class |
| + assert(_currentClass == type); |
| + _currentClass = null; |
| + |
| var result = _finishClassDef(type, body); |
| if (jsPeerName != null) { |
| @@ -1235,7 +1245,12 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor { |
| var typeArgs = null; |
| if (type is ParameterizedType) { |
| var args = type.typeArguments; |
| - if (args.any((a) => a != types.dynamicType)) { |
| + // For a generic class with dynamic type parameters, try to use the |
| + // raw form: new S() instead of new S<dynamic>() if possible. |
| + var isCurrentClass = |
|
Jennifer Messerly
2015/05/11 16:35:08
could this just be:
var isCurrentClass = type
vsm
2015/05/11 17:51:09
Done.
|
| + type is InterfaceType ? type.element.type == _currentClass : false; |
| + if (args.isNotEmpty && isCurrentClass || |
|
Jennifer Messerly
2015/05/11 16:35:08
maybe split these into two cases:
if (args.any((a
vsm
2015/05/11 17:51:09
Ahh, nice. Done!
|
| + args.any((a) => a != types.dynamicType)) { |
| name = '$name\$'; |
| typeArgs = args.map(_emitTypeName); |
| } |