@@ -1825,7 +1825,74 @@ module AutomaticExpr = struct
18251825 Exp. apply ~loc ~attrs jsx_expr
18261826 ([(nolabel, component_name_expr); (nolabel, props_record)]
18271827 @ key_and_unit)
1828- else failwith " TODO"
1828+ else if starts_with_uppercase name then
1829+ (* MyModule.make *)
1830+ let make_id =
1831+ Exp. ident ~loc: tag_name.loc
1832+ {txt = Ldot (tag_name.txt, " make" ); loc = tag_name.loc}
1833+ in
1834+ let props_record =
1835+ (* Append current props with JSXPropValue("children")
1836+ This will later be transformed correctly into a record. *)
1837+ let props_with_children =
1838+ match children with
1839+ | JSXChildrenItems [] -> props
1840+ | JSXChildrenItems [expr] | JSXChildrenSpreading expr ->
1841+ props
1842+ @ [
1843+ JSXPropValue
1844+ ( {txt = " children" ; loc = Location. none},
1845+ false ,
1846+ mapper.expr mapper expr );
1847+ ]
1848+ | JSXChildrenItems xs ->
1849+ (* this is a hack to support react components that introspect into their children *)
1850+ props
1851+ @ [
1852+ JSXPropValue
1853+ ( {txt = " children" ; loc = Location. none},
1854+ false ,
1855+ Exp. apply
1856+ (Exp. ident
1857+ {
1858+ txt = module_access_name config " array" ;
1859+ loc = Location. none;
1860+ })
1861+ [
1862+ (Nolabel , Exp. array (List. map (mapper.expr mapper) xs));
1863+ ] );
1864+ ]
1865+ in
1866+ mk_record_from_props mapper loc props_with_children
1867+ in
1868+ let jsx_expr, key_and_unit =
1869+ match try_find_key_prop props with
1870+ | None ->
1871+ ( Exp. ident
1872+ {
1873+ loc = Location. none;
1874+ txt =
1875+ module_access_name config
1876+ (if has_multiple_literal_children then " jsxs" else " jsx" );
1877+ },
1878+ [] )
1879+ | Some key_prop ->
1880+ ( Exp. ident
1881+ {
1882+ loc = Location. none;
1883+ txt =
1884+ module_access_name config
1885+ (if has_multiple_literal_children then " jsxsKeyed"
1886+ else " jsxKeyed" );
1887+ },
1888+ [key_prop; (nolabel, unit_expr ~loc: Location. none)] )
1889+ in
1890+ Exp. apply ~loc ~attrs jsx_expr
1891+ ([(nolabel, make_id); (nolabel, props_record)] @ key_and_unit)
1892+ else
1893+ Jsx_common. raise_error ~loc
1894+ " JSX: element name is neither upper- or lowercase, got \" %s\" "
1895+ (Longident. flatten tag_name.txt |> String. concat " ." )
18291896 | e -> default_mapper.expr mapper e
18301897end
18311898
0 commit comments