mvz-live_ast 2.1.2 → 2.3.0

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: 33748a6b01c44b3b88da1cc0aad7270f7e1fb7670c7f73999dc84f4d97b967df
4
- data.tar.gz: b1754e7fb57d4b55cc02f286865dad014f672d7a62fd022c04a26024b122ecd5
3
+ metadata.gz: ca502ae0e2cbb2e943b0caf4302e2a5c46b4984dbdaf7ef89f6a80bfa466a444
4
+ data.tar.gz: e795adb5aff696f94d85ea03255b565ea470f5cd744cf654cdae8dc410e0a48e
5
5
  SHA512:
6
- metadata.gz: 8a100e55251ed50bd535e2055d8c363d07127a065ad4b993ef00e79229b63f3a8bfce4c616550274381487963280b04f4058f3fa42740767c99de8ce14622a4c
7
- data.tar.gz: 53d0943b4aa6f226ad12ba95973ae2b070d356de7fd7a17fba495886a792368286483e58ec5391f84651534c7e81b14e8bd7a31963dbc4310fc579ff024b0791
6
+ metadata.gz: db874d0f84452171be93d1ac3d609ab3b5cba4c39f4481074cfe231e5d6e47045960b89a7ff88a252da40bf90a5686ba04abf0c50db680276c01d662d473e1c1
7
+ data.tar.gz: 8788a717371b24ba186ed1924d3b85480802bdb0009fcb6ad78f0d945f585d496fb575bc71de6d0bb04e82f992c9aa313462d4e2b5c525463e26fb6e70afa6c2
data/CHANGES.rdoc CHANGED
@@ -1,5 +1,17 @@
1
1
  = live_ast Changes
2
2
 
3
+ == Version 2.3.0
4
+
5
+ * Make load error message match original exactly
6
+ * Support Ruby 3.2 through 3.4, dropping support for Ruby 3.0 and 3.1
7
+
8
+ == Version 2.2.0
9
+
10
+ * Improve error message compatibility for instance_eval filename argument
11
+ * Drop support for Ruby 2.7
12
+ * Fix source location for eval with binding and no location
13
+ * Add support for Ruby 3.2 and 3.3
14
+
3
15
  == Version 2.1.2
4
16
 
5
17
  * Raise informative acception for methods defined in the prelude
data/README.rdoc CHANGED
@@ -80,7 +80,7 @@ sexps used by tools such as <code>ruby2ruby</code>.
80
80
 
81
81
  LiveAST is thread-safe.
82
82
 
83
- Ruby 2.6.0 or higher is required.
83
+ Ruby 2.7.0 or higher is required.
84
84
 
85
85
  == Links
86
86
 
@@ -384,7 +384,7 @@ assumed that the file is unmodified between the moment it is
384
384
  == License
385
385
 
386
386
  Copyright (c) 2011 James M. Lawrence. All rights reserved.
387
- Copyright (c) 2014-2022 Matijs van Zuijlen. All rights reserved.
387
+ Copyright (c) 2014-2025 Matijs van Zuijlen. All rights reserved.
388
388
 
389
389
  Permission is hereby granted, free of charge, to any person
390
390
  obtaining a copy of this software and associated documentation files
@@ -7,7 +7,7 @@ module Kernel
7
7
 
8
8
  # The same as +eval+ except that the binding argument is required
9
9
  # and AST-accessible objects are created.
10
- def ast_eval(*args)
11
- LiveAST::Evaler.eval(args[0], *args)
10
+ def ast_eval(string, bind, filename = nil, lineno = nil)
11
+ LiveAST::Evaler.eval(string, string, bind, filename, lineno)
12
12
  end
13
13
  end
data/lib/live_ast/base.rb CHANGED
@@ -51,8 +51,8 @@ module LiveAST
51
51
  #
52
52
  # Equivalent to <code>Kernel#ast_eval</code>.
53
53
  #
54
- def eval(*args) # :nodoc:
55
- Evaler.eval(args[0], *args)
54
+ def eval(string, bind, filename = nil, lineno = nil) # :nodoc:
55
+ Evaler.eval(string, string, bind, filename, lineno)
56
56
  end
57
57
 
58
58
  #
@@ -7,18 +7,25 @@ module LiveAST
7
7
  def arg_to_str(arg)
8
8
  arg.to_str
9
9
  rescue NameError
10
- thing = arg.nil? ? nil : arg.class
10
+ thing = arg&.class
11
11
 
12
12
  message = "no implicit conversion of #{thing.inspect} into String"
13
13
  raise TypeError, message
14
14
  end
15
15
 
16
16
  def arg_to_str2(arg)
17
+ return "" if arg.nil? && RUBY_VERSION >= "3.3.0"
18
+
17
19
  arg.to_str
18
20
  rescue NameError
19
- thing = arg.nil? ? nil : arg.class
21
+ thing = arg&.class
22
+
23
+ message = if arg.nil?
24
+ "wrong argument type #{thing.inspect} (expected String)"
25
+ else
26
+ "no implicit conversion of #{thing.inspect} into String"
27
+ end
20
28
 
21
- message = "wrong argument type #{thing.inspect} (expected String)"
22
29
  raise TypeError, message
23
30
  end
24
31
 
@@ -38,18 +45,13 @@ module LiveAST
38
45
  raise TypeError, message
39
46
  end
40
47
 
41
- def location_for_eval(*args)
42
- bind, *location = args
43
-
44
- if bind
45
- case location.size
46
- when 0
47
- bind.source_location
48
- when 1
49
- [location.first, 1]
50
- else
51
- location
52
- end
48
+ def location_for_eval(bind, filename = nil, lineno = nil)
49
+ if filename
50
+ lineno ||= 1
51
+ [filename, lineno]
52
+ elsif RUBY_VERSION >= "3.3.0"
53
+ file, line = bind.source_location
54
+ ["(eval at #{file}:#{line})", 1]
53
55
  else
54
56
  ["(eval)", 1]
55
57
  end
@@ -5,10 +5,12 @@ module LiveAST
5
5
  class << self
6
6
  include Common
7
7
 
8
- def eval(parser_source, *args)
9
- evaler_source, bind, *rest = handle_args(*args)
8
+ def eval(parser_source, evaler_source, bind, filename = nil, lineno = nil)
9
+ evaler_source = arg_to_str evaler_source
10
+ check_is_binding bind
11
+ filename = arg_to_str filename if filename
10
12
 
11
- file, line = location_for_eval(bind, *rest)
13
+ file, line = location_for_eval(bind, filename, lineno)
12
14
  file = LiveAST.strip_token(file)
13
15
 
14
16
  key, = Linker.new_cache_synced(parser_source, file, line, false)
@@ -20,15 +22,6 @@ module LiveAST
20
22
  raise e
21
23
  end
22
24
  end
23
-
24
- def handle_args(*args)
25
- args.tap do
26
- check_arity(args, 2..4)
27
- args[0] = arg_to_str(args[0])
28
- check_is_binding(args[1])
29
- args[2] = arg_to_str(args[2]) if args[2]
30
- end
31
- end
32
25
  end
33
26
  end
34
27
  end
@@ -2,8 +2,9 @@
2
2
 
3
3
  module LiveAST
4
4
  class Cache
5
- def initialize(*args)
6
- @source, @user_line = args
5
+ def initialize(file, lineno)
6
+ @source = file
7
+ @user_line = lineno
7
8
  @asts = nil
8
9
  end
9
10
 
@@ -73,6 +74,7 @@ module LiveAST
73
74
  def find_ast(*location)
74
75
  raise ASTNotFoundError unless location.size == 2
75
76
  raise RawEvalError if location.first == "(eval)"
77
+ raise RawEvalError if location.first.match?(/^\(eval at .*\)$/) # Ruby 3.3
76
78
  raise ASTNotFoundError if location.first == "<internal:prelude>"
77
79
 
78
80
  ast = fetch_from_cache(*location)
@@ -109,10 +111,8 @@ module LiveAST
109
111
  return key, cache
110
112
  end
111
113
 
112
- def new_cache_synced(*args)
113
- @mutex.synchronize do
114
- new_cache(*args)
115
- end
114
+ def new_cache_synced(...)
115
+ @mutex.synchronize { new_cache(...) }
116
116
  end
117
117
 
118
118
  def flush_cache
@@ -3,8 +3,8 @@
3
3
 
4
4
  module LiveAST
5
5
  module Reader
6
- UTF8_BOM = /\A\xef\xbb\xbf/.freeze
7
- MAGIC_COMMENT = /\A(?:#!.*?\n)?\s*\#.*(?:en)?coding\s*[:=]\s*([^\s;]+)/.freeze
6
+ UTF8_BOM = /\A\xef\xbb\xbf/
7
+ MAGIC_COMMENT = /\A(?:#!.*?\n)?\s*\#.*(?:en)?coding\s*[:=]\s*([^\s;]+)/
8
8
 
9
9
  def self.read(file)
10
10
  contents = File.read(file, encoding: "BINARY")
@@ -13,8 +13,14 @@ module LiveAST
13
13
 
14
14
  # magic comment overrides BOM
15
15
  encoding = contents[MAGIC_COMMENT, 1] || utf8 || "US-ASCII"
16
+ encoding = strip_special encoding
17
+ begin
18
+ Encoding.find encoding
19
+ rescue ArgumentError
20
+ raise ArgumentError, "unknown encoding name: #{encoding}"
21
+ end
16
22
 
17
- contents.force_encoding(strip_special(encoding))
23
+ contents.force_encoding encoding
18
24
  end
19
25
 
20
26
  def self.strip_special(encoding)
@@ -6,8 +6,9 @@ module Kernel
6
6
  private
7
7
 
8
8
  alias live_ast_original_caller caller
9
- def caller(*args)
10
- c = live_ast_original_caller(*args)
9
+
10
+ def caller(...)
11
+ c = live_ast_original_caller(...)
11
12
  c.shift
12
13
  c.map { |line| LiveAST.strip_token line }
13
14
  end
@@ -53,12 +53,11 @@ module Kernel
53
53
 
54
54
  alias live_ast_original_eval eval
55
55
 
56
- def eval(*args)
57
- LiveAST::Common.check_arity(args, 1..4)
56
+ def eval(string, binding = nil, filename = nil, lineno = nil)
58
57
  LiveAST.eval(
59
- args[0],
60
- args[1] || Binding.of_caller(1),
61
- *LiveAST::Common.location_for_eval(*args[1..3]))
58
+ string,
59
+ binding || Binding.of_caller(1),
60
+ filename, lineno)
62
61
  end
63
62
  end
64
63
 
@@ -66,8 +65,8 @@ end
66
65
  class Binding
67
66
  alias live_ast_original_binding_eval eval
68
67
 
69
- def eval(*args)
70
- LiveAST.eval(args[0], self, *args[1..])
68
+ def eval(string, filename = nil, lineno = nil)
69
+ LiveAST.eval(string, self, filename, lineno)
71
70
  end
72
71
  end
73
72
 
@@ -75,6 +74,8 @@ end
75
74
  class BasicObject
76
75
  alias live_ast_original_instance_eval instance_eval
77
76
 
77
+ # Arity must be handled in code because the first argument is only required
78
+ # if no block is passed.
78
79
  def instance_eval(*args, &block)
79
80
  if block
80
81
  live_ast_original_instance_eval(*args, &block)
@@ -92,6 +93,8 @@ end
92
93
  class Module
93
94
  alias live_ast_original_module_eval module_eval
94
95
 
96
+ # Arity must be handled in code because the first argument is only required
97
+ # if no block is passed.
95
98
  def module_eval(*args, &block)
96
99
  if block
97
100
  live_ast_original_module_eval(*args, &block)
@@ -7,9 +7,9 @@ module Kernel
7
7
 
8
8
  alias live_ast_original_raise raise
9
9
 
10
- def raise(*args)
10
+ def raise(...)
11
11
  ex = begin
12
- live_ast_original_raise(*args)
12
+ live_ast_original_raise(...)
13
13
  rescue Exception => e
14
14
  e
15
15
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LiveAST
4
- VERSION = "2.1.2"
4
+ VERSION = "2.3.0"
5
5
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mvz-live_ast
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James M. Lawrence
8
8
  - Matijs van Zuijlen
9
- autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2022-10-23 00:00:00.000000000 Z
11
+ date: 1980-01-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: ruby2ruby
@@ -74,117 +73,117 @@ dependencies:
74
73
  - !ruby/object:Gem::Version
75
74
  version: '5.0'
76
75
  - !ruby/object:Gem::Dependency
77
- name: rake
76
+ name: minitest-focus
78
77
  requirement: !ruby/object:Gem::Requirement
79
78
  requirements:
80
79
  - - "~>"
81
80
  - !ruby/object:Gem::Version
82
- version: '13.0'
81
+ version: '1.4'
83
82
  type: :development
84
83
  prerelease: false
85
84
  version_requirements: !ruby/object:Gem::Requirement
86
85
  requirements:
87
86
  - - "~>"
88
87
  - !ruby/object:Gem::Version
89
- version: '13.0'
88
+ version: '1.4'
90
89
  - !ruby/object:Gem::Dependency
91
- name: rake-manifest
90
+ name: rake
92
91
  requirement: !ruby/object:Gem::Requirement
93
92
  requirements:
94
93
  - - "~>"
95
94
  - !ruby/object:Gem::Version
96
- version: 0.2.0
95
+ version: '13.0'
97
96
  type: :development
98
97
  prerelease: false
99
98
  version_requirements: !ruby/object:Gem::Requirement
100
99
  requirements:
101
100
  - - "~>"
102
101
  - !ruby/object:Gem::Version
103
- version: 0.2.0
102
+ version: '13.0'
104
103
  - !ruby/object:Gem::Dependency
105
- name: rdoc
104
+ name: rake-manifest
106
105
  requirement: !ruby/object:Gem::Requirement
107
106
  requirements:
108
107
  - - "~>"
109
108
  - !ruby/object:Gem::Version
110
- version: '6.2'
109
+ version: 0.2.0
111
110
  type: :development
112
111
  prerelease: false
113
112
  version_requirements: !ruby/object:Gem::Requirement
114
113
  requirements:
115
114
  - - "~>"
116
115
  - !ruby/object:Gem::Version
117
- version: '6.2'
116
+ version: 0.2.0
118
117
  - !ruby/object:Gem::Dependency
119
118
  name: rubocop
120
119
  requirement: !ruby/object:Gem::Requirement
121
120
  requirements:
122
121
  - - "~>"
123
122
  - !ruby/object:Gem::Version
124
- version: '1.25'
123
+ version: '1.76'
125
124
  type: :development
126
125
  prerelease: false
127
126
  version_requirements: !ruby/object:Gem::Requirement
128
127
  requirements:
129
128
  - - "~>"
130
129
  - !ruby/object:Gem::Version
131
- version: '1.25'
130
+ version: '1.76'
132
131
  - !ruby/object:Gem::Dependency
133
132
  name: rubocop-minitest
134
133
  requirement: !ruby/object:Gem::Requirement
135
134
  requirements:
136
135
  - - "~>"
137
136
  - !ruby/object:Gem::Version
138
- version: 0.22.0
137
+ version: 0.38.0
139
138
  type: :development
140
139
  prerelease: false
141
140
  version_requirements: !ruby/object:Gem::Requirement
142
141
  requirements:
143
142
  - - "~>"
144
143
  - !ruby/object:Gem::Version
145
- version: 0.22.0
144
+ version: 0.38.0
146
145
  - !ruby/object:Gem::Dependency
147
146
  name: rubocop-packaging
148
147
  requirement: !ruby/object:Gem::Requirement
149
148
  requirements:
150
149
  - - "~>"
151
150
  - !ruby/object:Gem::Version
152
- version: 0.5.0
151
+ version: 0.6.0
153
152
  type: :development
154
153
  prerelease: false
155
154
  version_requirements: !ruby/object:Gem::Requirement
156
155
  requirements:
157
156
  - - "~>"
158
157
  - !ruby/object:Gem::Version
159
- version: 0.5.0
158
+ version: 0.6.0
160
159
  - !ruby/object:Gem::Dependency
161
160
  name: rubocop-performance
162
161
  requirement: !ruby/object:Gem::Requirement
163
162
  requirements:
164
163
  - - "~>"
165
164
  - !ruby/object:Gem::Version
166
- version: '1.13'
165
+ version: '1.25'
167
166
  type: :development
168
167
  prerelease: false
169
168
  version_requirements: !ruby/object:Gem::Requirement
170
169
  requirements:
171
170
  - - "~>"
172
171
  - !ruby/object:Gem::Version
173
- version: '1.13'
172
+ version: '1.25'
174
173
  - !ruby/object:Gem::Dependency
175
174
  name: rubocop-rake
176
175
  requirement: !ruby/object:Gem::Requirement
177
176
  requirements:
178
177
  - - "~>"
179
178
  - !ruby/object:Gem::Version
180
- version: 0.6.0
179
+ version: 0.7.1
181
180
  type: :development
182
181
  prerelease: false
183
182
  version_requirements: !ruby/object:Gem::Requirement
184
183
  requirements:
185
184
  - - "~>"
186
185
  - !ruby/object:Gem::Version
187
- version: 0.6.0
186
+ version: 0.7.1
188
187
  description: |2
189
188
  LiveAST enables a program to find the ASTs of objects created by dynamically
190
189
  generated code.
@@ -193,8 +192,8 @@ email:
193
192
  executables: []
194
193
  extensions: []
195
194
  extra_rdoc_files:
196
- - README.rdoc
197
195
  - CHANGES.rdoc
196
+ - README.rdoc
198
197
  files:
199
198
  - CHANGES.rdoc
200
199
  - README.rdoc
@@ -228,7 +227,6 @@ metadata:
228
227
  source_code_uri: https://github.com/mvz/live_ast
229
228
  changelog_uri: https://github.com/mvz/live_ast/blob/master/CHANGES.rdoc
230
229
  rubygems_mfa_required: 'true'
231
- post_install_message:
232
230
  rdoc_options:
233
231
  - "--main"
234
232
  - README.rdoc
@@ -242,15 +240,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
242
240
  requirements:
243
241
  - - ">="
244
242
  - !ruby/object:Gem::Version
245
- version: 2.6.0
243
+ version: 3.2.0
246
244
  required_rubygems_version: !ruby/object:Gem::Requirement
247
245
  requirements:
248
246
  - - ">="
249
247
  - !ruby/object:Gem::Version
250
248
  version: '0'
251
249
  requirements: []
252
- rubygems_version: 3.3.7
253
- signing_key:
250
+ rubygems_version: 3.7.2
254
251
  specification_version: 4
255
252
  summary: Live abstract syntax trees of methods and procs.
256
253
  test_files: []