@@ -11,7 +11,7 @@ const {
11
11
resolveImportFilePathSync
12
12
} = require ( 'babel-file-loader' ) ;
13
13
const { isFlowIdentifier } = require ( 'babel-flow-identifiers' ) ;
14
- const { getTypeBinding } = require ( " babel-type-scopes" ) ;
14
+ const { getTypeBinding } = require ( ' babel-type-scopes' ) ;
15
15
const { getIdentifierKind } = require ( 'babel-identifiers' ) ;
16
16
const { isReactComponentClass } = require ( 'babel-react-components' ) ;
17
17
const createBabylonOptions = require ( 'babylon-options' ) ;
@@ -600,7 +600,7 @@ converters.Identifier = (path, context) /*: K.Id*/ => {
600
600
let kind = getIdentifierKind ( path ) ;
601
601
let name = path . node . name ;
602
602
603
- if ( context . mode === " value" ) {
603
+ if ( context . mode === ' value' ) {
604
604
let res = { } ;
605
605
if ( kind === 'reference' ) {
606
606
let binding = path . scope . getBinding ( name ) ;
@@ -680,21 +680,21 @@ converters.Identifier = (path, context) /*: K.Id*/ => {
680
680
} else if ( isTsIdentifier ( path ) ) {
681
681
let foundPath = path . scope . getBinding ( name ) ;
682
682
if (
683
- foundPath && (
684
- foundPath . path . isImportDefaultSpecifier ( ) ||
685
- foundPath . path . isImportNamespaceSpecifier ( ) ||
686
- foundPath . path . isImportSpecifier ( ) )
683
+ foundPath &&
684
+ ( foundPath . path . isImportDefaultSpecifier ( ) ||
685
+ foundPath . path . isImportNamespaceSpecifier ( ) ||
686
+ foundPath . path . isImportSpecifier ( ) )
687
687
) {
688
688
return convert ( foundPath . path , context ) ;
689
689
}
690
690
691
691
let tsBinding = getTypeBinding ( path , name ) ;
692
692
if ( ! tsBinding ) {
693
693
return {
694
- kind : "id" ,
695
- name,
694
+ kind : 'id' ,
695
+ name
696
696
} ;
697
- } ;
697
+ }
698
698
bindingPath = tsBinding . path . parentPath ;
699
699
} else {
700
700
bindingPath = path . scope . getBinding ( name ) ;
@@ -706,7 +706,10 @@ converters.Identifier = (path, context) /*: K.Id*/ => {
706
706
}
707
707
708
708
// If path is a descendant of bindingPath and share the same name, this is a recursive type.
709
- if ( path . isDescendant ( bindingPath ) && bindingPath . get ( 'id' ) . node . name === name ) {
709
+ if (
710
+ path . isDescendant ( bindingPath ) &&
711
+ bindingPath . get ( 'id' ) . node . name === name
712
+ ) {
710
713
return { kind : 'id' , name } ;
711
714
}
712
715
@@ -824,8 +827,8 @@ converters.TSUndefinedKeyword = (path, context) /*: K.Void */ => {
824
827
825
828
converters . TSTypeLiteral = ( path , context ) /*: K.Obj*/ => {
826
829
return {
827
- kind : 'object' ,
828
- members : path . get ( 'members' ) . map ( memberPath => convert ( memberPath , context ) )
830
+ kind : 'object' ,
831
+ members : path . get ( 'members' ) . map ( memberPath => convert ( memberPath , context ) )
829
832
} ;
830
833
} ;
831
834
@@ -834,13 +837,13 @@ converters.TSPropertySignature = (path, context) /*: K.Property */ => {
834
837
kind : 'property' ,
835
838
optional : ! ! path . node . optional ,
836
839
key : convert ( path . get ( 'key' ) , context ) ,
837
- value : convert ( path . get ( 'typeAnnotation' ) , context ) ,
838
- }
840
+ value : convert ( path . get ( 'typeAnnotation' ) , context )
841
+ } ;
839
842
} ;
840
843
841
- converters . TSTypeAliasDeclaration = ( path , context ) /*: K.Obj */ => {
844
+ converters . TSTypeAliasDeclaration = ( path , context ) /*: K.Obj */ => {
842
845
return convert ( path . get ( 'typeAnnotation' ) , context ) ;
843
- }
846
+ } ;
844
847
845
848
converters . TSLiteralType = ( path ) /*: K.String */ => {
846
849
return {
@@ -856,14 +859,14 @@ converters.TSTypeReference = (path, context) /*: K.Generic */ => {
856
859
return {
857
860
kind : 'generic' ,
858
861
typeParams : convert ( typeParameters , context ) ,
859
- value : convert ( path . get ( 'typeName' ) , context ) ,
860
- }
862
+ value : convert ( path . get ( 'typeName' ) , context )
863
+ } ;
861
864
}
862
865
863
866
return {
864
- kind : " generic" ,
865
- value : convert ( path . get ( " typeName" ) , context )
866
- }
867
+ kind : ' generic' ,
868
+ value : convert ( path . get ( ' typeName' ) , context )
869
+ } ;
867
870
} ;
868
871
869
872
converters . TSUnionType = ( path , context ) /*: K.Union*/ => {
@@ -881,16 +884,15 @@ converters.TSTupleType = (path, context) /*: K.Tuple*/ => {
881
884
} ;
882
885
883
886
converters . TSFunctionType = ( path , context ) /*: K.Generic */ => {
884
- const parameters = path . get ( "parameters" ) . map ( p => convertParameter ( p , context ) ) ;
885
- const returnType = convert (
886
- path . get ( "typeAnnotation" ) ,
887
- context
888
- ) ;
887
+ const parameters = path
888
+ . get ( 'parameters' )
889
+ . map ( p => convertParameter ( p , context ) ) ;
890
+ const returnType = convert ( path . get ( 'typeAnnotation' ) , context ) ;
889
891
890
892
return {
891
- kind : " generic" ,
893
+ kind : ' generic' ,
892
894
value : {
893
- kind : " function" ,
895
+ kind : ' function' ,
894
896
returnType,
895
897
parameters
896
898
}
@@ -902,20 +904,20 @@ converters.TSMethodSignature = (path, context) /*: K.Property */ => {
902
904
kind : 'property' ,
903
905
optional : ! ! path . node . optional ,
904
906
key : convert ( path . get ( 'key' ) , context ) ,
905
- value : convertMethodCall ( path , context ) ,
906
- }
907
- }
907
+ value : convertMethodCall ( path , context )
908
+ } ;
909
+ } ;
908
910
909
911
converters . TSCallSignatureDeclaration = ( path , context ) /*: K.Property */ => {
910
912
return {
911
913
kind : 'property' ,
912
914
key : {
913
- kind : 'string' ,
915
+ kind : 'string'
914
916
} ,
915
917
optional : false ,
916
918
value : convertMethodCall ( path , context )
917
919
} ;
918
- }
920
+ } ;
919
921
920
922
converters . TSInterfaceDeclaration = ( path , context ) /*: K.Obj */ => {
921
923
const extendedTypes = extendedTypesMembers ( path , context ) ;
@@ -924,12 +926,12 @@ converters.TSInterfaceDeclaration = (path, context) /*: K.Obj */ => {
924
926
kind : 'object' ,
925
927
// Merge the current interface members with any extended members
926
928
members : interfaceType . members . concat ( extendedTypes )
927
- }
929
+ } ;
928
930
} ;
929
931
930
932
converters . TSExpressionWithTypeArguments = ( path , context ) /*: K.Id */ => {
931
- return convert ( path . get ( 'expression' ) , context )
932
- }
933
+ return convert ( path . get ( 'expression' ) , context ) ;
934
+ } ;
933
935
934
936
converters . TSInterfaceBody = ( path , context ) /*: K.Obj */ => {
935
937
return {
@@ -939,33 +941,33 @@ converters.TSInterfaceBody = (path, context) /*: K.Obj */ => {
939
941
} ;
940
942
941
943
converters . TSTypeAnnotation = ( path , context ) => {
942
- return convert ( path . get ( " typeAnnotation" ) , context ) ;
944
+ return convert ( path . get ( ' typeAnnotation' ) , context ) ;
943
945
} ;
944
946
945
947
converters . TSQualifiedName = ( path , context ) /*: K.Id */ => {
946
- const left = convert ( path . get ( " left" ) , context ) ;
947
- const right = convert ( path . get ( " right" ) , context ) ;
948
+ const left = convert ( path . get ( ' left' ) , context ) ;
949
+ const right = convert ( path . get ( ' right' ) , context ) ;
948
950
949
951
return {
950
952
kind : 'id' ,
951
- name : `${ left . name } .${ right . name } ` ,
952
- }
953
+ name : `${ left . name } .${ right . name } `
954
+ } ;
953
955
} ;
954
956
955
957
converters . TSEnumDeclaration = ( path , context ) /*: K.Union */ => {
956
- const { name } = path . get ( "id" ) . node ;
957
- const types = path . get ( " members" ) . map ( p => {
958
+ const { name } = path . get ( 'id' ) . node ;
959
+ const types = path . get ( ' members' ) . map ( p => {
958
960
const member = convert ( p , context ) ;
959
961
return {
960
962
kind : member . kind ,
961
- name : `${ name } .${ member . name } ` ,
962
- }
963
+ name : `${ name } .${ member . name } `
964
+ } ;
963
965
} ) ;
964
- return { kind : " union" , types } ;
966
+ return { kind : ' union' , types } ;
965
967
} ;
966
968
967
969
converters . TSEnumMember = ( path , context ) => {
968
- return convert ( path . get ( "id" ) , context ) ;
970
+ return convert ( path . get ( 'id' ) , context ) ;
969
971
} ;
970
972
971
973
converters . TSArray = ( path , context ) /*: K.Any */ => {
@@ -979,7 +981,10 @@ converters.TSArrayType = (path, context) /*: K.ArrayType */ => {
979
981
} ;
980
982
} ;
981
983
982
- converters . TSTypeParameterInstantiation = ( path , context ) /*: K.TypeParams */ => {
984
+ converters . TSTypeParameterInstantiation = (
985
+ path ,
986
+ context
987
+ ) /*: K.TypeParams */ => {
983
988
return {
984
989
kind : 'typeParams' ,
985
990
params : path . get ( 'params' ) . map ( param => convert ( param , context ) )
@@ -1010,18 +1015,20 @@ converters.ArrayTypeAnnotation = (path, context) /*: K.ArrayType*/ => {
1010
1015
1011
1016
converters . TSIntersectionType = ( path , context ) /*: K.Intersection*/ => {
1012
1017
const types = path . get ( 'types' ) . map ( type => convert ( type , context ) ) ;
1013
- return { kind : 'intersection' , types }
1014
- }
1018
+ return { kind : 'intersection' , types } ;
1019
+ } ;
1015
1020
1016
- converters . TSIndexSignature = ( path , context ) /*: K.Property */ => {
1021
+ converters . TSIndexSignature = ( path , context ) /*: K.Property */ => {
1017
1022
const id = path . get ( 'parameters' ) [ 0 ] ;
1018
1023
return {
1019
1024
kind : 'property' ,
1020
1025
key : {
1021
1026
kind : 'id' ,
1022
- name : `[${ convert ( id , context ) . name } : ${ convert ( id . get ( 'typeAnnotation' ) , context ) . kind } ]`
1027
+ name : `[${ convert ( id , context ) . name } : ${
1028
+ convert ( id . get ( 'typeAnnotation' ) , context ) . kind
1029
+ } ]`
1023
1030
} ,
1024
- value : convert ( path . get ( 'typeAnnotation' ) , context ) ,
1031
+ value : convert ( path . get ( 'typeAnnotation' ) , context )
1025
1032
} ;
1026
1033
} ;
1027
1034
@@ -1038,8 +1045,8 @@ converters.TSNullKeyword = (path, context) /*: K.Null */ => {
1038
1045
} ;
1039
1046
1040
1047
converters . TSThisType = ( path , context ) /*:K.This */ => {
1041
- return { kind : 'custom' , value : 'this' }
1042
- }
1048
+ return { kind : 'custom' , value : 'this' } ;
1049
+ } ;
1043
1050
1044
1051
function extendedTypesMembers ( path , context ) {
1045
1052
const members = path . get ( 'extends' ) ;
@@ -1123,7 +1130,7 @@ function importConverterGeneral(path, context) /*: K.Import */ {
1123
1130
}
1124
1131
1125
1132
let exported = matchExported ( file , name ) ;
1126
-
1133
+
1127
1134
if ( ! exported ) {
1128
1135
exported = recursivelyResolveExportAll ( file . path , context , name ) ;
1129
1136
@@ -1258,7 +1265,7 @@ converters.ExportNamedDeclaration = (path, context) /*: K.Export */ => {
1258
1265
context . resolveOptions
1259
1266
) ;
1260
1267
1261
- file = loadFileSync ( actualPath ) ;
1268
+ file = loadFileSync ( actualPath , context . parserOpts ) ;
1262
1269
// We need to calculate name from the specifiers, I think knowing that there
1263
1270
// will always be one specifier
1264
1271
let resolvedValue = matchExported ( file , name ) ;
@@ -1291,11 +1298,10 @@ converters.ImportSpecifier = (path, context) /*: K.Import */ => {
1291
1298
} ;
1292
1299
1293
1300
function convertMethodCall ( path , context ) /*: K.Func */ {
1294
- const parameters = path . get ( 'parameters' ) . map ( p => convertParameter ( p , context ) ) ;
1295
- const returnType = convert (
1296
- path . get ( 'typeAnnotation' ) ,
1297
- context
1298
- ) ;
1301
+ const parameters = path
1302
+ . get ( 'parameters' )
1303
+ . map ( p => convertParameter ( p , context ) ) ;
1304
+ const returnType = convert ( path . get ( 'typeAnnotation' ) , context ) ;
1299
1305
1300
1306
return {
1301
1307
kind : 'function' ,
@@ -1306,10 +1312,10 @@ function convertMethodCall(path, context) /*: K.Func */ {
1306
1312
1307
1313
function mapComment ( comment ) {
1308
1314
return {
1309
- type : comment . type === " CommentLine" ? " commentLine" : " commentBlock" ,
1315
+ type : comment . type === ' CommentLine' ? ' commentLine' : ' commentBlock' ,
1310
1316
value : normalizeComment ( comment ) ,
1311
1317
raw : comment . value
1312
- }
1318
+ } ;
1313
1319
}
1314
1320
1315
1321
function attachCommentProperty ( source , dest , name ) {
0 commit comments