@@ -52,6 +52,7 @@ import {
52
52
EmptyStatement ,
53
53
ExportImportStatement ,
54
54
ExportStatement ,
55
+ ExportDefaultStatement ,
55
56
ExpressionStatement ,
56
57
ForStatement ,
57
58
IfStatement ,
@@ -230,6 +231,10 @@ export class ASTBuilder {
230
231
this . visitExportStatement ( < ExportStatement > node ) ;
231
232
break ;
232
233
}
234
+ case NodeKind . EXPORTDEFAULT : {
235
+ this . visitExportDefaultStatement ( < ExportDefaultStatement > node ) ;
236
+ break ;
237
+ }
233
238
case NodeKind . EXPORTIMPORT : {
234
239
this . visitExportImportStatement ( < ExportImportStatement > node ) ;
235
240
break ;
@@ -851,15 +856,19 @@ export class ASTBuilder {
851
856
}
852
857
}
853
858
854
- visitClassDeclaration ( node : ClassDeclaration ) : void {
859
+ visitClassDeclaration ( node : ClassDeclaration , isDefault : bool = false ) : void {
855
860
var decorators = node . decorators ;
856
861
if ( decorators ) {
857
862
for ( let i = 0 , k = decorators . length ; i < k ; ++ i ) {
858
863
this . serializeDecorator ( decorators [ i ] ) ;
859
864
}
860
865
}
861
- this . serializeExternalModifiers ( node ) ;
862
866
var sb = this . sb ;
867
+ if ( isDefault ) {
868
+ sb . push ( "export default " ) ;
869
+ } else {
870
+ this . serializeExternalModifiers ( node ) ;
871
+ }
863
872
if ( node . is ( CommonFlags . ABSTRACT ) ) sb . push ( "abstract " ) ;
864
873
if ( node . name . text . length ) {
865
874
sb . push ( "class " ) ;
@@ -931,9 +940,13 @@ export class ASTBuilder {
931
940
visitEmptyStatement ( node : EmptyStatement ) : void {
932
941
}
933
942
934
- visitEnumDeclaration ( node : EnumDeclaration ) : void {
943
+ visitEnumDeclaration ( node : EnumDeclaration , isDefault : bool = false ) : void {
935
944
var sb = this . sb ;
936
- this . serializeExternalModifiers ( node ) ;
945
+ if ( isDefault ) {
946
+ sb . push ( "export default " ) ;
947
+ } else {
948
+ this . serializeExternalModifiers ( node ) ;
949
+ }
937
950
if ( node . is ( CommonFlags . CONST ) ) sb . push ( "const " ) ;
938
951
sb . push ( "enum " ) ;
939
952
this . visitIdentifierExpression ( node . name ) ;
@@ -1011,6 +1024,33 @@ export class ASTBuilder {
1011
1024
sb . push ( ";" ) ;
1012
1025
}
1013
1026
1027
+ visitExportDefaultStatement ( node : ExportDefaultStatement ) : void {
1028
+ var declaration = node . declaration ;
1029
+ switch ( declaration . kind ) {
1030
+ case NodeKind . ENUMDECLARATION : {
1031
+ this . visitEnumDeclaration ( < EnumDeclaration > declaration , true ) ;
1032
+ break ;
1033
+ }
1034
+ case NodeKind . FUNCTIONDECLARATION : {
1035
+ this . visitFunctionDeclaration ( < FunctionDeclaration > declaration , true ) ;
1036
+ break ;
1037
+ }
1038
+ case NodeKind . CLASSDECLARATION : {
1039
+ this . visitClassDeclaration ( < ClassDeclaration > declaration , true ) ;
1040
+ break ;
1041
+ }
1042
+ case NodeKind . INTERFACEDECLARATION : {
1043
+ this . visitInterfaceDeclaration ( < InterfaceDeclaration > declaration , true ) ;
1044
+ break ;
1045
+ }
1046
+ case NodeKind . NAMESPACEDECLARATION : {
1047
+ this . visitNamespaceDeclaration ( < NamespaceDeclaration > declaration , true ) ;
1048
+ break ;
1049
+ }
1050
+ default : assert ( false ) ;
1051
+ }
1052
+ }
1053
+
1014
1054
visitExpressionStatement ( node : ExpressionStatement ) : void {
1015
1055
this . visitNode ( node . expression ) ;
1016
1056
}
@@ -1065,16 +1105,20 @@ export class ASTBuilder {
1065
1105
this . visitNode ( node . statement ) ;
1066
1106
}
1067
1107
1068
- visitFunctionDeclaration ( node : FunctionDeclaration ) : void {
1108
+ visitFunctionDeclaration ( node : FunctionDeclaration , isDefault : bool = false ) : void {
1069
1109
var sb = this . sb ;
1070
1110
var decorators = node . decorators ;
1071
1111
if ( decorators ) {
1072
1112
for ( let i = 0 , k = decorators . length ; i < k ; ++ i ) {
1073
1113
this . serializeDecorator ( decorators [ i ] ) ;
1074
1114
}
1075
1115
}
1076
- this . serializeExternalModifiers ( node ) ;
1077
- this . serializeAccessModifiers ( node ) ;
1116
+ if ( isDefault ) {
1117
+ sb . push ( "export default " ) ;
1118
+ } else {
1119
+ this . serializeExternalModifiers ( node ) ;
1120
+ this . serializeAccessModifiers ( node ) ;
1121
+ }
1078
1122
if ( node . name . text . length ) {
1079
1123
sb . push ( "function " ) ;
1080
1124
} else {
@@ -1230,15 +1274,19 @@ export class ASTBuilder {
1230
1274
this . visitTypeNode ( node . valueType ) ;
1231
1275
}
1232
1276
1233
- visitInterfaceDeclaration ( node : InterfaceDeclaration ) : void {
1277
+ visitInterfaceDeclaration ( node : InterfaceDeclaration , isDefault : bool = false ) : void {
1234
1278
var decorators = node . decorators ;
1235
1279
if ( decorators ) {
1236
1280
for ( let i = 0 , k = decorators . length ; i < k ; ++ i ) {
1237
1281
this . serializeDecorator ( decorators [ i ] ) ;
1238
1282
}
1239
1283
}
1240
- this . serializeExternalModifiers ( node ) ;
1241
1284
var sb = this . sb ;
1285
+ if ( isDefault ) {
1286
+ sb . push ( "export default " ) ;
1287
+ } else {
1288
+ this . serializeExternalModifiers ( node ) ;
1289
+ }
1242
1290
sb . push ( "interface " ) ;
1243
1291
this . visitIdentifierExpression ( node . name ) ;
1244
1292
var typeParameters = node . typeParameters ;
@@ -1284,15 +1332,19 @@ export class ASTBuilder {
1284
1332
this . visitFunctionCommon ( node ) ;
1285
1333
}
1286
1334
1287
- visitNamespaceDeclaration ( node : NamespaceDeclaration ) : void {
1335
+ visitNamespaceDeclaration ( node : NamespaceDeclaration , isDefault : bool = false ) : void {
1288
1336
var decorators = node . decorators ;
1289
1337
if ( decorators ) {
1290
1338
for ( let i = 0 , k = decorators . length ; i < k ; ++ i ) {
1291
1339
this . serializeDecorator ( decorators [ i ] ) ;
1292
1340
}
1293
1341
}
1294
- this . serializeExternalModifiers ( node ) ;
1295
1342
var sb = this . sb ;
1343
+ if ( isDefault ) {
1344
+ sb . push ( "export default " ) ;
1345
+ } else {
1346
+ this . serializeExternalModifiers ( node ) ;
1347
+ }
1296
1348
sb . push ( "namespace " ) ;
1297
1349
this . visitIdentifierExpression ( node . name ) ;
1298
1350
var members = node . members ;
0 commit comments