@@ -502,7 +502,6 @@ export default class DeclarationTranspiler extends base.TranspilerBase {
502
502
let sourceFile = node as ts . SourceFile ;
503
503
this . visitMergingOverloads ( sourceFile . statements ) ;
504
504
if ( this . containsPromises ) {
505
- this . addImport ( 'dart:async' , 'Completer' ) ;
506
505
this . addImport ( 'package:js/js_util.dart' , 'promiseToFuture' ) ;
507
506
this . emit ( `@JS() abstract class Promise<T> {}\n` ) ;
508
507
}
@@ -843,17 +842,14 @@ export default class DeclarationTranspiler extends base.TranspilerBase {
843
842
keyword : string , decl : base . ClassLike | ts . TypeLiteralNode , name : ts . Identifier ,
844
843
typeParameters : ts . NodeArray < ts . TypeParameterDeclaration > ,
845
844
heritageClauses : ts . NodeArray < ts . HeritageClause > ) {
845
+ const visitName = ( ) => {
846
+ this . visitClassLikeName ( name , typeParameters , heritageClauses , false ) ;
847
+ } ;
848
+ const visitNameOfExtensions = ( ) => {
849
+ this . visitClassLikeName ( name , typeParameters , heritageClauses , true ) ;
850
+ } ;
846
851
this . emit ( keyword ) ;
847
- this . fc . visitTypeName ( name ) ;
848
- if ( typeParameters ) {
849
- this . emit ( '<' ) ;
850
- this . enterTypeArguments ( ) ;
851
- this . visitList ( typeParameters ) ;
852
- this . exitTypeArguments ( ) ;
853
- this . emit ( '>' ) ;
854
- }
855
-
856
- this . visitEachIfPresent ( heritageClauses ) ;
852
+ visitName ( ) ;
857
853
this . emit ( '{' ) ;
858
854
859
855
this . maybeEmitFakeConstructors ( decl ) ;
@@ -876,12 +872,32 @@ export default class DeclarationTranspiler extends base.TranspilerBase {
876
872
this . visitClassBody ( decl , name ) ;
877
873
this . emit ( '}\n' ) ;
878
874
if ( this . promiseMethods . size ) {
879
- this . emitMethodsAsExtensions ( name , this . promiseMethods ) ;
875
+ this . emitMethodsAsExtensions ( name , visitName , visitNameOfExtensions , this . promiseMethods ) ;
880
876
this . promiseMethods . clear ( ) ;
881
877
}
882
878
this . emit ( '\n' ) ;
883
879
}
884
880
881
+ private visitClassLikeName (
882
+ name : ts . Identifier , typeParameters : ts . NodeArray < ts . TypeParameterDeclaration > ,
883
+ heritageClauses : ts . NodeArray < ts . HeritageClause > , extension : boolean ) {
884
+ this . fc . visitTypeName ( name ) ;
885
+
886
+ if ( extension ) {
887
+ this . emitNoSpace ( 'Extensions' ) ;
888
+ }
889
+
890
+ if ( typeParameters ) {
891
+ this . emit ( '<' ) ;
892
+ this . enterTypeArguments ( ) ;
893
+ this . visitList ( typeParameters ) ;
894
+ this . exitTypeArguments ( ) ;
895
+ this . emit ( '>' ) ;
896
+ }
897
+
898
+ this . visitEachIfPresent ( heritageClauses ) ;
899
+ }
900
+
885
901
private visitDeclarationMetadata ( decl : ts . Declaration ) {
886
902
this . visitEachIfPresent ( decl . modifiers ) ;
887
903
@@ -932,26 +948,32 @@ export default class DeclarationTranspiler extends base.TranspilerBase {
932
948
}
933
949
934
950
private emitMethodsAsExtensions (
935
- className : ts . Identifier , methods : Set < ts . FunctionLikeDeclaration > ) {
951
+ className : ts . Identifier , visitName : ( ) => void , visitNameOfExtensions : ( ) => void ,
952
+ methods : Set < ts . FunctionLikeDeclaration > ) {
936
953
// Emit private class containing external methods
937
954
this . emit ( `@JS('${ base . ident ( className ) } ')` ) ;
938
955
this . emit ( `abstract class _` ) ;
939
- this . fc . visitTypeName ( className ) ;
956
+ visitName ( ) ;
940
957
this . emit ( '{' ) ;
941
958
for ( const declaration of methods ) {
942
959
this . visitFunctionLike ( declaration ) ;
943
960
}
944
961
this . emit ( '}\n' ) ;
945
962
946
963
// Emit extensions on public class to expose methods
947
- this . emit ( 'extension on' ) ;
948
- this . fc . visitTypeName ( className ) ;
964
+ this . emit ( 'extension' ) ;
965
+ visitNameOfExtensions ( ) ;
966
+ this . emit ( 'on' ) ;
967
+ visitName ( ) ;
949
968
this . emit ( '{' ) ;
950
969
for ( const declaration of methods ) {
951
970
if ( ! base . isPromise ( declaration . type ) ) {
952
971
continue ;
953
972
}
954
973
this . emit ( 'Future' ) ;
974
+ if ( ts . isTypeReferenceNode ( declaration . type ) ) {
975
+ this . maybeVisitTypeArguments ( declaration . type ) ;
976
+ }
955
977
this . emit ( base . ident ( declaration . name ) ) ;
956
978
this . visitParameters ( declaration . parameters , { namesOnly : false } ) ;
957
979
this . emit ( '{' ) ;
0 commit comments