ruby2js 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/README.md +11 -5
- data/lib/ruby2js/converter/class.rb +41 -30
- data/lib/ruby2js/converter/hash.rb +2 -1
- data/lib/ruby2js/converter/send.rb +5 -3
- data/lib/ruby2js/filter/angularrb.rb +8 -3
- data/lib/ruby2js/filter/functions.rb +10 -3
- data/lib/ruby2js/version.rb +1 -1
- data/ruby2js.gemspec +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZTQ1ZGU1ZTI0NWQ4ZmMwNzNiMjExYjk1MWY5YWJkNTY1MzYzNTQwYg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MmI0MjVhYjkwNzg5YTUxZTgzMDhhYWE3NjM0MmU2NmIyNjQ4MGJkYw==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NzZmNjgxYzU1YmFjZTU4ZmI0MWJkY2I1YmZjN2YxN2RmOTkzOGRhYzNmN2Rm
|
10
|
+
ZWIzMTIxYWM1NmYxOTRjOTI5MjA5NzY3MTc4Yjk4MWM0MDQ0YTNjMTc3NGEy
|
11
|
+
NDk0NGE1ZjFkOTQ3YzRlNzAzNmVkYjZmMTAxNmIzZTNkYTlhODU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OTc5OTkwNmY2Yzc1MzgxMWNkN2M5YjFlYzAyNDE3N2M5MTllMTE4ZjA0MWI3
|
14
|
+
NjlmOWM0ODQ3NTAzZWY1YzFiNWFkMWVhOTE5OThiNmY1Y2UwZjRmYmVkNzll
|
15
|
+
MTU0OTQ0YTU3NzVkNGQ1NGJlNzYzMjgzNzBkMWYwMWM1ZjAxOWE=
|
data/README.md
CHANGED
@@ -13,13 +13,11 @@ calls IF there are either one or more arguments passed OR parenthesis are
|
|
13
13
|
used, otherwise Ruby method calls become JavaScript property accesses.
|
14
14
|
By default, methods, lambdas, and procs return `undefined`.
|
15
15
|
|
16
|
-
Ruby attribute accessors,
|
16
|
+
Ruby attribute accessors, methods defined with no parameters and no
|
17
|
+
parenthesis, as well as setter method definitions, are
|
17
18
|
mapped to
|
18
19
|
[Object.defineProperty](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty?redirectlocale=en-US&redirectslug=JavaScript%2FReference%2FGlobal_Objects%2FObject%2FdefineProperty),
|
19
|
-
so avoid these if you wish to target users running IE8 or lower.
|
20
|
-
methods defined with no arguments are presumed to be defining a property
|
21
|
-
accessor; if you want a method with no arguments append a `!` to the method
|
22
|
-
name.
|
20
|
+
so avoid these if you wish to target users running IE8 or lower.
|
23
21
|
|
24
22
|
Filters may be provided to add Ruby-specific or framework specific
|
25
23
|
behavior. Filters are essentially macro facilities that operate on
|
@@ -237,6 +235,14 @@ the script.
|
|
237
235
|
implicit `use` statements
|
238
236
|
* maps constant assignments in an angular module to a filter
|
239
237
|
* maps class definitions in an angular module to a filter
|
238
|
+
* within a controller or within a `link` method in a directive:
|
239
|
+
* maps `apply`, `broadcast`, `digest`, `emit`, `eval`, `evalAsync`, and
|
240
|
+
`parent` calls to `$scope` functions.
|
241
|
+
* maps `apply!`, `broadcast!`, `digest!`, `eval!`, and `evalAsync!`
|
242
|
+
calls to `$rootScope` functions.
|
243
|
+
* maps `filter` calls to '$filter` calls.
|
244
|
+
* maps `timeout` and `interval` calls with a block to `$timeout` and
|
245
|
+
`$interval` calls where the block is passed as the first parameter.
|
240
246
|
|
241
247
|
* [angular-route](https://github.com/rubys/ruby2js/blob/master/lib/ruby2js/filter/angular-routerb.rb)
|
242
248
|
|
@@ -31,19 +31,19 @@ module Ruby2JS
|
|
31
31
|
elsif m.children.first =~ /=/
|
32
32
|
# property setter
|
33
33
|
sym = :"#{m.children.first.to_s[0..-2]}"
|
34
|
-
s(:prop, s(:attr, name, :prototype), sym
|
35
|
-
enumerable: s(:true), configurable: s(:true),
|
36
|
-
set: s(:block, s(:send, nil, :proc), *m.children[1..-1]))
|
34
|
+
s(:prop, s(:attr, name, :prototype), sym =>
|
35
|
+
{enumerable: s(:true), configurable: s(:true),
|
36
|
+
set: s(:block, s(:send, nil, :proc), *m.children[1..-1])})
|
37
37
|
else
|
38
38
|
if m.children[1].children.length == 0 and
|
39
39
|
m.children.first !~ /!/ and m.loc and m.loc.name and
|
40
40
|
m.loc.name.source_buffer.source[m.loc.name.end_pos] != '('
|
41
41
|
|
42
42
|
# property getter
|
43
|
-
s(:prop, s(:attr, name, :prototype), m.children.first
|
44
|
-
enumerable: s(:true), configurable: s(:true),
|
43
|
+
s(:prop, s(:attr, name, :prototype), m.children.first =>
|
44
|
+
{enumerable: s(:true), configurable: s(:true),
|
45
45
|
get: s(:block, s(:send, nil, :proc), m.children[1],
|
46
|
-
s(:autoreturn, *m.children[2..-1])))
|
46
|
+
s(:autoreturn, *m.children[2..-1]))})
|
47
47
|
else
|
48
48
|
# method: add to prototype
|
49
49
|
s(:method, s(:attr, name, :prototype),
|
@@ -55,18 +55,18 @@ module Ruby2JS
|
|
55
55
|
elsif m.type == :defs and m.children.first == s(:self)
|
56
56
|
if m.children[1] =~ /=$/
|
57
57
|
# class property setter
|
58
|
-
s(:prop, name, m.children[1].to_s[0..-2]
|
59
|
-
enumerable: s(:true), configurable: s(:true),
|
60
|
-
set: s(:block, s(:send, nil, :proc), *m.children[2..-1]))
|
58
|
+
s(:prop, name, m.children[1].to_s[0..-2] =>
|
59
|
+
{enumerable: s(:true), configurable: s(:true),
|
60
|
+
set: s(:block, s(:send, nil, :proc), *m.children[2..-1])})
|
61
61
|
elsif m.children[2].children.length == 0 and
|
62
62
|
m.children[1] !~ /!/ and m.loc and m.loc.name and
|
63
63
|
m.loc.name.source_buffer.source[m.loc.name.end_pos] != '('
|
64
64
|
|
65
65
|
# class property getter
|
66
|
-
s(:prop, name, m.children[1].to_s
|
67
|
-
enumerable: s(:true), configurable: s(:true),
|
66
|
+
s(:prop, name, m.children[1].to_s =>
|
67
|
+
{enumerable: s(:true), configurable: s(:true),
|
68
68
|
get: s(:block, s(:send, nil, :proc), m.children[2],
|
69
|
-
s(:autoreturn, *m.children[3..-1])))
|
69
|
+
s(:autoreturn, *m.children[3..-1]))})
|
70
70
|
else
|
71
71
|
# class method definition: add to prototype
|
72
72
|
s(:prototype, s(:send, name, "#{m.children[1]}=",
|
@@ -77,30 +77,30 @@ module Ruby2JS
|
|
77
77
|
if m.children[1] == :attr_accessor
|
78
78
|
m.children[2..-1].map do |sym|
|
79
79
|
var = sym.children.first
|
80
|
-
s(:prop, s(:attr, name, :prototype), var
|
81
|
-
enumerable: s(:true), configurable: s(:true),
|
80
|
+
s(:prop, s(:attr, name, :prototype), var =>
|
81
|
+
{enumerable: s(:true), configurable: s(:true),
|
82
82
|
get: s(:block, s(:send, nil, :proc), s(:args),
|
83
83
|
s(:return, s(:ivar, :"@#{var}"))),
|
84
84
|
set: s(:block, s(:send, nil, :proc), s(:args, s(:arg, var)),
|
85
|
-
s(:ivasgn, :"@#{var}", s(:lvar, var))))
|
85
|
+
s(:ivasgn, :"@#{var}", s(:lvar, var)))})
|
86
86
|
end
|
87
87
|
elsif m.children[1] == :attr_reader
|
88
88
|
m.children[2..-1].map do |sym|
|
89
89
|
var = sym.children.first
|
90
|
-
s(:prop, s(:attr, name, :prototype), var
|
91
|
-
get: s(:block, s(:send, nil, :proc), s(:args),
|
90
|
+
s(:prop, s(:attr, name, :prototype), var =>
|
91
|
+
{get: s(:block, s(:send, nil, :proc), s(:args),
|
92
92
|
s(:return, s(:ivar, :"@#{var}"))),
|
93
93
|
enumerable: s(:true),
|
94
|
-
configurable: s(:true))
|
94
|
+
configurable: s(:true)})
|
95
95
|
end
|
96
96
|
elsif m.children[1] == :attr_writer
|
97
97
|
m.children[2..-1].map do |sym|
|
98
98
|
var = sym.children.first
|
99
|
-
s(:prop, s(:attr, name, :prototype), var
|
100
|
-
set: s(:block, s(:send, nil, :proc), s(:args, s(:arg, var)),
|
99
|
+
s(:prop, s(:attr, name, :prototype), var =>
|
100
|
+
{set: s(:block, s(:send, nil, :proc), s(:args, s(:arg, var)),
|
101
101
|
s(:ivasgn, :"@#{var}", s(:lvar, var))),
|
102
102
|
enumerable: s(:true),
|
103
|
-
configurable: s(:true))
|
103
|
+
configurable: s(:true)})
|
104
104
|
end
|
105
105
|
else
|
106
106
|
# class method call
|
@@ -138,9 +138,11 @@ module Ruby2JS
|
|
138
138
|
next unless body[i] and body[i].type == :prop
|
139
139
|
for j in i+1...body.length
|
140
140
|
break unless body[j] and body[j].type == :prop
|
141
|
-
if body[i].children[0
|
142
|
-
merge = body[i].children[
|
143
|
-
|
141
|
+
if body[i].children[0] == body[j].children[0]
|
142
|
+
merge = Hash[(body[i].children[1].to_a+body[j].children[1].to_a).
|
143
|
+
group_by(&:first).map {|name, values|
|
144
|
+
[name, values.map(&:last).reduce(:merge)]}]
|
145
|
+
body[j] = s(:prop, body[j].children[0], merge)
|
144
146
|
body[i] = nil
|
145
147
|
break
|
146
148
|
end
|
@@ -176,11 +178,12 @@ module Ruby2JS
|
|
176
178
|
s(:pair, s(:str, node.children[1].to_s.chomp('=')),
|
177
179
|
node.children[2])
|
178
180
|
else
|
179
|
-
|
181
|
+
node.children[1].map {|prop, descriptor|
|
182
|
+
s(:pair, s(:prop, prop), descriptor)}
|
180
183
|
end
|
181
184
|
end
|
182
185
|
body[start...start+methods] =
|
183
|
-
s(:send, name, :prototype=, s(:hash, *pairs))
|
186
|
+
s(:send, name, :prototype=, s(:hash, *pairs.flatten))
|
184
187
|
end
|
185
188
|
end
|
186
189
|
|
@@ -209,10 +212,18 @@ module Ruby2JS
|
|
209
212
|
instance_method, @instance_method = @instance_method, @ast
|
210
213
|
@block_this, @block_depth = false, 0
|
211
214
|
if @ast.type == :prop
|
212
|
-
obj,
|
213
|
-
|
214
|
-
|
215
|
-
|
215
|
+
obj, props = *args
|
216
|
+
if props.length == 1
|
217
|
+
prop, descriptor = props.flatten
|
218
|
+
parse s(:send, s(:const, nil, :Object), :defineProperty,
|
219
|
+
obj, s(:sym, prop), s(:hash,
|
220
|
+
*descriptor.map { |key, value| s(:pair, s(:sym, key), value) }))
|
221
|
+
else
|
222
|
+
parse s(:send, s(:const, nil, :Object), :defineProperties,
|
223
|
+
obj, s(:hash, *props.map {|prop, descriptor|
|
224
|
+
s(:pair, s(:sym, prop), s(:hash, *descriptor.map {|key, value|
|
225
|
+
s(:pair, s(:sym, key), value) }))}))
|
226
|
+
end
|
216
227
|
elsif @ast.type == :method
|
217
228
|
parse s(:send, *args)
|
218
229
|
else
|
@@ -9,6 +9,7 @@ module Ruby2JS
|
|
9
9
|
handle :hash do |*pairs|
|
10
10
|
pairs.map! do |node|
|
11
11
|
begin
|
12
|
+
block_this, block_depth = @block_this, @block_depth
|
12
13
|
@block_this, @block_depth = false, 0
|
13
14
|
|
14
15
|
left, right = node.children
|
@@ -30,7 +31,7 @@ module Ruby2JS
|
|
30
31
|
end
|
31
32
|
|
32
33
|
ensure
|
33
|
-
@block_this, @block_depth =
|
34
|
+
@block_this, @block_depth = block_this, block_depth
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
@@ -45,7 +45,7 @@ module Ruby2JS
|
|
45
45
|
if receiver
|
46
46
|
group_receiver = receiver.type == :send &&
|
47
47
|
op_index < operator_index( receiver.children[1] ) if receiver
|
48
|
-
group_receiver ||=
|
48
|
+
group_receiver ||= [:begin, :dstr, :dsym].include? receiver.type
|
49
49
|
end
|
50
50
|
|
51
51
|
if target
|
@@ -125,7 +125,8 @@ module Ruby2JS
|
|
125
125
|
else
|
126
126
|
if not ast.is_method?
|
127
127
|
if receiver
|
128
|
-
|
128
|
+
call = (group_receiver ? group(receiver) : parse(receiver))
|
129
|
+
"#{ call }.#{ method }"
|
129
130
|
else
|
130
131
|
parse s(:lvasgn, method), @state
|
131
132
|
end
|
@@ -133,7 +134,8 @@ module Ruby2JS
|
|
133
134
|
parse s(:send, s(:attr, receiver, method), :apply,
|
134
135
|
(receiver || s(:nil)), s(:array, *args))
|
135
136
|
else
|
136
|
-
call =
|
137
|
+
call = (group_receiver ? group(receiver) : parse(receiver))
|
138
|
+
call = "#{ call }#{ '.' if receiver && method}#{ method }"
|
137
139
|
args = args.map {|a| parse a}
|
138
140
|
if args.any? {|arg| arg.to_s.include? "\n"}
|
139
141
|
"#{ call }(#{ args.join(', ') })"
|
@@ -184,6 +184,11 @@ module Ruby2JS
|
|
184
184
|
ng_watch(node, :$on)
|
185
185
|
when :observe
|
186
186
|
ng_observe(node)
|
187
|
+
when :timeout, :interval
|
188
|
+
method = (call.children[1] == :timeout ? :$timeout : :$interval)
|
189
|
+
process s(:gvar, method) # for dependency injection purposes
|
190
|
+
process s(:send, nil, method, s(:block, s(:send, nil, :proc),
|
191
|
+
*node.children[1..-1]), *call.children[2..-1])
|
187
192
|
else
|
188
193
|
super
|
189
194
|
end
|
@@ -460,9 +465,6 @@ module Ruby2JS
|
|
460
465
|
|
461
466
|
def on_send(node)
|
462
467
|
if @ngContext == :controller
|
463
|
-
# map well known method names to the appropriate service
|
464
|
-
scope, method = NG_METHOD_MAP[node.children[1]]
|
465
|
-
|
466
468
|
if node.children[0..1] == [nil, :interpolate] and @ngScope
|
467
469
|
@ngClassUses << :$interpolate
|
468
470
|
if node.children.length > 3 and node.children[3].type == :nil
|
@@ -485,6 +487,9 @@ module Ruby2JS
|
|
485
487
|
end
|
486
488
|
end
|
487
489
|
|
490
|
+
# map well known method names to the appropriate service
|
491
|
+
scope, method = NG_METHOD_MAP[node.children[1]]
|
492
|
+
|
488
493
|
return super unless node.children.first == nil and method
|
489
494
|
|
490
495
|
scope = s(:gvar, scope) if scope
|
@@ -5,6 +5,13 @@ module Ruby2JS
|
|
5
5
|
module Functions
|
6
6
|
include SEXP
|
7
7
|
|
8
|
+
VAR_TO_ASSIGN = {
|
9
|
+
lvar: :lvasgn,
|
10
|
+
ivar: :ivasgn,
|
11
|
+
cvar: :cvasgn,
|
12
|
+
gvar: :gvasgn
|
13
|
+
}
|
14
|
+
|
8
15
|
def on_send(node)
|
9
16
|
target, method, *args = node.children
|
10
17
|
|
@@ -36,9 +43,9 @@ module Ruby2JS
|
|
36
43
|
|
37
44
|
elsif [:sub!, :gsub!].include? method
|
38
45
|
method = :"#{method.to_s[0..-2]}"
|
39
|
-
if target.type
|
40
|
-
process s(
|
41
|
-
s(:
|
46
|
+
if VAR_TO_ASSIGN.keys.include? target.type
|
47
|
+
process s(VAR_TO_ASSIGN[target.type], target.children[0],
|
48
|
+
s(:send, target, method, *node.children[2..-1]))
|
42
49
|
elsif target.type == :send
|
43
50
|
if target.children[0] == nil
|
44
51
|
process s(:lvasgn, target.children[1], s(:send,
|
data/lib/ruby2js/version.rb
CHANGED
data/ruby2js.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "ruby2js"
|
5
|
-
s.version = "1.
|
5
|
+
s.version = "1.8.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Sam Ruby"]
|
9
|
-
s.date = "2014-
|
9
|
+
s.date = "2014-04-02"
|
10
10
|
s.description = " The base package maps Ruby syntax to JavaScript semantics.\n Filters may be provided to add Ruby-specific or framework specific\n behavior.\n"
|
11
11
|
s.email = "rubys@intertwingly.net"
|
12
12
|
s.files = ["ruby2js.gemspec", "README.md", "lib/ruby2js", "lib/ruby2js/rails.rb", "lib/ruby2js/version.rb", "lib/ruby2js/converter", "lib/ruby2js/converter/kwbegin.rb", "lib/ruby2js/converter/const.rb", "lib/ruby2js/converter/return.rb", "lib/ruby2js/converter/prototype.rb", "lib/ruby2js/converter/opasgn.rb", "lib/ruby2js/converter/xstr.rb", "lib/ruby2js/converter/args.rb", "lib/ruby2js/converter/defs.rb", "lib/ruby2js/converter/literal.rb", "lib/ruby2js/converter/array.rb", "lib/ruby2js/converter/if.rb", "lib/ruby2js/converter/nil.rb", "lib/ruby2js/converter/logical.rb", "lib/ruby2js/converter/next.rb", "lib/ruby2js/converter/while.rb", "lib/ruby2js/converter/whilepost.rb", "lib/ruby2js/converter/arg.rb", "lib/ruby2js/converter/case.rb", "lib/ruby2js/converter/break.rb", "lib/ruby2js/converter/hash.rb", "lib/ruby2js/converter/for.rb", "lib/ruby2js/converter/boolean.rb", "lib/ruby2js/converter/module.rb", "lib/ruby2js/converter/var.rb", "lib/ruby2js/converter/undef.rb", "lib/ruby2js/converter/blockpass.rb", "lib/ruby2js/converter/until.rb", "lib/ruby2js/converter/regexp.rb", "lib/ruby2js/converter/untilpost.rb", "lib/ruby2js/converter/masgn.rb", "lib/ruby2js/converter/cvasgn.rb", "lib/ruby2js/converter/block.rb", "lib/ruby2js/converter/super.rb", "lib/ruby2js/converter/ivar.rb", "lib/ruby2js/converter/send.rb", "lib/ruby2js/converter/vasgn.rb", "lib/ruby2js/converter/defined.rb", "lib/ruby2js/converter/def.rb", "lib/ruby2js/converter/sym.rb", "lib/ruby2js/converter/cvar.rb", "lib/ruby2js/converter/ivasgn.rb", "lib/ruby2js/converter/casgn.rb", "lib/ruby2js/converter/self.rb", "lib/ruby2js/converter/begin.rb", "lib/ruby2js/converter/dstr.rb", "lib/ruby2js/converter/class.rb", "lib/ruby2js/cgi.rb", "lib/ruby2js/converter.rb", "lib/ruby2js/filter", "lib/ruby2js/filter/return.rb", "lib/ruby2js/filter/strict.rb", "lib/ruby2js/filter/angularrb.rb", "lib/ruby2js/filter/underscore.rb", "lib/ruby2js/filter/angular-resource.rb", "lib/ruby2js/filter/functions.rb", "lib/ruby2js/filter/jquery.rb", "lib/ruby2js/filter/angular-route.rb", "lib/ruby2js/sinatra.rb", "lib/ruby2js.rb"]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby2js
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Ruby
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|