synvert-core 0.51.0 → 0.53.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 +11 -0
- data/README.md +5 -6
- data/lib/synvert/core/node_ext.rb +10 -6
- data/lib/synvert/core/rewriter.rb +2 -0
- data/lib/synvert/core/rewriter/action/append_action.rb +3 -3
- data/lib/synvert/core/rewriter/action/insert_action.rb +1 -3
- 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_action.rb +1 -3
- data/lib/synvert/core/rewriter/action/replace_with_action.rb +3 -4
- data/lib/synvert/core/rewriter/action/wrap_action.rb +2 -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/{within_scope.rb → within_scope_spec.rb} +0 -0
- data/{synvert-core.gemspec → synvert-core-ruby.gemspec} +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a56859d257b024e86f223d076c77d4effd93d6ffef44de99091d49a62a12841e
|
|
4
|
+
data.tar.gz: f0b8658b8701417180ae578eb2ba5c7607e634327ced470e2ad0017980a2e0d8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 320beadaca69f8e9613f1cd15c5c6fd71bf7bd51881af453ade6e99f56e9516b782264b0d63d4398bbd4fe61af8cb3c7df78d517d0e29762f76de2c2d2091255
|
|
7
|
+
data.tar.gz: 22a208b06b416f70e191e7215e21016d603a06ff91a0c7ad8795333906179f46b325e0507ffafd65b7fcebc639e99a6aaba5428632ac6f19b87a2b41dedf9e47
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 0.53.0 (2021-08-22)
|
|
4
|
+
|
|
5
|
+
* Fix nested child in Node#child_node_range
|
|
6
|
+
* Rename synvert-core to synvert-core-ruby
|
|
7
|
+
|
|
8
|
+
## 0.52.0 (2021-08-21)
|
|
9
|
+
|
|
10
|
+
* ``Node#child_node_range`` supports nested child
|
|
11
|
+
* Require `fileutils`
|
|
12
|
+
* Rename `Node#indent` to `Node#column`
|
|
13
|
+
|
|
3
14
|
## 0.51.0 (2021-08-12)
|
|
4
15
|
|
|
5
16
|
* Add `wrap` action
|
data/README.md
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# synvert-core-ruby
|
|
2
2
|
|
|
3
3
|
<img src="https://xinminlabs.github.io/synvert/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
39
|
[1]: https://xinminlabs.github.io/synvert/
|
|
41
|
-
[2]: https://rubydoc.info/github/xinminlabs/synvert-core/master/frames
|
|
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
|
|
@@ -4,10 +4,8 @@ module Synvert::Core
|
|
|
4
4
|
# AddAction to add code to the node.
|
|
5
5
|
class Rewriter::InsertAction < Rewriter::Action
|
|
6
6
|
def initialize(instance, code, at:)
|
|
7
|
-
|
|
8
|
-
@code = code
|
|
7
|
+
super(instance, code)
|
|
9
8
|
@at = at
|
|
10
|
-
@node = @instance.current_node
|
|
11
9
|
end
|
|
12
10
|
|
|
13
11
|
# Begin position to insert code.
|
|
@@ -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
|
|
@@ -4,10 +4,8 @@ module Synvert::Core
|
|
|
4
4
|
# ReplaceAction to replace child node with code.
|
|
5
5
|
class Rewriter::ReplaceAction < Rewriter::Action
|
|
6
6
|
def initialize(instance, *selectors, with:)
|
|
7
|
-
|
|
7
|
+
super(instance, with)
|
|
8
8
|
@selectors = selectors
|
|
9
|
-
@code = with
|
|
10
|
-
@node = @instance.current_node
|
|
11
9
|
end
|
|
12
10
|
|
|
13
11
|
# Begin position of code to replace.
|
|
@@ -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
|
|
@@ -7,10 +7,8 @@ module Synvert::Core
|
|
|
7
7
|
# we have to put those 2 actions into 2 within_file scopes.
|
|
8
8
|
class Rewriter::WrapAction < Rewriter::Action
|
|
9
9
|
def initialize(instance, with:, indent: nil)
|
|
10
|
-
|
|
11
|
-
@
|
|
12
|
-
@node = @instance.current_node
|
|
13
|
-
@indent = indent || @node.indent
|
|
10
|
+
super(instance, with)
|
|
11
|
+
@indent = indent || @node.column
|
|
14
12
|
end
|
|
15
13
|
|
|
16
14
|
# Begin position of code to wrap.
|
|
@@ -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
|
|
File without changes
|
|
@@ -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.53.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-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -194,12 +194,12 @@ files:
|
|
|
194
194
|
- spec/synvert/core/rewriter/instance_spec.rb
|
|
195
195
|
- spec/synvert/core/rewriter/ruby_version_spec.rb
|
|
196
196
|
- spec/synvert/core/rewriter/scope/goto_scope_spec.rb
|
|
197
|
-
- spec/synvert/core/rewriter/scope/
|
|
197
|
+
- spec/synvert/core/rewriter/scope/within_scope_spec.rb
|
|
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: {}
|
|
@@ -218,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
218
218
|
- !ruby/object:Gem::Version
|
|
219
219
|
version: '0'
|
|
220
220
|
requirements: []
|
|
221
|
-
rubygems_version: 3.
|
|
221
|
+
rubygems_version: 3.2.22
|
|
222
222
|
signing_key:
|
|
223
223
|
specification_version: 4
|
|
224
224
|
summary: convert ruby code to better syntax.
|
|
@@ -247,7 +247,7 @@ test_files:
|
|
|
247
247
|
- spec/synvert/core/rewriter/instance_spec.rb
|
|
248
248
|
- spec/synvert/core/rewriter/ruby_version_spec.rb
|
|
249
249
|
- spec/synvert/core/rewriter/scope/goto_scope_spec.rb
|
|
250
|
-
- spec/synvert/core/rewriter/scope/
|
|
250
|
+
- spec/synvert/core/rewriter/scope/within_scope_spec.rb
|
|
251
251
|
- spec/synvert/core/rewriter/scope_spec.rb
|
|
252
252
|
- spec/synvert/core/rewriter/warning_spec.rb
|
|
253
253
|
- spec/synvert/core/rewriter_spec.rb
|