ruby2js 2.1.3 → 2.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e5edb71b06e042e1f87d9e2680248470f3f1bb2
4
- data.tar.gz: 596aa3eb654805d1dcc3f4ad7a7921ca2a439c48
3
+ metadata.gz: 61852c6fdba706a1d5ae24c3cdcd55a40a979e59
4
+ data.tar.gz: 69ea3b2877046ce8525d4b1ed45ae42c20e5f88b
5
5
  SHA512:
6
- metadata.gz: ab33c1be48046ea978ebfbd5c1cc0eaf982ad0c498c0c97336c22ad562e045f11a8b55070ac56652eaadc8a4590f3ae71a37b7ff133942cdcad0d9f467419ce6
7
- data.tar.gz: c28e2fe9c0c5bafc81d21d2e18b475e0f45ec3bcf2997702063b1b1b42513d5461f728c4da2d6e126c58ccf3cf99b7b266c725928f224f92eb976c584e1a637c
6
+ metadata.gz: 67c6196a25c760be25a0db0f4d254610ac159bdec78cad82dbf48a488f775dc6016153441f65f8bd66a0e8f684e5c7f999b46f78fc373ab1ef9524959f0bdf16
7
+ data.tar.gz: e4cd05d2859a8cdb70164709bacdaf85e553ba8321b72977a3ccbfa7be845fc832c70d8c0766e220b8c8033f808de5dece5fd2d37858916cb35d88981e40e474
@@ -38,7 +38,8 @@ module Ruby2JS
38
38
  def on_class(node)
39
39
  cname, inheritance, *body = node.children
40
40
  return super unless cname.children.first == nil
41
- return super unless inheritance == s(:const, nil, :Vue)
41
+ return super unless inheritance == s(:const, nil, :Vue) or
42
+ inheritance == s(:const, s(:const, nil, :Vue), :Mixin)
42
43
 
43
44
  # traverse down to actual list of class statements
44
45
  if body.length == 1
@@ -53,13 +54,17 @@ module Ruby2JS
53
54
  methods = []
54
55
  computed = []
55
56
  setters = []
57
+ options = []
58
+ mixins = []
56
59
 
57
60
  # insert constructor if none present
58
- unless body.any? {|statement|
59
- statement.type == :def and statement.children.first ==:initialize}
60
- then
61
- body = body.dup
62
- body.unshift s(:def, :initialize, s(:args), nil)
61
+ if inheritance == s(:const, nil, :Vue)
62
+ unless body.any? {|statement|
63
+ statement.type == :def and statement.children.first ==:initialize}
64
+ then
65
+ body = body.dup
66
+ body.unshift s(:def, :initialize, s(:args), nil)
67
+ end
63
68
  end
64
69
 
65
70
  @vue_inventory = vue_walk(node)
@@ -79,11 +84,23 @@ module Ruby2JS
79
84
  # convert body into hash
80
85
  body.each do |statement|
81
86
 
82
- # named values
87
+ # named values (template, props, options, mixin[s])
83
88
  if statement.type == :send and statement.children.first == nil
84
89
  if [:template, :props].include? statement.children[1]
85
90
  hash << s(:pair, s(:sym, statement.children[1]),
86
91
  statement.children[2])
92
+
93
+ elsif
94
+ statement.children[1] == :options and
95
+ statement.children[2].type == :hash
96
+ then
97
+ options += statement.children[2].children
98
+
99
+ elsif statement.children[1] == :mixin or
100
+ statement.children[1] == :mixins
101
+ then
102
+
103
+ mixins += statement.children[2..-1]
87
104
  end
88
105
 
89
106
  # methods
@@ -182,6 +199,10 @@ module Ruby2JS
182
199
  end
183
200
  end
184
201
 
202
+ # add options to the front
203
+ hash.unshift(*options)
204
+
205
+ # add properties before that
185
206
  unless hash.any? {|pair| pair.children[0].children[0] == :props}
186
207
  unless @vue_inventory[:cvar].empty?
187
208
  hash.unshift s(:pair, s(:sym, :props), s(:array,
@@ -189,14 +210,19 @@ module Ruby2JS
189
210
  end
190
211
  end
191
212
 
192
- # add methods to hash
213
+ # add mixins before that
214
+ unless mixins.empty?
215
+ hash.unshift s(:pair, s(:sym, :mixins), s(:array, *mixins))
216
+ end
217
+
218
+ # append methods to hash
193
219
  unless methods.empty?
194
220
  hash << s(:pair, s(:sym, :methods), s(:hash, *methods))
195
221
  end
196
222
 
197
223
  @vue_instance = []
198
224
 
199
- # add setters to computed list
225
+ # append setters to computed list
200
226
  setters.each do |setter|
201
227
  index = computed.find_index do |pair|
202
228
  pair.children[0].children[0].to_s ==
@@ -213,7 +239,7 @@ module Ruby2JS
213
239
  end
214
240
  end
215
241
 
216
- # add computed to hash
242
+ # append computed to hash
217
243
  unless computed.empty?
218
244
  hash << s(:pair, s(:sym, :computed), s(:hash, *computed))
219
245
  end
@@ -223,10 +249,15 @@ module Ruby2JS
223
249
  sub(/^[A-Z]/) {|c| c.downcase}.
224
250
  gsub(/[A-Z]/) {|c| "-#{c.downcase}"}
225
251
 
226
- # build component
227
- s(:casgn, nil, cname.children.last,
228
- s(:send, s(:const, nil, :Vue), :component,
229
- s(:str, camel), s(:hash, *hash)))
252
+ if inheritance == s(:const, nil, :Vue)
253
+ # build component
254
+ s(:casgn, nil, cname.children.last,
255
+ s(:send, s(:const, nil, :Vue), :component,
256
+ s(:str, camel), s(:hash, *hash)))
257
+ else
258
+ # build mixin
259
+ s(:casgn, nil, cname.children.last, s(:hash, *hash))
260
+ end
230
261
  end
231
262
 
232
263
  # expand 'wunderbar' like method calls
@@ -729,6 +760,16 @@ module Ruby2JS
729
760
  s(:attr, s(:attr, s(:self), :$props), node.children[0].to_s[2..-1])
730
761
  end
731
762
 
763
+ # expand $options to this.$options
764
+ def on_gvar(node)
765
+ return super unless @vue_self
766
+ if node.children[0] == :$options
767
+ node.updated :attr, [s(:self), :$options]
768
+ else
769
+ super
770
+ end
771
+ end
772
+
732
773
  # prevent attempts to assign to Vue properties
733
774
  def on_cvasgn(node)
734
775
  return super unless @vue_self
@@ -752,14 +793,29 @@ module Ruby2JS
752
793
  end
753
794
  end
754
795
 
796
+ # for instance variables, map @x+= to this.x+=
797
+ # for computed variables with setters, map x+= to this.x+=
755
798
  def on_op_asgn(node)
756
799
  return super unless @vue_self
757
- return super unless node.children.first.type == :ivasgn
758
- node.updated nil, [s(:attr, @vue_self,
759
- node.children[0].children[0].to_s[1..-1]),
760
- node.children[1], process(node.children[2])]
800
+ if node.children.first.type == :ivasgn
801
+ node.updated nil, [s(:attr, @vue_self,
802
+ node.children[0].children[0].to_s[1..-1]),
803
+ node.children[1], process(node.children[2])]
804
+
805
+ elsif
806
+ node.children.first.type == :lvasgn and
807
+ @vue_instance.include? node.children[0].children[0]
808
+ then
809
+ node.updated nil, [s(:attr, s(:self),
810
+ node.children[0].children[0]),
811
+ node.children[1], process(node.children[2])]
812
+
813
+ else
814
+ super
815
+ end
761
816
  end
762
817
 
818
+ # for computed variables with setters, map x= to this.x=
763
819
  def on_lvasgn(node)
764
820
  return super unless @vue_instance.include? node.children.first
765
821
  s(:send, s(:self), "#{node.children.first}=",
@@ -2,7 +2,7 @@ module Ruby2JS
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 2
4
4
  MINOR = 1
5
- TINY = 3
5
+ TINY = 4
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/ruby2js.gemspec CHANGED
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: ruby2js 2.1.3 ruby lib
2
+ # stub: ruby2js 2.1.4 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "ruby2js".freeze
6
- s.version = "2.1.3"
6
+ s.version = "2.1.4"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
10
10
  s.authors = ["Sam Ruby".freeze]
11
- s.date = "2017-09-07"
11
+ s.date = "2017-09-08"
12
12
  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
13
13
  s.email = "rubys@intertwingly.net".freeze
14
14
  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/rails.rb".freeze, "lib/ruby2js/serializer.rb".freeze, "lib/ruby2js/sinatra.rb".freeze, "lib/ruby2js/version.rb".freeze, "ruby2js.gemspec".freeze]
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: 2.1.3
4
+ version: 2.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Ruby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-07 00:00:00.000000000 Z
11
+ date: 2017-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser