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 a642fe4da82618211f0ff3717842618acf9f03c7..7968477d5d816011b86da3a396f3464ee81f64e7 100644 |
| --- a/pkg/dev_compiler/lib/src/compiler/code_generator.dart |
| +++ b/pkg/dev_compiler/lib/src/compiler/code_generator.dart |
| @@ -754,8 +754,8 @@ class CodeGenerator extends GeneralizingAstVisitor |
| _defineClass(classElem, className, classExpr, isCallable, body); |
| // Emit things that come after the ES6 `class ... { ... }`. |
| - var jsPeerName = _getJSPeerName(classElem); |
| - _setBaseClass(classElem, className, jsPeerName, body); |
| + var jsPeerNames = _getJSPeerNames(classElem); |
| + _setBaseClass(classElem, className, jsPeerNames, body); |
| _emitClassTypeTests(classElem, className, body); |
| @@ -774,7 +774,9 @@ class CodeGenerator extends GeneralizingAstVisitor |
| body = <JS.Statement>[classDef]; |
| _emitStaticFields(staticFields, staticFieldOverrides, classElem, body); |
| - _registerExtensionType(classElem, jsPeerName, body); |
| + for (var peer in jsPeerNames) { |
| + _registerExtensionType(classElem, peer, body); |
| + } |
| return _statement(body); |
| } |
| @@ -1569,16 +1571,19 @@ class CodeGenerator extends GeneralizingAstVisitor |
| /// |
| /// For example for dart:_interceptors `JSArray` this will return "Array", |
| /// referring to the JavaScript built-in `Array` type. |
| - String _getJSPeerName(ClassElement classElem) { |
| - var jsPeerName = getAnnotationName( |
| + List<String> _getJSPeerNames(ClassElement classElem) { |
| + var jsPeerNames = getAnnotationName( |
| classElem, |
| (a) => |
| isJsPeerInterface(a) || |
| isNativeAnnotation(a) && _extensionTypes.isNativeClass(classElem)); |
| - if (jsPeerName != null && jsPeerName.contains(',')) { |
| - jsPeerName = jsPeerName.split(',')[0]; |
| + if (jsPeerNames != null) { |
| + // Omit the special name "!nonleaf" and any future hacks starting with "!" |
| + return jsPeerNames.split(',').where( |
| + (peer) => !peer.startsWith("!")).toList(); |
| + } else { |
| + return []; |
| } |
| - return jsPeerName; |
| } |
| void _registerExtensionType( |
| @@ -1590,12 +1595,14 @@ class CodeGenerator extends GeneralizingAstVisitor |
| } |
| void _setBaseClass(ClassElement classElem, JS.Expression className, |
| - String jsPeerName, List<JS.Statement> body) { |
| - if (jsPeerName != null && classElem.typeParameters.isNotEmpty) { |
| - // TODO(jmesserly): we should really just extend Array in the first place. |
| - var newBaseClass = js.call('dart.global.#', [jsPeerName]); |
| - body.add(js.statement( |
| - 'dart.setExtensionBaseClass(#, #);', [className, newBaseClass])); |
| + List<String> jsPeerNames, List<JS.Statement> body) { |
| + if (jsPeerNames.isNotEmpty && classElem.typeParameters.isNotEmpty) { |
| + for (var peer in jsPeerNames) { |
| + // TODO(jmesserly): we should just extend Array in the first place |
| + var newBaseClass = js.call('dart.global.#', [peer]); |
| + body.add(js.statement( |
| + 'dart.setExtensionBaseClass(#, #);', [className, newBaseClass])); |
|
vsm
2016/10/17 23:08:29
Hmm - I'm a little surprised this works. Looking
vsm
2016/10/17 23:17:59
Ahh, looks like combination of type parameters and
|
| + } |
| } else if (_hasDeferredSupertype.contains(classElem)) { |
| var newBaseClass = _emitType(classElem.type.superclass, |
| nameType: false, subClass: classElem, className: className); |