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