8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/ruby2js/filter/cjs.rb', line 8
def on_send(node)
return super unless node.children[1] == :export
if node.children[2].type == :def
fn = node.children[2]
node.updated(nil, [
s(:attr, nil, :exports),
fn.children[0].to_s + '=',
s(:block, s(:send, nil, :proc), *process_all(fn.children[1..-1]))
])
elsif node.children[2].type == :lvasgn
assign = node.children[2]
node.updated(nil, [
s(:attr, nil, :exports),
assign.children[0].to_s + '=',
*assign.children[1..-1]
])
elsif \
node.children[2].type == :send and
node.children[2].children[0..1] == [nil, :async] and
node.children[2].children[2].type == :def
then
fn = node.children[2].children[2]
node.updated(nil, [
s(:attr, nil, :exports),
fn.children[0].to_s + '=',
s(:send, nil, :async,
s(:block, s(:send, nil, :proc),
*process_all(fn.children[1..-1])))
])
elsif \
node.children[2].type == :send and
node.children[2].children[0..1] == [nil, :default]
then
node = node.children[2]
node.updated(nil, [
s(:attr, nil, :module),
:exports=,
node.children[2]
])
else
super
end
end
|