<commit_before>open Ast_mapper
open Ast_helper
open Asttypes
open Parsetree
open Longident

type tag_type =
    | Tag_name
    | React_class

let rec parse_attr pexp_desc loc collector =
    match pexp_desc with
    | {pexp_desc = Pexp_construct ({txt = Lident "::"; loc = loc}, (Some (
        { pexp_desc = Pexp_tuple ([
            { pexp_desc = Pexp_apply (
                {pexp_desc = Pexp_ident ({ txt = Lident attr_name; loc = _})},
                [(_, argument)]
            )};
            next
        ])}
    )))} ->
        parse_attr next loc ((attr_name, argument) :: collector)
    | {pexp_desc = Pexp_construct ({txt = Lident "[]"; loc = _}, None)} ->
        (* Done parsing! *)
        collector
    | _ -> raise (Location.Error (
        Location.error ~loc "[%jsx] expected a valid attribute"))

let parse_attrs pexp_desc loc =
    (* build up a list of attr-value pairs for making a class *)
    let attr_list = parse_attr pexp_desc loc [] in
    if List.length attr_list == 0 then
        None
    else
        Some ("props", Exp.extension ({txt="js"; loc=loc}, 
            PStr [
                Str.eval (
                    Exp.object_ (
                        Cstr.mk (Pat.any ()) [
                        ]
                    )
                )
            ]
        ))

let make_component kind ident props loc =
    let class_constr = match kind with<commit_msg>Correctly parses props<commit_after>open Ast_mapper
open Ast_helper
open Asttypes
open Parsetree
open Longident

type tag_type =
    | Tag_name
    | React_class

let rec parse_attr pexp_desc loc collector =
    match pexp_desc with
    | {pexp_desc = Pexp_construct ({txt = Lident "::"; loc = loc}, (Some (
        { pexp_desc = Pexp_tuple ([
            { pexp_desc = Pexp_apply (
                {pexp_desc = Pexp_ident ({ txt = Lident attr_name; loc = _})},
                [(_, argument)]
            )};
            next
        ])}
    )))} ->
        parse_attr next loc ((attr_name, argument) :: collector)
    | {pexp_desc = Pexp_construct ({txt = Lident "[]"; loc = _}, None)} ->
        (* Done parsing! *)
        collector
    | _ -> raise (Location.Error (
        Location.error ~loc "[%jsx] expected a valid attribute"))

let parse_attrs pexp_desc loc =
    (* build up a list of attr-value pairs for making a class *)
    let attr_list = parse_attr pexp_desc loc [] in
    if List.length attr_list == 0 then
        None
    else
        let fields = List.map (fun (attr_name, argument) ->
            Cf.mk (Pcf_val ({txt=attr_name;loc=loc}, Immutable, Cfk_concrete (Fresh, argument)))
        ) attr_list in
        Some ("props", Exp.extension ({txt="js"; loc=loc}, 
            PStr [
                Str.eval (
                    Exp.object_ (
                        Cstr.mk (Pat.any ()) fields
                    )
                )
            ]
        ))

let make_component kind ident props loc =
    let class_constr = match kind with
{'fraction_non_alphanumeric': 0.10796221322537113, 'fraction_numerical': 0.0006747638326585695, 'mean_word_length': 1.773620205799813, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '601762', 'n_tokens_mistral': 912, 'n_tokens_neox': 877, 'n_words': 247}