Chromium Code Reviews| Index: pkg/dev_compiler/lib/src/compiler/code_generator.dart |
| diff --git a/pkg/dev_compiler/lib/src/compiler/code_generator.dart b/pkg/dev_compiler/lib/src/compiler/code_generator.dart |
| index b1e665ae2838b7eaebe48d2b31dfeb9711d92d97..f3c9526cb47ba2afdf82d394c39000e81dfb61be 100644 |
| --- a/pkg/dev_compiler/lib/src/compiler/code_generator.dart |
| +++ b/pkg/dev_compiler/lib/src/compiler/code_generator.dart |
| @@ -752,18 +752,34 @@ class CodeGenerator extends Object |
| } |
| @override |
| - visitFunctionTypeAlias(FunctionTypeAlias node) { |
| - FunctionTypeAliasElement element = node.element; |
| + visitFunctionTypeAlias(FunctionTypeAlias node) => _emitTypedef(node); |
| + |
| + @override |
| + visitGenericTypeAlias(GenericTypeAlias node) => _emitTypedef(node); |
| + |
| + JS.Statement _emitTypedef(TypeAlias node) { |
| + var element = node.element as FunctionTypeAliasElement; |
| + FunctionType type; |
| + var typeFormals = element.typeParameters; |
| + if (element is GenericTypeAliasElement) { |
| + type = element.function.type; |
| + } else { |
| + type = element.type; |
| + if (typeFormals.isNotEmpty) { |
|
vsm
2017/04/21 22:19:54
Is this if not needed in the GenericTypeAliasEleme
Jennifer Messerly
2017/04/21 22:39:59
no it is not needed. GenericTypeAliasElement repre
|
| + // Skip past the type formals, we'll add them back below, so these |
| + // type parameter names will end up in scope in the generated JS. |
| + type = type.instantiate(typeFormals.map((f) => f.type).toList()); |
| + } |
| + } |
| JS.Expression body = annotate( |
| _callHelper('typedef(#, () => #)', [ |
| js.string(element.name, "'"), |
| - _emitType(element.type, nameType: false, lowerTypedef: true) |
| + _emitType(type, nameType: false, lowerTypedef: true) |
| ]), |
| node, |
| element); |
| - var typeFormals = element.typeParameters; |
| if (typeFormals.isNotEmpty) { |
| return _defineClassTypeArguments(element, typeFormals, |
| js.statement('const # = #;', [element.name, body])); |
| @@ -773,12 +789,6 @@ class CodeGenerator extends Object |
| } |
| @override |
| - visitGenericTypeAlias(GenericTypeAlias node) { |
| - throw new UnimplementedError('Generic type aliases are not implemented. ' |
| - 'See https://github.com/dart-lang/sdk/issues/27971'); |
| - } |
| - |
| - @override |
| JS.Expression visitTypeName(TypeName node) { |
| if (node.type == null) { |
| // TODO(jmesserly): if the type fails to resolve, should we generate code |
| @@ -3039,7 +3049,7 @@ class CodeGenerator extends Object |
| } |
| var typeFormals = type.typeFormals; |
| - if (typeFormals.isNotEmpty && !lowerTypedef) { |
| + if (typeFormals.isNotEmpty) { |
| // TODO(jmesserly): this is a suboptimal representation for universal |
| // function types (as callable functions). See discussion at |
| // https://github.com/dart-lang/sdk/issues/27333 |