Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file ast_uncurry_gen.ml
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798(* Copyright (C) 2020- Hongbo Zhang, Authors of ReScript
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In addition to the permissions granted to you by the LGPL, you may combine
* or link a "work that uses the Library" with a publicly distributed version
* of this file to produce a combined library or application, then distribute
* that combined work under the terms of your choosing, with no requirement
* to comply with the obligations normally placed on you by section 4 of the
* LGPL version 3 (or the corresponding section of a later version of the LGPL
* should you choose to use a later version).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)openAst_helper(* Handling `fun [@this]` used in `object [@bs] end` *)letto_method_callbackloc(self:Ast_mapper.mapper)labelpatbody:Parsetree.expression_desc=Bs_syntaxerr.optional_errloclabel;letrecauxacc(body:Parsetree.expression)=matchAst_attributes.process_attributes_revbody.pexp_attributeswith|Nothing,_->(matchbody.pexp_descwith|Pexp_fun(arg_label,_,arg,body)->Bs_syntaxerr.optional_errlocarg_label;aux((arg_label,self.patselfarg)::acc)body|_-> (self.exprselfbody,acc))|_,_->(self.exprselfbody,acc)inletfirst_arg=self.patselfpat inifnot(Ast_pat.is_single_variable_pattern_conservativefirst_arg)thenBs_syntaxerr.errfirst_arg.ppat_locBs_this_simple_pattern;letresult,rev_extra_args=aux[(label,first_arg)]bodyinlet body=Ext_list.fold_left rev_extra_args result(fune(label,p)->Ast_helper.Exp.fun_~loclabelNonepe)inletarity=List.lengthrev_extra_argsinletarity_s=string_of_intarityinParsetree.Pexp_apply(Exp.ident ~loc{loc;txt=Ldot(Ast_literal.Lid.js_oo,"unsafe_to_method")},[(Nolabel,Exp.constraint_~loc(Exp.record~loc[({loc;txt=Ast_literal.Lid.hidden_fieldarity_s},body)]None)(Typ.constr~loc{loc;txt=Ldot(Ast_literal.Lid.js_meth_callback,"arity"^arity_s);}[Typ.any~loc()]));])letto_uncurry_fnloc (self:Ast_mapper.mapper)(label:Asttypes.arg_label)patbody:Parsetree.expression_desc =Bs_syntaxerr.optional_errloclabel;letrecauxacc(body:Parsetree.expression)=matchAst_attributes.process_attributes_revbody.pexp_attributeswith|Nothing,_->(matchbody.pexp_descwith|Pexp_fun(arg_label,_,arg,body)->Bs_syntaxerr.optional_errlocarg_label;aux((arg_label,self.patselfarg)::acc)body|_-> (self.exprselfbody,acc))|_,_->(self.exprselfbody,acc)inletfirst_arg=self.patselfpat inletresult,rev_extra_args=aux [(label,first_arg)]bodyinlet body=Ext_list.fold_left rev_extra_args result(fune(label,p)->Ast_helper.Exp.fun_~loclabelNonepe)inletlen=List.length rev_extra_args inletarity=matchrev_extra_args with|[(_,p)]->Ast_pat.is_unit_cont~yes:0~no:lenp|_->leninBs_syntaxerr.err_large_aritylocarity;letarity_s=string_of_intarityinPexp_record([({txt=Ldot(Ast_literal.Lid.js_fn,"I"^arity_s);loc},body)],None)