mvz-live_ast 2.1.1 → 2.2.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: d2f6177411755421ed4f570258386498d1fb2f1e4215f63e29742047b81140b5
4
- data.tar.gz: 8b963f0d5b60cae5977e22c17e7acedff8fdcfeba9437fa0f5ed4c5b963e64ba
3
+ metadata.gz: 55a4905b0508e1fb40901c7459dba58c4955dd176c37c3d420e105754588707e
4
+ data.tar.gz: 8d1e9426cbb0eb669047fe8e73717012f4c5493b63a8971152c5dfb261bc5959
5
5
  SHA512:
6
- metadata.gz: b6747a62bfcc46aa05ab45612b2b80831936f0b4bce3ba439f1ef0fe5468ddaaa09771e0c9b8f324c5e0ab49048dca50a13186a19c4016f8678b10ed87474841
7
- data.tar.gz: fbf59148663fe10cadfa3bb127c0c4df7c93349b662f72239dbaaf78691fb43e38a812ce9a9d7ea4607b21da4a923671985cb66b867011207401e0b9426adba2
6
+ metadata.gz: 4465fa6540167ff69f472dcba3a881e4ef039795eaaeb2d79e7cb95142de456047fd9b42589779889875bb2ed30508160361a89dc43d91a81c470a76b288345b
7
+ data.tar.gz: 1cc74db8fed7f2a011a142fa44ce86e1e56a082a571b7a66104a5ed2b63f340f3f7ea2a7fe7b8d944a55b92f151818a558d688b497737aa7858cb9076daeb27d
data/CHANGES.rdoc CHANGED
@@ -1,5 +1,16 @@
1
1
  = live_ast Changes
2
2
 
3
+ == Version 2.2.0
4
+
5
+ * Improve error message compatibility for instance_eval filename argument
6
+ * Drop support for Ruby 2.7
7
+ * Fix source location for eval with binding and no location
8
+ * Add support for Ruby 3.2 and 3.3
9
+
10
+ == Version 2.1.2
11
+
12
+ * Raise informative acception for methods defined in the prelude
13
+
3
14
  == Version 2.1.1
4
15
 
5
16
  * Loosen dependency on ruby2ruby
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.3.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 Matijs van Zuijlen. All rights reserved.
387
+ Copyright (c) 2014-2022 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,8 @@ 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
78
+ raise ASTNotFoundError if location.first == "<internal:prelude>"
76
79
 
77
80
  ast = fetch_from_cache(*location)
78
81
  raise MultipleDefinitionsOnSameLineError if ast == :multiple
@@ -108,10 +111,8 @@ module LiveAST
108
111
  return key, cache
109
112
  end
110
113
 
111
- def new_cache_synced(*args)
112
- @mutex.synchronize do
113
- new_cache(*args)
114
- end
114
+ def new_cache_synced(...)
115
+ @mutex.synchronize { new_cache(...) }
115
116
  end
116
117
 
117
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")
@@ -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.1"
4
+ VERSION = "2.2.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mvz-live_ast
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James M. Lawrence
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-10-14 00:00:00.000000000 Z
12
+ date: 2024-01-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ruby2ruby
@@ -74,103 +74,103 @@ dependencies:
74
74
  - !ruby/object:Gem::Version
75
75
  version: '5.0'
76
76
  - !ruby/object:Gem::Dependency
77
- name: rake
77
+ name: minitest-focus
78
78
  requirement: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '13.0'
82
+ version: '1.4'
83
83
  type: :development
84
84
  prerelease: false
85
85
  version_requirements: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '13.0'
89
+ version: '1.4'
90
90
  - !ruby/object:Gem::Dependency
91
- name: rake-manifest
91
+ name: rake
92
92
  requirement: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.2.0
96
+ version: '13.0'
97
97
  type: :development
98
98
  prerelease: false
99
99
  version_requirements: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 0.2.0
103
+ version: '13.0'
104
104
  - !ruby/object:Gem::Dependency
105
- name: rdoc
105
+ name: rake-manifest
106
106
  requirement: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '6.2'
110
+ version: 0.2.0
111
111
  type: :development
112
112
  prerelease: false
113
113
  version_requirements: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '6.2'
117
+ version: 0.2.0
118
118
  - !ruby/object:Gem::Dependency
119
119
  name: rubocop
120
120
  requirement: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '1.25'
124
+ version: '1.51'
125
125
  type: :development
126
126
  prerelease: false
127
127
  version_requirements: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: '1.25'
131
+ version: '1.51'
132
132
  - !ruby/object:Gem::Dependency
133
133
  name: rubocop-minitest
134
134
  requirement: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: 0.22.0
138
+ version: 0.34.2
139
139
  type: :development
140
140
  prerelease: false
141
141
  version_requirements: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: 0.22.0
145
+ version: 0.34.2
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: rubocop-packaging
148
148
  requirement: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: 0.5.0
152
+ version: 0.5.2
153
153
  type: :development
154
154
  prerelease: false
155
155
  version_requirements: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: 0.5.0
159
+ version: 0.5.2
160
160
  - !ruby/object:Gem::Dependency
161
161
  name: rubocop-performance
162
162
  requirement: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: '1.13'
166
+ version: '1.20'
167
167
  type: :development
168
168
  prerelease: false
169
169
  version_requirements: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: '1.13'
173
+ version: '1.20'
174
174
  - !ruby/object:Gem::Dependency
175
175
  name: rubocop-rake
176
176
  requirement: !ruby/object:Gem::Requirement
@@ -242,14 +242,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
242
242
  requirements:
243
243
  - - ">="
244
244
  - !ruby/object:Gem::Version
245
- version: 2.6.0
245
+ version: 3.0.0
246
246
  required_rubygems_version: !ruby/object:Gem::Requirement
247
247
  requirements:
248
248
  - - ">="
249
249
  - !ruby/object:Gem::Version
250
250
  version: '0'
251
251
  requirements: []
252
- rubygems_version: 3.3.7
252
+ rubygems_version: 3.5.3
253
253
  signing_key:
254
254
  specification_version: 4
255
255
  summary: Live abstract syntax trees of methods and procs.