# frozen_string_literal: truerequire'opal/nodes/base'require'opal/nodes/call'moduleOpalmoduleNodes# recvr.JS[:prop]# => recvr.propclassJsAttrNode<Basehandle:jsattrchildren:recvr,:propertydefcompilepushrecv(recvr),'[',expr(property),']'endend# recvr.JS[:prop] = value# => recvr.prop = valueclassJsAttrAsgnNode<Basehandle:jsattrasgnchildren:recvr,:property,:valuedefcompilepushrecv(recvr),'[',expr(property),'] = ',expr(value)endendclassJsCallNode<CallNodehandle:jscalldefinitialize(*)super# For .JS. call we pass a block# as a plain JS callbackif@iter@arglist=@arglist<<@iterend@iter=nilenddefcompiledefault_compileenddefmethod_jsid".#{meth}"enddefcompile_using_sendpushrecv(receiver_sexp),method_jsid,'.apply(null'compile_argumentsifiterpush'.concat(',expr(iter),')'endpush')'endend# /regexp/ =~ rhs# s(:match_with_lvasgn, lhs, rhs)classMatch3Node<Basehandle:match_with_lvasgnchildren:lhs,:rhsdefcompilesexp=s(:send,lhs,:=~,rhs)# Handle named matches like: /(?<abc>b)/ =~ 'b'iflhs.type==:regexp&&lhs.children.first.type==:strre=lhs.children.first.children.firstnames=re.scan(/\(\?<([^>]*)>/).flatten.map(&:to_sym)unlessnames.empty?# $m3names = $~ ? $~.named_captures : {}names_def=s(:lvasgn,:$m3names,s(:if,s(:gvar,:$~),s(:send,s(:gvar,:$~),:named_captures),s(:hash)))names=names.mapdo|name|# abc = $m3names[:abc]s(:lvasgn,name,s(:send,s(:lvar,:$m3names),:[],s(:sym,name)))endifstmt?# We don't care about a return value of this one, so we# ignore it and just assign the local variables.## (/(?<abc>b)/ =~ 'f')# $m3names = $~ ? $~.named_captures : {}# abc = $m3names[:abc]sexp=s(:begin,sexp,names_def,*names)else# We actually do care about a return value, so we must# keep it saved.## $m3tmp = (/(?<abc>b)/ =~ 'f')# $m3names = $~ ? $~.named_captures : {}# abc = $m3names[:abc]# $m3tmpsexp=s(:begin,s(:lvasgn,:$m3tmp,sexp),names_def,*names,s(:lvar,:$m3tmp))endendendpushprocess(sexp,@level)endendendend