ruby2js 3.6.1 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -7
- data/lib/ruby2js.rb +32 -9
- data/lib/ruby2js/converter.rb +8 -2
- data/lib/ruby2js/converter/assign.rb +159 -0
- data/lib/ruby2js/converter/begin.rb +7 -2
- data/lib/ruby2js/converter/case.rb +7 -2
- data/lib/ruby2js/converter/class.rb +77 -21
- data/lib/ruby2js/converter/class2.rb +39 -11
- data/lib/ruby2js/converter/def.rb +6 -2
- data/lib/ruby2js/converter/dstr.rb +8 -3
- data/lib/ruby2js/converter/hash.rb +9 -5
- data/lib/ruby2js/converter/hide.rb +13 -0
- data/lib/ruby2js/converter/if.rb +10 -2
- data/lib/ruby2js/converter/import.rb +18 -3
- data/lib/ruby2js/converter/kwbegin.rb +9 -2
- data/lib/ruby2js/converter/literal.rb +2 -2
- data/lib/ruby2js/converter/module.rb +37 -5
- data/lib/ruby2js/converter/opasgn.rb +8 -0
- data/lib/ruby2js/converter/send.rb +41 -2
- data/lib/ruby2js/converter/vasgn.rb +5 -0
- data/lib/ruby2js/demo.rb +53 -0
- data/lib/ruby2js/es2022.rb +5 -0
- data/lib/ruby2js/es2022/strict.rb +3 -0
- data/lib/ruby2js/filter.rb +9 -1
- data/lib/ruby2js/filter/active_functions.rb +1 -0
- data/lib/ruby2js/filter/cjs.rb +2 -0
- data/lib/ruby2js/filter/esm.rb +44 -10
- data/lib/ruby2js/filter/functions.rb +84 -95
- data/lib/ruby2js/filter/{wunderbar.rb → jsx.rb} +29 -7
- data/lib/ruby2js/filter/react.rb +191 -56
- data/lib/ruby2js/filter/require.rb +100 -5
- data/lib/ruby2js/filter/return.rb +13 -1
- data/lib/ruby2js/filter/stimulus.rb +185 -0
- data/lib/ruby2js/jsx.rb +291 -0
- data/lib/ruby2js/namespace.rb +75 -0
- data/lib/ruby2js/version.rb +3 -3
- metadata +12 -4
@@ -0,0 +1,75 @@
|
|
1
|
+
# Instances of this class keep track of both classes and modules that we have
|
2
|
+
# seen before, as well as the methods and properties that are defined in each.
|
3
|
+
#
|
4
|
+
# Use cases this enables:
|
5
|
+
#
|
6
|
+
# * detection of "open" classes and modules, i.e., redefining a class or
|
7
|
+
# module that was previously declared in order to add or modify methods
|
8
|
+
# or properties.
|
9
|
+
#
|
10
|
+
# * knowing when to prefix method or property access with `this.` and
|
11
|
+
# when to add `.bind(this)` for methods and properties that were defined
|
12
|
+
# outside of this class.
|
13
|
+
#
|
14
|
+
module Ruby2JS
|
15
|
+
class Namespace
|
16
|
+
def initialize
|
17
|
+
@active = [] # current scope
|
18
|
+
@seen = {} # history of all definitions seen previously
|
19
|
+
end
|
20
|
+
|
21
|
+
# convert an AST name which is represented as a set of nested
|
22
|
+
# s(:const, # ...) into an array of symbols that represent
|
23
|
+
# the relative path.
|
24
|
+
def resolve(token, result = [])
|
25
|
+
return [] unless token&.type == :const
|
26
|
+
resolve(token.children.first, result)
|
27
|
+
result.push(token.children.last)
|
28
|
+
end
|
29
|
+
|
30
|
+
# return the active scope as a flat array of symbols
|
31
|
+
def active
|
32
|
+
@active.flatten.compact
|
33
|
+
end
|
34
|
+
|
35
|
+
# enter a new scope, which may be a nested subscope. Mark the new scope
|
36
|
+
# as seen, and return any previous definition that may have been seen
|
37
|
+
# before.
|
38
|
+
def enter(name)
|
39
|
+
@active.push resolve(name)
|
40
|
+
previous = @seen[active]
|
41
|
+
@seen[active] ||= {}
|
42
|
+
previous
|
43
|
+
end
|
44
|
+
|
45
|
+
# return the set of known properties (and methods) for either the current
|
46
|
+
# scope or a named subscope.
|
47
|
+
def getOwnProps(name = nil)
|
48
|
+
@seen[active + resolve(name)]&.dup || {}
|
49
|
+
end
|
50
|
+
|
51
|
+
# add new props (and methods) to the current scope.
|
52
|
+
def defineProps(props, namespace=active)
|
53
|
+
@seen[namespace] ||= {}
|
54
|
+
@seen[namespace].merge! props || {}
|
55
|
+
end
|
56
|
+
|
57
|
+
# find a named scope which may be relative to any point in the ancestry of
|
58
|
+
# the current scope. Return the properties for that scope.
|
59
|
+
def find(name)
|
60
|
+
name = resolve(name)
|
61
|
+
prefix = active
|
62
|
+
while prefix.pop
|
63
|
+
result = @seen[prefix + name]
|
64
|
+
return result if result
|
65
|
+
end
|
66
|
+
{}
|
67
|
+
end
|
68
|
+
|
69
|
+
# leave a given scope. Note that the scope may be compound (e.g., M::N),
|
70
|
+
# and if so, it will pop the entire resolved name.
|
71
|
+
def leave()
|
72
|
+
@active.pop
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/ruby2js/version.rb
CHANGED
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:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Ruby
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-02-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: parser
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- lib/ruby2js/converter/arg.rb
|
56
56
|
- lib/ruby2js/converter/args.rb
|
57
57
|
- lib/ruby2js/converter/array.rb
|
58
|
+
- lib/ruby2js/converter/assign.rb
|
58
59
|
- lib/ruby2js/converter/begin.rb
|
59
60
|
- lib/ruby2js/converter/block.rb
|
60
61
|
- lib/ruby2js/converter/blockpass.rb
|
@@ -74,6 +75,7 @@ files:
|
|
74
75
|
- lib/ruby2js/converter/fileline.rb
|
75
76
|
- lib/ruby2js/converter/for.rb
|
76
77
|
- lib/ruby2js/converter/hash.rb
|
78
|
+
- lib/ruby2js/converter/hide.rb
|
77
79
|
- lib/ruby2js/converter/if.rb
|
78
80
|
- lib/ruby2js/converter/import.rb
|
79
81
|
- lib/ruby2js/converter/in.rb
|
@@ -106,6 +108,7 @@ files:
|
|
106
108
|
- lib/ruby2js/converter/xnode.rb
|
107
109
|
- lib/ruby2js/converter/xstr.rb
|
108
110
|
- lib/ruby2js/converter/yield.rb
|
111
|
+
- lib/ruby2js/demo.rb
|
109
112
|
- lib/ruby2js/es2015.rb
|
110
113
|
- lib/ruby2js/es2015/strict.rb
|
111
114
|
- lib/ruby2js/es2016.rb
|
@@ -120,6 +123,8 @@ files:
|
|
120
123
|
- lib/ruby2js/es2020/strict.rb
|
121
124
|
- lib/ruby2js/es2021.rb
|
122
125
|
- lib/ruby2js/es2021/strict.rb
|
126
|
+
- lib/ruby2js/es2022.rb
|
127
|
+
- lib/ruby2js/es2022/strict.rb
|
123
128
|
- lib/ruby2js/execjs.rb
|
124
129
|
- lib/ruby2js/filter.rb
|
125
130
|
- lib/ruby2js/filter/active_functions.rb
|
@@ -128,6 +133,7 @@ files:
|
|
128
133
|
- lib/ruby2js/filter/esm.rb
|
129
134
|
- lib/ruby2js/filter/functions.rb
|
130
135
|
- lib/ruby2js/filter/jquery.rb
|
136
|
+
- lib/ruby2js/filter/jsx.rb
|
131
137
|
- lib/ruby2js/filter/matchAll.rb
|
132
138
|
- lib/ruby2js/filter/minitest-jasmine.rb
|
133
139
|
- lib/ruby2js/filter/node.rb
|
@@ -136,11 +142,13 @@ files:
|
|
136
142
|
- lib/ruby2js/filter/require.rb
|
137
143
|
- lib/ruby2js/filter/return.rb
|
138
144
|
- lib/ruby2js/filter/securerandom.rb
|
145
|
+
- lib/ruby2js/filter/stimulus.rb
|
139
146
|
- lib/ruby2js/filter/tagged_templates.rb
|
140
147
|
- lib/ruby2js/filter/underscore.rb
|
141
148
|
- lib/ruby2js/filter/vue.rb
|
142
|
-
- lib/ruby2js/filter/wunderbar.rb
|
143
149
|
- lib/ruby2js/haml.rb
|
150
|
+
- lib/ruby2js/jsx.rb
|
151
|
+
- lib/ruby2js/namespace.rb
|
144
152
|
- lib/ruby2js/rails.rb
|
145
153
|
- lib/ruby2js/serializer.rb
|
146
154
|
- lib/ruby2js/sinatra.rb
|
@@ -166,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
174
|
- !ruby/object:Gem::Version
|
167
175
|
version: '0'
|
168
176
|
requirements: []
|
169
|
-
rubygems_version: 3.1.
|
177
|
+
rubygems_version: 3.1.2
|
170
178
|
signing_key:
|
171
179
|
specification_version: 4
|
172
180
|
summary: Minimal yet extensible Ruby to JavaScript conversion.
|