@@ -634,45 +634,6 @@ impl ESTree for FormalParametersRest<'_, '_> {
634634 }
635635}
636636
637- /// Serializer for `params` field of `Function`.
638- ///
639- /// In TS AST, this adds `this_param` to start of the array.
640- #[ ast_meta]
641- #[ estree(
642- ts_type = "ParamPattern[]" ,
643- raw_deser = "
644- const params = DESER[Box<FormalParameters>](POS_OFFSET.params);
645- /* IF_TS */
646- const thisParam = DESER[Option<Box<TSThisParameter>>](POS_OFFSET.this_param)
647- if (thisParam !== null) params.unshift(thisParam);
648- /* END_IF_TS */
649- params
650- "
651- ) ]
652- pub struct FunctionFormalParameters < ' a , ' b > ( pub & ' b Function < ' a > ) ;
653-
654- impl ESTree for FunctionFormalParameters < ' _ , ' _ > {
655- fn serialize < S : Serializer > ( & self , serializer : S ) {
656- let mut seq = serializer. serialize_sequence ( ) ;
657-
658- if S :: INCLUDE_TS_FIELDS {
659- if let Some ( this_param) = & self . 0 . this_param {
660- seq. serialize_element ( this_param) ;
661- }
662- }
663-
664- for item in & self . 0 . params . items {
665- seq. serialize_element ( item) ;
666- }
667-
668- if let Some ( rest) = & self . 0 . params . rest {
669- seq. serialize_element ( & FormalParametersRest ( rest) ) ;
670- }
671-
672- seq. end ( ) ;
673- }
674- }
675-
676637/// Serializer for `key` field of `MethodDefinition`.
677638///
678639/// In TS-ESTree `"constructor"` in `class C { "constructor"() {} }`
@@ -719,29 +680,6 @@ impl ESTree for MethodDefinitionKey<'_, '_> {
719680 }
720681}
721682
722- /// Serializer for `extends` field of `TSInterfaceDeclaration`.
723- ///
724- /// Serialize `extends` as an empty array if it's `None`.
725- #[ ast_meta]
726- #[ estree(
727- ts_type = "Array<TSInterfaceHeritage>" ,
728- raw_deser = "
729- const extendsArr = DESER[Option<Vec<TSInterfaceHeritage>>](POS_OFFSET.extends);
730- extendsArr === null ? [] : extendsArr
731- "
732- ) ]
733- pub struct TSInterfaceDeclarationExtends < ' a , ' b > ( pub & ' b TSInterfaceDeclaration < ' a > ) ;
734-
735- impl ESTree for TSInterfaceDeclarationExtends < ' _ , ' _ > {
736- fn serialize < S : Serializer > ( & self , serializer : S ) {
737- if let Some ( extends) = & self . 0 . extends {
738- extends. serialize ( serializer) ;
739- } else {
740- [ ( ) ; 0 ] . serialize ( serializer) ;
741- }
742- }
743- }
744-
745683/// Serializer for `specifiers` field of `ImportDeclaration`.
746684///
747685/// Serialize `specifiers` as an empty array if it's `None`.
@@ -1127,6 +1065,162 @@ impl ESTree for TSMappedTypeModifierOperatorConverter<'_> {
11271065 }
11281066}
11291067
1068+ /// Serializer for `params` field of `Function`.
1069+ ///
1070+ /// In TS AST, this adds `this_param` to start of the `params` array.
1071+ #[ ast_meta]
1072+ #[ estree(
1073+ ts_type = "ParamPattern[]" ,
1074+ raw_deser = "
1075+ const params = DESER[Box<FormalParameters>](POS_OFFSET.params);
1076+ /* IF_TS */
1077+ const thisParam = DESER[Option<Box<TSThisParameter>>](POS_OFFSET.this_param)
1078+ if (thisParam !== null) params.unshift(thisParam);
1079+ /* END_IF_TS */
1080+ params
1081+ "
1082+ ) ]
1083+ pub struct FunctionFormalParameters < ' a , ' b > ( pub & ' b Function < ' a > ) ;
1084+
1085+ impl ESTree for FunctionFormalParameters < ' _ , ' _ > {
1086+ fn serialize < S : Serializer > ( & self , serializer : S ) {
1087+ let mut seq = serializer. serialize_sequence ( ) ;
1088+
1089+ if S :: INCLUDE_TS_FIELDS {
1090+ if let Some ( this_param) = & self . 0 . this_param {
1091+ seq. serialize_element ( this_param) ;
1092+ }
1093+ }
1094+
1095+ for item in & self . 0 . params . items {
1096+ seq. serialize_element ( item) ;
1097+ }
1098+
1099+ if let Some ( rest) = & self . 0 . params . rest {
1100+ seq. serialize_element ( & FormalParametersRest ( rest) ) ;
1101+ }
1102+
1103+ seq. end ( ) ;
1104+ }
1105+ }
1106+
1107+ /// Serializer for `params` field of `TSCallSignatureDeclaration`.
1108+ ///
1109+ /// These add `this_param` to start of the `params` array.
1110+ #[ ast_meta]
1111+ #[ estree(
1112+ ts_type = "ParamPattern[]" ,
1113+ raw_deser = "
1114+ const params = DESER[Box<FormalParameters>](POS_OFFSET.params);
1115+ const thisParam = DESER[Option<Box<TSThisParameter>>](POS_OFFSET.this_param)
1116+ if (thisParam !== null) params.unshift(thisParam);
1117+ params
1118+ "
1119+ ) ]
1120+ pub struct TSCallSignatureDeclarationFormalParameters < ' a , ' b > (
1121+ pub & ' b TSCallSignatureDeclaration < ' a > ,
1122+ ) ;
1123+
1124+ impl ESTree for TSCallSignatureDeclarationFormalParameters < ' _ , ' _ > {
1125+ fn serialize < S : Serializer > ( & self , serializer : S ) {
1126+ let v = self . 0 ;
1127+ serialize_formal_params_with_this_param ( v. this_param . as_ref ( ) , & v. params , serializer) ;
1128+ }
1129+ }
1130+
1131+ /// Serializer for `params` field of `TSMethodSignature`.
1132+ ///
1133+ /// These add `this_param` to start of the `params` array.
1134+ #[ ast_meta]
1135+ #[ estree(
1136+ ts_type = "ParamPattern[]" ,
1137+ raw_deser = "
1138+ const params = DESER[Box<FormalParameters>](POS_OFFSET.params);
1139+ const thisParam = DESER[Option<Box<TSThisParameter>>](POS_OFFSET.this_param)
1140+ if (thisParam !== null) params.unshift(thisParam);
1141+ params
1142+ "
1143+ ) ]
1144+ pub struct TSMethodSignatureFormalParameters < ' a , ' b > ( pub & ' b TSMethodSignature < ' a > ) ;
1145+
1146+ impl ESTree for TSMethodSignatureFormalParameters < ' _ , ' _ > {
1147+ fn serialize < S : Serializer > ( & self , serializer : S ) {
1148+ let v = self . 0 ;
1149+ serialize_formal_params_with_this_param ( v. this_param . as_deref ( ) , & v. params , serializer) ;
1150+ }
1151+ }
1152+
1153+ /// Serializer for `params` field of `TSFunctionType`.
1154+ ///
1155+ /// These add `this_param` to start of the `params` array.
1156+ #[ ast_meta]
1157+ #[ estree(
1158+ ts_type = "ParamPattern[]" ,
1159+ raw_deser = "
1160+ const params = DESER[Box<FormalParameters>](POS_OFFSET.params);
1161+ const thisParam = DESER[Option<Box<TSThisParameter>>](POS_OFFSET.this_param)
1162+ if (thisParam !== null) params.unshift(thisParam);
1163+ params
1164+ "
1165+ ) ]
1166+ pub struct TSFunctionTypeFormalParameters < ' a , ' b > ( pub & ' b TSFunctionType < ' a > ) ;
1167+
1168+ impl ESTree for TSFunctionTypeFormalParameters < ' _ , ' _ > {
1169+ fn serialize < S : Serializer > ( & self , serializer : S ) {
1170+ let v = self . 0 ;
1171+ serialize_formal_params_with_this_param ( v. this_param . as_deref ( ) , & v. params , serializer) ;
1172+ }
1173+ }
1174+
1175+ /// Shared serialization logic used by:
1176+ /// - `TSCallSignatureDeclarationFormalParameters`
1177+ /// - `TSMethodSignatureFormalParameters`
1178+ /// - `TSFunctionTypeFormalParameters`
1179+ fn serialize_formal_params_with_this_param < ' a , S : Serializer > (
1180+ this_param : Option < & TSThisParameter < ' a > > ,
1181+ params : & FormalParameters < ' a > ,
1182+ serializer : S ,
1183+ ) {
1184+ let mut seq = serializer. serialize_sequence ( ) ;
1185+
1186+ if let Some ( this_param) = this_param {
1187+ seq. serialize_element ( this_param) ;
1188+ }
1189+
1190+ for item in & params. items {
1191+ seq. serialize_element ( item) ;
1192+ }
1193+
1194+ if let Some ( rest) = & params. rest {
1195+ seq. serialize_element ( & FormalParametersRest ( rest) ) ;
1196+ }
1197+
1198+ seq. end ( ) ;
1199+ }
1200+
1201+ /// Serializer for `extends` field of `TSInterfaceDeclaration`.
1202+ ///
1203+ /// Serialize `extends` as an empty array if it's `None`.
1204+ #[ ast_meta]
1205+ #[ estree(
1206+ ts_type = "Array<TSInterfaceHeritage>" ,
1207+ raw_deser = "
1208+ const extendsArr = DESER[Option<Vec<TSInterfaceHeritage>>](POS_OFFSET.extends);
1209+ extendsArr === null ? [] : extendsArr
1210+ "
1211+ ) ]
1212+ pub struct TSInterfaceDeclarationExtends < ' a , ' b > ( pub & ' b TSInterfaceDeclaration < ' a > ) ;
1213+
1214+ impl ESTree for TSInterfaceDeclarationExtends < ' _ , ' _ > {
1215+ fn serialize < S : Serializer > ( & self , serializer : S ) {
1216+ if let Some ( extends) = & self . 0 . extends {
1217+ extends. serialize ( serializer) ;
1218+ } else {
1219+ EmptyArray ( ( ) ) . serialize ( serializer) ;
1220+ }
1221+ }
1222+ }
1223+
11301224// --------------------
11311225// Comments
11321226// --------------------
0 commit comments