@@ -233,43 +233,15 @@ let makeExternalDecl fnName loc namedArgListWithKeyAndRef namedTypeList =
233
233
(makePropsType ~loc namedTypeList)
234
234
[@@ raises Invalid_argument ]
235
235
236
- let rec newtypeToVar newtype typ =
237
- let traverse = newtypeToVar newtype in
238
- { typ with ptyp_desc =
236
+ let newtypeToVar newtype type_ =
237
+ let typ (mapper : Ast_mapper.mapper ) typ =
239
238
match typ.ptyp_desc with
240
- | Ptyp_constr ({ txt = Lident name } , _ ) when name = newtype -> Ptyp_var newtype
241
- | Ptyp_constr (ident , args ) -> Ptyp_constr (ident, List. map traverse args)
242
- | Ptyp_arrow (label , typ , rest ) -> Ptyp_arrow (label, traverse typ, traverse rest)
243
- | Ptyp_tuple (types ) -> Ptyp_tuple (List. map traverse types)
244
- | Ptyp_class (ident , args ) -> Ptyp_class (ident, List. map traverse args)
245
- | Ptyp_alias (typ , alias ) -> Ptyp_alias (traverse typ, alias)
246
- | Ptyp_poly (vars , rest ) -> Ptyp_poly (vars, traverse rest)
247
- | Ptyp_variant (fields , flag , labels ) ->
248
- let fields =
249
- List. map (function
250
- | Rtag (label , attrs , flag , args ) -> Rtag (label, attrs, flag, List. map traverse args)
251
- | Rinherit typ -> Rinherit (traverse typ))
252
- fields
253
- in
254
- Ptyp_variant (fields, flag, labels)
255
- | Ptyp_object (fields , flag ) ->
256
- let fields =
257
- List. map (function
258
- | Otag (label , attrs , typ ) -> Otag (label, attrs, traverse typ)
259
- | Oinherit typ -> Oinherit (traverse typ))
260
- fields
261
- in
262
- Ptyp_object (fields, flag)
263
- | Ptyp_package (ident , substitutions ) ->
264
- let substitutions =
265
- List. map
266
- (fun (ident , typ ) -> (ident, traverse typ))
267
- substitutions
268
- in
269
- Ptyp_package (ident, substitutions)
270
- | Ptyp_extension _ -> Location. raise_errorf " extensions are not allowed in @react.component definitions"
271
- | (Ptyp_any | Ptyp_var _ ) as typ -> typ
272
- }
239
+ | Ptyp_constr ({txt = Lident name } , _ ) when name = newtype ->
240
+ {typ with ptyp_desc = Ptyp_var newtype}
241
+ | _ -> Ast_mapper. default_mapper.typ mapper typ
242
+ in
243
+ let mapper = {Ast_mapper. default_mapper with typ} in
244
+ mapper.typ mapper type_
273
245
274
246
(* TODO: some line number might still be wrong *)
275
247
let jsxMapper () =
0 commit comments