ruby2js 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- N2MxNDBkNGRmOTUxZmM0NjRlYWQ5N2RmODgzMTgxZTNiNDU2MDU4NA==
4
+ ZGIyMDBkZWFkNDE5ZDFlOTliNDE0MDMwMjgwMmNlYWZkZDcxOWNiMg==
5
5
  data.tar.gz: !binary |-
6
- ZmFiMGY3NTM1MmViNTY4YjQ5OWQyYmMzMDQzZGYwZmFhOTY2ZDZiYg==
6
+ NzIxOTk3NjM1YzRkMDA1NTI3ZThiMTI0MzE3NzIyYWFhNmE3MmIwMA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MGMwY2ZlNWIzZWY5ZDdlOTQ1ZjUxMWNiMDZmMTczMjBiNmU0YTNjYWQ4ZDZm
10
- MDBmZTcyZDkyNzJjMDIwNjQyN2E4ZWE3MTRhMzAwZDRhODFhY2IxNjgzYTY2
11
- ZDUwNTg5MWJhNzRiMjlkNzE4MzEyYWJkOTc4YTQwZjFhOTNiMWY=
9
+ MjRmNDE4NWQxN2MxNTAxOThkZTUzYzFiMGU0ZDZiM2EwNTI3ZDZlYmQyY2Fh
10
+ MDg4MGM3YjVlMWI4NGQwMWY0ODhmMjQ5YTE1ZjdmN2JmOWRiYWI5ZDdjNzM0
11
+ ZDM0NWExNWFjZjg1NzQ1MTNhNWNkMGMwYjg1MjIxMDdkYjI3NDU=
12
12
  data.tar.gz: !binary |-
13
- OTc3MjViYjAyY2Q3ZWIwMzA2ZGNjMjdkMDQ0OTc2YjVkYzk0ZDc3ZmEwODcw
14
- YThkMGVlMmViNjFkZTNmYWJjMWNhZDg2ZDI5MDQ5NzU2ODZmZjBiMzQzZTdl
15
- Yzg1Y2FkYTI5MzM1NmY1ZTViYjJmOTRmZTgyZWQyM2JmODZiNjc=
13
+ OGYxYTNmNjNjNWY5OTkxYmQ0YTljNDhkM2JmZmU0NmY5ZTMzNTZhZjc3OWVi
14
+ NjcxZDQ3NmQ2N2Y1M2QzNTNmYjE5ODZjNTNmZDc2YTM0MGVhOTAzZWE4YTc0
15
+ NDFiOGU4NjU2YjA1MGYzOGE3Mjk2ODM5Y2IzNTc2MjdjNDFkMGY=
data/README.md CHANGED
@@ -61,7 +61,7 @@ quite different if `a` is a Hash.
61
61
 
62
62
  One way to resolve this is to change the way indexing operators are evaluated,
63
63
  and to provide a runtime library that adds properties to global JavaScript
64
- objects to handle this. It’s the approach that [Opal](http://opalrb.org/)
64
+ objects to handle this. This is the approach that [Opal](http://opalrb.org/)
65
65
  takes. It is a fine approach, with a number of benefits. It also has some
66
66
  notable drawbacks. For example,
67
67
  [readability](http://opalrb.org/try/#code:a%20%3D%20%22abc%22%3B%20puts%20a[-1])
@@ -76,11 +76,11 @@ A third approach would be to do static transformations on the source in order
76
76
  to address common usage patterns or idioms. These transformations can even be
77
77
  occasionally unsafe, as long as the transformations themselves are opt-in.
78
78
  ruby2js provides a number of such filters, including one that handles negative
79
- indexes when passes as a literal. As indicated above, this is unsafe in that
79
+ indexes when passed as a literal. As indicated above, this is unsafe in that
80
80
  it will do the wrong thing when it encounters a hash index which is expressed
81
81
  as a literal constant negative one. My experience is that such is rare enough
82
82
  to be safely ignored, but YMMV. More troublesome, this also won’t work when
83
- the index is not a literal (e.g., `a[n]`) where the index happens to be
83
+ the index is not a literal (e.g., `a[n]`) and the index happens to be
84
84
  negative at runtime.
85
85
 
86
86
  This quickly gets into gray areas. `each` in Ruby is a common method that
@@ -104,9 +104,9 @@ includes three such integrations:
104
104
  * [Sinatra](https://github.com/rubys/ruby2js/blob/master/lib/ruby2js/sinatra.rb)
105
105
  * [Rails](https://github.com/rubys/ruby2js/blob/master/lib/ruby2js/rails.rb)
106
106
 
107
- As you might expect, CGI is a bit sluggish. By constrast, Sinatra are quite
108
- speedy as the bulk of the time is spend on the initial load of the required
109
- libraries.
107
+ As you might expect, CGI is a bit sluggish. By constrast, Sinatra and Rails
108
+ are quite speedy as the bulk of the time is spend on the initial load of the
109
+ required libraries.
110
110
 
111
111
  Filters
112
112
  ---
@@ -123,24 +123,29 @@ the script.
123
123
 
124
124
  * [functions](https://github.com/rubys/ruby2js/blob/master/lib/ruby2js/filter/functions.rb)
125
125
 
126
- * `to_s` becomes `to_String`
127
- * `to_i` becomes `parseInt`
128
- * `to_f` becomes `parseFloat`
129
- * `sub` becomes `replace`
130
- * `gsub` becomes `replace //g`
131
- * `first` becomes `[0]`
132
- * `last` becomes `[*.length-1]`
126
+ * `.to_s` becomes `to_String`
127
+ * `.to_a` becomes `to_Array`
128
+ * `.to_i` becomes `parseInt`
129
+ * `.to_f` becomes `parseFloat`
130
+ * `.sub` becomes `replace`
131
+ * `.ord` becomes `charCodeAt(0)`
132
+ * `.chr` becomes `fromCharCode`
133
+ * `.gsub` becomes `replace //g`
134
+ * `.first` becomes `[0]`
135
+ * `.last` becomes `[*.length-1]`
133
136
  * `[-n]` becomes `[*.length-n]` for literal values of `n`
134
- * `[n..m]` becomes `slice(n,m+1)`
135
- * `[n...m]` becomes `slice(n,m)`
137
+ * `[n..m]` becomes `.slice(n,m+1)`
138
+ * `[n...m]` becomes `.slice(n,m)`
139
+ * `[/r/, n]` becomes `.match(/r/)[n]`
136
140
  * `.empty?` becomes `.length == 0`
137
141
  * `.clear!` becomes `.length = 0`
142
+ * `.replace!` becomes `.length = 0; ...push.apply(*)`
138
143
  * `.include?` becomes `.indexOf() != -1`
139
144
  * `.any?` becomes `.some`
140
145
  * `.all?` becomes `.every`
141
146
  * `puts` becomes `console.log`
142
- * `each` becomes `forEach` unless jquery is included
143
- * `each_with_index` becomes `forEach`
147
+ * `.each` becomes `forEach` unless jquery is included
148
+ * `.each_with_index` becomes `forEach`
144
149
  * `setInterval` and `setTimeout` allow block to be treated as the
145
150
  first parameter on the call
146
151
 
@@ -149,7 +154,7 @@ the script.
149
154
  * maps Ruby unary operator `~` to jQuery `$` function
150
155
  * maps Ruby attribute syntax to jquery attribute syntax
151
156
  * maps `$$` to jQuery `$` function
152
- * defaults fourth parameter of $$.post to :jquery, allowing Ruby block
157
+ * defaults the fourth parameter of $$.post to :jquery, allowing Ruby block
153
158
  syntax to be used for the success function.
154
159
 
155
160
  * [angularrb](https://github.com/rubys/ruby2js/blob/master/lib/ruby2js/filter/angularrb.rb)
@@ -159,6 +164,7 @@ the script.
159
164
  angular module functions.
160
165
  * maps `use` statements to formal arguments or array values (as
161
166
  appropriate) depending on the module function.
167
+ * maps `watch` statments to calls to `$scope.$watch`.
162
168
  * tracks globals variable and constant references and adds additional
163
169
  implicit `use` statements
164
170
  * maps constant assignments in an angular module to a filter
@@ -178,7 +184,9 @@ the script.
178
184
 
179
185
  [Wunderbar](https://github.com/rubys/wunderbar) includes additional demos:
180
186
 
181
- * [wiki](https://github.com/rubys/wunderbar/blob/master/demo/wiki.rb) makes
187
+ * [chat](https://github.com/rubys/wunderbar/blob/master/demo/chat.rb),
188
+ [diskusage](https://github.com/rubys/wunderbar/blob/master/demo/diskusage.rb),
189
+ and [wiki](https://github.com/rubys/wunderbar/blob/master/demo/wiki.rb) make
182
190
  use of the jquery filter.
183
191
 
184
192
  * [angularjs](https://github.com/rubys/wunderbar/blob/master/demo/angularjs.rb)
@@ -197,7 +205,7 @@ framework, and only use one of the many integrations that
197
205
  [Opal](http://opalrb.org/) provides, then Opal is the way to go right now.
198
206
 
199
207
  ruby2js is for those that want to produce JavaScript that looks like it
200
- wasn’t machine generated, and with the absolute bare minimum in terms of
208
+ wasn’t machine generated, and want the absolute bare minimum in terms of
201
209
  limitations as to what JavaScript can be produced.
202
210
 
203
211
  [Try](http://intertwingly.net/projects/ruby2js/all) for yourself.
data/lib/ruby2js.rb CHANGED
@@ -11,6 +11,12 @@ module Ruby2JS
11
11
  Parser::AST::Node.new type, args
12
12
  end
13
13
  end
14
+
15
+ class Processor < Parser::AST::Processor
16
+ def on_attr(node)
17
+ node.updated nil, [process(node.children.first), node.children.last]
18
+ end
19
+ end
14
20
  end
15
21
 
16
22
  def self.convert(source, options={})
@@ -29,7 +35,7 @@ module Ruby2JS
29
35
  filters = options[:filters] || Filter::DEFAULTS
30
36
 
31
37
  unless filters.empty?
32
- filter = Parser::AST::Processor
38
+ filter = Filter::Processor
33
39
  filters.reverse.each do |mod|
34
40
  filter = Class.new(filter) {include mod}
35
41
  end
@@ -15,6 +15,7 @@ module Ruby2JS
15
15
  @ws = ' '
16
16
  @varstack = []
17
17
  @width = 80
18
+ @next_token = :return
18
19
 
19
20
  @handlers = {}
20
21
  @@handlers.each do |name|
@@ -94,7 +95,6 @@ end
94
95
 
95
96
  # see https://github.com/whitequark/parser/blob/master/doc/AST_FORMAT.md
96
97
 
97
- require 'ruby2js/converter/andasgn'
98
98
  require 'ruby2js/converter/arg'
99
99
  require 'ruby2js/converter/args'
100
100
  require 'ruby2js/converter/array'
@@ -126,7 +126,6 @@ require 'ruby2js/converter/module'
126
126
  require 'ruby2js/converter/next'
127
127
  require 'ruby2js/converter/nil'
128
128
  require 'ruby2js/converter/opasgn'
129
- require 'ruby2js/converter/orasgn'
130
129
  require 'ruby2js/converter/prototype'
131
130
  require 'ruby2js/converter/regexp'
132
131
  require 'ruby2js/converter/return'
@@ -6,6 +6,7 @@ module Ruby2JS
6
6
 
7
7
  handle :break do |n=nil|
8
8
  raise NotImplementedError, "break argument #{ n.inspect }" if n
9
+ raise NotImplementedError, "break outside of loop" if @next_token == :return
9
10
  'break'
10
11
  end
11
12
  end
@@ -38,6 +38,9 @@ module Ruby2JS
38
38
  elsif m.type == :cvasgn
39
39
  # class variable
40
40
  s(:send, name, "_#{m.children[0][2..-1]}=", *m.children[1..-1])
41
+ elsif m.type == :send and m.children[0].type == :cvar
42
+ s(:send, s(:attr, name, "_#{m.children[0].children[0][2..-1]}"),
43
+ *m.children[1..-1])
41
44
  elsif m.type == :casgn and m.children[0] == nil
42
45
  # class constant
43
46
  s(:send, name, "#{m.children[1]}=", *m.children[2..-1])
@@ -83,9 +83,14 @@ module Ruby2JS
83
83
  end
84
84
  end
85
85
 
86
- nl = @nl unless body == s(:begin)
87
- "function#{ " #{name}" if name }(#{ parse args }) " +
88
- "{#{nl}#{ scope body, vars}#{nl}}"
86
+ nl = @nl unless body == s(:begin)
87
+ begin
88
+ next_token, @next_token = @next_token, :return
89
+ "function#{ " #{name}" if name }(#{ parse args }) " +
90
+ "{#{nl}#{ scope body, vars}#{nl}}"
91
+ ensure
92
+ @next_token = next_token
93
+ end
89
94
  end
90
95
  end
91
96
  end
@@ -10,17 +10,22 @@ module Ruby2JS
10
10
  # (...)
11
11
 
12
12
  handle :for do |var, expression, block|
13
- if expression.type == :irange
14
- "for (var #{parse var} = #{ parse expression.children.first }; " +
15
- "#{ parse var } <= #{ parse expression.children.last }; " +
16
- "#{ parse var }++) {#@nl#{ scope block }#@nl}"
17
- elsif expression.type == :erange
18
- "for (var #{parse var} = #{ parse expression.children.first }; " +
19
- "#{ parse var } < #{ parse expression.children.last }; " +
20
- "#{ parse var }++) {#@nl#{ scope block }#@nl}"
21
- else
22
- "for (var #{parse var} in #{ parse expression }) " +
23
- "{#@nl#{ scope block }#@nl}"
13
+ begin
14
+ next_token, @next_token = @next_token, :continue
15
+ if expression.type == :irange
16
+ "for (var #{parse var} = #{ parse expression.children.first }; " +
17
+ "#{ parse var } <= #{ parse expression.children.last }; " +
18
+ "#{ parse var }++) {#@nl#{ scope block }#@nl}"
19
+ elsif expression.type == :erange
20
+ "for (var #{parse var} = #{ parse expression.children.first }; " +
21
+ "#{ parse var } < #{ parse expression.children.last }; " +
22
+ "#{ parse var }++) {#@nl#{ scope block }#@nl}"
23
+ else
24
+ "for (var #{parse var} in #{ parse expression }) " +
25
+ "{#@nl#{ scope block }#@nl}"
26
+ end
27
+ ensure
28
+ @next_token = next_token
24
29
  end
25
30
  end
26
31
  end
@@ -6,10 +6,25 @@ module Ruby2JS
6
6
  # (...)
7
7
  # (...))
8
8
 
9
+ INVERT_OP = {
10
+ :< => :>=,
11
+ :<= => :>,
12
+ :== => :!=,
13
+ :!= => :==,
14
+ :> => :<=,
15
+ :>= => :<
16
+ }
17
+
9
18
  handle :if do |condition, then_block, else_block|
10
19
  # return parse condition if not else_block and not then_block
11
20
  if else_block and not then_block
12
- return parse(s(:if, s(:send, condition, :!), else_block, nil), @state)
21
+ if condition.type == :send and INVERT_OP.include? condition.children[1]
22
+ return parse(s(:if, s(:send, condition.children[0],
23
+ INVERT_OP[condition.children[1]], condition.children[2]),
24
+ else_block,nil), @state)
25
+ else
26
+ return parse(s(:if, s(:send, condition, :!), else_block, nil), @state)
27
+ end
13
28
  end
14
29
 
15
30
  then_block ||= s(:nil)
@@ -16,16 +16,16 @@ module Ruby2JS
16
16
  type = @ast.type
17
17
  op_index = operator_index type
18
18
 
19
- left = left.children.first if left and left.type == :begin
20
19
  lgroup = LOGICAL.include?( left.type ) &&
21
- op_index <= operator_index( left.type )
20
+ op_index < operator_index( left.type )
21
+ lgroup = true if left and left.type == :begin
22
22
  left = parse left
23
23
  left = "(#{ left })" if lgroup
24
24
 
25
25
  if right
26
- right = right.children.first if right.type == :begin
27
26
  rgroup = LOGICAL.include?( right.type ) &&
28
- op_index <= operator_index( right.type )
27
+ op_index < operator_index( right.type )
28
+ rgroup = true if right.type == :begin
29
29
  right = parse right
30
30
  right = "(#{ right })" if rgroup
31
31
  end
@@ -6,7 +6,7 @@ module Ruby2JS
6
6
 
7
7
  handle :next do |n=nil|
8
8
  raise NotImplementedError, "next argument #{ n.inspect }" if n
9
- 'continue'
9
+ @next_token.to_s
10
10
  end
11
11
  end
12
12
  end
@@ -5,7 +5,13 @@ module Ruby2JS
5
5
  # (lvasgn :a) :+
6
6
  # (int 1))
7
7
 
8
+ # NOTE: and-asgn and or_asgn handled below
9
+
8
10
  handle :op_asgn do |var, op, value|
11
+ var = s(:ivar, var.children.first) if var.type == :ivasgn
12
+ var = s(:lvar, var.children.first) if var.type == :lvasgn
13
+ var = s(:cvar, var.children.first) if var.type == :cvasgn
14
+
9
15
  if [:+, :-].include?(op) and value.type==:int and value.children==[1]
10
16
  if @state == :statement
11
17
  "#{ parse var }#{ op }#{ op }"
@@ -16,5 +22,30 @@ module Ruby2JS
16
22
  "#{ parse var } #{ op }= #{ parse value }"
17
23
  end
18
24
  end
25
+
26
+ # (or-asgn
27
+ # (lvasgn :a)
28
+ # (int 1))
29
+
30
+ # (and-asgn
31
+ # (lvasgn :a)
32
+ # (int 1))
33
+
34
+ handle :or_asgn, :and_asgn do |asgn, value|
35
+ type = (@ast.type == :and_asgn ? :and : :or)
36
+
37
+ vtype = nil
38
+ vtype = :lvar if asgn.type == :lvasgn
39
+ vtype = :ivar if asgn.type == :ivasgn
40
+ vtype = :cvar if asgn.type == :cvasgn
41
+
42
+ if vtype
43
+ parse s(asgn.type, asgn.children.first, s(type,
44
+ s(vtype, asgn.children.first), value))
45
+ else
46
+ parse s(:send, asgn.children.first, "#{asgn.children[1]}=",
47
+ s(type, asgn, value))
48
+ end
49
+ end
19
50
  end
20
51
  end
@@ -4,12 +4,20 @@ module Ruby2JS
4
4
  # (send nil :puts
5
5
  # (int 1))
6
6
 
7
- # (attr nil :puts
7
+ # (attr nil :puts)
8
+
9
+ # (sendw nil :puts
8
10
  # (int 1))
9
11
 
10
- handle :send, :attr do |receiver, method, *args|
12
+ # Note: attr and sendw are only generated by filters. Attr forces
13
+ # interpretation as an attribute vs a function call with zero parameters.
14
+ # Sendw forces parameters to be placed on separate lines.
15
+
16
+ handle :send, :sendw, :attr do |receiver, method, *args|
11
17
  ast = @ast
12
18
 
19
+ width = ((ast.type == :sendw && !@nl.empty?) ? 0 : @width)
20
+
13
21
  if method =~ /\w[!?]$/
14
22
  raise NotImplementedError, "invalid method name #{ method }"
15
23
  end
@@ -30,15 +38,22 @@ module Ruby2JS
30
38
  end
31
39
  end
32
40
 
33
- op_index = operator_index method
41
+ op_index = operator_index method
34
42
  if op_index != -1
35
43
  target = args.first
36
- target = target.children.first if target and target.type == :begin
37
- receiver = receiver.children.first if receiver.type == :begin
38
44
  end
39
45
 
40
- group_receiver = receiver.type == :send && op_index <= operator_index( receiver.children[1] ) if receiver
41
- group_target = target.type == :send && op_index <= operator_index( target.children[1] ) if target
46
+ if receiver
47
+ group_receiver = receiver.type == :send &&
48
+ op_index < operator_index( receiver.children[1] ) if receiver
49
+ group_receiver ||= (receiver.type == :begin)
50
+ end
51
+
52
+ if target
53
+ group_target = target.type == :send &&
54
+ op_index < operator_index( target.children[1] )
55
+ group_target ||= (target.type == :begin)
56
+ end
42
57
 
43
58
  if method == :!
44
59
  if receiver.type == :defined?
@@ -129,7 +144,7 @@ module Ruby2JS
129
144
  args = args.map {|a| parse a}
130
145
  if args.any? {|arg| arg.to_s.include? "\n"}
131
146
  "#{ call }(#{ args.join(', ') })"
132
- elsif args.map {|arg| arg.length+2}.reduce(&:+).to_i < @width-10
147
+ elsif args.map {|arg| arg.length+2}.reduce(&:+).to_i < width-10
133
148
  "#{ call }(#{ args.join(', ') })"
134
149
  else
135
150
  "#{ call }(#@nl#{ args.join(",#@ws") }#@nl)"
@@ -6,7 +6,12 @@ module Ruby2JS
6
6
  # (...))
7
7
 
8
8
  handle :while do |condition, block|
9
- "while (#{ parse condition }) {#@nl#{ scope block }#@nl}"
9
+ begin
10
+ next_token, @next_token = @next_token, :continue
11
+ "while (#{ parse condition }) {#@nl#{ scope block }#@nl}"
12
+ ensure
13
+ @next_token = next_token
14
+ end
10
15
  end
11
16
  end
12
17
  end
@@ -8,7 +8,12 @@ module Ruby2JS
8
8
 
9
9
  handle :while_post do |condition, block|
10
10
  block = block.updated(:begin) if block.type == :kwbegin
11
- "do {#@nl#{ scope block }#@nl} while (#{ parse condition })"
11
+ begin
12
+ next_token, @next_token = @next_token, :continue
13
+ "do {#@nl#{ scope block }#@nl} while (#{ parse condition })"
14
+ ensure
15
+ @next_token = next_token
16
+ end
12
17
  end
13
18
  end
14
19
  end
@@ -25,31 +25,17 @@ module Ruby2JS
25
25
  @ngAppUses << :ngRoute
26
26
  code = s(:lvar, rp)
27
27
 
28
- hash = proc do |pairs|
29
- if pairs.length == 1 and pairs.first.type == :begin
30
- pairs = pairs.first.children
31
- end
32
- s(:hash, *pairs.map {|pair|
33
- if pair.type == :send
34
- s(:pair, s(:sym, pair.children[1]), pair.children[2])
35
- else
36
- s(:pair, s(:sym, pair.children[0]), pair.children[1])
37
- end
38
- })
39
- end
40
-
41
28
  node.children[1..-2].each do |child|
42
- code = s(:send, code, :when, child.children.first,
43
- hash[child.children[1..-1]])
29
+ code = s(:sendw, code, :when, child.children.first,
30
+ AngularRB.hash(child.children[1..-1]))
44
31
  end
45
32
 
46
33
  if node.children.last
47
- code = s(:send, code, :otherwise,
48
- hash[node.children[-1..-1]])
34
+ code = s(:sendw, code, :otherwise,
35
+ AngularRB.hash(node.children[-1..-1]))
49
36
  end
50
37
 
51
- s(:send, s(:lvar, @ngApp), :config, s(:array, s(:str, rp.to_s),
52
- s(:block,
38
+ s(:send, @ngApp, :config, s(:array, s(:str, rp.to_s), s(:block,
53
39
  s(:send, nil, :proc), s(:args, s(:arg, rp)), code)))
54
40
  end
55
41
  end
@@ -6,8 +6,36 @@ module Ruby2JS
6
6
  module AngularRB
7
7
  include SEXP
8
8
 
9
+ def self.s(type, *args)
10
+ Parser::AST::Node.new type, args
11
+ end
12
+
13
+ Angular = s(:const, nil, :Angular)
14
+
15
+ # convert simple assignments, simple method calls, and simple method
16
+ # definitions into a hash when possible; return false otherwise
17
+ def self.hash(pairs)
18
+ if pairs.length == 1 and pairs.first.type == :begin
19
+ pairs = pairs.first.children
20
+ end
21
+
22
+ s(:hash, *pairs.map {|pair|
23
+ if pair.type == :send and pair.children[0] == nil
24
+ s(:pair, s(:sym, pair.children[1]), pair.children[2])
25
+ elsif pair.type == :lvasgn
26
+ s(:pair, s(:sym, pair.children[0]), pair.children[1])
27
+ elsif pair.type == :def
28
+ s(:pair, s(:sym, pair.children[0]), s(:block, s(:send, nil, :proc),
29
+ *pair.children[1..-1]))
30
+ else
31
+ return false
32
+ end
33
+ })
34
+ end
35
+
9
36
  def initialize(*args)
10
37
  @ngApp = nil
38
+ @ngContext = nil
11
39
  @ngAppUses = []
12
40
  @ngClassUses = []
13
41
  @ngClassOmit = []
@@ -28,10 +56,9 @@ module Ruby2JS
28
56
  module_name = node.children[0]
29
57
  parent_name = module_name.children[0]
30
58
 
31
- return super unless parent_name and parent_name.type == :const
32
- return super unless parent_name.children == [nil, :Angular]
59
+ return super unless parent_name == Angular
33
60
 
34
- @ngApp = module_name.children[1]
61
+ @ngApp = s(:lvar, module_name.children[1])
35
62
  @ngChildren = node.children[1..-1]
36
63
  while @ngChildren.length == 1 and @ngChildren.first and @ngChildren.first.type == :begin
37
64
  @ngChildren = @ngChildren.first.children.dup
@@ -45,11 +72,12 @@ module Ruby2JS
45
72
  depends = depends.map {|node| node.children.first.to_s}.uniq.
46
73
  map {|sym| s(:str, sym)}
47
74
 
48
- name, @ngApp, @ngChildren = @ngApp, nil, nil
75
+ ngApp, @ngApp, @ngChildren = @ngApp, nil, nil
76
+ name = module_name.children[1].to_s
49
77
 
50
78
  # construct app
51
- app = s(:send, s(:lvar, :angular), :module, s(:str, name.to_s),
52
- s(:array, *depends.uniq))
79
+ app = s(:send, s(:lvar, :angular), :module,
80
+ s(:str, name), s(:array, *depends.uniq))
53
81
 
54
82
  # return a single chained statement when there is only one call
55
83
  block.compact!
@@ -57,9 +85,9 @@ module Ruby2JS
57
85
  return app
58
86
  elsif block.length == 1
59
87
  call = block.first.children.first
60
- if block.first.type == :send and call == s(:lvar, name)
88
+ if block.first.type == :send and call == ngApp
61
89
  return block.first.updated nil, [app, *block.first.children[1..-1]]
62
- elsif block.first.type == :block and call.children.first == s(:lvar, name)
90
+ elsif block.first.type == :block and call.children.first == ngApp
63
91
  call = call.updated nil, [app, *call.children[1..-1]]
64
92
  return block.first.updated nil, [call, *block.first.children[1..-1]]
65
93
  end
@@ -82,6 +110,7 @@ module Ruby2JS
82
110
  return super unless @ngApp and @ngChildren.include? node
83
111
  name = node.children.first
84
112
  if name.children.first == nil
113
+ @ngClassUses, @ngClassOmit = [], []
85
114
  block = [node.children.last]
86
115
  uses = extract_uses(block)
87
116
  node = s(:class, name, node.children[1],
@@ -93,7 +122,7 @@ module Ruby2JS
93
122
  map {|sym| s(:arg, sym)}
94
123
  @ngClassUses, @ngClassOmit = [], []
95
124
 
96
- s(:block, s(:send, s(:lvar, @ngApp), :factory,
125
+ s(:block, s(:send, @ngApp, :factory,
97
126
  s(:sym, name.children.last)), s(:args, *args),
98
127
  s(:begin, node, s(:return, s(:const, nil, name.children.last))))
99
128
  else
@@ -108,21 +137,38 @@ module Ruby2JS
108
137
  # directive :name { ... }
109
138
 
110
139
  def on_block(node)
111
- return super unless @ngApp
140
+ ngApp = @ngApp
112
141
  call = node.children.first
113
- return super if call.children.first
114
-
115
- case call.children[1]
116
- when :controller
117
- ng_controller(node)
118
- when :factory
119
- ng_factory(node)
120
- when :filter
121
- ng_filter(node)
122
- when :directive
123
- ng_controller(node) # reuse template
142
+ target = call.children.first
143
+ if target and target.type == :const and target.children.first == Angular
144
+ @ngApp = s(:send, s(:lvar, :angular), :module, s(:str,
145
+ target.children.last.to_s))
124
146
  else
125
- super
147
+ return super if target
148
+ return super unless @ngApp
149
+ end
150
+
151
+ begin
152
+ case call.children[1]
153
+ when :controller
154
+ ng_controller(node, :controller)
155
+ when :factory
156
+ ng_factory(node)
157
+ when :filter
158
+ ng_filter(node)
159
+ when :directive
160
+ hash = AngularRB.hash(node.children[2..-1])
161
+ if hash
162
+ node = node.updated nil, [*node.children[0..1], s(:return, hash)]
163
+ end
164
+ ng_controller(node, :directive)
165
+ when :watch
166
+ ng_watch(node)
167
+ else
168
+ super
169
+ end
170
+ ensure
171
+ @ngApp = ngApp
126
172
  end
127
173
  end
128
174
 
@@ -131,10 +177,15 @@ module Ruby2JS
131
177
  # ...
132
178
  # end
133
179
  #
134
- def ng_controller(node)
180
+ # output:
181
+ # AppName.controller("name", do |uses|
182
+ # ...
183
+ # end
184
+ def ng_controller(node, scope)
185
+ ngContext, @ngContext = @ngContext, scope
186
+ @ngClassUses, @ngClassOmit = [], []
135
187
  target = node.children.first
136
- target = target.updated(nil, [s(:lvar, @ngApp),
137
- *target.children[1..-1]])
188
+ target = target.updated(nil, [@ngApp, *target.children[1..-1]])
138
189
 
139
190
  block = process_all(node.children[2..-1])
140
191
 
@@ -144,9 +195,11 @@ module Ruby2JS
144
195
  args += @ngClassUses.map {|sym| s(:arg, sym)} + extract_uses(block)
145
196
  args = args.map {|node| node.children.first.to_sym}.uniq.
146
197
  map {|sym| s(:arg, sym)}
147
- @ngClassUses, @ngClassOmit = [], []
148
198
 
149
199
  node.updated :block, [target, s(:args, *args), s(:begin, *block)]
200
+ ensure
201
+ @ngClassUses, @ngClassOmit = [], []
202
+ @ngContext = ngContext
150
203
  end
151
204
 
152
205
  # input:
@@ -163,12 +216,13 @@ module Ruby2JS
163
216
  :or, :regexp, :self, :send, :str, :sym, :true, :undefined?, :xstr ]
164
217
 
165
218
  def ng_filter(node)
219
+ @ngClassUses, @ngClassOmit = [], []
166
220
  call = node.children.first
167
221
 
168
222
  # insert return
169
223
  args = process_all(node.children[1].children)
170
224
  block = process_all(node.children[2..-1])
171
- uses = @ngClassUses.uniq.map {|sym| s(:arg, sym)}
225
+ uses = (@ngClassUses - @ngClassOmit).uniq.map {|sym| s(:arg, sym)}
172
226
  tail = [block.pop || s(:nil)]
173
227
  while tail.length == 1 and tail.first.type == :begin
174
228
  tail = tail.first.children.dup
@@ -178,7 +232,7 @@ module Ruby2JS
178
232
 
179
233
  # construct a function returning a function
180
234
  inner = s(:block, s(:send, nil, :lambda), s(:args, *args), *block)
181
- outer = s(:send, s(:lvar, @ngApp), :filter, *call.children[2..-1])
235
+ outer = s(:send, @ngApp, :filter, *call.children[2..-1])
182
236
 
183
237
  node.updated nil, [outer, s(:args, *uses), s(:return, inner)]
184
238
  end
@@ -192,7 +246,7 @@ module Ruby2JS
192
246
  # AppName.factory :name, [uses, lambda {|uses| ...}]
193
247
  def ng_factory(node)
194
248
  call = node.children.first
195
- call = call.updated(nil, [s(:lvar, @ngApp), *call.children[1..-1]])
249
+ call = call.updated(nil, [@ngApp, *call.children[1..-1]])
196
250
 
197
251
  # insert return
198
252
  block = process_all(node.children[2..-1])
@@ -230,6 +284,57 @@ module Ruby2JS
230
284
  s(:args), process(node.children[2]))
231
285
  end
232
286
 
287
+ # convert ivar referencess in controllers to $scope
288
+ def on_ivar(node)
289
+ if @ngContext == :controller
290
+ process s(:attr, s(:gvar, :$scope), node.children.first.to_s[1..-1])
291
+ else
292
+ super
293
+ end
294
+ end
295
+
296
+ # input:
297
+ # watch 'expression' do |oldvalue, newvalue|
298
+ # ...
299
+ # end
300
+ #
301
+ # output:
302
+ # $scope.$watch 'expression' do |oldvalue, newvalue|
303
+ # ...
304
+ # end
305
+ def ng_watch(node)
306
+ call = node.children.first
307
+ if @ngContext == :controller and call.children.first == nil
308
+ call = s(:send, s(:gvar, :$scope), :$watch, *call.children[2..-1])
309
+ node = node.updated nil, [call, *node.children[1..-1]]
310
+ end
311
+ return process node
312
+ end
313
+
314
+ # convert ivar assignments in controllers to $scope
315
+ def on_ivasgn(node)
316
+ if @ngContext == :controller
317
+ if node.children.length == 1
318
+ process s(:attr, s(:gvar, :$scope),
319
+ "#{node.children.first.to_s[1..-1]}")
320
+ else
321
+ process s(:send, s(:gvar, :$scope),
322
+ "#{node.children.first.to_s[1..-1]}=", node.children.last)
323
+ end
324
+ else
325
+ super
326
+ end
327
+ end
328
+
329
+ # convert instance method definitions in controllers to $scope
330
+ def on_def(node)
331
+ if @ngContext == :controller
332
+ process s(:defs, s(:gvar, :$scope), *node.children)
333
+ else
334
+ super
335
+ end
336
+ end
337
+
233
338
  def on_gvar(node)
234
339
  if @ngClassUses
235
340
  @ngClassUses << node.children.first
@@ -12,36 +12,56 @@ module Ruby2JS
12
12
  if node.children[1] == :to_s
13
13
  s(:send, target, :toString, *args)
14
14
 
15
+ elsif node.children[1] == :to_a
16
+ s(:send, target, :toArray, *args)
17
+
15
18
  elsif node.children[1] == :to_i
16
19
  node.updated nil, [nil, :parseInt, target, *args]
17
20
 
18
21
  elsif node.children[1] == :to_f
19
- node.updated nil, [nil, :parseFloat, target, *args]
22
+ process node.updated nil, [nil, :parseFloat, target, *args]
20
23
 
21
24
  elsif node.children[1] == :sub and node.children.length == 4
22
25
  source, method, before, after = node.children
23
- node.updated nil, [source, :replace, before, after]
26
+ process node.updated nil, [source, :replace, before, after]
24
27
 
25
28
  elsif node.children[1] == :gsub and node.children.length == 4
26
29
  source, method, before, after = node.children
27
30
  if before.type == :regexp
28
- before = s(:regexp, before.children.first,
29
- s(:regopt, :g, *before.children[1]))
31
+ before = s(:regexp, *before.children[0...-1],
32
+ s(:regopt, :g, *before.children.last))
30
33
  elsif before.type == :str
31
34
  before = s(:regexp, s(:str, Regexp.escape(before.children.first)),
32
35
  s(:regopt, :g))
33
36
  end
34
- node.updated nil, [source, :replace, before, after]
37
+ process node.updated nil, [source, :replace, before, after]
38
+
39
+ elsif node.children[1] == :ord and node.children.length == 2
40
+ if target.type == :str
41
+ s(:int, target.children.last.ord)
42
+ else
43
+ node.updated nil, [target, :charCodeAt, s(:int, 0)]
44
+ end
45
+
46
+ elsif node.children[1] == :chr and node.children.length == 2
47
+ if target.type == :int
48
+ s(:str, target.children.last.chr)
49
+ else
50
+ node.updated nil, [s(:const, nil, :String), :fromCharCode, target]
51
+ end
35
52
 
36
53
  elsif node.children[1] == :empty? and node.children.length == 2
37
- s(:send, s(:attr, node.children[0], :length), :==, s(:int, 0))
54
+ s(:send, s(:attr, target, :length), :==, s(:int, 0))
38
55
 
39
56
  elsif node.children[1] == :clear! and node.children.length == 2
40
- s(:send, node.children[0], :length=, s(:int, 0))
57
+ s(:send, target, :length=, s(:int, 0))
58
+
59
+ elsif node.children[1] == :replace! and node.children.length == 3
60
+ s(:begin, s(:send, target, :length=, s(:int, 0)),
61
+ s(:send, target, :push, s(:splat, node.children[2])))
41
62
 
42
63
  elsif node.children[1] == :include? and node.children.length == 3
43
- s(:send, s(:send, node.children[0], :indexOf, node.children[2]),
44
- :!=, s(:int, -1))
64
+ s(:send, s(:send, target, :indexOf, args.first), :!=, s(:int, -1))
45
65
 
46
66
  elsif node.children[1] == :each
47
67
  if @each # disable `each` mapping, see jquery filter for an example
@@ -51,48 +71,54 @@ module Ruby2JS
51
71
  end
52
72
 
53
73
  elsif node.children[0..1] == [nil, :puts]
54
- s(:send, s(:attr, nil, :console), :log, *node.children[2..-1])
74
+ s(:send, s(:attr, nil, :console), :log, *args)
55
75
 
56
76
  elsif node.children[1..-1] == [:first]
57
- node.updated nil, [node.children[0], :[], s(:int, 0)]
77
+ node.updated nil, [target, :[], s(:int, 0)]
58
78
 
59
79
  elsif node.children[1..-1] == [:last]
60
- on_send node.updated nil, [node.children[0], :[], s(:int, -1)]
80
+ on_send node.updated nil, [target, :[], s(:int, -1)]
61
81
 
62
- elsif node.children[1] == :[] and node.children.length == 3
63
- source = node.children[0]
64
- index = node.children[2]
82
+ elsif node.children[1] == :[]
83
+ index = args.first
65
84
 
66
85
  # resolve negative literal indexes
67
86
  i = proc do |index|
68
87
  if index.type == :int and index.children.first < 0
69
- s(:send, s(:attr, source, :length), :-,
88
+ s(:send, s(:attr, target, :length), :-,
70
89
  s(:int, -index.children.first))
71
90
  else
72
91
  index
73
92
  end
74
93
  end
75
94
 
76
- if index.type == :int and index.children.first < 0
77
- node.updated nil, [source, :[], i.(index)]
95
+ if index.type == :regexp
96
+ s(:send, s(:send, target, :match, index), :[],
97
+ args[1] || s(:int, 0))
98
+
99
+ elsif node.children.length != 3
100
+ super
101
+
102
+ elsif index.type == :int and index.children.first < 0
103
+ node.updated nil, [target, :[], i.(index)]
78
104
 
79
105
  elsif index.type == :erange
80
106
  start, finish = index.children
81
- node.updated nil, [source, :slice, i.(start), i.(finish)]
107
+ node.updated nil, [target, :slice, i.(start), i.(finish)]
82
108
 
83
109
  elsif index.type == :irange
84
110
  start, finish = index.children
85
111
  start = i.(start)
86
112
  if finish.type == :int
87
113
  if finish.children.first == -1
88
- finish = s(:attr, source, :length)
114
+ finish = s(:attr, target, :length)
89
115
  else
90
116
  finish = i.(s(:int, finish.children.first+1))
91
117
  end
92
118
  else
93
119
  finish = s(:send, finish, :+, s(:int, 1))
94
120
  end
95
- node.updated nil, [source, :slice, start, finish]
121
+ node.updated nil, [target, :slice, start, finish]
96
122
 
97
123
  else
98
124
  super
@@ -113,11 +139,16 @@ module Ruby2JS
113
139
  block = process s(:block, s(:send, nil, :proc), *node.children[1..-1])
114
140
  call.updated nil, [*call.children[0..1], block, *call.children[2..-1]]
115
141
 
116
- elsif [:any?].include? call.children[1] and call.children.length == 2
142
+ elsif [:sub, :gsub].include? call.children[1]
143
+ return super if call.children.first == nil
144
+ block = s(:block, s(:send, nil, :proc), *node.children[1..-1])
145
+ process call.updated(nil, [*call.children, block])
146
+
147
+ elsif call.children[1] == :any? and call.children.length == 2
117
148
  call = call.updated nil, [call.children.first, :some]
118
149
  node.updated nil, [call, *node.children[1..-1]]
119
150
 
120
- elsif [:all?].include? call.children[1] and call.children.length == 2
151
+ elsif call.children[1] == :all? and call.children.length == 2
121
152
  call = call.updated nil, [call.children.first, :every]
122
153
  node.updated nil, [call, *node.children[1..-1]]
123
154
 
@@ -119,17 +119,17 @@ module Ruby2JS
119
119
  if node.children[1] == :~ and node.children[0].children[1] == :~
120
120
  # consecutive tildes
121
121
  if node.children[0].children[0].children[1] == :~
122
- result = process(node.children[0].children[0].children[0])
122
+ result = node.children[0].children[0].children[0]
123
123
  else
124
- result = s(:send, process(node.children[0].children[0]), :~)
124
+ result = s(:attr, node.children[0].children[0], :~)
125
125
  end
126
- s(:send, s(:send, result, :~), :~)
126
+ s(:attr, s(:attr, process(result), :~), :~)
127
127
  else
128
128
  # possible getter/setter
129
129
  method = node.children[1]
130
130
  method = method.to_s.chomp('=') if method =~ /=$/
131
131
  rewrite = [rewrite_tilda[node.children[0]],
132
- method, *process_all(node.children[2..-1])]
132
+ method, *node.children[2..-1]]
133
133
  if props.include? node.children[1]
134
134
  node.updated nil, rewrite
135
135
  elsif domprops.include? method.to_s
@@ -142,17 +142,17 @@ module Ruby2JS
142
142
  elsif node.type == :block
143
143
  # method call with a block parameter
144
144
  node.updated nil, [rewrite_tilda[node.children[0]],
145
- *process_all(node.children[1..-1])]
145
+ *node.children[1..-1]]
146
146
  elsif node.type == :array
147
147
  # innermost expression is an array
148
- s(:send, nil, '$', *process(node))
148
+ s(:send, nil, '$', *node)
149
149
  else
150
150
  # innermost expression is a scalar
151
- s(:send, nil, '$', process(node))
151
+ s(:send, nil, '$', node)
152
152
  end
153
153
  end
154
154
 
155
- rewrite_tilda[node].children[0]
155
+ process rewrite_tilda[node].children[0]
156
156
  else
157
157
  super
158
158
  end
@@ -1,7 +1,7 @@
1
1
  module Ruby2JS
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
- MINOR = 2
4
+ MINOR = 3
5
5
  TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
data/ruby2js.gemspec CHANGED
@@ -2,14 +2,14 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "ruby2js"
5
- s.version = "1.2.0"
5
+ s.version = "1.3.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 = "2013-12-18"
9
+ s.date = "2014-01-07"
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
- s.files = ["ruby2js.gemspec", "README.md", "lib/ruby2js", "lib/ruby2js/rails.rb", "lib/ruby2js/version.rb", "lib/ruby2js/converter", "lib/ruby2js/converter/orasgn.rb", "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/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/andasgn.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/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"]
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/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/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"]
13
13
  s.homepage = "http://github.com/rubys/ruby2js"
14
14
  s.licenses = ["MIT"]
15
15
  s.require_paths = ["lib"]
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.2.0
4
+ version: 1.3.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: 2013-12-18 00:00:00.000000000 Z
11
+ date: 2014-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -35,7 +35,6 @@ files:
35
35
  - README.md
36
36
  - lib/ruby2js/rails.rb
37
37
  - lib/ruby2js/version.rb
38
- - lib/ruby2js/converter/orasgn.rb
39
38
  - lib/ruby2js/converter/kwbegin.rb
40
39
  - lib/ruby2js/converter/const.rb
41
40
  - lib/ruby2js/converter/return.rb
@@ -78,7 +77,6 @@ files:
78
77
  - lib/ruby2js/converter/ivasgn.rb
79
78
  - lib/ruby2js/converter/casgn.rb
80
79
  - lib/ruby2js/converter/self.rb
81
- - lib/ruby2js/converter/andasgn.rb
82
80
  - lib/ruby2js/converter/begin.rb
83
81
  - lib/ruby2js/converter/dstr.rb
84
82
  - lib/ruby2js/converter/class.rb
@@ -1,12 +0,0 @@
1
- module Ruby2JS
2
- class Converter
3
-
4
- # (and-asgn
5
- # (lvasgn :a
6
- # (int 1))
7
-
8
- handle :and_asgn do |var, value|
9
- "#{ parse var } = #{parse var} && #{ parse value }"
10
- end
11
- end
12
- end
@@ -1,12 +0,0 @@
1
- module Ruby2JS
2
- class Converter
3
-
4
- # (or-asgn
5
- # (lvasgn :a
6
- # (int 1))
7
-
8
- handle :or_asgn do |var, value|
9
- "#{ parse var } = #{parse var} || #{ parse value }"
10
- end
11
- end
12
- end