ruby2js 2.1.24 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +91 -50
  3. data/lib/ruby2js/converter/args.rb +10 -0
  4. data/lib/ruby2js/converter/block.rb +1 -1
  5. data/lib/ruby2js/converter/case.rb +1 -1
  6. data/lib/ruby2js/converter/casgn.rb +6 -1
  7. data/lib/ruby2js/converter/class.rb +7 -2
  8. data/lib/ruby2js/converter/class2.rb +167 -0
  9. data/lib/ruby2js/converter/def.rb +54 -6
  10. data/lib/ruby2js/converter/defs.rb +11 -5
  11. data/lib/ruby2js/converter/dstr.rb +26 -0
  12. data/lib/ruby2js/converter/for.rb +3 -3
  13. data/lib/ruby2js/converter/hash.rb +31 -6
  14. data/lib/ruby2js/converter/if.rb +1 -1
  15. data/lib/ruby2js/converter/ivasgn.rb +5 -2
  16. data/lib/ruby2js/converter/masgn.rb +41 -4
  17. data/lib/ruby2js/converter/send.rb +71 -10
  18. data/lib/ruby2js/converter/super.rb +21 -8
  19. data/lib/ruby2js/converter/vasgn.rb +5 -1
  20. data/lib/ruby2js/converter/while.rb +13 -0
  21. data/lib/ruby2js/converter.rb +32 -5
  22. data/lib/ruby2js/es2015/strict.rb +3 -0
  23. data/lib/ruby2js/es2015.rb +5 -0
  24. data/lib/ruby2js/es2016/strict.rb +3 -0
  25. data/lib/ruby2js/es2016.rb +5 -0
  26. data/lib/ruby2js/es2017/strict.rb +3 -0
  27. data/lib/ruby2js/es2017.rb +5 -0
  28. data/lib/ruby2js/execjs.rb +1 -1
  29. data/lib/ruby2js/filter/camelCase.rb +1 -1
  30. data/lib/ruby2js/filter/functions.rb +49 -2
  31. data/lib/ruby2js/filter/vue.rb +66 -45
  32. data/lib/ruby2js/strict.rb +3 -0
  33. data/lib/ruby2js/version.rb +3 -3
  34. data/lib/ruby2js.rb +41 -0
  35. data/ruby2js.gemspec +3 -1
  36. metadata +10 -6
  37. data/lib/ruby2js/filter/angular-resource.rb +0 -25
  38. data/lib/ruby2js/filter/angular-route.rb +0 -44
  39. data/lib/ruby2js/filter/angularrb.rb +0 -604
  40. data/lib/ruby2js/filter/strict.rb +0 -20
@@ -41,7 +41,7 @@ module Ruby2JS
41
41
  # before:
42
42
  # (class (const nil :Foo) (const nil :Vue) nil)
43
43
  # after:
44
- # (casgn nil :Foo, (send nil, :Vue, :component, (:str, "foo"),
44
+ # (casgn nil :Foo, (send nil, :Vue, :component, (:str, "foo"),
45
45
  # s(:hash)))
46
46
  def on_class(node)
47
47
  cname, inheritance, *body = node.children
@@ -69,11 +69,12 @@ module Ruby2JS
69
69
  computed = []
70
70
  setters = []
71
71
  options = []
72
+ el = nil
72
73
  mixins = []
73
74
 
74
75
  # insert constructor if none present
75
76
  if inheritance == s(:const, nil, :Vue)
76
- unless body.any? {|statement|
77
+ unless body.any? {|statement|
77
78
  statement.type == :def and statement.children.first ==:initialize}
78
79
  then
79
80
  body = body.dup
@@ -102,12 +103,12 @@ module Ruby2JS
102
103
  end
103
104
  end
104
105
 
105
- elsif
106
+ elsif
106
107
  statement.type == :send and statement.children[0] == cname and
107
108
  statement.children[1].to_s.end_with? '='
108
109
  then
109
110
  @vue_reactive << statement.updated(:send, [
110
- s(:attr, s(:const, nil, :Vue), :util), :defineReactive, cname,
111
+ s(:attr, s(:const, nil, :Vue), :util), :defineReactive, cname,
111
112
  s(:sym, statement.children[1].to_s[0..-2]),
112
113
  process(statement.children[2])])
113
114
 
@@ -120,15 +121,21 @@ module Ruby2JS
120
121
  # named values (template, props, options, mixin[s])
121
122
  if statement.type == :send and statement.children.first == nil
122
123
  if [:template, :props].include? statement.children[1]
123
- hash << s(:pair, s(:sym, statement.children[1]),
124
+ hash << s(:pair, s(:sym, statement.children[1]),
124
125
  statement.children[2])
125
126
 
126
- elsif
127
+ elsif
127
128
  statement.children[1] == :options and
128
129
  statement.children[2].type == :hash
129
130
  then
130
131
  options += statement.children[2].children
131
132
 
133
+ elsif
134
+ statement.children[1] == :el and
135
+ statement.children[2].type == :str
136
+ then
137
+ el = statement.children[2]
138
+
132
139
  elsif statement.children[1] == :mixin or
133
140
  statement.children[1] == :mixins
134
141
  then
@@ -182,7 +189,7 @@ module Ruby2JS
182
189
  uninitialized = @vue_inventory[:ivar].dup
183
190
 
184
191
  block.children.each do |child|
185
- if child.type == :ivasgn
192
+ if child.type == :ivasgn
186
193
  uninitialized.delete child.children.first
187
194
  end
188
195
  end
@@ -196,15 +203,15 @@ module Ruby2JS
196
203
  end
197
204
 
198
205
  pairs += uninitialized.map do |symbol|
199
- s(:pair, s(:sym, symbol.to_s[1..-1]),
206
+ s(:pair, s(:sym, symbol.to_s[1..-1]),
200
207
  s(:attr, nil, :undefined))
201
208
  end
202
209
 
203
210
  block = s(:return, s(:hash, *pairs))
204
211
  else
205
212
  # general case: build up a hash incrementally
206
- block = s(:begin, s(:gvasgn, :$_,
207
- s(:hash, *uninitialized.map {|sym|
213
+ block = s(:begin, s(:gvasgn, :$_,
214
+ s(:hash, *uninitialized.map {|sym|
208
215
  s(:pair, s(:sym, sym.to_s[1..-1]),
209
216
  s(:attr, nil, :undefined))})),
210
217
  block, s(:return, s(:gvar, :$_)))
@@ -224,7 +231,7 @@ module Ruby2JS
224
231
  @comments[pair] = @comments[statement]
225
232
  if VUE_LIFECYCLE.include? method
226
233
  hash << pair
227
- elsif not statement.is_method?
234
+ elsif not statement.is_method?
228
235
  computed << pair
229
236
  elsif method.to_s.end_with? '='
230
237
  setters << pair
@@ -244,7 +251,7 @@ module Ruby2JS
244
251
  # add properties before that
245
252
  unless hash.any? {|pair| pair.children[0].children[0] == :props}
246
253
  unless @vue_inventory[:cvar].empty?
247
- hash.unshift s(:pair, s(:sym, :props), s(:array,
254
+ hash.unshift s(:pair, s(:sym, :props), s(:array,
248
255
  *@vue_inventory[:cvar].map {|sym| s(:str, sym.to_s[2..-1])}))
249
256
  end
250
257
  end
@@ -254,6 +261,9 @@ module Ruby2JS
254
261
  hash.unshift s(:pair, s(:sym, :mixins), s(:array, *mixins))
255
262
  end
256
263
 
264
+ # add el as first, if app has
265
+ hash.unshift(s(:pair, s(:sym, :el), el)) if el
266
+
257
267
  # append methods to hash
258
268
  unless methods.empty?
259
269
  hash << s(:pair, s(:sym, :methods), s(:hash, *methods))
@@ -263,7 +273,7 @@ module Ruby2JS
263
273
 
264
274
  # append setters to computed list
265
275
  setters.each do |setter|
266
- index = computed.find_index do |pair|
276
+ index = computed.find_index do |pair|
267
277
  pair.children[0].children[0].to_s ==
268
278
  setter.children[0].children[0]
269
279
  end
@@ -291,17 +301,28 @@ module Ruby2JS
291
301
  camel = "#{camel}-" if camel =~ /^[a-z]*$/
292
302
 
293
303
  if inheritance == s(:const, nil, :Vue)
294
- # build component
295
- defn = s(:casgn, nil, cname,
296
- s(:send, s(:const, nil, :Vue), :component,
297
- s(:str, camel), s(:hash, *hash)))
304
+ hash_keys = hash.map do |pair|
305
+ pair.children[0].children[0].to_s
306
+ end
307
+
308
+ if hash_keys.any? {|key| %w(render template).include? key}
309
+ # build component
310
+ defn = s(:casgn, nil, cname,
311
+ s(:send, s(:const, nil, :Vue), :component,
312
+ s(:str, camel), s(:hash, *hash)))
313
+ else
314
+ # build app
315
+ defn = s(:casgn, nil, cname,
316
+ s(:send, s(:const, nil, :Vue), :new,
317
+ s(:hash, *hash)))
318
+ end
298
319
  else
299
320
  # build mixin
300
321
  defn = s(:casgn, nil, cname, s(:hash, *hash))
301
322
  end
302
323
 
303
324
  # append class methods (if any)
304
- class_methods = body.select do |statement|
325
+ class_methods = body.select do |statement|
305
326
  statement.type == :defs and statement.children[0] == s(:self)
306
327
  end
307
328
 
@@ -316,7 +337,7 @@ module Ruby2JS
316
337
  s(:block, s(:send , nil, :proc), method.children[2],
317
338
  *process_all(method.children[3..-1])))
318
339
  else
319
- getter = class_methods.find do |other_method|
340
+ getter = class_methods.find do |other_method|
320
341
  "#{other_method.children[1]}=" == method.children[1].to_s
321
342
  end
322
343
 
@@ -335,7 +356,7 @@ module Ruby2JS
335
356
  else
336
357
  # setter only
337
358
  s(:send, s(:const, nil, :Object), :defineProperty,
338
- s(:const, nil, cname),
359
+ s(:const, nil, cname),
339
360
  s(:str, method.children[1].to_s[0..-2]),
340
361
  s(:hash, s(:pair, s(:sym, :enumerable), s(:true)),
341
362
  s(:pair, s(:sym, :configurable), s(:true)),
@@ -346,7 +367,7 @@ module Ruby2JS
346
367
  end
347
368
 
348
369
  elsif
349
- class_methods.any? do |other_method|
370
+ class_methods.any? do |other_method|
350
371
  other_method.children[1].to_s == "#{method.children[1]}="
351
372
  end
352
373
  then
@@ -359,7 +380,7 @@ module Ruby2JS
359
380
  s(:hash, s(:pair, s(:sym, :enumerable), s(:true)),
360
381
  s(:pair, s(:sym, :configurable), s(:true)),
361
382
  s(:pair, s(:sym, :get), s(:block, s(:send, nil, :proc),
362
- method.children[2],
383
+ method.children[2],
363
384
  s(:autoreturn, *process_all(method.children[3..-1]))))))
364
385
  end
365
386
 
@@ -492,11 +513,11 @@ module Ruby2JS
492
513
  left = expr.children[1]
493
514
  right = expr.children[2] || s(:nil)
494
515
 
495
- expr = expr.updated(nil,
516
+ expr = expr.updated(nil,
496
517
  [expr.children[0], left, right])
497
518
  end
498
519
 
499
- hash[:class] = s(:array,
520
+ hash[:class] = s(:array,
500
521
  *values.join(' ').split(' ').map {|str| s(:str, str)},
501
522
  expr)
502
523
  end
@@ -506,7 +527,7 @@ module Ruby2JS
506
527
  hash[:class] = s(:array, expr)
507
528
  end
508
529
  else
509
- hash[:class] = s(:array,
530
+ hash[:class] = s(:array,
510
531
  *values.join(' ').split(' ').map {|str| s(:str, str)})
511
532
  end
512
533
  end
@@ -619,15 +640,15 @@ module Ruby2JS
619
640
  # test if value is assignable
620
641
  test = value
621
642
  loop do
622
- break unless test and test.type == :send
643
+ break unless test and test.type == :send
623
644
  break unless (test.children.length == 2 and
624
645
  test.children.last.instance_of? Symbol and
625
646
  not [:not, :!, :*, :+, :-].include? test.children.last) or
626
647
  test.children[1] == :[]
627
- test = test.children.first
648
+ test = test.children.first
628
649
  end
629
650
 
630
- if value and value.type != :cvar and (not test or
651
+ if value and value.type != :cvar and (not test or
631
652
  test.is_a? Symbol or [:ivar, :cvar, :self].include? test.type)
632
653
  then
633
654
  hash[:domProps][attr] ||= value
@@ -672,9 +693,9 @@ module Ruby2JS
672
693
 
673
694
  # put attributes up front
674
695
  unless hash.empty?
675
- pairs = hash.to_a.map do |k1, v1|
696
+ pairs = hash.to_a.map do |k1, v1|
676
697
  next if Hash === v1 and v1.empty?
677
- s(:pair, s(:str, k1.to_s),
698
+ s(:pair, s(:str, k1.to_s),
678
699
  if Parser::AST::Node === v1
679
700
  v1
680
701
  else
@@ -716,8 +737,8 @@ module Ruby2JS
716
737
  # }())
717
738
  #
718
739
  @vue_apply = true
719
-
720
- element = node.updated :send, [nil, @vue_h,
740
+
741
+ element = node.updated :send, [nil, @vue_h,
721
742
  *process_all(args),
722
743
  s(:send, s(:block, s(:send, nil, :proc),
723
744
  s(:args, s(:shadowarg, :$_)), s(:begin,
@@ -768,7 +789,7 @@ module Ruby2JS
768
789
  element = node.updated nil, [*@vue_h,
769
790
  *process_all(node.children[2..-1])]
770
791
  else
771
- element = node.updated nil, [nil, @vue_h,
792
+ element = node.updated nil, [nil, @vue_h,
772
793
  *process_all(node.children[2..-1])]
773
794
  end
774
795
 
@@ -784,7 +805,7 @@ module Ruby2JS
784
805
  node.children[0] == s(:const, nil, :Vue)
785
806
  then
786
807
  # vm methods
787
- node.updated nil, [s(:self), "$#{node.children[1]}",
808
+ node.updated nil, [s(:self), "$#{node.children[1]}",
788
809
  *process_all(node.children[2..-1])]
789
810
 
790
811
  elsif node.children[0] and node.children[0].type == :send
@@ -887,12 +908,12 @@ module Ruby2JS
887
908
  #
888
909
  begin
889
910
  vue_apply, @vue_apply = @vue_apply, true
890
-
891
- element = node.updated :send, [nil, @vue_h,
911
+
912
+ element = node.updated :send, [nil, @vue_h,
892
913
  *child.children[2..-1],
893
914
  s(:send, s(:block, s(:send, nil, :proc),
894
915
  s(:args, s(:shadowarg, :$_)), s(:begin,
895
- s(:lvasgn, :$_, s(:array)),
916
+ s(:lvasgn, :$_, s(:array)),
896
917
  process(node.children[2]),
897
918
  s(:return, s(:lvar, :$_)))), :[])]
898
919
  ensure
@@ -965,11 +986,11 @@ module Ruby2JS
965
986
 
966
987
  # expand @= to @vue_self.=
967
988
  def on_ivasgn(node)
968
- return super unless @vue_self
989
+ return super unless @vue_self
969
990
  if node.children.length == 1
970
991
  s(:attr, @vue_self, "#{node.children[0].to_s[1..-1]}")
971
992
  else
972
- s(:send, @vue_self, "#{node.children[0].to_s[1..-1]}=",
993
+ s(:send, @vue_self, "#{node.children[0].to_s[1..-1]}=",
973
994
  process(node.children[1]))
974
995
  end
975
996
  end
@@ -979,15 +1000,15 @@ module Ruby2JS
979
1000
  def on_op_asgn(node)
980
1001
  return super unless @vue_self
981
1002
  if node.children.first.type == :ivasgn
982
- node.updated nil, [s(:attr, @vue_self,
1003
+ node.updated nil, [s(:attr, @vue_self,
983
1004
  node.children[0].children[0].to_s[1..-1]),
984
1005
  node.children[1], process(node.children[2])]
985
1006
 
986
- elsif
1007
+ elsif
987
1008
  node.children.first.type == :lvasgn and
988
1009
  @vue_props.include? node.children[0].children[0]
989
1010
  then
990
- node.updated nil, [s(:attr, s(:self),
1011
+ node.updated nil, [s(:attr, s(:self),
991
1012
  node.children[0].children[0]),
992
1013
  node.children[1], process(node.children[2])]
993
1014
 
@@ -1007,7 +1028,7 @@ module Ruby2JS
1007
1028
  def on_pair(node)
1008
1029
  key, value = node.children
1009
1030
  return super unless Parser::AST::Node === value
1010
- return super unless value.type == :send and
1031
+ return super unless value.type == :send and
1011
1032
  value.children.length == 2 and
1012
1033
  value.children[0] == nil and
1013
1034
  @vue_methods.include? value.children[1]
@@ -1022,11 +1043,11 @@ module Ruby2JS
1022
1043
  if Parser::AST::Node === node
1023
1044
  if node.type == :send
1024
1045
  # wunderbar style calls
1025
- return false if node.children[0] == nil and
1046
+ return false if node.children[0] == nil and
1026
1047
  node.children[1].to_s.start_with? '_'
1027
1048
 
1028
1049
  # Vue.createElement calls
1029
- return false if node.children[0] == s(:const, nil, :Vue) and
1050
+ return false if node.children[0] == s(:const, nil, :Vue) and
1030
1051
  node.children[1] == :createElement
1031
1052
  end
1032
1053
 
@@ -0,0 +1,3 @@
1
+ require 'ruby2js'
2
+
3
+ Ruby2JS.strict_default = true
@@ -1,8 +1,8 @@
1
1
  module Ruby2JS
2
2
  module VERSION #:nodoc:
3
- MAJOR = 2
4
- MINOR = 1
5
- TINY = 24
3
+ MAJOR = 3
4
+ MINOR = 0
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/ruby2js.rb CHANGED
@@ -14,6 +14,25 @@ module Ruby2JS
14
14
  class SyntaxError < RuntimeError
15
15
  end
16
16
 
17
+ @@eslevel_default = 2009 # ecmascript 5
18
+ @@strict_default = false
19
+
20
+ def self.eslevel_default
21
+ @@eslevel_default
22
+ end
23
+
24
+ def self.eslevel_default=(level)
25
+ @@eslevel_default = level
26
+ end
27
+
28
+ def self.strict_default
29
+ @@strict_default
30
+ end
31
+
32
+ def self.strict_default=(level)
33
+ @@strict_default = level
34
+ end
35
+
17
36
  module Filter
18
37
  DEFAULTS = []
19
38
 
@@ -40,6 +59,18 @@ module Ruby2JS
40
59
  @options = options
41
60
  end
42
61
 
62
+ def es2015
63
+ @options[:eslevel] >= 2015
64
+ end
65
+
66
+ def es2016
67
+ @options[:eslevel] >= 2016
68
+ end
69
+
70
+ def es2017
71
+ @options[:eslevel] >= 2017
72
+ end
73
+
43
74
  def process(node)
44
75
  ast, @ast = @ast, node
45
76
  replacement = super
@@ -54,11 +85,16 @@ module Ruby2JS
54
85
  end
55
86
 
56
87
  # handle all of the 'invented' ast types
88
+ def on_async(node); on_def(node); end
89
+ def on_asyncs(node); on_defs(node); end
57
90
  def on_attr(node); on_send(node); end
58
91
  def on_autoreturn(node); on_return(node); end
92
+ def on_await(node); on_send(node); end
59
93
  def on_call(node); on_send(node); end
60
94
  def on_constructor(node); on_def(node); end
61
95
  def on_defp(node); on_defs(node); end
96
+ def on_for_of(node); on_for(node); end
97
+ def on_in?(node); on_send(node); end
62
98
  def on_method(node); on_send(node); end
63
99
  def on_prop(node); on_array(node); end
64
100
  def on_prototype(node); on_begin(node); end
@@ -88,6 +124,9 @@ module Ruby2JS
88
124
  end
89
125
 
90
126
  def self.convert(source, options={})
127
+ options[:eslevel] ||= @@eslevel_default
128
+ options[:strict] = @@strict_default if options[:strict] == nil
129
+
91
130
  if Proc === source
92
131
  file,line = source.source_location
93
132
  source = File.read(file.dup.untaint).untaint
@@ -119,6 +158,8 @@ module Ruby2JS
119
158
 
120
159
  ruby2js.binding = options[:binding]
121
160
  ruby2js.ivars = options[:ivars]
161
+ ruby2js.eslevel = options[:eslevel]
162
+ ruby2js.strict = options[:strict]
122
163
  if ruby2js.binding and not ruby2js.ivars
123
164
  ruby2js.ivars = ruby2js.binding.eval \
124
165
  'Hash[instance_variables.map {|var| [var, instance_variable_get(var)]}]'
data/ruby2js.gemspec CHANGED
@@ -1,6 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  lib = File.expand_path('../lib/', __FILE__)
3
3
  $:.unshift lib unless $:.include?(lib)
4
+ require 'ruby2js/version'
4
5
 
5
6
  Gem::Specification.new do |s|
6
7
  s.name = "ruby2js".freeze
@@ -12,7 +13,8 @@ Gem::Specification.new do |s|
12
13
  s.date = "2017-11-13"
13
14
  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".freeze
14
15
  s.email = "rubys@intertwingly.net".freeze
15
- s.files = ["README.md".freeze, "lib/ruby2js".freeze, "lib/ruby2js.rb".freeze, "lib/ruby2js/cgi.rb".freeze, "lib/ruby2js/converter".freeze, "lib/ruby2js/converter.rb".freeze, "lib/ruby2js/converter/arg.rb".freeze, "lib/ruby2js/converter/args.rb".freeze, "lib/ruby2js/converter/array.rb".freeze, "lib/ruby2js/converter/begin.rb".freeze, "lib/ruby2js/converter/block.rb".freeze, "lib/ruby2js/converter/blockpass.rb".freeze, "lib/ruby2js/converter/boolean.rb".freeze, "lib/ruby2js/converter/break.rb".freeze, "lib/ruby2js/converter/case.rb".freeze, "lib/ruby2js/converter/casgn.rb".freeze, "lib/ruby2js/converter/class.rb".freeze, "lib/ruby2js/converter/const.rb".freeze, "lib/ruby2js/converter/cvar.rb".freeze, "lib/ruby2js/converter/cvasgn.rb".freeze, "lib/ruby2js/converter/def.rb".freeze, "lib/ruby2js/converter/defined.rb".freeze, "lib/ruby2js/converter/defs.rb".freeze, "lib/ruby2js/converter/dstr.rb".freeze, "lib/ruby2js/converter/for.rb".freeze, "lib/ruby2js/converter/hash.rb".freeze, "lib/ruby2js/converter/if.rb".freeze, "lib/ruby2js/converter/in.rb".freeze, "lib/ruby2js/converter/ivar.rb".freeze, "lib/ruby2js/converter/ivasgn.rb".freeze, "lib/ruby2js/converter/kwbegin.rb".freeze, "lib/ruby2js/converter/literal.rb".freeze, "lib/ruby2js/converter/logical.rb".freeze, "lib/ruby2js/converter/masgn.rb".freeze, "lib/ruby2js/converter/module.rb".freeze, "lib/ruby2js/converter/next.rb".freeze, "lib/ruby2js/converter/nil.rb".freeze, "lib/ruby2js/converter/nthref.rb".freeze, "lib/ruby2js/converter/opasgn.rb".freeze, "lib/ruby2js/converter/prototype.rb".freeze, "lib/ruby2js/converter/regexp.rb".freeze, "lib/ruby2js/converter/return.rb".freeze, "lib/ruby2js/converter/self.rb".freeze, "lib/ruby2js/converter/send.rb".freeze, "lib/ruby2js/converter/super.rb".freeze, "lib/ruby2js/converter/sym.rb".freeze, "lib/ruby2js/converter/undef.rb".freeze, "lib/ruby2js/converter/until.rb".freeze, "lib/ruby2js/converter/untilpost.rb".freeze, "lib/ruby2js/converter/var.rb".freeze, "lib/ruby2js/converter/vasgn.rb".freeze, "lib/ruby2js/converter/while.rb".freeze, "lib/ruby2js/converter/whilepost.rb".freeze, "lib/ruby2js/converter/xstr.rb".freeze, "lib/ruby2js/execjs.rb".freeze, "lib/ruby2js/filter".freeze, "lib/ruby2js/filter/angular-resource.rb".freeze, "lib/ruby2js/filter/angular-route.rb".freeze, "lib/ruby2js/filter/angularrb.rb".freeze, "lib/ruby2js/filter/camelCase.rb".freeze, "lib/ruby2js/filter/functions.rb".freeze, "lib/ruby2js/filter/jquery.rb".freeze, "lib/ruby2js/filter/minitest-jasmine.rb".freeze, "lib/ruby2js/filter/react.rb".freeze, "lib/ruby2js/filter/require.rb".freeze, "lib/ruby2js/filter/return.rb".freeze, "lib/ruby2js/filter/rubyjs.rb".freeze, "lib/ruby2js/filter/strict.rb".freeze, "lib/ruby2js/filter/underscore.rb".freeze, "lib/ruby2js/filter/vue.rb".freeze, "lib/ruby2js/haml.rb".freeze, "lib/ruby2js/rails.rb".freeze, "lib/ruby2js/serializer.rb".freeze, "lib/ruby2js/sinatra.rb".freeze, "lib/ruby2js/version.rb".freeze, "ruby2js.gemspec".freeze]
16
+ s.files = %w(ruby2js.gemspec README.md) + Dir.glob("{lib}/**/*")
17
+
16
18
  s.homepage = "http://github.com/rubys/ruby2js".freeze
17
19
  s.licenses = ["MIT".freeze]
18
20
  s.required_ruby_version = Gem::Requirement.new(">= 1.9.3".freeze)
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: 2.1.24
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Ruby
@@ -48,6 +48,7 @@ files:
48
48
  - lib/ruby2js/converter/case.rb
49
49
  - lib/ruby2js/converter/casgn.rb
50
50
  - lib/ruby2js/converter/class.rb
51
+ - lib/ruby2js/converter/class2.rb
51
52
  - lib/ruby2js/converter/const.rb
52
53
  - lib/ruby2js/converter/cvar.rb
53
54
  - lib/ruby2js/converter/cvasgn.rb
@@ -85,10 +86,13 @@ files:
85
86
  - lib/ruby2js/converter/while.rb
86
87
  - lib/ruby2js/converter/whilepost.rb
87
88
  - lib/ruby2js/converter/xstr.rb
89
+ - lib/ruby2js/es2015.rb
90
+ - lib/ruby2js/es2015/strict.rb
91
+ - lib/ruby2js/es2016.rb
92
+ - lib/ruby2js/es2016/strict.rb
93
+ - lib/ruby2js/es2017.rb
94
+ - lib/ruby2js/es2017/strict.rb
88
95
  - lib/ruby2js/execjs.rb
89
- - lib/ruby2js/filter/angular-resource.rb
90
- - lib/ruby2js/filter/angular-route.rb
91
- - lib/ruby2js/filter/angularrb.rb
92
96
  - lib/ruby2js/filter/camelCase.rb
93
97
  - lib/ruby2js/filter/functions.rb
94
98
  - lib/ruby2js/filter/jquery.rb
@@ -97,13 +101,13 @@ files:
97
101
  - lib/ruby2js/filter/require.rb
98
102
  - lib/ruby2js/filter/return.rb
99
103
  - lib/ruby2js/filter/rubyjs.rb
100
- - lib/ruby2js/filter/strict.rb
101
104
  - lib/ruby2js/filter/underscore.rb
102
105
  - lib/ruby2js/filter/vue.rb
103
106
  - lib/ruby2js/haml.rb
104
107
  - lib/ruby2js/rails.rb
105
108
  - lib/ruby2js/serializer.rb
106
109
  - lib/ruby2js/sinatra.rb
110
+ - lib/ruby2js/strict.rb
107
111
  - lib/ruby2js/version.rb
108
112
  - ruby2js.gemspec
109
113
  homepage: http://github.com/rubys/ruby2js
@@ -126,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
130
  version: '0'
127
131
  requirements: []
128
132
  rubyforge_project:
129
- rubygems_version: 2.6.11
133
+ rubygems_version: 2.6.14
130
134
  signing_key:
131
135
  specification_version: 4
132
136
  summary: Minimal yet extensible Ruby to JavaScript conversion.
@@ -1,25 +0,0 @@
1
- require 'ruby2js/filter/angularrb'
2
-
3
- module Ruby2JS
4
- module Filter
5
- module AngularResource
6
- include SEXP
7
-
8
- # input:
9
- # $resource.new(args)
10
- #
11
- # output:
12
- # $resource(args)
13
-
14
- def on_send(node)
15
- return super unless @ngApp and node.children[1] == :new
16
- return super unless node.children[0] == s(:gvar, :$resource)
17
- node = super(node)
18
- @ngAppUses << :ngResource
19
- node.updated nil, [nil, :$resource, *node.children[2..-1]]
20
- end
21
- end
22
-
23
- DEFAULTS.push AngularResource
24
- end
25
- end
@@ -1,44 +0,0 @@
1
- require 'ruby2js/filter/angularrb'
2
-
3
- module Ruby2JS
4
- module Filter
5
- module AngularRoute
6
- include SEXP
7
-
8
- # input:
9
- # case $routeProvider
10
- # when '/path'
11
- # templateUrl = 'partials/path.html'
12
- # else
13
- # redirectTo '/path'
14
- # end
15
- #
16
- # output:
17
- # AppName.config(["$routeProvider", function($routeProvider) {
18
- # $routeProvider.when("/path", {templateUrl: 'partials/path.html'}).
19
- # otherwise({redirectTo: "/path"}))
20
-
21
- def on_case(node)
22
- rp = :$routeProvider
23
- return super unless @ngApp and node.children.first == s(:gvar, rp)
24
- @ngAppUses << :ngRoute
25
- code = s(:lvar, rp)
26
-
27
- node.children[1..-2].each do |child|
28
- code = s(:sendw, code, :when, child.children.first,
29
- AngularRB.hash(child.children[1..-1]))
30
- end
31
-
32
- if node.children.last
33
- code = s(:sendw, code, :otherwise,
34
- AngularRB.hash(node.children[-1..-1]))
35
- end
36
-
37
- s(:send, @ngApp, :config, s(:array, s(:str, rp.to_s), s(:block,
38
- s(:send, nil, :proc), s(:args, s(:arg, rp)), code)))
39
- end
40
- end
41
-
42
- DEFAULTS.push AngularRoute
43
- end
44
- end