synvert-core 1.25.0 → 1.26.1
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 +12 -0
- data/Gemfile.lock +7 -7
- data/README.md +1 -0
- data/lib/synvert/core/engine/erb.rb +2 -2
- data/lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb +1 -0
- data/lib/synvert/core/rewriter/instance.rb +14 -0
- data/lib/synvert/core/rewriter.rb +17 -1
- data/lib/synvert/core/version.rb +1 -1
- data/spec/synvert/core/engine/haml_spec.rb +3 -3
- data/spec/synvert/core/engine/slim_spec.rb +3 -3
- data/spec/synvert/core/rewriter/instance_spec.rb +17 -5
- data/spec/synvert/core/rewriter_spec.rb +28 -1
- 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: 76425d306537f25b4323935112165ad6bbc02714793e39d7287ee97b884f2284
|
4
|
+
data.tar.gz: 276cb3ec3ee5685b3233b51105ac1de4233927f3e7bcd89bac01e5d761aa5869
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0e36b19d07fb73b93898b48833e5419e1f5e258da0c9660cf8584efdb142e6d4495a9a47105884ba558b6f2a2070c83eebfe54aee22f64d5eb4cfd3a3c712e8
|
7
|
+
data.tar.gz: 6058cc41e9ac61a497d1ddb0f8cb642a48797d67ace1a0e7d513fbae1cce9a7fa50d4a35162caf3e396e0630f5ac394bd63d0a75a83f0a1012a7ef9d8b4a18fc
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 1.26.1 (2023-05-06)
|
4
|
+
|
5
|
+
* Compact test results
|
6
|
+
* Fix erb regex
|
7
|
+
|
8
|
+
## 1.26.0 (2023-04-18)
|
9
|
+
|
10
|
+
* `add_file` and `remove_file` work for test
|
11
|
+
* Add `indent` dsl
|
12
|
+
* Add `type` to Action
|
13
|
+
* Update `node_mutation` to 1.15.3
|
14
|
+
|
3
15
|
## 1.25.0 (2023-04-17)
|
4
16
|
|
5
17
|
* Update `wrap` dsl
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
synvert-core (1.
|
4
|
+
synvert-core (1.26.1)
|
5
5
|
activesupport (< 7.0.0)
|
6
|
-
node_mutation (>= 1.15.
|
6
|
+
node_mutation (>= 1.15.3)
|
7
7
|
node_query (>= 1.12.1)
|
8
8
|
parallel
|
9
9
|
parser
|
@@ -39,7 +39,7 @@ GEM
|
|
39
39
|
guard (~> 2.1)
|
40
40
|
guard-compat (~> 1.1)
|
41
41
|
rspec (>= 2.99.0, < 4.0)
|
42
|
-
i18n (1.
|
42
|
+
i18n (1.13.0)
|
43
43
|
concurrent-ruby (~> 1.0)
|
44
44
|
listen (3.7.1)
|
45
45
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
@@ -48,13 +48,13 @@ GEM
|
|
48
48
|
method_source (1.0.0)
|
49
49
|
minitest (5.18.0)
|
50
50
|
nenv (0.3.0)
|
51
|
-
node_mutation (1.15.
|
51
|
+
node_mutation (1.15.3)
|
52
52
|
node_query (1.12.1)
|
53
53
|
notiffany (0.1.3)
|
54
54
|
nenv (~> 0.1)
|
55
55
|
shellany (~> 0.0)
|
56
|
-
parallel (1.
|
57
|
-
parser (3.2.2.
|
56
|
+
parallel (1.23.0)
|
57
|
+
parser (3.2.2.1)
|
58
58
|
ast (~> 2.4.1)
|
59
59
|
parser_node_ext (1.0.0)
|
60
60
|
parser
|
@@ -82,7 +82,7 @@ GEM
|
|
82
82
|
thor (1.2.1)
|
83
83
|
tzinfo (2.0.6)
|
84
84
|
concurrent-ruby (~> 1.0)
|
85
|
-
zeitwerk (2.6.
|
85
|
+
zeitwerk (2.6.8)
|
86
86
|
|
87
87
|
PLATFORMS
|
88
88
|
ruby
|
data/README.md
CHANGED
@@ -88,6 +88,7 @@ Actions:
|
|
88
88
|
|
89
89
|
* [append](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#append-instance_method) - append the code to the bottom of current node body
|
90
90
|
* [prepend](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#prepend-instance_method) - prepend the code to the bottom of current node body
|
91
|
+
* [indent](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#indent-instance_method) - indent code
|
91
92
|
* [insert](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#insert-instance_method) - insert code
|
92
93
|
* [insert_after](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#insert_after-instance_method) - insert the code next to the current node
|
93
94
|
* [insert_before](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#insert_before-instance_method) - insert the code previous to the current node
|
@@ -10,8 +10,8 @@ module Synvert::Core
|
|
10
10
|
# @return [String] encoded ruby code.
|
11
11
|
def encode(source)
|
12
12
|
source.gsub(/%>.*?<%=?/m) { |str| ';' + replace_all_code_but_white_space_characters(str[1..-1]) }
|
13
|
-
.sub(
|
14
|
-
.sub(
|
13
|
+
.sub(/^.*<%=?/m) { |str| replace_all_code_but_white_space_characters(str) }
|
14
|
+
.sub(/%>.*$/m) { |str| ';' + replace_all_code_but_white_space_characters(str[1..-1]) }
|
15
15
|
end
|
16
16
|
|
17
17
|
# Generate an empty proc.
|
@@ -381,6 +381,20 @@ module Synvert::Core
|
|
381
381
|
@current_mutation.wrap(@current_node, prefix: prefix, suffix: suffix, newline: newline)
|
382
382
|
end
|
383
383
|
|
384
|
+
# It indent the code of current node.
|
385
|
+
# @example
|
386
|
+
# # class Foobar
|
387
|
+
# # end
|
388
|
+
# # =>
|
389
|
+
# # class Foobar
|
390
|
+
# # end
|
391
|
+
# within_node type: 'class' do
|
392
|
+
# indent
|
393
|
+
# end
|
394
|
+
def indent(tab_size: 1)
|
395
|
+
@current_mutation.indent(@current_node, tab_size: tab_size)
|
396
|
+
end
|
397
|
+
|
384
398
|
# No operation.
|
385
399
|
def noop
|
386
400
|
@current_mutation.noop(@current_node)
|
@@ -264,6 +264,14 @@ module Synvert::Core
|
|
264
264
|
def add_file(filename, content)
|
265
265
|
return unless @options[:run_instance]
|
266
266
|
|
267
|
+
unless @options[:write_to_file]
|
268
|
+
result = NodeMutation::Result.new(affected: true, conflicted: false)
|
269
|
+
result.actions = [NodeMutation::Struct::Action.new(:add_file, 0, 0, content)]
|
270
|
+
result.file_path = filename
|
271
|
+
@test_results << result
|
272
|
+
return
|
273
|
+
end
|
274
|
+
|
267
275
|
filepath = File.join(Configuration.root_path, filename)
|
268
276
|
if File.exist?(filepath)
|
269
277
|
puts "File #{filepath} already exists."
|
@@ -283,6 +291,14 @@ module Synvert::Core
|
|
283
291
|
def remove_file(filename)
|
284
292
|
return unless @options[:run_instance]
|
285
293
|
|
294
|
+
unless @options[:write_to_file]
|
295
|
+
result = NodeMutation::Result.new(affected: true, conflicted: false)
|
296
|
+
result.actions = [NodeMutation::Struct::Action.new(:remove_file, 0, -1)]
|
297
|
+
result.file_path = filename
|
298
|
+
@test_results << result
|
299
|
+
return
|
300
|
+
end
|
301
|
+
|
286
302
|
file_path = File.join(Configuration.root_path, filename)
|
287
303
|
File.delete(file_path) if File.exist?(file_path)
|
288
304
|
end
|
@@ -367,7 +383,7 @@ module Synvert::Core
|
|
367
383
|
end
|
368
384
|
|
369
385
|
def merge_test_results(results)
|
370
|
-
@test_results += results.select { |result| result.affected? }
|
386
|
+
@test_results += results.compact.select { |result| result.affected? }
|
371
387
|
end
|
372
388
|
end
|
373
389
|
end
|
data/lib/synvert/core/version.rb
CHANGED
@@ -217,11 +217,11 @@ module Synvert::Core
|
|
217
217
|
EOS
|
218
218
|
proc = Engine::Haml.generate_transform_proc(encoded_source)
|
219
219
|
actions = [
|
220
|
-
NodeMutation::Struct::Action.new(50, 55, ''),
|
220
|
+
NodeMutation::Struct::Action.new(:delete, 50, 55, ''),
|
221
221
|
# first end position is 69
|
222
|
-
NodeMutation::Struct::Action.new(100, 105, ''),
|
222
|
+
NodeMutation::Struct::Action.new(:delete, 100, 105, ''),
|
223
223
|
# second end position is 111
|
224
|
-
NodeMutation::Struct::Action.new(120, 125, '')
|
224
|
+
NodeMutation::Struct::Action.new(:delete, 120, 125, '')
|
225
225
|
]
|
226
226
|
proc.call(actions)
|
227
227
|
expect(actions.first.start).to eq 50
|
@@ -204,11 +204,11 @@ module Synvert::Core
|
|
204
204
|
EOS
|
205
205
|
proc = Engine::Slim.generate_transform_proc(encoded_source)
|
206
206
|
actions = [
|
207
|
-
NodeMutation::Struct::Action.new(50, 55, ''),
|
207
|
+
NodeMutation::Struct::Action.new(:delete, 50, 55, ''),
|
208
208
|
# first end position is 69
|
209
|
-
NodeMutation::Struct::Action.new(100, 105, ''),
|
209
|
+
NodeMutation::Struct::Action.new(:delete, 100, 105, ''),
|
210
210
|
# second end position is 111
|
211
|
-
NodeMutation::Struct::Action.new(120, 125, '')
|
211
|
+
NodeMutation::Struct::Action.new(:delete, 120, 125, '')
|
212
212
|
]
|
213
213
|
proc.call(actions)
|
214
214
|
expect(actions.first.start).to eq 50
|
@@ -245,6 +245,16 @@ module Synvert::Core
|
|
245
245
|
instance.wrap prefix: 'module Foobar', suffix: 'end', newline: true
|
246
246
|
end
|
247
247
|
|
248
|
+
it 'parses indent' do
|
249
|
+
instance.instance_variable_set(:@current_mutation, double)
|
250
|
+
instance.current_node = double
|
251
|
+
expect(instance.instance_variable_get(:@current_mutation)).to receive(:indent).with(
|
252
|
+
instance.current_node,
|
253
|
+
tab_size: 1
|
254
|
+
)
|
255
|
+
instance.indent
|
256
|
+
end
|
257
|
+
|
248
258
|
it 'parses noop' do
|
249
259
|
instance.instance_variable_set(:@current_mutation, double)
|
250
260
|
instance.current_node = double
|
@@ -430,8 +440,8 @@ module Synvert::Core
|
|
430
440
|
results = instance.test
|
431
441
|
expect(results.file_path).to eq 'spec/models/post_spec.rb'
|
432
442
|
expect(results.actions).to eq [
|
433
|
-
NodeMutation::Struct::Action.new(35, 59, 'create :user'),
|
434
|
-
NodeMutation::Struct::Action.new(69, 105, 'create :post, user: user')
|
443
|
+
NodeMutation::Struct::Action.new(:replace, 35, 59, 'create :user'),
|
444
|
+
NodeMutation::Struct::Action.new(:replace, 69, 105, 'create :post, user: user')
|
435
445
|
]
|
436
446
|
end
|
437
447
|
|
@@ -469,7 +479,7 @@ module Synvert::Core
|
|
469
479
|
allow(File).to receive(:read).with('./app/views/posts/_form.html.erb', encoding: 'UTF-8').and_return(input)
|
470
480
|
result = instance.test
|
471
481
|
expect(result.file_path).to eq 'app/views/posts/_form.html.erb'
|
472
|
-
expect(result.actions).to eq [NodeMutation::Struct::Action.new(2, 2, '=')]
|
482
|
+
expect(result.actions).to eq [NodeMutation::Struct::Action.new(:insert, 2, 2, '=')]
|
473
483
|
end
|
474
484
|
|
475
485
|
it 'updates haml file' do
|
@@ -491,8 +501,9 @@ module Synvert::Core
|
|
491
501
|
result = instance.test
|
492
502
|
expect(result.file_path).to eq 'app/views/posts/_form.html.haml'
|
493
503
|
expect(result.actions).to eq [
|
494
|
-
NodeMutation::Struct::Action.new("= form_for ".length, "= form_for @post".length, 'post'),
|
504
|
+
NodeMutation::Struct::Action.new(:replace, "= form_for ".length, "= form_for @post".length, 'post'),
|
495
505
|
NodeMutation::Struct::Action.new(
|
506
|
+
:replace,
|
496
507
|
"= form_for @post do |f|\n= form_for ".length,
|
497
508
|
"= form_for @post do |f|\n= form_for @post".length,
|
498
509
|
'post'
|
@@ -519,8 +530,9 @@ module Synvert::Core
|
|
519
530
|
result = instance.test
|
520
531
|
expect(result.file_path).to eq 'app/views/posts/_form.html.slim'
|
521
532
|
expect(result.actions).to eq [
|
522
|
-
NodeMutation::Struct::Action.new("= form_for ".length, "= form_for @post".length, 'post'),
|
533
|
+
NodeMutation::Struct::Action.new(:replace, "= form_for ".length, "= form_for @post".length, 'post'),
|
523
534
|
NodeMutation::Struct::Action.new(
|
535
|
+
:replace,
|
524
536
|
"= form_for @post do |f|\n= form_for ".length,
|
525
537
|
"= form_for @post do |f|\n= form_for @post".length,
|
526
538
|
'post'
|
@@ -68,7 +68,7 @@ module Synvert::Core
|
|
68
68
|
expect(results[0].file_path).to eq '/code.rb'
|
69
69
|
expect(results[0].affected?).to be_truthy
|
70
70
|
expect(results[0].conflicted?).to be_falsey
|
71
|
-
expect(results[0].actions).to eq [NodeMutation::Struct::Action.new(6, 12, 'Synvert')]
|
71
|
+
expect(results[0].actions).to eq [NodeMutation::Struct::Action.new(:replace, 6, 12, 'Synvert')]
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
@@ -169,6 +169,18 @@ module Synvert::Core
|
|
169
169
|
rewriter.process_with_sandbox
|
170
170
|
expect(File.exist?('./foo.bar')).to be_falsey
|
171
171
|
end
|
172
|
+
|
173
|
+
it 'returns test result' do
|
174
|
+
rewriter =
|
175
|
+
Rewriter.new 'group', 'rewriter2' do
|
176
|
+
add_file 'foo.bar', 'FooBar'
|
177
|
+
end
|
178
|
+
result = rewriter.test
|
179
|
+
expect(result[0].file_path).to eq 'foo.bar'
|
180
|
+
expect(result[0].affected?).to be_truthy
|
181
|
+
expect(result[0].conflicted?).to be_falsey
|
182
|
+
expect(result[0].actions).to eq [NodeMutation::Struct::Action.new(:add_file, 0, 0, 'FooBar')]
|
183
|
+
end
|
172
184
|
end
|
173
185
|
|
174
186
|
describe 'parses remove_file' do
|
@@ -201,6 +213,21 @@ module Synvert::Core
|
|
201
213
|
expect(File.exist?('./foo.bar')).to be_truthy
|
202
214
|
FileUtils.rm './foo.bar'
|
203
215
|
end
|
216
|
+
|
217
|
+
it 'returns test result' do
|
218
|
+
File.write './foo.bar', 'FooBar'
|
219
|
+
rewriter =
|
220
|
+
Rewriter.new 'group', 'rewriter2' do
|
221
|
+
remove_file 'foo.bar'
|
222
|
+
end
|
223
|
+
result = rewriter.test
|
224
|
+
expect(result[0].file_path).to eq 'foo.bar'
|
225
|
+
expect(result[0].affected?).to be_truthy
|
226
|
+
expect(result[0].conflicted?).to be_falsey
|
227
|
+
expect(result[0].actions).to eq [NodeMutation::Struct::Action.new(:remove_file, 0, -1, nil)]
|
228
|
+
expect(File.exist?('./foo.bar')).to be_truthy
|
229
|
+
FileUtils.rm './foo.bar'
|
230
|
+
end
|
204
231
|
end
|
205
232
|
|
206
233
|
describe 'parses add_snippet' do
|
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.1"
|
24
|
-
spec.add_runtime_dependency "node_mutation", ">= 1.15.
|
24
|
+
spec.add_runtime_dependency "node_mutation", ">= 1.15.3"
|
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.
|
4
|
+
version: 1.26.1
|
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-
|
11
|
+
date: 2023-05-06 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.15.
|
47
|
+
version: 1.15.3
|
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.15.
|
54
|
+
version: 1.15.3
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: parser
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|