steadfast 0.0.3 → 0.1.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: c6e3d1e91bd27e7c92b511ef755e05095e691e6489173aded42938aa6ecbdd58
4
- data.tar.gz: 75a299fc9c1b3bfc89e81dbc6e1bfb0085a470b4a239aeffc02b63adefc509ad
3
+ metadata.gz: 92df33342d9993952237fdf8273133ad4a99998e33beeabc456c2d709582a8d3
4
+ data.tar.gz: 95dc43ba5d717aa4c756ebe61e44b104757f2b47e27c53e68751bfc1d4def9c7
5
5
  SHA512:
6
- metadata.gz: 070eb4137ab096dcb11625c593c880952ecbd8150057849608eb8972368f047c66ff8837c0b900072620380d026f2d4043ac928aa8654f504803c683ab2a3c4c
7
- data.tar.gz: 314ca97af4862e20ceab634ac1ebe3e6f72a2eac2c67c933a1df27fa1deb84a35a07a09f044311d13c53f0f4cfbde00bf60d09260a7faa72e4402709e6277153
6
+ metadata.gz: cbf3ee2e52c30ce03b7a25a80301e20a3e853a931e070b56e40564aa08cd662537d000e268c7349f4b7332e85ae378944c39e10e3615ca07a1e2543acd6f6f91
7
+ data.tar.gz: 188670f7bee400928fcbacdcfd177f2f9bc86adcb1b09be673b7d24cf8d479e52209721a00a10f81830f1f28d97dbfb474529f7654c32cc119f725cc6bf01b54
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.1.0 2026-11-23
2
+
3
+ - Improve source mapping, make it work for derivative synthetic ASTs
4
+ - Add automatic source location info in `Steadfast.eval_ast`
5
+
1
6
  # 0.0.3 2026-11-23
2
7
 
3
8
  - Implement `Steadfast.eval_ast`
@@ -49,7 +49,7 @@ module Steadfast
49
49
  n.deconstruct_keys(nil).each do |k, v|
50
50
  if v.is_a?(Ruby::Prism::Node)
51
51
  v2 = visit(v)
52
- changes[k] = v2 if (v2 != v)
52
+ changes[k] = v2 if v2 != v
53
53
  elsif v in [Ruby::Prism::Node, *]
54
54
  v2 = v.map { visit(it) }
55
55
  changes[k] = v2 if v2 != v
@@ -711,7 +711,7 @@ module Steadfast
711
711
  # @return [void]
712
712
  def emit_newline
713
713
  return if @buffer[-1] == "\n"
714
-
714
+
715
715
  @buffer << "\n"
716
716
  @line += 1
717
717
  end
@@ -1,4 +1,4 @@
1
1
  module Steadfast
2
2
  # Steadfast version
3
- VERSION = '0.0.3'
3
+ VERSION = '0.1.0'
4
4
  end
data/lib/steadfast.rb CHANGED
@@ -25,7 +25,7 @@ module Steadfast
25
25
 
26
26
  class << self
27
27
  # Returns the global Steadfast source map hash. Currently *not* thread-safe.
28
- #
28
+ #
29
29
  # @return [Hash] source map
30
30
  def sourcemap
31
31
  @sourcemap ||= {}
@@ -38,14 +38,25 @@ module Steadfast
38
38
  # @return [Array<String>] translated source map
39
39
  def translate_backtrace(bt)
40
40
  bt.map {
41
- if (m = it.match(/^(.+)(\:in.+)$/)) && (loc = sourcemap[m[1]])
42
- "#{sourcemap[m[1]]}#{m[2]}"
41
+ if (m = it.match(/^(.+)(\:in.+)$/)) && (loc = find_sourcemap_entry(m[1]))
42
+ "#{loc}#{m[2]}"
43
43
  else
44
44
  it
45
45
  end
46
46
  }
47
47
  end
48
48
 
49
+ # Returns a mapped location for the given location entry.
50
+ #
51
+ # @param loc [String] location string of the form file:line
52
+ # @return [String, nil] mapped location
53
+ def find_sourcemap_entry(loc)
54
+ loc = sourcemap[loc]
55
+ return nil if !loc
56
+
57
+ (loc =~ /^\(steadfast-[0-9a-f]+\)\:\d+$/) ? find_sourcemap_entry(loc) : loc
58
+ end
59
+
49
60
  # Returns an AST for the given object.
50
61
  #
51
62
  # @param obj [Proc, Method, UnboundedMethod, Ruby::Prism::Node]
@@ -86,14 +97,21 @@ module Steadfast
86
97
  # @param eval_receiver [any]
87
98
  # @param eval_binding [Binding, nil]
88
99
  # @return [any]
89
- def eval_ast(ast, eval_receiver = nil, eval_binding = nil)
100
+ def eval_ast(ast, eval_receiver = nil, eval_binding = nil, source_location: nil)
90
101
  raise ArgumentError, "Not an AST" if !ast.is_a?(Ruby::Prism::Node)
91
-
92
- src = to_source(ast)
102
+
103
+ case source_location
104
+ when nil
105
+ source_location = ["(steadfast-#{SecureRandom.hex(4)})", 1]
106
+ when :caller
107
+ l = caller_locations[0]
108
+ source_location = [l.path, l.lineno]
109
+ end
110
+ src = to_source(ast, source_location:, sourcemap: true)
93
111
  if eval_receiver
94
112
  eval_receiver.instance_eval(src)
95
113
  else
96
- eval(src, eval_binding || binding)
114
+ eval(src, eval_binding || binding, source_location[0], source_location[1])
97
115
  end
98
116
  end
99
117
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: steadfast
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner