syntax_tree 4.3.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -56,14 +56,6 @@ module SyntaxTree
56
56
  with_new_environment { super }
57
57
  end
58
58
 
59
- def visit_defs(node)
60
- with_new_environment { super }
61
- end
62
-
63
- def visit_def_endless(node)
64
- with_new_environment { super }
65
- end
66
-
67
59
  # Visit for keeping track of local arguments, such as method and block
68
60
  # arguments
69
61
  def visit_params(node)
@@ -11,7 +11,7 @@ module SyntaxTree
11
11
  # Visit an ARefField node.
12
12
  alias visit_aref_field visit_child_nodes
13
13
 
14
- # Visit an Alias node.
14
+ # Visit an AliasNode node.
15
15
  alias visit_alias visit_child_nodes
16
16
 
17
17
  # Visit an ArgBlock node.
@@ -62,6 +62,9 @@ module SyntaxTree
62
62
  # Visit a Binary node.
63
63
  alias visit_binary visit_child_nodes
64
64
 
65
+ # Visit a Block node.
66
+ alias visit_block visit_child_nodes
67
+
65
68
  # Visit a BlockArg node.
66
69
  alias visit_blockarg visit_child_nodes
67
70
 
@@ -71,9 +74,6 @@ module SyntaxTree
71
74
  # Visit a BodyStmt node.
72
75
  alias visit_bodystmt visit_child_nodes
73
76
 
74
- # Visit a BraceBlock node.
75
- alias visit_brace_block visit_child_nodes
76
-
77
77
  # Visit a Break node.
78
78
  alias visit_break visit_child_nodes
79
79
 
@@ -119,24 +119,9 @@ module SyntaxTree
119
119
  # Visit a Def node.
120
120
  alias visit_def visit_child_nodes
121
121
 
122
- # Visit a DefEndless node.
123
- alias visit_def_endless visit_child_nodes
124
-
125
122
  # Visit a Defined node.
126
123
  alias visit_defined visit_child_nodes
127
124
 
128
- # Visit a Defs node.
129
- alias visit_defs visit_child_nodes
130
-
131
- # Visit a DoBlock node.
132
- alias visit_do_block visit_child_nodes
133
-
134
- # Visit a Dot2 node.
135
- alias visit_dot2 visit_child_nodes
136
-
137
- # Visit a Dot3 node.
138
- alias visit_dot3 visit_child_nodes
139
-
140
125
  # Visit a DynaSymbol node.
141
126
  alias visit_dyna_symbol visit_child_nodes
142
127
 
@@ -167,9 +152,6 @@ module SyntaxTree
167
152
  # Visit an ExcessedComma node.
168
153
  alias visit_excessed_comma visit_child_nodes
169
154
 
170
- # Visit a FCall node.
171
- alias visit_fcall visit_child_nodes
172
-
173
155
  # Visit a Field node.
174
156
  alias visit_field visit_child_nodes
175
157
 
@@ -203,12 +185,9 @@ module SyntaxTree
203
185
  # Visit an Ident node.
204
186
  alias visit_ident visit_child_nodes
205
187
 
206
- # Visit an If node.
188
+ # Visit an IfNode node.
207
189
  alias visit_if visit_child_nodes
208
190
 
209
- # Visit an IfMod node.
210
- alias visit_if_mod visit_child_nodes
211
-
212
191
  # Visit an IfOp node.
213
192
  alias visit_if_op visit_child_nodes
214
193
 
@@ -311,6 +290,9 @@ module SyntaxTree
311
290
  # Visit a QWordsBeg node.
312
291
  alias visit_qwords_beg visit_child_nodes
313
292
 
293
+ # Visit a RangeNode node
294
+ alias visit_range visit_child_nodes
295
+
314
296
  # Visit a RAssign node.
315
297
  alias visit_rassign visit_child_nodes
316
298
 
@@ -356,9 +338,6 @@ module SyntaxTree
356
338
  # Visit a Return node.
357
339
  alias visit_return visit_child_nodes
358
340
 
359
- # Visit a Return0 node.
360
- alias visit_return0 visit_child_nodes
361
-
362
341
  # Visit a RParen node.
363
342
  alias visit_rparen visit_child_nodes
364
343
 
@@ -428,21 +407,12 @@ module SyntaxTree
428
407
  # Visit an Undef node.
429
408
  alias visit_undef visit_child_nodes
430
409
 
431
- # Visit an Unless node.
410
+ # Visit an UnlessNode node.
432
411
  alias visit_unless visit_child_nodes
433
412
 
434
- # Visit an UnlessMod node.
435
- alias visit_unless_mod visit_child_nodes
436
-
437
- # Visit an Until node.
413
+ # Visit an UntilNode node.
438
414
  alias visit_until visit_child_nodes
439
415
 
440
- # Visit an UntilMod node.
441
- alias visit_until_mod visit_child_nodes
442
-
443
- # Visit a VarAlias node.
444
- alias visit_var_alias visit_child_nodes
445
-
446
416
  # Visit a VarField node.
447
417
  alias visit_var_field visit_child_nodes
448
418
 
@@ -458,12 +428,9 @@ module SyntaxTree
458
428
  # Visit a When node.
459
429
  alias visit_when visit_child_nodes
460
430
 
461
- # Visit a While node.
431
+ # Visit a WhileNode node.
462
432
  alias visit_while visit_child_nodes
463
433
 
464
- # Visit a WhileMod node.
465
- alias visit_while_mod visit_child_nodes
466
-
467
434
  # Visit a Word node.
468
435
  alias visit_word visit_child_nodes
469
436
 
@@ -479,12 +446,9 @@ module SyntaxTree
479
446
  # Visit a XStringLiteral node.
480
447
  alias visit_xstring_literal visit_child_nodes
481
448
 
482
- # Visit a Yield node.
449
+ # Visit a YieldNode node.
483
450
  alias visit_yield visit_child_nodes
484
451
 
485
- # Visit a Yield0 node.
486
- alias visit_yield0 visit_child_nodes
487
-
488
452
  # Visit a ZSuper node.
489
453
  alias visit_zsuper visit_child_nodes
490
454
 
data/lib/syntax_tree.rb CHANGED
@@ -16,6 +16,7 @@ require_relative "syntax_tree/visitor"
16
16
  require_relative "syntax_tree/visitor/field_visitor"
17
17
  require_relative "syntax_tree/visitor/json_visitor"
18
18
  require_relative "syntax_tree/visitor/match_visitor"
19
+ require_relative "syntax_tree/visitor/mutation_visitor"
19
20
  require_relative "syntax_tree/visitor/pretty_print_visitor"
20
21
  require_relative "syntax_tree/visitor/environment"
21
22
  require_relative "syntax_tree/visitor/with_environment"
@@ -53,14 +54,25 @@ module SyntaxTree
53
54
  end
54
55
 
55
56
  # Parses the given source and returns the formatted source.
56
- def self.format(source, maxwidth = DEFAULT_PRINT_WIDTH)
57
- formatter = Formatter.new(source, [], maxwidth)
57
+ def self.format(
58
+ source,
59
+ maxwidth = DEFAULT_PRINT_WIDTH,
60
+ options: Formatter::Options.new
61
+ )
62
+ formatter = Formatter.new(source, [], maxwidth, options: options)
58
63
  parse(source).format(formatter)
59
64
 
60
65
  formatter.flush
61
66
  formatter.output.join
62
67
  end
63
68
 
69
+ # A convenience method for creating a new mutation visitor.
70
+ def self.mutation
71
+ visitor = Visitor::MutationVisitor.new
72
+ yield visitor
73
+ visitor
74
+ end
75
+
64
76
  # Returns the source from the given filepath taking into account any potential
65
77
  # magic encoding comments.
66
78
  def self.read(filepath)
data/syntax_tree.gemspec CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
26
  spec.require_paths = %w[lib]
27
27
 
28
- spec.add_dependency "prettier_print", ">= 1.0.2"
28
+ spec.add_dependency "prettier_print", ">= 1.1.0"
29
29
 
30
30
  spec.add_development_dependency "bundler"
31
31
  spec.add_development_dependency "minitest"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: syntax_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.0
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Newton
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-28 00:00:00.000000000 Z
11
+ date: 2022-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prettier_print
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.2
19
+ version: 1.1.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 1.0.2
26
+ version: 1.1.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -102,6 +102,7 @@ executables:
102
102
  extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
+ - ".gitattributes"
105
106
  - ".github/dependabot.yml"
106
107
  - ".github/workflows/auto-merge.yml"
107
108
  - ".github/workflows/gh-pages.yml"
@@ -143,6 +144,7 @@ files:
143
144
  - lib/syntax_tree/visitor/field_visitor.rb
144
145
  - lib/syntax_tree/visitor/json_visitor.rb
145
146
  - lib/syntax_tree/visitor/match_visitor.rb
147
+ - lib/syntax_tree/visitor/mutation_visitor.rb
146
148
  - lib/syntax_tree/visitor/pretty_print_visitor.rb
147
149
  - lib/syntax_tree/visitor/with_environment.rb
148
150
  - syntax_tree.gemspec