synvert-core 1.22.0 → 1.22.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 +4 -4
- data/CHANGELOG.md +11 -0
- data/Gemfile.lock +3 -5
- data/lib/synvert/core/engine/erb.rb +9 -3
- data/lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb +8 -2
- data/lib/synvert/core/rewriter/instance.rb +5 -3
- data/lib/synvert/core/version.rb +1 -1
- data/lib/synvert/core.rb +0 -1
- data/spec/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action_spec.rb +25 -4
- data/spec/synvert/core/rewriter/instance_spec.rb +12 -7
- data/synvert-core-ruby.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 125adb6c7e7a82a3b03fa233fa0d43f9beabd1c46eb620323297689e7f47826f
|
4
|
+
data.tar.gz: 96118a021ba37a5723bc284b75163f7e897dc23b57d9bcc62c8203f0de9c6dbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b1bd83e3d44bd056afb750005d27e3f03627f203c3d426ca7a1aca67343edb3184e46e32333532cbc0d953fd6ec56ed07985194cf6e7bf6cc3deeed20e7a91f
|
7
|
+
data.tar.gz: 70cd42406792039a01298a47fbd53451de86f66d955da83174d7ee81ae271c89e8a7e98c9a317c097eddf7cac837afa15206fdfdf6b499c623b6fb721fbe2f9f
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 1.22.2 (2023-03-31)
|
4
|
+
|
5
|
+
* Do not replace white space characters in erb engine
|
6
|
+
* Check erb source in `ReplaceErbStmtWithExprAction`
|
7
|
+
* Update `node_mutation` to 1.13.1
|
8
|
+
|
9
|
+
## 1.22.1 (2023-03-31)
|
10
|
+
|
11
|
+
* Fix indent when `insert_after` or `insert_before` to a child node
|
12
|
+
* Update `node_mutation` to 1.13.0
|
13
|
+
|
3
14
|
## 1.22.0 (2023-03-24)
|
4
15
|
|
5
16
|
* Add `and_comma` option to `insert`, `insert_before`, `insert_after` api
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
synvert-core (1.22.
|
4
|
+
synvert-core (1.22.2)
|
5
5
|
activesupport (< 7.0.0)
|
6
|
-
node_mutation (>= 1.
|
6
|
+
node_mutation (>= 1.13.1)
|
7
7
|
node_query (>= 1.12.0)
|
8
8
|
parallel
|
9
9
|
parser
|
@@ -22,7 +22,6 @@ GEM
|
|
22
22
|
coderay (1.1.3)
|
23
23
|
concurrent-ruby (1.2.2)
|
24
24
|
diff-lcs (1.5.0)
|
25
|
-
erubis (2.7.0)
|
26
25
|
fakefs (2.4.0)
|
27
26
|
ffi (1.15.5)
|
28
27
|
formatador (1.1.0)
|
@@ -49,8 +48,7 @@ GEM
|
|
49
48
|
method_source (1.0.0)
|
50
49
|
minitest (5.18.0)
|
51
50
|
nenv (0.3.0)
|
52
|
-
node_mutation (1.
|
53
|
-
erubis
|
51
|
+
node_mutation (1.13.1)
|
54
52
|
node_query (1.12.0)
|
55
53
|
notiffany (0.1.3)
|
56
54
|
nenv (~> 0.1)
|
@@ -9,9 +9,15 @@ module Synvert::Core
|
|
9
9
|
# @param source [String] erb code.
|
10
10
|
# @return [String] encoded ruby code.
|
11
11
|
def encode(source)
|
12
|
-
source.gsub(/%>.*?<%=?/m) { |str|
|
13
|
-
.sub(/^.*?<%=?/m) { |str|
|
14
|
-
.sub(/%>.*?$/m) { |str|
|
12
|
+
source.gsub(/%>.*?<%=?/m) { |str| replace_all_code_but_white_space_characters(str) }
|
13
|
+
.sub(/^.*?<%=?/m) { |str| replace_all_code_but_white_space_characters(str) }
|
14
|
+
.sub(/%>.*?$/m) { |str| replace_all_code_but_white_space_characters(str) }
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def replace_all_code_but_white_space_characters(source)
|
20
|
+
source.gsub(/\S/, ' ')
|
15
21
|
end
|
16
22
|
end
|
17
23
|
end
|
@@ -8,8 +8,9 @@ module Synvert::Core
|
|
8
8
|
# Initialize a ReplaceErbStmtWithExprAction.
|
9
9
|
#
|
10
10
|
# @param node [Synvert::Core::Rewriter::Node]
|
11
|
-
def initialize(node)
|
11
|
+
def initialize(node, erb_source)
|
12
12
|
super(node, nil)
|
13
|
+
@erb_source = erb_source
|
13
14
|
end
|
14
15
|
|
15
16
|
# The new erb expr code.
|
@@ -23,7 +24,12 @@ module Synvert::Core
|
|
23
24
|
|
24
25
|
# Calculate the begin the end positions.
|
25
26
|
def calculate_position
|
26
|
-
@start = NodeMutation.adapter.get_start(@node)
|
27
|
+
@start = NodeMutation.adapter.get_start(@node)
|
28
|
+
loop do
|
29
|
+
@start -= 1
|
30
|
+
break if @erb_source[@start] == '%'
|
31
|
+
end
|
32
|
+
@start += 1
|
27
33
|
@end = @start
|
28
34
|
end
|
29
35
|
end
|
@@ -268,7 +268,7 @@ module Synvert::Core
|
|
268
268
|
# @param to [String] where to insert, if it is nil, will insert to current node.
|
269
269
|
# @param and_comma [Boolean] insert extra comma.
|
270
270
|
def insert_after(code, to: nil, and_comma: false)
|
271
|
-
column = ' ' * NodeMutation.adapter.get_start_loc(@current_node).column
|
271
|
+
column = ' ' * NodeMutation.adapter.get_start_loc(@current_node, to).column
|
272
272
|
@current_mutation.insert(@current_node, "\n#{column}#{code}", at: 'end', to: to, and_comma: and_comma)
|
273
273
|
end
|
274
274
|
|
@@ -285,7 +285,7 @@ module Synvert::Core
|
|
285
285
|
# @param to [String] where to insert, if it is nil, will insert to current node.
|
286
286
|
# @param and_comma [Boolean] insert extra comma.
|
287
287
|
def insert_before(code, to: nil, and_comma: false)
|
288
|
-
column = ' ' * NodeMutation.adapter.get_start_loc(@current_node).column
|
288
|
+
column = ' ' * NodeMutation.adapter.get_start_loc(@current_node, to).column
|
289
289
|
@current_mutation.insert(@current_node, "#{code}\n#{column}", at: 'beginning', to: to, and_comma: and_comma)
|
290
290
|
end
|
291
291
|
|
@@ -300,7 +300,9 @@ module Synvert::Core
|
|
300
300
|
# replace_erb_stmt_with_expr
|
301
301
|
# end
|
302
302
|
def replace_erb_stmt_with_expr
|
303
|
-
|
303
|
+
absolute_file_path = File.join(Configuration.root_path, @file_path)
|
304
|
+
erb_source = read_source(absolute_file_path)
|
305
|
+
action = Rewriter::ReplaceErbStmtWithExprAction.new(@current_node, erb_source)
|
304
306
|
add_action(action)
|
305
307
|
end
|
306
308
|
|
data/lib/synvert/core/version.rb
CHANGED
data/lib/synvert/core.rb
CHANGED
@@ -4,12 +4,33 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
module Synvert::Core
|
6
6
|
RSpec.describe Rewriter::ReplaceErbStmtWithExprAction do
|
7
|
-
context 'replace with
|
7
|
+
context 'replace with whitespace' do
|
8
8
|
subject {
|
9
|
-
|
10
|
-
source = Engine::Erb.encode(
|
9
|
+
erb_source = "<% form_for post do |f| %>\n<% end %>"
|
10
|
+
source = Engine::Erb.encode(erb_source)
|
11
11
|
node = Parser::CurrentRuby.parse(source).children.first
|
12
|
-
described_class.new(node).process
|
12
|
+
described_class.new(node, erb_source).process
|
13
|
+
}
|
14
|
+
|
15
|
+
it 'gets start' do
|
16
|
+
expect(subject.start).to eq '<%'.length
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'gets end' do
|
20
|
+
expect(subject.end).to eq '<%'.length
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'gets new_code' do
|
24
|
+
expect(subject.new_code).to eq '='
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'replace without whitespace' do
|
29
|
+
subject {
|
30
|
+
erb_source = "<%form_for post do |f|%>\n<%end%>"
|
31
|
+
source = Engine::Erb.encode(erb_source)
|
32
|
+
node = Parser::CurrentRuby.parse(source).children.first
|
33
|
+
described_class.new(node, erb_source).process
|
13
34
|
}
|
14
35
|
|
15
36
|
it 'gets start' do
|
@@ -155,10 +155,10 @@ module Synvert::Core
|
|
155
155
|
instance.current_node,
|
156
156
|
"\n Foobar",
|
157
157
|
at: 'end',
|
158
|
-
to:
|
158
|
+
to: 'caller',
|
159
159
|
and_comma: false
|
160
160
|
)
|
161
|
-
instance.insert_after 'Foobar'
|
161
|
+
instance.insert_after 'Foobar', to: 'caller'
|
162
162
|
end
|
163
163
|
|
164
164
|
it 'parses insert_before' do
|
@@ -169,18 +169,23 @@ module Synvert::Core
|
|
169
169
|
instance.current_node,
|
170
170
|
"Foobar\n ",
|
171
171
|
at: 'beginning',
|
172
|
-
to:
|
172
|
+
to: 'caller',
|
173
173
|
and_comma: false
|
174
174
|
)
|
175
|
-
instance.insert_before 'Foobar'
|
175
|
+
instance.insert_before 'Foobar', to: 'caller'
|
176
176
|
end
|
177
177
|
|
178
178
|
it 'parses replace_erb_stmt_with_expr' do
|
179
179
|
instance.instance_variable_set(:@current_mutation, double)
|
180
180
|
instance.current_node = double
|
181
181
|
action = double
|
182
|
+
erb_source = '<% form_for @post do |f| %><% end %>'
|
183
|
+
allow(File).to receive(:read).and_return(erb_source)
|
182
184
|
expect(instance.instance_variable_get(:@current_mutation)).to receive(:actions).and_return([])
|
183
|
-
expect(Rewriter::ReplaceErbStmtWithExprAction).to receive(:new).with(
|
185
|
+
expect(Rewriter::ReplaceErbStmtWithExprAction).to receive(:new).with(
|
186
|
+
instance.current_node,
|
187
|
+
erb_source
|
188
|
+
).and_return(action)
|
184
189
|
expect(action).to receive(:process)
|
185
190
|
instance.replace_erb_stmt_with_expr
|
186
191
|
end
|
@@ -356,7 +361,7 @@ module Synvert::Core
|
|
356
361
|
<%= form_for @post do |f| %>
|
357
362
|
<% end %>
|
358
363
|
EOS
|
359
|
-
|
364
|
+
allow(File).to receive(:read).with('./app/views/posts/_form.html.erb', encoding: 'UTF-8').and_return(input)
|
360
365
|
expect(File).to receive(:write).with('./app/views/posts/_form.html.erb', output)
|
361
366
|
instance.process
|
362
367
|
end
|
@@ -419,7 +424,7 @@ module Synvert::Core
|
|
419
424
|
<% form_for @post do |f| %>
|
420
425
|
<% end %>
|
421
426
|
EOS
|
422
|
-
|
427
|
+
allow(File).to receive(:read).with('./app/views/posts/_form.html.erb', encoding: 'UTF-8').and_return(input)
|
423
428
|
result = instance.test
|
424
429
|
expect(result.file_path).to eq 'app/views/posts/_form.html.erb'
|
425
430
|
expect(result.actions).to eq [NodeMutation::Struct::Action.new(2, 2, '=')]
|
data/synvert-core-ruby.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.add_runtime_dependency "activesupport", "< 7.0.0"
|
23
23
|
spec.add_runtime_dependency "node_query", ">= 1.12.0"
|
24
|
-
spec.add_runtime_dependency "node_mutation", ">= 1.
|
24
|
+
spec.add_runtime_dependency "node_mutation", ">= 1.13.1"
|
25
25
|
spec.add_runtime_dependency "parser"
|
26
26
|
spec.add_runtime_dependency "parser_node_ext", ">= 1.0.0"
|
27
27
|
spec.add_runtime_dependency "parallel"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: synvert-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.22.
|
4
|
+
version: 1.22.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.
|
47
|
+
version: 1.13.1
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 1.
|
54
|
+
version: 1.13.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: parser
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|