synvert-core 1.31.0 → 1.32.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/Gemfile.lock +18 -13
- data/README.md +0 -1
- data/lib/synvert/core/rewriter/instance.rb +16 -2
- data/lib/synvert/core/rewriter.rb +2 -17
- data/lib/synvert/core/utils.rb +2 -2
- data/lib/synvert/core/version.rb +1 -1
- data/lib/synvert/core.rb +1 -0
- data/spec/synvert/core/rewriter_spec.rb +0 -9
- data/synvert-core-ruby.gemspec +6 -4
- metadata +38 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eba97ad9bc0ca05de1f79a1fcfeb5bca602d71117d1ec9bef2e540e0180cffb3
|
4
|
+
data.tar.gz: 92d790d50d7d11c4d726bf16e30de8de4874cfbfec00b1c28043190e888b4e3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 490772f30d18037ad305217bfa7ae5ddce828a8decdecac855c8666a52beb92e23786f1057f3f3528d93005eebe07d15cc550479c7116c8434e6b2f275248125
|
7
|
+
data.tar.gz: 92450dc3df3f69e664e1b95e98c17814a3ad9e1c700c5b73741703abb54fbc96a598f0e5cc4783331355f8fb153dbe08ef41bb098327520e5851724a6a103355
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 1.32.0 (2024-02-11)
|
4
|
+
|
5
|
+
* Support `prism`
|
6
|
+
* Update `node_mutation` to 1.23.0
|
7
|
+
* Update `node_query` to 1.15.0
|
8
|
+
|
9
|
+
## 1.31.1 (2024-01-30)
|
10
|
+
|
11
|
+
* Update `node_mutation` to 1.22.4
|
12
|
+
* Remove `redo_until_no_change` dsl
|
13
|
+
|
3
14
|
## 1.31.0 (2024-01-14)
|
4
15
|
|
5
16
|
* Support `Configuration.test_result` in `add_file` and `remove_file` dsl
|
data/Gemfile.lock
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
synvert-core (1.
|
4
|
+
synvert-core (1.32.0)
|
5
5
|
activesupport (< 7.0.0)
|
6
|
-
node_mutation (>= 1.
|
7
|
-
node_query (>= 1.
|
6
|
+
node_mutation (>= 1.23.0)
|
7
|
+
node_query (>= 1.15.0)
|
8
8
|
parallel
|
9
9
|
parser
|
10
|
-
parser_node_ext (>= 1.2.
|
10
|
+
parser_node_ext (>= 1.2.2)
|
11
|
+
prism
|
12
|
+
prism_ext (>= 0.2.2)
|
11
13
|
syntax_tree
|
12
|
-
syntax_tree_ext (>= 0.
|
14
|
+
syntax_tree_ext (>= 0.7.1)
|
13
15
|
|
14
16
|
GEM
|
15
17
|
remote: https://rubygems.org/
|
@@ -22,7 +24,7 @@ GEM
|
|
22
24
|
zeitwerk (~> 2.3)
|
23
25
|
ast (2.4.2)
|
24
26
|
coderay (1.1.3)
|
25
|
-
concurrent-ruby (1.2.
|
27
|
+
concurrent-ruby (1.2.3)
|
26
28
|
diff-lcs (1.5.0)
|
27
29
|
fakefs (2.4.0)
|
28
30
|
ffi (1.15.5)
|
@@ -48,20 +50,23 @@ GEM
|
|
48
50
|
rb-inotify (~> 0.9, >= 0.9.10)
|
49
51
|
lumberjack (1.2.8)
|
50
52
|
method_source (1.0.0)
|
51
|
-
minitest (5.
|
53
|
+
minitest (5.22.2)
|
52
54
|
nenv (0.3.0)
|
53
|
-
node_mutation (1.
|
54
|
-
node_query (1.
|
55
|
+
node_mutation (1.23.0)
|
56
|
+
node_query (1.15.0)
|
55
57
|
notiffany (0.1.3)
|
56
58
|
nenv (~> 0.1)
|
57
59
|
shellany (~> 0.0)
|
58
60
|
parallel (1.24.0)
|
59
|
-
parser (3.3.0.
|
61
|
+
parser (3.3.0.5)
|
60
62
|
ast (~> 2.4.1)
|
61
63
|
racc
|
62
|
-
parser_node_ext (1.2.
|
64
|
+
parser_node_ext (1.2.2)
|
63
65
|
parser
|
64
66
|
prettier_print (1.2.1)
|
67
|
+
prism (0.22.0)
|
68
|
+
prism_ext (0.2.2)
|
69
|
+
prism
|
65
70
|
pry (0.14.1)
|
66
71
|
coderay (~> 1.1)
|
67
72
|
method_source (~> 1.0)
|
@@ -86,12 +91,12 @@ GEM
|
|
86
91
|
shellany (0.0.1)
|
87
92
|
syntax_tree (6.2.0)
|
88
93
|
prettier_print (>= 1.2.0)
|
89
|
-
syntax_tree_ext (0.
|
94
|
+
syntax_tree_ext (0.7.1)
|
90
95
|
syntax_tree
|
91
96
|
thor (1.2.1)
|
92
97
|
tzinfo (2.0.6)
|
93
98
|
concurrent-ruby (~> 1.0)
|
94
|
-
zeitwerk (2.6.
|
99
|
+
zeitwerk (2.6.13)
|
95
100
|
|
96
101
|
PLATFORMS
|
97
102
|
ruby
|
data/README.md
CHANGED
@@ -70,7 +70,6 @@ DSLs are as follows
|
|
70
70
|
* [helper_method](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#helper_method-instance_method) - define a helper method
|
71
71
|
* [add_snippet](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#add_snippet-instance_method) - call another rewriter
|
72
72
|
* [call_helper](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#call_helper-instance_method) - call a shared rewriter
|
73
|
-
* [redo_until_no_change](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#redo_until_no_change-instance_method) - run the snippet until no change
|
74
73
|
|
75
74
|
Scopes:
|
76
75
|
|
@@ -4,6 +4,8 @@ require 'parser/current'
|
|
4
4
|
require 'parser_node_ext'
|
5
5
|
require 'syntax_tree'
|
6
6
|
require 'syntax_tree_ext'
|
7
|
+
require 'prism'
|
8
|
+
require 'prism_ext'
|
7
9
|
|
8
10
|
module Synvert::Core
|
9
11
|
# Instance is an execution unit, it finds specified ast nodes,
|
@@ -490,8 +492,11 @@ module Synvert::Core
|
|
490
492
|
# @param encoded_source [String] encoded source code
|
491
493
|
# @return [Node] ast node for file
|
492
494
|
def parse_code(file_path, encoded_source)
|
493
|
-
|
495
|
+
case @rewriter.parser
|
496
|
+
when Synvert::SYNTAX_TREE_PARSER
|
494
497
|
parse_code_by_syntax_tree(file_path, encoded_source)
|
498
|
+
when Synvert::PRISM_PARSER
|
499
|
+
parse_code_by_prism(file_path, encoded_source)
|
495
500
|
else
|
496
501
|
parse_code_by_parser(file_path, encoded_source)
|
497
502
|
end
|
@@ -517,7 +522,16 @@ module Synvert::Core
|
|
517
522
|
# @param encoded_source [String] encoded source code
|
518
523
|
# @return [Node] ast node for file
|
519
524
|
def parse_code_by_syntax_tree(_file_path, encoded_source)
|
520
|
-
SyntaxTree
|
525
|
+
SyntaxTree.parse(encoded_source).statements
|
526
|
+
end
|
527
|
+
|
528
|
+
# Parse code ast node by prism.
|
529
|
+
#
|
530
|
+
# @param file_path [String] file path
|
531
|
+
# @param encoded_source [String] encoded source code
|
532
|
+
# @return [Node] ast node for file
|
533
|
+
def parse_code_by_prism(_file_path, encoded_source)
|
534
|
+
Prism.parse(encoded_source).value.statements
|
521
535
|
end
|
522
536
|
end
|
523
537
|
end
|
@@ -119,7 +119,6 @@ module Synvert::Core
|
|
119
119
|
@sub_snippets = []
|
120
120
|
@warnings = []
|
121
121
|
@affected_files = Set.new
|
122
|
-
@redo_until_no_change = false
|
123
122
|
@options = DEFAULT_OPTIONS.dup
|
124
123
|
@test_results = Hash.new { |h, k| h[k] = [] }
|
125
124
|
self.class.register(@group, @name, self)
|
@@ -130,8 +129,6 @@ module Synvert::Core
|
|
130
129
|
def process
|
131
130
|
@affected_files = Set.new
|
132
131
|
instance_eval(&@block)
|
133
|
-
|
134
|
-
process if !@affected_files.empty? && @redo_until_no_change # redo
|
135
132
|
end
|
136
133
|
|
137
134
|
# Process rewriter with sandbox mode.
|
@@ -146,9 +143,6 @@ module Synvert::Core
|
|
146
143
|
@affected_files = Set.new
|
147
144
|
instance_eval(&@block)
|
148
145
|
|
149
|
-
if !@affected_files.empty? && @redo_until_no_change # redo
|
150
|
-
test
|
151
|
-
end
|
152
146
|
if Configuration.test_result == 'new_source'
|
153
147
|
@test_results.values.flatten
|
154
148
|
else
|
@@ -199,11 +193,11 @@ module Synvert::Core
|
|
199
193
|
# configure({ parser: Synvert::PARSER_PARSER })
|
200
194
|
# configure({ strategy: 'allow_insert_at_same_position' })
|
201
195
|
# @param options [Hash]
|
202
|
-
# @option parser [String] Synvert::PARSER_PARSER or Synvert::
|
196
|
+
# @option parser [String] Synvert::PARSER_PARSER, Synvert::SYNTAX_TREE_PARSER, or Synvert::PRISM_PARSER
|
203
197
|
# @option strategy [String] 'allow_insert_at_same_position'
|
204
198
|
def configure(options)
|
205
199
|
@options = @options.merge(options)
|
206
|
-
if options[:parser] && ![Synvert::PARSER_PARSER, Synvert::SYNTAX_TREE_PARSER].include?(options[:parser])
|
200
|
+
if options[:parser] && ![Synvert::PARSER_PARSER, Synvert::SYNTAX_TREE_PARSER, Synvert::PRISM_PARSER].include?(options[:parser])
|
207
201
|
raise Errors::ParserNotSupported.new("Parser #{options[:parser]} not supported")
|
208
202
|
end
|
209
203
|
end
|
@@ -406,15 +400,6 @@ module Synvert::Core
|
|
406
400
|
@helpers << { name: name, block: block }
|
407
401
|
end
|
408
402
|
|
409
|
-
# Rerun the snippet until no change.
|
410
|
-
# @example
|
411
|
-
# Synvert::Rewriter.new 'ruby', 'nested_class_definition' do
|
412
|
-
# redo_until_no_change
|
413
|
-
# end
|
414
|
-
def redo_until_no_change
|
415
|
-
@redo_until_no_change = true
|
416
|
-
end
|
417
|
-
|
418
403
|
private
|
419
404
|
|
420
405
|
# Handle one file.
|
data/lib/synvert/core/utils.rb
CHANGED
@@ -16,7 +16,7 @@ module Synvert::Core
|
|
16
16
|
uri = URI.parse(format_url(snippet_name))
|
17
17
|
return uri.open.read if remote_snippet_exists?(uri)
|
18
18
|
|
19
|
-
raise Errors::SnippetNotFound.new("#{snippet_name}
|
19
|
+
raise Errors::SnippetNotFound.new("#{snippet_name} not found")
|
20
20
|
elsif is_valid_file?(snippet_name)
|
21
21
|
return File.read(snippet_name)
|
22
22
|
else
|
@@ -26,7 +26,7 @@ module Synvert::Core
|
|
26
26
|
snippet_uri = URI.parse(format_url(remote_snippet_url(snippet_name)))
|
27
27
|
return snippet_uri.open.read if remote_snippet_exists?(snippet_uri)
|
28
28
|
|
29
|
-
raise Errors::SnippetNotFound.new("#{snippet_name}
|
29
|
+
raise Errors::SnippetNotFound.new("#{snippet_name} not found")
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
data/lib/synvert/core/version.rb
CHANGED
data/lib/synvert/core.rb
CHANGED
@@ -382,15 +382,6 @@ module Synvert::Core
|
|
382
382
|
expect(instance.dynamic_helper('arg1', 'arg2')).to eq 'dynamic result'
|
383
383
|
end
|
384
384
|
|
385
|
-
it 'parses redo_until_no_change' do
|
386
|
-
rewriter =
|
387
|
-
Rewriter.new 'group', 'name' do
|
388
|
-
redo_until_no_change
|
389
|
-
end
|
390
|
-
rewriter.process
|
391
|
-
expect(rewriter.instance_variable_get('@redo_until_no_change')).to be_truthy
|
392
|
-
end
|
393
|
-
|
394
385
|
describe 'class methods' do
|
395
386
|
before :each do
|
396
387
|
Rewriter.clear
|
data/synvert-core-ruby.gemspec
CHANGED
@@ -20,11 +20,13 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
22
|
spec.add_runtime_dependency "activesupport", "< 7.0.0"
|
23
|
-
spec.add_runtime_dependency "node_query", ">= 1.
|
24
|
-
spec.add_runtime_dependency "node_mutation", ">= 1.
|
23
|
+
spec.add_runtime_dependency "node_query", ">= 1.15.0"
|
24
|
+
spec.add_runtime_dependency "node_mutation", ">= 1.23.0"
|
25
25
|
spec.add_runtime_dependency "parser"
|
26
|
-
spec.add_runtime_dependency "parser_node_ext", ">= 1.2.
|
26
|
+
spec.add_runtime_dependency "parser_node_ext", ">= 1.2.2"
|
27
27
|
spec.add_runtime_dependency "syntax_tree"
|
28
|
-
spec.add_runtime_dependency "syntax_tree_ext", ">= 0.
|
28
|
+
spec.add_runtime_dependency "syntax_tree_ext", ">= 0.7.1"
|
29
|
+
spec.add_runtime_dependency "prism"
|
30
|
+
spec.add_runtime_dependency "prism_ext", ">= 0.2.2"
|
29
31
|
spec.add_runtime_dependency "parallel"
|
30
32
|
end
|
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.32.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -30,28 +30,28 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.
|
33
|
+
version: 1.15.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.
|
40
|
+
version: 1.15.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: node_mutation
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.
|
47
|
+
version: 1.23.0
|
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.23.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: parser
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 1.2.
|
75
|
+
version: 1.2.2
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 1.2.
|
82
|
+
version: 1.2.2
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: syntax_tree
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,14 +100,42 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 0.
|
103
|
+
version: 0.7.1
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 0.
|
110
|
+
version: 0.7.1
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: prism
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: prism_ext
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.2.2
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.2.2
|
111
139
|
- !ruby/object:Gem::Dependency
|
112
140
|
name: parallel
|
113
141
|
requirement: !ruby/object:Gem::Requirement
|