syntax_tree 4.0.0 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 10f0ce4d457d0e9f5bd36e167de9b1904ddfae5194f5b6be022aa269ca292703
4
- data.tar.gz: 52fc74a1cdef543d8b6c47c4cc8843530f8e3ef3ad91ae28d8394e3438c78059
3
+ metadata.gz: 959bd2a452303ffb7565ee0ce9641cc1167609c7c2231fc12d476d35db44ae34
4
+ data.tar.gz: d1d15bf2076e7ee83caf30d1371d3d2e3c43415349e5e89e39efca68ccda0339
5
5
  SHA512:
6
- metadata.gz: b4eb3a6cdf87afb63722f01b3ba3840fa96766a5636585cdec3b17d5b6ad630746d3e06e05b599960bb907db084a30c644cd2778868684f5f681953a1dbb411e
7
- data.tar.gz: 994023a5b4da885e0b9eccd1641381e00b7142f47efbb75d27bcfe4da4b36c1cb07f000cbdbc5f0d5b57e5ef2d9c00c43bfff9251bd236cdc9e5eee01e21d683
6
+ metadata.gz: 814586875ea83553dcf691b374056617b0491af9237c5fc4332da559cec7cf459593b515549cdf33c2a5b3bd45a79b01b8fa9c6bb027646799f3fb935b1b37b1
7
+ data.tar.gz: a7a70c1d9b77b7c9f3c460973760cabf7446fa794e1254da25536657e7094c9bbcdb6522f08a00a26fe317d982b31b48e9f99758e2a9dde093b5c7998cdf047a
data/.rubocop.yml CHANGED
@@ -13,6 +13,9 @@ AllCops:
13
13
  Layout/LineLength:
14
14
  Max: 80
15
15
 
16
+ Lint/AmbiguousBlockAssociation:
17
+ Enabled: false
18
+
16
19
  Lint/DuplicateBranch:
17
20
  Enabled: false
18
21
 
data/CHANGELOG.md CHANGED
@@ -6,6 +6,20 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [4.0.2] - 2022-10-19
10
+
11
+ ### Changed
12
+
13
+ - [#177](https://github.com/ruby-syntax-tree/syntax_tree/pull/177) - Fix up various other issues with the environment visitor addition.
14
+
15
+ ## [4.0.1] - 2022-10-18
16
+
17
+ ### Changed
18
+
19
+ - [#172](https://github.com/ruby-syntax-tree/syntax_tree/pull/172) - Use a refinement for `Symbol#name` addition so that other runtimes or tools don't get confused by its availability.
20
+ - [#173](https://github.com/ruby-syntax-tree/syntax_tree/pull/173) - Fix the `current_environment` usage to use the method instead of the instance variable.
21
+ - [#175](https://github.com/ruby-syntax-tree/syntax_tree/pull/175) - Update `prettier_print` requirement since v1.0.0 had a bug with `#breakable_return`.
22
+
9
23
  ## [4.0.0] - 2022-10-17
10
24
 
11
25
  ### Added
@@ -383,7 +397,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
383
397
 
384
398
  - 🎉 Initial release! 🎉
385
399
 
386
- [unreleased]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v4.0.0...HEAD
400
+ [unreleased]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v4.0.2...HEAD
401
+ [4.0.2]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v4.0.1...v4.0.2
402
+ [4.0.1]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v4.0.0...v4.0.1
387
403
  [4.0.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.6.3...v4.0.0
388
404
  [3.6.3]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.6.2...v3.6.3
389
405
  [3.6.2]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.6.1...v3.6.2
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- syntax_tree (4.0.0)
5
- prettier_print (>= 1.0.0)
4
+ syntax_tree (4.0.2)
5
+ prettier_print (>= 1.0.2)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
@@ -14,7 +14,7 @@ GEM
14
14
  parallel (1.22.1)
15
15
  parser (3.1.2.1)
16
16
  ast (~> 2.4.1)
17
- prettier_print (1.0.0)
17
+ prettier_print (1.0.2)
18
18
  rainbow (3.1.1)
19
19
  rake (13.0.6)
20
20
  regexp_parser (2.6.0)
@@ -29,7 +29,7 @@ GEM
29
29
  rubocop-ast (>= 1.20.1, < 2.0)
30
30
  ruby-progressbar (~> 1.7)
31
31
  unicode-display_width (>= 1.4.0, < 3.0)
32
- rubocop-ast (1.21.0)
32
+ rubocop-ast (1.22.0)
33
33
  parser (>= 3.1.1.0)
34
34
  ruby-progressbar (1.11.0)
35
35
  simplecov (0.21.2)
@@ -1651,6 +1651,20 @@ module SyntaxTree
1651
1651
  # array << value
1652
1652
  #
1653
1653
  class Binary < Node
1654
+ # Since Binary's operator is a symbol, it's better to use the `name` method
1655
+ # than to allocate a new string every time. This is a tiny performance
1656
+ # optimization, but enough that it shows up in the profiler. Adding this in
1657
+ # for older Ruby versions.
1658
+ unless :+.respond_to?(:name)
1659
+ using Module.new {
1660
+ refine Symbol do
1661
+ def name
1662
+ to_s.freeze
1663
+ end
1664
+ end
1665
+ }
1666
+ end
1667
+
1654
1668
  # [untyped] the left-hand side of the expression
1655
1669
  attr_reader :left
1656
1670
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SyntaxTree
4
- VERSION = "4.0.0"
4
+ VERSION = "4.0.2"
5
5
  end
@@ -44,8 +44,12 @@ module SyntaxTree
44
44
  with_new_environment { super }
45
45
  end
46
46
 
47
+ # When we find a method invocation with a block, only the code that happens
48
+ # inside of the block needs a fresh environment. The method invocation
49
+ # itself happens in the same environment
47
50
  def visit_method_add_block(node)
48
- with_new_environment { super }
51
+ visit(node.call)
52
+ with_new_environment { visit(node.block) }
49
53
  end
50
54
 
51
55
  def visit_def(node)
@@ -63,20 +67,18 @@ module SyntaxTree
63
67
  # Visit for keeping track of local arguments, such as method and block
64
68
  # arguments
65
69
  def visit_params(node)
66
- node.requireds.each do |param|
67
- @current_environment.add_local_definition(param, :argument)
68
- end
70
+ add_argument_definitions(node.requireds)
69
71
 
70
72
  node.posts.each do |param|
71
- @current_environment.add_local_definition(param, :argument)
73
+ current_environment.add_local_definition(param, :argument)
72
74
  end
73
75
 
74
76
  node.keywords.each do |param|
75
- @current_environment.add_local_definition(param.first, :argument)
77
+ current_environment.add_local_definition(param.first, :argument)
76
78
  end
77
79
 
78
80
  node.optionals.each do |param|
79
- @current_environment.add_local_definition(param.first, :argument)
81
+ current_environment.add_local_definition(param.first, :argument)
80
82
  end
81
83
 
82
84
  super
@@ -84,21 +86,21 @@ module SyntaxTree
84
86
 
85
87
  def visit_rest_param(node)
86
88
  name = node.name
87
- @current_environment.add_local_definition(name, :argument) if name
89
+ current_environment.add_local_definition(name, :argument) if name
88
90
 
89
91
  super
90
92
  end
91
93
 
92
94
  def visit_kwrest_param(node)
93
95
  name = node.name
94
- @current_environment.add_local_definition(name, :argument) if name
96
+ current_environment.add_local_definition(name, :argument) if name
95
97
 
96
98
  super
97
99
  end
98
100
 
99
101
  def visit_blockarg(node)
100
102
  name = node.name
101
- @current_environment.add_local_definition(name, :argument) if name
103
+ current_environment.add_local_definition(name, :argument) if name
102
104
 
103
105
  super
104
106
  end
@@ -108,7 +110,7 @@ module SyntaxTree
108
110
  value = node.value
109
111
 
110
112
  if value.is_a?(SyntaxTree::Ident)
111
- @current_environment.add_local_definition(value, :variable)
113
+ current_environment.add_local_definition(value, :variable)
112
114
  end
113
115
 
114
116
  super
@@ -117,25 +119,30 @@ module SyntaxTree
117
119
  alias visit_pinned_var_ref visit_var_field
118
120
 
119
121
  # Visits for keeping track of variable and argument usages
120
- def visit_aref_field(node)
121
- name = node.collection.value
122
- @current_environment.add_local_usage(name, :variable) if name
123
-
124
- super
125
- end
126
-
127
122
  def visit_var_ref(node)
128
123
  value = node.value
129
124
 
130
125
  if value.is_a?(SyntaxTree::Ident)
131
- definition = @current_environment.find_local(value.value)
126
+ definition = current_environment.find_local(value.value)
132
127
 
133
128
  if definition
134
- @current_environment.add_local_usage(value, definition.type)
129
+ current_environment.add_local_usage(value, definition.type)
135
130
  end
136
131
  end
137
132
 
138
133
  super
139
134
  end
135
+
136
+ private
137
+
138
+ def add_argument_definitions(list)
139
+ list.each do |param|
140
+ if param.is_a?(SyntaxTree::MLHSParen)
141
+ add_argument_definitions(param.contents.parts)
142
+ else
143
+ current_environment.add_local_definition(param, :argument)
144
+ end
145
+ end
146
+ end
140
147
  end
141
148
  end
data/lib/syntax_tree.rb CHANGED
@@ -22,16 +22,6 @@ require_relative "syntax_tree/visitor/with_environment"
22
22
 
23
23
  require_relative "syntax_tree/parser"
24
24
 
25
- # We rely on Symbol#name being available, which is only available in Ruby 3.0+.
26
- # In case we're running on an older Ruby version, we polyfill it here.
27
- unless :+.respond_to?(:name)
28
- class Symbol # rubocop:disable Style/Documentation
29
- def name
30
- to_s.freeze
31
- end
32
- end
33
- end
34
-
35
25
  # Syntax Tree is a suite of tools built on top of the internal CRuby parser. It
36
26
  # provides the ability to generate a syntax tree from source, as well as the
37
27
  # tools necessary to inspect and manipulate that syntax tree. It can be used to
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.0"
28
+ spec.add_dependency "prettier_print", ">= 1.0.2"
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.0.0
4
+ version: 4.0.2
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-17 00:00:00.000000000 Z
11
+ date: 2022-10-19 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.0
19
+ version: 1.0.2
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.0
26
+ version: 1.0.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement