@@ -5,7 +5,6 @@ open Parsetree
5
5
open Longident
6
6
7
7
let moduleAccessName = Jsx_common. mkModuleAccessName
8
- let jsxComponentName = Jsx_common. mkJsxComponentName
9
8
10
9
let nolabel = Nolabel
11
10
@@ -119,7 +118,10 @@ let extractChildren ?(removeLastPositionUnit = false) ~loc propsAndChildren =
119
118
let merlinFocus = ({loc = Location. none; txt = " merlin.focus" }, PStr [] )
120
119
121
120
(* Helper method to filter out any attribute that isn't [@react.component] *)
122
- let otherAttrsPure ~config (loc , _ ) = loc.txt <> jsxComponentName config
121
+ let otherAttrsPure (loc , _ ) =
122
+ match loc.txt with
123
+ | "react.component" | "jsx.component" -> false
124
+ | _ -> true
123
125
124
126
(* Finds the name of the variable the binding is assigned to, otherwise raises Invalid_argument *)
125
127
let rec getFnName binding =
@@ -904,12 +906,10 @@ let vbMatchExpr namedArgList expr =
904
906
aux (List. rev namedArgList)
905
907
906
908
let mapBinding ~config ~emptyLoc ~pstr_loc ~fileName ~recFlag binding =
907
- if Jsx_common. hasAttrOnBinding ~config binding then (
909
+ if Jsx_common. hasAttrOnBinding binding then (
908
910
checkMultipleComponents ~config ~loc: pstr_loc;
909
911
let binding = Jsx_common. removeArity binding in
910
- let coreTypeOfAttr =
911
- Jsx_common. coreTypeOfAttrs ~config binding.pvb_attributes
912
- in
912
+ let coreTypeOfAttr = Jsx_common. coreTypeOfAttrs binding.pvb_attributes in
913
913
let typVarsOfCoreType =
914
914
coreTypeOfAttr
915
915
|> Option. map Jsx_common. typVarsOfCoreType
@@ -922,8 +922,7 @@ let mapBinding ~config ~emptyLoc ~pstr_loc ~fileName ~recFlag binding =
922
922
binding with
923
923
pvb_pat = {binding.pvb_pat with ppat_loc = emptyLoc};
924
924
pvb_loc = emptyLoc;
925
- pvb_attributes =
926
- binding.pvb_attributes |> List. filter (otherAttrsPure ~config );
925
+ pvb_attributes = binding.pvb_attributes |> List. filter otherAttrsPure;
927
926
}
928
927
in
929
928
let fnName = getFnName binding.pvb_pat in
@@ -1152,7 +1151,7 @@ let transformStructureItem ~config item =
1152
1151
pstr_desc =
1153
1152
Pstr_primitive ({pval_attributes; pval_type} as value_description);
1154
1153
} as pstr -> (
1155
- match List. filter ( Jsx_common. hasAttr ~config ) pval_attributes with
1154
+ match List. filter Jsx_common. hasAttr pval_attributes with
1156
1155
| [] -> [item]
1157
1156
| [_] ->
1158
1157
checkMultipleComponents ~config ~loc: pstr_loc;
@@ -1161,7 +1160,7 @@ let transformStructureItem ~config item =
1161
1160
let pval_type = Jsx_common. extractUncurried pval_type in
1162
1161
let coreTypeOfAttr = Jsx_common. coreTypeOfAttrs pval_attributes in
1163
1162
let typVarsOfCoreType =
1164
- coreTypeOfAttr ~config
1163
+ coreTypeOfAttr
1165
1164
|> Option. map Jsx_common. typVarsOfCoreType
1166
1165
|> Option. value ~default: []
1167
1166
in
@@ -1183,7 +1182,7 @@ let transformStructureItem ~config item =
1183
1182
let retPropsType =
1184
1183
Typ. constr ~loc: pstr_loc
1185
1184
(Location. mkloc (Lident " props" ) pstr_loc)
1186
- (match coreTypeOfAttr ~config with
1185
+ (match coreTypeOfAttr with
1187
1186
| None -> makePropsTypeParams namedTypeList
1188
1187
| Some _ -> (
1189
1188
match typVarsOfCoreType with
@@ -1192,8 +1191,8 @@ let transformStructureItem ~config item =
1192
1191
in
1193
1192
(* type props<'x, 'y> = { x: 'x, y?: 'y, ... } *)
1194
1193
let propsRecordType =
1195
- makePropsRecordType ~core TypeOfAttr:(coreTypeOfAttr ~config )
1196
- ~typ VarsOfCoreType " props " pstr_loc namedTypeList
1194
+ makePropsRecordType ~core TypeOfAttr ~typ VarsOfCoreType " props " pstr_loc
1195
+ namedTypeList
1197
1196
in
1198
1197
(* can't be an arrow because it will defensively uncurry *)
1199
1198
let newExternalType =
@@ -1212,8 +1211,7 @@ let transformStructureItem ~config item =
1212
1211
{
1213
1212
value_description with
1214
1213
pval_type = {pval_type with ptyp_desc = newExternalType};
1215
- pval_attributes =
1216
- List. filter (otherAttrsPure ~config ) pval_attributes;
1214
+ pval_attributes = List. filter otherAttrsPure pval_attributes;
1217
1215
};
1218
1216
}
1219
1217
in
@@ -1259,7 +1257,7 @@ let transformSignatureItem ~config item =
1259
1257
psig_loc;
1260
1258
psig_desc = Psig_value ({pval_attributes; pval_type} as psig_desc);
1261
1259
} as psig -> (
1262
- match List. filter ( Jsx_common. hasAttr ~config ) pval_attributes with
1260
+ match List. filter Jsx_common. hasAttr pval_attributes with
1263
1261
| [] -> [item]
1264
1262
| [_] ->
1265
1263
checkMultipleComponents ~config ~loc: psig_loc;
@@ -1269,7 +1267,7 @@ let transformSignatureItem ~config item =
1269
1267
let hasForwardRef = ref false in
1270
1268
let coreTypeOfAttr = Jsx_common. coreTypeOfAttrs pval_attributes in
1271
1269
let typVarsOfCoreType =
1272
- coreTypeOfAttr ~config
1270
+ coreTypeOfAttr
1273
1271
|> Option. map Jsx_common. typVarsOfCoreType
1274
1272
|> Option. value ~default: []
1275
1273
in
@@ -1298,16 +1296,16 @@ let transformSignatureItem ~config item =
1298
1296
let retPropsType =
1299
1297
Typ. constr
1300
1298
(Location. mkloc (Lident " props" ) psig_loc)
1301
- (match coreTypeOfAttr ~config with
1299
+ (match coreTypeOfAttr with
1302
1300
| None -> makePropsTypeParams namedTypeList
1303
1301
| Some _ -> (
1304
1302
match typVarsOfCoreType with
1305
1303
| [] -> []
1306
1304
| _ -> [Typ. any () ]))
1307
1305
in
1308
1306
let propsRecordType =
1309
- makePropsRecordTypeSig ~core TypeOfAttr:(coreTypeOfAttr ~config )
1310
- ~typ VarsOfCoreType " props " psig_loc
1307
+ makePropsRecordTypeSig ~core TypeOfAttr ~typ VarsOfCoreType " props "
1308
+ psig_loc
1311
1309
((* If there is Nolabel arg, regard the type as ref in forwardRef *)
1312
1310
(if ! hasForwardRef then
1313
1311
[(true , " ref" , [] , Location. none, refType Location. none)]
@@ -1331,8 +1329,7 @@ let transformSignatureItem ~config item =
1331
1329
{
1332
1330
psig_desc with
1333
1331
pval_type = {pval_type with ptyp_desc = newExternalType};
1334
- pval_attributes =
1335
- List. filter (otherAttrsPure ~config ) pval_attributes;
1332
+ pval_attributes = List. filter otherAttrsPure pval_attributes;
1336
1333
};
1337
1334
}
1338
1335
in
0 commit comments