Skip to content

Commit

Permalink
add property expr jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
joongwon committed Dec 23, 2024
1 parent e51bd75 commit 53a8e0e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 12 additions & 2 deletions lib/js_syntax.ml
Original file line number Diff line number Diff line change
Expand Up @@ -497,10 +497,20 @@ and convert_expr ((_, expr) : (Loc.t, Loc.t) Flow_ast.Expression.t) :
(* TODO: handle opening and attributes and children *)
let name =
match name with
| Identifier (_, { name; _ }) -> name
| Identifier (_, { name; _ }) -> Var name
| MemberExpression (_, name) ->
let open Flow_ast.JSX.MemberExpression in
let rec loop { _object; property = _, { name; _ }; _ } =
let obj = match _object with
| Identifier (_, { name; _ }) -> Var name
| MemberExpression (_, obj) -> loop obj
in
Get { obj; idx = Const (String name) }
in
loop name
| _ -> raise NotImplemented (* non-identifier JSX element name *)
in
View [ App { fn = Var name; arg = Const Unit } ]
View [ App { fn = name; arg = Const Unit } ]
| JSXFragment _ ->
(* TODO *)
View [ Const Unit ]
Expand Down
4 changes: 2 additions & 2 deletions test/test_react_trace.ml
Original file line number Diff line number Diff line change
Expand Up @@ -505,11 +505,11 @@ let js_literal () =

let js_jsx () =
let open Syntax in
let js, _ = parse_js "<></>; <Comp />" in
let js, _ = parse_js "<></>; <Comp />; <Mod.Comp />" in
let prog = Js_syntax.convert js in
Alcotest.(check' (of_pp Sexp.pp_hum))
~msg:"convert jsx" ~actual:(Prog.sexp_of_t prog)
~expected:(parse_prog "view [()]; view [Comp ()]" |> Prog.sexp_of_t)
~expected:(parse_prog {|view [()]; view [Comp ()]; view [(Mod["Comp"]) ()]|} |> Prog.sexp_of_t)

let js_op () =
let open Syntax in
Expand Down

0 comments on commit 53a8e0e

Please sign in to comment.