sirop 0.7 → 0.8

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: 0aa1bac2ed98532aeed671c846e23c49d64a0df0c838f908d345aff6b3eb20db
4
- data.tar.gz: 0efe8bb07a5f691e60978b8a523891808dd849c2b05d62aa28fad1b5b46045ed
3
+ metadata.gz: a44ab3d216adc8e5bda83ca86fef998d8c059ac7f62b3ab4c4b1688be65a24a6
4
+ data.tar.gz: 8c4b7b1aa49f6e293ca2f161ade3f8c1b14ad386644e7abc713eefc7798bcbd7
5
5
  SHA512:
6
- metadata.gz: c92e0f7c2cf5c4452e4af50b5b1e99786eb8d2453668020c5a9fe2d955f242562e96d068b23fee50a304bc02f446e903c43ec8bb720cff0a681a648e6528f7d4
7
- data.tar.gz: daf7af4d543398a0e34d4e0521737d179ed120530921c5b560148bbe806e3f38d8b7c12b9d2e3c0665eed26560f46106e80e23751fd0258c354df9d4fa7b1354
6
+ metadata.gz: 5cfbd57a4e23be3fb959462f6c76aaf1af3e2810c80b81560772965d39654d7975a6aeb7f2441f0c33b9811c898f005ac89eb163ed4215099df7b47abc60e2ca
7
+ data.tar.gz: 8c778dee6a5a416438e37972684ee6cd12d8b8332c4422b099c913b14425d3acb6c63f092f7e8433277f409807724f70fe267e6b7e08d5f21b9367d682d69b3e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.8 2025-08-06
2
+
3
+ - Add source map generation
4
+ - Require Ruby 3.4 or higher
5
+
1
6
  # 0.7 2025-07-24
2
7
 
3
8
  - Add minimize_whitespace option to `Sourcifier#initialize`
@@ -98,10 +98,19 @@ module Sirop
98
98
 
99
99
  def to_source(node)
100
100
  @buffer.clear
101
+ @source_map = nil
101
102
  visit(node)
102
103
  @buffer
103
104
  end
104
105
 
106
+ def to_source_with_source_map(obj, node, line_ofs)
107
+ @buffer.clear
108
+ @source_map_line_ofs = line_ofs
109
+ @source_map = { source_fn: obj.source_location.first }
110
+ visit(node)
111
+ [@buffer, @source_map]
112
+ end
113
+
105
114
  def loc_start(loc)
106
115
  [loc.start_line, loc.start_column]
107
116
  end
@@ -111,9 +120,18 @@ module Sirop
111
120
  end
112
121
 
113
122
  def emit(str)
123
+ update_source_map
114
124
  @buffer << str
115
125
  end
116
126
 
127
+ def update_source_map
128
+ return if !@source_map
129
+
130
+ buffer_cur_line = @buffer.count("\n") + 1
131
+ orig_source_cur_line = @last_loc_start ? @last_loc_start.first : 1
132
+ @source_map[buffer_cur_line] ||= orig_source_cur_line
133
+ end
134
+
117
135
  def adjust_whitespace(loc)
118
136
  return if loc.is_a?(Sirop::Injection)
119
137
 
data/lib/sirop/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Sirop
2
2
  # Sirop version
3
- VERSION = '0.7'
3
+ VERSION = '0.8'
4
4
  end
data/lib/sirop.rb CHANGED
@@ -27,6 +27,11 @@ module Sirop
27
27
  Sourcifier.new(**).to_source(obj)
28
28
  end
29
29
 
30
+ def to_source_with_source_map(obj, line_ofs = 0, **)
31
+ ast = to_ast(obj)
32
+ Sourcifier.new(**).to_source_with_source_map(obj, ast, line_ofs)
33
+ end
34
+
30
35
  private
31
36
 
32
37
  def proc_ast(proc)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sirop
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.7'
4
+ version: '0.8'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  requirements: []
79
- rubygems_version: 3.6.8
79
+ rubygems_version: 3.6.9
80
80
  specification_version: 4
81
81
  summary: 'Sirop: Ruby code rewriter'
82
82
  test_files: []