synvert-core 0.51.1 → 0.54.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 +4 -4
- data/CHANGELOG.md +12 -1
- data/README.md +7 -8
- data/lib/synvert/core/node_ext.rb +10 -6
- data/lib/synvert/core/rewriter/action/append_action.rb +3 -3
- data/lib/synvert/core/rewriter/action/delete_action.rb +3 -3
- data/lib/synvert/core/rewriter/action/insert_action.rb +1 -1
- data/lib/synvert/core/rewriter/action/insert_after_action.rb +1 -1
- data/lib/synvert/core/rewriter/action/prepend_action.rb +2 -2
- data/lib/synvert/core/rewriter/action/replace_with_action.rb +3 -4
- data/lib/synvert/core/rewriter/action/wrap_action.rb +1 -1
- data/lib/synvert/core/rewriter/instance.rb +4 -4
- data/lib/synvert/core/rewriter/scope/goto_scope.rb +4 -4
- data/lib/synvert/core/rewriter/scope/within_scope.rb +4 -3
- data/lib/synvert/core/version.rb +1 -1
- data/spec/synvert/core/node_ext_spec.rb +14 -2
- data/spec/synvert/core/rewriter/scope/goto_scope_spec.rb +1 -1
- data/{synvert-core.gemspec → 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: 1c7ee99e848625ed3bad729d3e08186370d5fb58d4412fb1d09d89bf15559a22
|
4
|
+
data.tar.gz: 30f16d4aa02a2a6f6677a5657b24296127869e17c5237a4b63f2d6d1ed658203
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 936f304f6b829be86eb1da55aa110a7b3ed7c249cb9da4a1bc5246a1d687fb8dd7548fe68a2632c4df874c921f829e05ec5cab838373b587db5a3e59b900a0ab
|
7
|
+
data.tar.gz: 15f39e1386ee166762dd3afca86b8d246e3cc8ea0cbdcb5efd15eb9141f911ffcaabaf15a6062f9a6fe31dc720e7242fe4a81633bc12ffa06c18efe431d4d410
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,19 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
-
## 0.
|
3
|
+
## 0.54.0 (2021-08-28)
|
4
4
|
|
5
|
+
* Change `goto_scope` param from array to string
|
6
|
+
|
7
|
+
## 0.53.0 (2021-08-22)
|
8
|
+
|
9
|
+
* Fix nested child in Node#child_node_range
|
10
|
+
* Rename synvert-core to synvert-core-ruby
|
11
|
+
|
12
|
+
## 0.52.0 (2021-08-21)
|
13
|
+
|
14
|
+
* ``Node#child_node_range`` supports nested child
|
5
15
|
* Require `fileutils`
|
16
|
+
* Rename `Node#indent` to `Node#column`
|
6
17
|
|
7
18
|
## 0.51.0 (2021-08-12)
|
8
19
|
|
data/README.md
CHANGED
@@ -1,12 +1,11 @@
|
|
1
|
-
#
|
1
|
+
# synvert-core-ruby
|
2
2
|
|
3
|
-
<img src="https://xinminlabs.
|
3
|
+
<img src="https://synvert.xinminlabs.com/img/logo_96.png" alt="logo" width="32" height="32" />
|
4
4
|
|
5
|
-

|
6
|
-
[](https://coveralls.io/r/xinminlabs/synvert-core)
|
5
|
+

|
7
6
|
[](http://badge.fury.io/rb/synvert-core)
|
8
7
|
|
9
|
-
synvert-core provides a dsl to convert ruby source code.
|
8
|
+
synvert-core-ruby provides a dsl to convert ruby source code.
|
10
9
|
|
11
10
|
## Installation
|
12
11
|
|
@@ -31,11 +30,11 @@ Or install it yourself as:
|
|
31
30
|
|
32
31
|
## Contributing
|
33
32
|
|
34
|
-
1. Fork it ( https://github.com/[my-github-username]/synvert-core/fork )
|
33
|
+
1. Fork it ( https://github.com/[my-github-username]/synvert-core-ruby/fork )
|
35
34
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
36
35
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
37
36
|
4. Push to the branch (`git push origin my-new-feature`)
|
38
37
|
5. Create a new Pull Request
|
39
38
|
|
40
|
-
[1]: https://xinminlabs.
|
41
|
-
[2]: https://rubydoc.info/github/xinminlabs/synvert-core/master/frames
|
39
|
+
[1]: https://synvert.xinminlabs.com
|
40
|
+
[2]: https://rubydoc.info/github/xinminlabs/synvert-core-ruby/master/frames
|
@@ -322,10 +322,10 @@ module Parser::AST
|
|
322
322
|
loc.expression&.source
|
323
323
|
end
|
324
324
|
|
325
|
-
# Get the
|
325
|
+
# Get the column of current node.
|
326
326
|
#
|
327
|
-
# @return [Integer]
|
328
|
-
def
|
327
|
+
# @return [Integer] column.
|
328
|
+
def column
|
329
329
|
loc.expression.column
|
330
330
|
end
|
331
331
|
|
@@ -341,7 +341,7 @@ module Parser::AST
|
|
341
341
|
# @param [String] name of child node.
|
342
342
|
# @return [Parser::Source::Range] source range of child node.
|
343
343
|
def child_node_range(child_name)
|
344
|
-
case [type, child_name]
|
344
|
+
case [type, child_name.to_sym]
|
345
345
|
when %i[block pipes], %i[def parentheses], %i[defs parentheses]
|
346
346
|
Parser::Source::Range.new('(string)', arguments.loc.expression.begin_pos, arguments.loc.expression.end_pos)
|
347
347
|
when %i[block arguments], %i[def arguments], %i[defs arguments]
|
@@ -369,8 +369,12 @@ module Parser::AST
|
|
369
369
|
Parser::Source::Range.new('(string)', loc.begin.begin_pos, loc.end.end_pos)
|
370
370
|
end
|
371
371
|
else
|
372
|
-
|
373
|
-
|
372
|
+
direct_child_name, nested_child_name = child_name.to_s.split('.', 2)
|
373
|
+
if respond_to?(direct_child_name)
|
374
|
+
child_node = send(direct_child_name)
|
375
|
+
|
376
|
+
return child_node.child_node_range(nested_child_name) if nested_child_name
|
377
|
+
|
374
378
|
return nil if child_node.nil?
|
375
379
|
|
376
380
|
if child_node.is_a?(Parser::AST::Node)
|
@@ -12,7 +12,7 @@ module Synvert::Core
|
|
12
12
|
if :begin == @node.type
|
13
13
|
@node.loc.expression.end_pos
|
14
14
|
else
|
15
|
-
@node.loc.expression.end_pos - @node.
|
15
|
+
@node.loc.expression.end_pos - @node.column - END_LENGTH
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -31,9 +31,9 @@ module Synvert::Core
|
|
31
31
|
# @return [String] n times whitesphace
|
32
32
|
def indent(node)
|
33
33
|
if %i[block class].include? node.type
|
34
|
-
' ' * (node.
|
34
|
+
' ' * (node.column + DEFAULT_INDENT)
|
35
35
|
else
|
36
|
-
' ' * node.
|
36
|
+
' ' * node.column
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -1,21 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Synvert::Core
|
4
|
-
#
|
4
|
+
# DeleteAction to delete code.
|
5
5
|
class Rewriter::DeleteAction < Rewriter::Action
|
6
6
|
def initialize(instance, *selectors)
|
7
7
|
super(instance, nil)
|
8
8
|
@selectors = selectors
|
9
9
|
end
|
10
10
|
|
11
|
-
# Begin position of code to
|
11
|
+
# Begin position of code to delete.
|
12
12
|
#
|
13
13
|
# @return [Integer] begin position.
|
14
14
|
def begin_pos
|
15
15
|
@selectors.map { |selector| @node.child_node_range(selector) }.compact.map(&:begin_pos).min
|
16
16
|
end
|
17
17
|
|
18
|
-
# End position of code to
|
18
|
+
# End position of code to delete.
|
19
19
|
#
|
20
20
|
# @return [Integer] end position.
|
21
21
|
def end_pos
|
@@ -38,9 +38,9 @@ module Synvert::Core
|
|
38
38
|
# @return [String] n times whitesphace
|
39
39
|
def indent(node)
|
40
40
|
if %i[block class].include? node.type
|
41
|
-
' ' * (node.
|
41
|
+
' ' * (node.column + DEFAULT_INDENT)
|
42
42
|
else
|
43
|
-
' ' * node.
|
43
|
+
' ' * node.column
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -24,7 +24,7 @@ module Synvert::Core
|
|
24
24
|
if rewritten_source.include?("\n")
|
25
25
|
new_code = []
|
26
26
|
rewritten_source.split("\n").each_with_index do |line, index|
|
27
|
-
new_code << (index == 0 ? line : indent
|
27
|
+
new_code << (index == 0 ? line : indent + line)
|
28
28
|
end
|
29
29
|
new_code.join("\n")
|
30
30
|
else
|
@@ -36,10 +36,9 @@ module Synvert::Core
|
|
36
36
|
|
37
37
|
# Indent of the node
|
38
38
|
#
|
39
|
-
# @param node [Parser::AST::Node]
|
40
39
|
# @return [String] n times whitesphace
|
41
|
-
def indent
|
42
|
-
' ' * node.
|
40
|
+
def indent
|
41
|
+
' ' * @node.column
|
43
42
|
end
|
44
43
|
end
|
45
44
|
end
|
@@ -139,7 +139,7 @@ module Synvert::Core
|
|
139
139
|
|
140
140
|
# Set current_node properly, process and set current_node back to original current_node.
|
141
141
|
#
|
142
|
-
# @param node [Parser::AST::Node] node set to
|
142
|
+
# @param node [Parser::AST::Node] node set to other_node
|
143
143
|
# @yield process
|
144
144
|
def process_with_other_node(node)
|
145
145
|
original_node = current_node
|
@@ -177,10 +177,10 @@ module Synvert::Core
|
|
177
177
|
# Parse goto_node dsl, it creates a [Synvert::Core::Rewriter::GotoScope] to go to a child node,
|
178
178
|
# then continue operating on the child node.
|
179
179
|
#
|
180
|
-
# @param
|
180
|
+
# @param child_node_name [Symbol|String] the name of the child nodes.
|
181
181
|
# @param block [Block] block code to continue operating on the matching nodes.
|
182
|
-
def goto_node(
|
183
|
-
Rewriter::GotoScope.new(self,
|
182
|
+
def goto_node(child_node_name, &block)
|
183
|
+
Rewriter::GotoScope.new(self, child_node_name, &block).process
|
184
184
|
end
|
185
185
|
|
186
186
|
# Parse if_exist_node dsl, it creates a [Synvert::Core::Rewriter::IfExistCondition] to check
|
@@ -6,11 +6,11 @@ module Synvert::Core
|
|
6
6
|
# Initialize a scope
|
7
7
|
#
|
8
8
|
# @param instance [Synvert::Core::Rewriter::Instance]
|
9
|
-
# @param
|
9
|
+
# @param child_node_name [Symbol|string]
|
10
10
|
# @param block [Block]
|
11
|
-
def initialize(instance,
|
11
|
+
def initialize(instance, child_node_name, &block)
|
12
12
|
@instance = instance
|
13
|
-
@
|
13
|
+
@child_node_name = child_node_name
|
14
14
|
@block = block
|
15
15
|
end
|
16
16
|
|
@@ -20,7 +20,7 @@ module Synvert::Core
|
|
20
20
|
return unless current_node
|
21
21
|
|
22
22
|
child_node = current_node
|
23
|
-
@
|
23
|
+
@child_node_name.to_s.split('.').each do |child_node_name|
|
24
24
|
child_node = child_node_name.is_a?(Parser::AST::Node) ? child_node_name : child_node.send(child_node_name)
|
25
25
|
end
|
26
26
|
@instance.process_with_other_node child_node do
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Synvert::Core
|
4
|
-
# WithinScope finds out nodes which match rules, then
|
4
|
+
# WithinScope finds out nodes which match rules, then changes its scope to matching node.
|
5
5
|
class Rewriter::WithinScope < Rewriter::Scope
|
6
6
|
# Initialize a scope
|
7
7
|
#
|
@@ -16,8 +16,9 @@ module Synvert::Core
|
|
16
16
|
@block = block
|
17
17
|
end
|
18
18
|
|
19
|
-
# Find out the matching nodes.
|
20
|
-
#
|
19
|
+
# Find out the matching nodes.
|
20
|
+
# It checks the current node and iterates all child nodes,
|
21
|
+
# then run the block code on each matching node.
|
21
22
|
def process
|
22
23
|
current_node = @instance.current_node
|
23
24
|
return unless current_node
|
data/lib/synvert/core/version.rb
CHANGED
@@ -359,10 +359,10 @@ describe Parser::AST::Node do
|
|
359
359
|
end
|
360
360
|
end
|
361
361
|
|
362
|
-
describe '#
|
362
|
+
describe '#column' do
|
363
363
|
it 'gets column number' do
|
364
364
|
node = parse(' FactoryGirl.create :post')
|
365
|
-
expect(node.
|
365
|
+
expect(node.column).to eq 2
|
366
366
|
end
|
367
367
|
end
|
368
368
|
|
@@ -520,6 +520,18 @@ describe Parser::AST::Node do
|
|
520
520
|
range = node.child_node_range(:pipes)
|
521
521
|
expect(range.to_range).to eq(24...30)
|
522
522
|
end
|
523
|
+
|
524
|
+
it 'checks caller.receiver' do
|
525
|
+
node = parse('Factory.define :user do |user|; end')
|
526
|
+
range = node.child_node_range('caller.receiver')
|
527
|
+
expect(range.to_range).to eq(0...7)
|
528
|
+
end
|
529
|
+
|
530
|
+
it 'checks caller.message' do
|
531
|
+
node = parse('Factory.define :user do |user|; end')
|
532
|
+
range = node.child_node_range('caller.message')
|
533
|
+
expect(range.to_range).to eq(8...14)
|
534
|
+
end
|
523
535
|
end
|
524
536
|
|
525
537
|
context 'class node' do
|
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.email = ["flyerhzm@gmail.com"]
|
12
12
|
spec.summary = 'convert ruby code to better syntax.'
|
13
13
|
spec.description = 'convert ruby code to better syntax automatically.'
|
14
|
-
spec.homepage = "https://github.com/xinminlabs/synvert-core"
|
14
|
+
spec.homepage = "https://github.com/xinminlabs/synvert-core-ruby"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0")
|
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: 0.
|
4
|
+
version: 0.54.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: 2021-08-
|
11
|
+
date: 2021-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -198,8 +198,8 @@ files:
|
|
198
198
|
- spec/synvert/core/rewriter/scope_spec.rb
|
199
199
|
- spec/synvert/core/rewriter/warning_spec.rb
|
200
200
|
- spec/synvert/core/rewriter_spec.rb
|
201
|
-
- synvert-core.gemspec
|
202
|
-
homepage: https://github.com/xinminlabs/synvert-core
|
201
|
+
- synvert-core-ruby.gemspec
|
202
|
+
homepage: https://github.com/xinminlabs/synvert-core-ruby
|
203
203
|
licenses:
|
204
204
|
- MIT
|
205
205
|
metadata: {}
|