ruby2js 1.12.1 → 1.12.2
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.
- data/lib/ruby2js/converter/arg.rb +7 -0
- data/lib/ruby2js/converter/args.rb +1 -1
- data/lib/ruby2js/converter/def.rb +6 -1
- data/lib/ruby2js/converter/hash.rb +5 -4
- data/lib/ruby2js/converter/send.rb +41 -30
- data/lib/ruby2js/filter/react.rb +4 -3
- data/lib/ruby2js/version.rb +1 -1
- data/ruby2js.gemspec +2 -2
- metadata +2 -2
@@ -10,5 +10,12 @@ module Ruby2JS
|
|
10
10
|
raise NotImplementedError, "argument #{ unknown.inspect }" if unknown
|
11
11
|
arg
|
12
12
|
end
|
13
|
+
|
14
|
+
# (shadowarg :a)
|
15
|
+
|
16
|
+
handle :shadowarg do |arg, unknown=nil|
|
17
|
+
raise NotImplementedError, "argument #{ unknown.inspect }" if unknown
|
18
|
+
nil
|
19
|
+
end
|
13
20
|
end
|
14
21
|
end
|
@@ -79,7 +79,12 @@ module Ruby2JS
|
|
79
79
|
s(:lvasgn, argname, value), nil)
|
80
80
|
body = s(:begin, default, *body.children)
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
|
+
if arg.type == :shadowarg
|
84
|
+
vars.delete(arg.children.first)
|
85
|
+
else
|
86
|
+
vars[arg.children.first] = true
|
87
|
+
end
|
83
88
|
end
|
84
89
|
end
|
85
90
|
|
@@ -11,10 +11,11 @@ module Ruby2JS
|
|
11
11
|
raise NotImplementedError, "kwsplat" if node.type == :kwsplat
|
12
12
|
|
13
13
|
begin
|
14
|
-
|
15
|
-
@block_this, @block_depth = false, 0
|
16
|
-
|
14
|
+
block_depth = @block_depth
|
17
15
|
left, right = node.children
|
16
|
+
|
17
|
+
@block_depth = 0 if Hash === right or right.type == :block
|
18
|
+
|
18
19
|
if left.type == :prop
|
19
20
|
result = []
|
20
21
|
if right[:get]
|
@@ -33,7 +34,7 @@ module Ruby2JS
|
|
33
34
|
end
|
34
35
|
|
35
36
|
ensure
|
36
|
-
@
|
37
|
+
@block_depth = block_depth
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
@@ -85,43 +85,54 @@ module Ruby2JS
|
|
85
85
|
elsif method =~ /=$/
|
86
86
|
"#{ parse receiver }#{ '.' if receiver }#{ method.to_s.sub(/=$/, ' =') } #{ parse args.first }"
|
87
87
|
|
88
|
-
elsif method == :new
|
89
|
-
|
90
|
-
|
91
|
-
receiver
|
92
|
-
|
93
|
-
|
94
|
-
# allow a RegExp to be constructed from another RegExp
|
95
|
-
if receiver == s(:const, nil, :RegExp)
|
96
|
-
if args.first.type == :regexp
|
97
|
-
opts = ''
|
98
|
-
if args.first.children.last.children.length > 0
|
99
|
-
opts = args.first.children.last.children.join
|
100
|
-
end
|
101
|
-
|
102
|
-
if args.length > 1
|
103
|
-
opts += args.last.children.last
|
104
|
-
end
|
88
|
+
elsif method == :new
|
89
|
+
if receiver
|
90
|
+
# map Ruby's "Regexp" to JavaScript's "Regexp"
|
91
|
+
if receiver == s(:const, nil, :Regexp)
|
92
|
+
receiver = s(:const, nil, :RegExp)
|
93
|
+
end
|
105
94
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
if args.length == 2 and args[1].type == :str
|
110
|
-
opts = args[1].children[0]
|
111
|
-
else
|
95
|
+
# allow a RegExp to be constructed from another RegExp
|
96
|
+
if receiver == s(:const, nil, :RegExp)
|
97
|
+
if args.first.type == :regexp
|
112
98
|
opts = ''
|
99
|
+
if args.first.children.last.children.length > 0
|
100
|
+
opts = args.first.children.last.children.join
|
101
|
+
end
|
102
|
+
|
103
|
+
if args.length > 1
|
104
|
+
opts += args.last.children.last
|
105
|
+
end
|
106
|
+
|
107
|
+
return parse s(:regexp, *args.first.children[0...-1],
|
108
|
+
s(:regopt, *opts.split('').map(&:to_sym)))
|
109
|
+
elsif args.first.type == :str
|
110
|
+
if args.length == 2 and args[1].type == :str
|
111
|
+
opts = args[1].children[0]
|
112
|
+
else
|
113
|
+
opts = ''
|
114
|
+
end
|
115
|
+
return parse s(:regexp, args.first,
|
116
|
+
s(:regopt, *opts.each_char.map {|c| c}))
|
113
117
|
end
|
114
|
-
return parse s(:regexp, args.first,
|
115
|
-
s(:regopt, *opts.each_char.map {|c| c}))
|
116
118
|
end
|
117
|
-
end
|
118
119
|
|
119
|
-
|
120
|
+
args = args.map {|a| parse a}.join(', ')
|
120
121
|
|
121
|
-
|
122
|
-
|
122
|
+
if ast.is_method?
|
123
|
+
"new #{ parse receiver }(#{ args })"
|
124
|
+
else
|
125
|
+
"new #{ parse receiver }"
|
126
|
+
end
|
127
|
+
elsif args.length == 1 and args.first.type == :send
|
128
|
+
# accommodation for JavaScript like new syntax w/argument list
|
129
|
+
parse s(:send, s(:const, nil, args.first.children[1]), :new,
|
130
|
+
*args.first.children[2..-1]), @state
|
131
|
+
elsif args.length == 1 and args.first.type == :const
|
132
|
+
# accommodation for JavaScript like new syntax w/o argument list
|
133
|
+
parse s(:attr, args.first, :new), @state
|
123
134
|
else
|
124
|
-
"
|
135
|
+
raise NotImplementedError, "use of JavaScript keyword new"
|
125
136
|
end
|
126
137
|
|
127
138
|
elsif method == :raise and receiver == nil
|
data/lib/ruby2js/filter/react.rb
CHANGED
@@ -186,7 +186,7 @@ module Ruby2JS
|
|
186
186
|
|
187
187
|
begin
|
188
188
|
if simple
|
189
|
-
# in the normal case,
|
189
|
+
# in the normal case, process each argument
|
190
190
|
reactApply, @reactApply = @reactApply, false
|
191
191
|
params += args.map {|arg| process(arg)}
|
192
192
|
else
|
@@ -196,13 +196,14 @@ module Ruby2JS
|
|
196
196
|
# will look something like the following:
|
197
197
|
#
|
198
198
|
# React.createElement(*proc {
|
199
|
-
# $_ = ['tag', hash]
|
199
|
+
# var $_ = ['tag', hash]
|
200
200
|
# $_.push(React.createElement(...))
|
201
201
|
# }())
|
202
202
|
#
|
203
203
|
# Base Ruby2JS processing will convert the 'splat' to 'apply'
|
204
204
|
params = [s(:splat, s(:send, s(:block, s(:send, nil, :proc),
|
205
|
-
s(:args
|
205
|
+
s(:args, s(:shadowarg, :$_)), s(:begin,
|
206
|
+
s(:lvasgn, :$_, s(:array, *params)),
|
206
207
|
*args.map {|arg| process arg},
|
207
208
|
s(:return, s(:lvar, :$_)))), :[]))]
|
208
209
|
end
|
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.12.
|
5
|
+
s.version = "1.12.2"
|
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 = "2015-01-
|
9
|
+
s.date = "2015-01-25"
|
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/converter.rb", "lib/ruby2js/version.rb", "lib/ruby2js/filter", "lib/ruby2js/filter/jquery.rb", "lib/ruby2js/filter/return.rb", "lib/ruby2js/filter/underscore.rb", "lib/ruby2js/filter/angularrb.rb", "lib/ruby2js/filter/minitest-jasmine.rb", "lib/ruby2js/filter/camelCase.rb", "lib/ruby2js/filter/strict.rb", "lib/ruby2js/filter/functions.rb", "lib/ruby2js/filter/angular-resource.rb", "lib/ruby2js/filter/react.rb", "lib/ruby2js/filter/angular-route.rb", "lib/ruby2js/sinatra.rb", "lib/ruby2js/rails.rb", "lib/ruby2js/cgi.rb", "lib/ruby2js/converter", "lib/ruby2js/converter/self.rb", "lib/ruby2js/converter/arg.rb", "lib/ruby2js/converter/dstr.rb", "lib/ruby2js/converter/xstr.rb", "lib/ruby2js/converter/sym.rb", "lib/ruby2js/converter/return.rb", "lib/ruby2js/converter/break.rb", "lib/ruby2js/converter/for.rb", "lib/ruby2js/converter/defined.rb", "lib/ruby2js/converter/cvasgn.rb", "lib/ruby2js/converter/whilepost.rb", "lib/ruby2js/converter/logical.rb", "lib/ruby2js/converter/args.rb", "lib/ruby2js/converter/def.rb", "lib/ruby2js/converter/prototype.rb", "lib/ruby2js/converter/class.rb", "lib/ruby2js/converter/nthref.rb", "lib/ruby2js/converter/opasgn.rb", "lib/ruby2js/converter/module.rb", "lib/ruby2js/converter/kwbegin.rb", "lib/ruby2js/converter/send.rb", "lib/ruby2js/converter/boolean.rb", "lib/ruby2js/converter/masgn.rb", "lib/ruby2js/converter/hash.rb", "lib/ruby2js/converter/cvar.rb", "lib/ruby2js/converter/ivasgn.rb", "lib/ruby2js/converter/case.rb", "lib/ruby2js/converter/const.rb", "lib/ruby2js/converter/vasgn.rb", "lib/ruby2js/converter/untilpost.rb", "lib/ruby2js/converter/begin.rb", "lib/ruby2js/converter/ivar.rb", "lib/ruby2js/converter/while.rb", "lib/ruby2js/converter/next.rb", "lib/ruby2js/converter/nil.rb", "lib/ruby2js/converter/blockpass.rb", "lib/ruby2js/converter/super.rb", "lib/ruby2js/converter/defs.rb", "lib/ruby2js/converter/array.rb", "lib/ruby2js/converter/block.rb", "lib/ruby2js/converter/if.rb", "lib/ruby2js/converter/until.rb", "lib/ruby2js/converter/regexp.rb", "lib/ruby2js/converter/casgn.rb", "lib/ruby2js/converter/undef.rb", "lib/ruby2js/converter/literal.rb", "lib/ruby2js/converter/var.rb", "lib/ruby2js.rb"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby2js
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.12.
|
4
|
+
version: 1.12.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-01-
|
12
|
+
date: 2015-01-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: parser
|