@@ -3,29 +3,16 @@ open Asttypes
3
3
open Parsetree
4
4
open Longident
5
5
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 =
12
7
match payload with
13
8
| PStr
14
9
({
15
10
pstr_desc =
16
11
Pstr_eval ({pexp_desc = Pexp_record (recordFields, None )}, _);
17
12
}
18
13
:: _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
+ | _ -> []
29
16
30
17
type configKey = Int | String
31
18
@@ -60,24 +47,16 @@ let getInt ~key fields =
60
47
let getString ~key fields = fields |> getJsxConfigByKey ~key ~type_: String
61
48
62
49
let 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
81
60
82
61
let isJsxConfigAttr ((loc , _ ) : attribute ) = loc.txt = " jsxConfig"
83
62
0 commit comments