Skip to content

Commit

Permalink
Revert "allow simplified @@jsxConfig"
Browse files Browse the repository at this point in the history
This reverts commit 7dcd211.
  • Loading branch information
zth committed Jan 25, 2024
1 parent 42ea11a commit cdcd333
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 35 deletions.
47 changes: 13 additions & 34 deletions jscomp/syntax/src/jsx_ppx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,16 @@ open Asttypes
open Parsetree
open Longident

type configPayload =
| ModuleName of string
| Fields of (t loc * expression) list
| Invalid

let getConfigPayload payload =
let getPayloadFields payload =
match payload with
| PStr
({
pstr_desc =
Pstr_eval ({pexp_desc = Pexp_record (recordFields, None)}, _);
}
:: _rest) ->
Fields recordFields
| PStr
({
pstr_desc =
Pstr_eval
({pexp_desc = Pexp_constant (Pconst_string (moduleName, _))}, _);
}
:: _rest) ->
ModuleName moduleName
| _ -> Invalid
recordFields
| _ -> []

type configKey = Int | String

Expand Down Expand Up @@ -60,24 +47,16 @@ let getInt ~key fields =
let getString ~key fields = fields |> getJsxConfigByKey ~key ~type_:String

let updateConfig config payload =
match getConfigPayload payload with
| Invalid -> () (* TODO(generic-jsx): Report error? *)
| ModuleName moduleName ->
config.Jsx_common.module_ <- moduleName;
if String.lowercase_ascii moduleName <> "react" then (
(* Force set automatic/version for anything but React *)
config.version <- 4;
config.mode <- "automatic")
| Fields fields -> (
(match getInt ~key:"version" fields with
| None -> ()
| Some i -> config.Jsx_common.version <- i);
(match getString ~key:"module_" fields with
| None -> ()
| Some s -> config.module_ <- s);
match getString ~key:"mode" fields with
| None -> ()
| Some s -> config.mode <- s)
let fields = getPayloadFields payload in
(match getInt ~key:"version" fields with
| None -> ()
| Some i -> config.Jsx_common.version <- i);
(match getString ~key:"module_" fields with
| None -> ()
| Some s -> config.module_ <- s);
match getString ~key:"mode" fields with
| None -> ()
| Some s -> config.mode <- s

let isJsxConfigAttr ((loc, _) : attribute) = loc.txt = "jsxConfig"

Expand Down
2 changes: 1 addition & 1 deletion jscomp/syntax/src/jsx_v4.ml
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ let transformLowercaseCall3 ~config mapper jsxExprLoc callExprLoc attrs
let domBinding =
match moduleAccessName config with
| "React" -> Lident "ReactDOM"
| generic -> Ldot (Lident generic, "Elements")
| generic -> Ldot (Lident generic, "DOM")
in

let children, nonChildrenProps =
Expand Down

0 comments on commit cdcd333

Please sign in to comment.