Skip to content

Commit d2520d2

Browse files
committedJun 17, 2014
Support and-op assignments using bracket reference
1 parent b999afa commit d2520d2

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed
 

‎lib/opal/nodes/call_special.rb

+14-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def compile
3939
sexp = s(:or, recvr, rhs)
4040
push expr(sexp)
4141
end
42-
end
42+
end
4343

4444
# a &&= rhs
4545
# s(:op_asgn_and, s(:lvar, :a), s(:lasgn, a:, rhs))
@@ -98,6 +98,19 @@ def compile_or
9898
end
9999
end
100100
end
101+
102+
def compile_and
103+
with_temp do |a| # args
104+
with_temp do |r| # recv
105+
aref = s(:call, s(:js_tmp, r), :[], s(:arglist, s(:js_tmp, a)))
106+
aset = s(:call, s(:js_tmp, r), :[]=, s(:arglist, s(:js_tmp, a), rhs))
107+
andop = s(:and, aref, aset)
108+
109+
push "(#{a} = ", expr(first_arg), ", #{r} = ", expr(lhs)
110+
push ", ", expr(andop), ")"
111+
end
112+
end
113+
end
101114
end
102115

103116
# lhs.b += rhs

0 commit comments

Comments
 (0)
Please sign in to comment.