unparser 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +5 -1
- data/Gemfile +1 -1
- data/Gemfile.lock +13 -14
- data/config/flay.yml +1 -1
- data/config/rubocop.yml +4 -0
- data/lib/unparser.rb +0 -1
- data/lib/unparser/ast.rb +10 -4
- data/lib/unparser/emitter/argument.rb +1 -1
- data/lib/unparser/emitter/send.rb +51 -3
- data/spec/unit/unparser_spec.rb +14 -0
- data/unparser.gemspec +1 -1
- metadata +1 -2
- data/lib/unparser/emitter/send/arguments.rb +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a1bb0cdd1d53883d86ca04f7ef43abedd068cffbf9ba370a85debb33e260e73
|
4
|
+
data.tar.gz: 5cfbeb83a56f3d6d1b4d921c8257d7e26d653cc0732176b76523fe3c9d375d5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ceee1a92f66ede9bcc67e477ae4271c4b28b80e846f68f368a95f52cc0968a093fb9cc22f7502d84e2c2ff60b3807fa8f12a6e736c54247afef813a3e09724bf
|
7
|
+
data.tar.gz: 3be9bd24acdb9f195341660a9bf8bb85c34cf519102418fa4f19e747914c4421fdca6448903660ab6903fb6e5f3ef863c06ad0f40984021ba72265625ce322c2
|
data/Changelog.md
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
GIT
|
2
2
|
remote: https://github.com/mbj/mutant
|
3
|
-
revision:
|
4
|
-
branch: change/to-modern-ast
|
3
|
+
revision: fd6bfe89c6be85433d116b62d1b2407af3ff7804
|
5
4
|
specs:
|
6
5
|
mutant (0.8.20)
|
7
6
|
abstract_type (~> 0.0.7)
|
@@ -17,7 +16,7 @@ GIT
|
|
17
16
|
parser (~> 2.5.1)
|
18
17
|
procto (~> 0.0.2)
|
19
18
|
regexp_parser (~> 1.2)
|
20
|
-
unparser (~> 0.
|
19
|
+
unparser (~> 0.4.0)
|
21
20
|
mutant-rspec (0.8.20)
|
22
21
|
mutant (~> 0.8.20)
|
23
22
|
rspec-core (>= 3.4.0, < 4.0.0)
|
@@ -59,22 +58,22 @@ GEM
|
|
59
58
|
equalizer (~> 0.0.9)
|
60
59
|
descendants_tracker (0.0.4)
|
61
60
|
thread_safe (~> 0.3, >= 0.3.1)
|
62
|
-
devtools (0.1.
|
61
|
+
devtools (0.1.22)
|
63
62
|
abstract_type (~> 0.0.7)
|
64
63
|
adamantium (~> 0.2.0)
|
65
64
|
anima (~> 0.3.0)
|
66
65
|
concord (~> 0.1.5)
|
67
|
-
flay (~> 2.
|
68
|
-
flog (~> 4.6.
|
69
|
-
mutant (~> 0.8.
|
70
|
-
mutant-rspec (~> 0.8.
|
66
|
+
flay (~> 2.12.0)
|
67
|
+
flog (~> 4.6.2)
|
68
|
+
mutant (~> 0.8.19)
|
69
|
+
mutant-rspec (~> 0.8.19)
|
71
70
|
procto (~> 0.0.3)
|
72
71
|
rake (~> 12.3.0)
|
73
|
-
reek (~> 5.0
|
72
|
+
reek (~> 5.2.0)
|
74
73
|
rspec (~> 3.8.0)
|
75
74
|
rspec-core (~> 3.8.0)
|
76
75
|
rspec-its (~> 1.2.0)
|
77
|
-
rubocop (~> 0.
|
76
|
+
rubocop (~> 0.60.0)
|
78
77
|
simplecov (~> 0.16.1)
|
79
78
|
yard (~> 0.9.16)
|
80
79
|
yardstick (~> 0.9.9)
|
@@ -82,7 +81,7 @@ GEM
|
|
82
81
|
docile (1.3.1)
|
83
82
|
equalizer (0.0.11)
|
84
83
|
erubis (2.7.0)
|
85
|
-
flay (2.
|
84
|
+
flay (2.12.0)
|
86
85
|
erubis (~> 2.7.0)
|
87
86
|
path_expander (~> 1.0)
|
88
87
|
ruby_parser (~> 3.0)
|
@@ -114,7 +113,7 @@ GEM
|
|
114
113
|
procto (0.0.3)
|
115
114
|
rainbow (3.0.0)
|
116
115
|
rake (12.3.1)
|
117
|
-
reek (5.0
|
116
|
+
reek (5.2.0)
|
118
117
|
codeclimate-engine-rb (~> 0.4.0)
|
119
118
|
kwalify (~> 0.7.0)
|
120
119
|
parser (>= 2.5.0.0, < 2.6, != 2.5.1.1)
|
@@ -136,14 +135,14 @@ GEM
|
|
136
135
|
diff-lcs (>= 1.2.0, < 2.0)
|
137
136
|
rspec-support (~> 3.8.0)
|
138
137
|
rspec-support (3.8.0)
|
139
|
-
rubocop (0.
|
138
|
+
rubocop (0.60.0)
|
140
139
|
jaro_winkler (~> 1.5.1)
|
141
140
|
parallel (~> 1.10)
|
142
141
|
parser (>= 2.5, != 2.5.1.1)
|
143
142
|
powerpack (~> 0.1)
|
144
143
|
rainbow (>= 2.2.2, < 4.0)
|
145
144
|
ruby-progressbar (~> 1.7)
|
146
|
-
unicode-display_width (~> 1.
|
145
|
+
unicode-display_width (~> 1.4.0)
|
147
146
|
ruby-progressbar (1.10.0)
|
148
147
|
ruby_parser (3.11.0)
|
149
148
|
sexp_processor (~> 4.9)
|
data/config/flay.yml
CHANGED
data/config/rubocop.yml
CHANGED
data/lib/unparser.rb
CHANGED
@@ -117,7 +117,6 @@ require 'unparser/emitter/send/unary'
|
|
117
117
|
require 'unparser/emitter/send/binary'
|
118
118
|
require 'unparser/emitter/send/regular'
|
119
119
|
require 'unparser/emitter/send/conditional'
|
120
|
-
require 'unparser/emitter/send/arguments'
|
121
120
|
require 'unparser/emitter/send/attribute_assignment'
|
122
121
|
require 'unparser/emitter/block'
|
123
122
|
require 'unparser/emitter/assignment'
|
data/lib/unparser/ast.rb
CHANGED
@@ -13,10 +13,16 @@ module Unparser
|
|
13
13
|
CLOSE_NODES = (RESET_NODES + INHERIT_NODES).freeze
|
14
14
|
|
15
15
|
# Nodes that assign a local variable
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
ASSIGN_NODES =
|
17
|
+
%i[
|
18
|
+
arg
|
19
|
+
kwarg
|
20
|
+
kwoptarg
|
21
|
+
lvasgn
|
22
|
+
optarg
|
23
|
+
procarg0
|
24
|
+
restarg
|
25
|
+
].to_set.freeze
|
20
26
|
|
21
27
|
# Test for local variable inherited scope reset
|
22
28
|
#
|
@@ -159,13 +159,52 @@ module Unparser
|
|
159
159
|
# @api private
|
160
160
|
#
|
161
161
|
def emit_arguments
|
162
|
-
if arguments.empty?
|
163
|
-
write('()')
|
162
|
+
if arguments.empty?
|
163
|
+
write('()') if receiver.nil? && avoid_clash?
|
164
164
|
else
|
165
|
-
|
165
|
+
normal_arguments
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
169
|
+
# Emit normal arguments
|
170
|
+
#
|
171
|
+
# @return [undefined]
|
172
|
+
#
|
173
|
+
# @api private
|
174
|
+
#
|
175
|
+
def normal_arguments
|
176
|
+
parentheses do
|
177
|
+
delimited_plain(effective_arguments)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
# The effective arguments
|
182
|
+
#
|
183
|
+
# @return [Parser::AST::Node]
|
184
|
+
#
|
185
|
+
# @api private
|
186
|
+
#
|
187
|
+
def effective_arguments
|
188
|
+
last = arguments.length - 1
|
189
|
+
arguments.each_with_index.map do |argument, index|
|
190
|
+
if last.equal?(index) && argument.type.equal?(:hash) && argument.children.any?
|
191
|
+
argument.updated(:hash_body)
|
192
|
+
else
|
193
|
+
argument
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
# Test if clash with local variable or constant needs to be avoided
|
199
|
+
#
|
200
|
+
# @return [Boolean]
|
201
|
+
#
|
202
|
+
# @api private
|
203
|
+
#
|
204
|
+
def avoid_clash?
|
205
|
+
local_variable_clash? || parses_as_constant?
|
206
|
+
end
|
207
|
+
|
169
208
|
# Test for local variable clash
|
170
209
|
#
|
171
210
|
# @return [Boolean]
|
@@ -185,6 +224,15 @@ module Unparser
|
|
185
224
|
string_selector[NON_ASSIGN_RANGE]
|
186
225
|
end
|
187
226
|
|
227
|
+
# Test if selector parses as constant
|
228
|
+
#
|
229
|
+
# @return [Boolean]
|
230
|
+
#
|
231
|
+
# @api private
|
232
|
+
#
|
233
|
+
def parses_as_constant?
|
234
|
+
Unparser.parse(selector.to_s).type.equal?(:const)
|
235
|
+
end
|
188
236
|
end # Send
|
189
237
|
end # Emitter
|
190
238
|
end # Unparser
|
data/spec/unit/unparser_spec.rb
CHANGED
@@ -597,6 +597,10 @@ describe Unparser, mutant_expression: 'Unparser::Emitter*' do
|
|
597
597
|
end.baz
|
598
598
|
RUBY
|
599
599
|
|
600
|
+
assert_source <<~'RUBY'
|
601
|
+
FOO()
|
602
|
+
RUBY
|
603
|
+
|
600
604
|
assert_terminated '(1..2).max'
|
601
605
|
assert_terminated '1..2.max'
|
602
606
|
assert_unterminated 'a || return'
|
@@ -1239,6 +1243,16 @@ describe Unparser, mutant_expression: 'Unparser::Emitter*' do
|
|
1239
1243
|
end
|
1240
1244
|
RUBY
|
1241
1245
|
|
1246
|
+
assert_source <<~'RUBY'
|
1247
|
+
def foo(bar: bar)
|
1248
|
+
end
|
1249
|
+
RUBY
|
1250
|
+
|
1251
|
+
assert_source <<~'RUBY'
|
1252
|
+
def foo(bar: bar())
|
1253
|
+
end
|
1254
|
+
RUBY
|
1255
|
+
|
1242
1256
|
assert_source <<~'RUBY'
|
1243
1257
|
def foo(*)
|
1244
1258
|
bar
|
data/unparser.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unparser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Markus Schirp
|
@@ -235,7 +235,6 @@ files:
|
|
235
235
|
- lib/unparser/emitter/retry.rb
|
236
236
|
- lib/unparser/emitter/root.rb
|
237
237
|
- lib/unparser/emitter/send.rb
|
238
|
-
- lib/unparser/emitter/send/arguments.rb
|
239
238
|
- lib/unparser/emitter/send/attribute_assignment.rb
|
240
239
|
- lib/unparser/emitter/send/binary.rb
|
241
240
|
- lib/unparser/emitter/send/conditional.rb
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Unparser
|
4
|
-
class Emitter
|
5
|
-
class Send
|
6
|
-
# Emitter for arguments of send nodes
|
7
|
-
class Arguments < Emitter
|
8
|
-
|
9
|
-
private
|
10
|
-
|
11
|
-
# Perform dispatch
|
12
|
-
#
|
13
|
-
# @return [undefined]
|
14
|
-
#
|
15
|
-
# @api private
|
16
|
-
#
|
17
|
-
def dispatch
|
18
|
-
return if children.empty?
|
19
|
-
|
20
|
-
parentheses do
|
21
|
-
delimited_plain(effective_arguments)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
# Return effective arguments
|
26
|
-
#
|
27
|
-
# @return [Parser::AST::Node]
|
28
|
-
#
|
29
|
-
# @api private
|
30
|
-
#
|
31
|
-
def effective_arguments
|
32
|
-
last = children.length - 1
|
33
|
-
children.each_with_index.map do |argument, index|
|
34
|
-
if last.equal?(index) && argument.type.equal?(:hash) && argument.children.any?
|
35
|
-
argument.updated(:hash_body)
|
36
|
-
else
|
37
|
-
argument
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
end # Arguments
|
43
|
-
end # Send
|
44
|
-
end # Emitter
|
45
|
-
end # Unparser
|