@@ -3,29 +3,16 @@ open Asttypes
33open Parsetree
44open Longident
55
6- type configPayload =
7- | ModuleName of string
8- | Fields of (t loc * expression ) list
9- | Invalid
10-
11- let getConfigPayload payload =
6+ let getPayloadFields payload =
127 match payload with
138 | PStr
149 ({
1510 pstr_desc =
1611 Pstr_eval ({pexp_desc = Pexp_record (recordFields, None )}, _);
1712 }
1813 :: _rest) ->
19- Fields recordFields
20- | PStr
21- ({
22- pstr_desc =
23- Pstr_eval
24- ({pexp_desc = Pexp_constant (Pconst_string (moduleName, _))}, _);
25- }
26- :: _rest) ->
27- ModuleName moduleName
28- | _ -> Invalid
14+ recordFields
15+ | _ -> []
2916
3017type configKey = Int | String
3118
@@ -60,24 +47,16 @@ let getInt ~key fields =
6047let getString ~key fields = fields |> getJsxConfigByKey ~key ~type_: String
6148
6249let updateConfig config payload =
63- match getConfigPayload payload with
64- | Invalid -> () (* TODO(generic-jsx): Report error? *)
65- | ModuleName moduleName ->
66- config.Jsx_common. module_ < - moduleName;
67- if String. lowercase_ascii moduleName <> " react" then (
68- (* Force set automatic/version for anything but React *)
69- config.version < - 4 ;
70- config.mode < - " automatic" )
71- | Fields fields -> (
72- (match getInt ~key: " version" fields with
73- | None -> ()
74- | Some i -> config.Jsx_common. version < - i);
75- (match getString ~key: " module_" fields with
76- | None -> ()
77- | Some s -> config.module_ < - s);
78- match getString ~key: " mode" fields with
79- | None -> ()
80- | Some s -> config.mode < - s)
50+ let fields = getPayloadFields payload in
51+ (match getInt ~key: " version" fields with
52+ | None -> ()
53+ | Some i -> config.Jsx_common. version < - i);
54+ (match getString ~key: " module_" fields with
55+ | None -> ()
56+ | Some s -> config.module_ < - s);
57+ match getString ~key: " mode" fields with
58+ | None -> ()
59+ | Some s -> config.mode < - s
8160
8261let isJsxConfigAttr ((loc , _ ) : attribute ) = loc.txt = " jsxConfig"
8362
0 commit comments