synvert-core 1.28.2 → 1.28.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +3 -3
- data/lib/synvert/core/version.rb +1 -1
- data/lib/synvert/core.rb +0 -1
- data/synvert-core-ruby.gemspec +1 -1
- metadata +4 -7
- data/lib/synvert/core/node_ext.rb +0 -130
- data/spec/synvert/core/node_ext_spec.rb +0 -108
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ea0617537582c8fe24441b78a96a9e7e3ec74ef50a85bd761f1a2c620bb67ae
|
4
|
+
data.tar.gz: 30aed9720e68b3014aced6cea3d80dcf48d746ffcc217b543c6211cd29545468
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4c4d9a0fe6833d651c25d9a574818a54976c5ffcd6ef018208763f277b990735361fca476488bfa831e8a4d5dcb96bc4b092bfc10506b5e6306b6a5941f3dd6
|
7
|
+
data.tar.gz: 4abe08f1cc6cf27ef830dbfcedb943737d11a377e5f87df3d6a7f67eabc6c6d790e86de647fe81a495a147cc1e2c90950a933c378665add69864f66b18a80fc2
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
synvert-core (1.28.
|
4
|
+
synvert-core (1.28.3)
|
5
5
|
activesupport (< 7.0.0)
|
6
|
-
node_mutation (>= 1.
|
6
|
+
node_mutation (>= 1.19.1)
|
7
7
|
node_query (>= 1.13.5)
|
8
8
|
parallel
|
9
9
|
parser
|
@@ -50,7 +50,7 @@ GEM
|
|
50
50
|
method_source (1.0.0)
|
51
51
|
minitest (5.18.1)
|
52
52
|
nenv (0.3.0)
|
53
|
-
node_mutation (1.
|
53
|
+
node_mutation (1.19.1)
|
54
54
|
node_query (1.13.5)
|
55
55
|
notiffany (0.1.3)
|
56
56
|
nenv (~> 0.1)
|
data/lib/synvert/core/version.rb
CHANGED
data/lib/synvert/core.rb
CHANGED
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.13.5"
|
24
|
-
spec.add_runtime_dependency "node_mutation", ">= 1.
|
24
|
+
spec.add_runtime_dependency "node_mutation", ">= 1.19.1"
|
25
25
|
spec.add_runtime_dependency "parser"
|
26
26
|
spec.add_runtime_dependency "parser_node_ext", ">= 1.2.0"
|
27
27
|
spec.add_runtime_dependency "syntax_tree"
|
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.28.
|
4
|
+
version: 1.28.3
|
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-06-
|
11
|
+
date: 2023-06-22 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.19.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.19.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: parser
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -149,7 +149,6 @@ files:
|
|
149
149
|
- lib/synvert/core/engine/slim.rb
|
150
150
|
- lib/synvert/core/errors.rb
|
151
151
|
- lib/synvert/core/helper.rb
|
152
|
-
- lib/synvert/core/node_ext.rb
|
153
152
|
- lib/synvert/core/rewriter.rb
|
154
153
|
- lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb
|
155
154
|
- lib/synvert/core/rewriter/condition.rb
|
@@ -173,7 +172,6 @@ files:
|
|
173
172
|
- spec/synvert/core/engine/haml_spec.rb
|
174
173
|
- spec/synvert/core/engine/slim_spec.rb
|
175
174
|
- spec/synvert/core/helper_spec.rb
|
176
|
-
- spec/synvert/core/node_ext_spec.rb
|
177
175
|
- spec/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action_spec.rb
|
178
176
|
- spec/synvert/core/rewriter/condition/if_exist_condition_spec.rb
|
179
177
|
- spec/synvert/core/rewriter/condition/if_only_exist_condition_spec.rb
|
@@ -220,7 +218,6 @@ test_files:
|
|
220
218
|
- spec/synvert/core/engine/haml_spec.rb
|
221
219
|
- spec/synvert/core/engine/slim_spec.rb
|
222
220
|
- spec/synvert/core/helper_spec.rb
|
223
|
-
- spec/synvert/core/node_ext_spec.rb
|
224
221
|
- spec/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action_spec.rb
|
225
222
|
- spec/synvert/core/rewriter/condition/if_exist_condition_spec.rb
|
226
223
|
- spec/synvert/core/rewriter/condition/if_only_exist_condition_spec.rb
|
@@ -1,130 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'parser'
|
4
|
-
|
5
|
-
module Parser::AST
|
6
|
-
# Extend Parser::AST::Node.
|
7
|
-
# {https://github.com/whitequark/parser/blob/master/lib/parser/ast/node.rb}
|
8
|
-
#
|
9
|
-
# Rules
|
10
|
-
#
|
11
|
-
# Synvert compares ast nodes with key / value pairs, each ast node has
|
12
|
-
# multiple attributes, e.g. +receiver+, +message+ and +arguments+, it
|
13
|
-
# matches only when all of key / value pairs match.
|
14
|
-
#
|
15
|
-
# +type: 'send', message: :include, arguments: ['FactoryGirl::Syntax::Methods']+
|
16
|
-
#
|
17
|
-
# Synvert does comparison based on the value type
|
18
|
-
#
|
19
|
-
# 1. if value is a symbol, then compares ast node value as symbol, e.g. +message: :include+
|
20
|
-
# 2. if value is a string, then compares ast node original source code, e.g. +name: 'Synvert::Application'+
|
21
|
-
# 3. if value is a regexp, then compares ast node original source code, e.g. +message: /find_all_by_/+
|
22
|
-
# 4. if value is an array, then compares each ast node, e.g. +arguments: ['FactoryGirl::Syntax::Methods']+
|
23
|
-
# 5. if value is nil, then check if ast node is nil, e.g. +arguments: [nil]+
|
24
|
-
# 6. if value is true or false, then check if ast node is :true or :false, e.g. +arguments: [false]+
|
25
|
-
# 7. if value is ast, then compare ast node directly, e.g. +to_ast: Parser::CurrentRuby.parse("self.class.serialized_attributes")+
|
26
|
-
#
|
27
|
-
# It can also compare nested key / value pairs, like
|
28
|
-
#
|
29
|
-
# +type: 'send', receiver: { type: 'send', receiver: { type: 'send', message: 'config' }, message: 'active_record' }, message: 'identity_map='+
|
30
|
-
#
|
31
|
-
# Source Code to Ast Node
|
32
|
-
# {https://playground.synvert.net/ruby}
|
33
|
-
class Node
|
34
|
-
# Get the file name of node.
|
35
|
-
#
|
36
|
-
# @return [String] file name.
|
37
|
-
def filename
|
38
|
-
loc.expression&.source_buffer.name
|
39
|
-
end
|
40
|
-
|
41
|
-
# Get the column of node.
|
42
|
-
#
|
43
|
-
# @return [Integer] column.
|
44
|
-
def column
|
45
|
-
loc.expression.column
|
46
|
-
end
|
47
|
-
|
48
|
-
# Get the line of node.
|
49
|
-
#
|
50
|
-
# @return [Integer] line.
|
51
|
-
def line
|
52
|
-
loc.expression.line
|
53
|
-
end
|
54
|
-
|
55
|
-
# Strip curly braces for hash.
|
56
|
-
# @example
|
57
|
-
# node # s(:hash, s(:pair, s(:sym, :foo), s(:str, "bar")))
|
58
|
-
# node.strip_curly_braces # "foo: 'bar'"
|
59
|
-
# @return [String]
|
60
|
-
def strip_curly_braces
|
61
|
-
return to_source unless type == :hash
|
62
|
-
|
63
|
-
to_source.sub(/^{(.*)}$/) { Regexp.last_match(1).strip }
|
64
|
-
end
|
65
|
-
|
66
|
-
# Wrap curly braces for hash.
|
67
|
-
# @example
|
68
|
-
# node # s(:hash, s(:pair, s(:sym, :foo), s(:str, "bar")))
|
69
|
-
# node.wrap_curly_braces # "{ foo: 'bar' }"
|
70
|
-
# @return [String]
|
71
|
-
def wrap_curly_braces
|
72
|
-
return to_source unless type == :hash
|
73
|
-
|
74
|
-
"{ #{to_source} }"
|
75
|
-
end
|
76
|
-
|
77
|
-
# Get single quote string.
|
78
|
-
# @example
|
79
|
-
# node # s(:str, "foobar")
|
80
|
-
# node.to_single_quote # "'foobar'"
|
81
|
-
# @return [String]
|
82
|
-
def to_single_quote
|
83
|
-
return to_source unless type == :str
|
84
|
-
|
85
|
-
"'#{to_value}'"
|
86
|
-
end
|
87
|
-
|
88
|
-
# Convert string to symbol.
|
89
|
-
# @example
|
90
|
-
# node # s(:str, "foobar")
|
91
|
-
# node.to_symbol # ":foobar"
|
92
|
-
# @return [String]
|
93
|
-
def to_symbol
|
94
|
-
return to_source unless type == :str
|
95
|
-
|
96
|
-
":#{to_value}"
|
97
|
-
end
|
98
|
-
|
99
|
-
# Convert symbol to string.
|
100
|
-
# @example
|
101
|
-
# node # s(:sym, :foobar)
|
102
|
-
# node.to_string # "foobar"
|
103
|
-
# @return [String]
|
104
|
-
def to_string
|
105
|
-
return to_source unless type == :sym
|
106
|
-
|
107
|
-
to_value.to_s
|
108
|
-
end
|
109
|
-
|
110
|
-
# Convert lambda {} to -> {}
|
111
|
-
# @example
|
112
|
-
# node # s(:block, s(:send, nil, :lambda), s(:args), s(:send, nil, :foobar))
|
113
|
-
# node.to_lambda_literal # "-> { foobar }"
|
114
|
-
# @return [String]
|
115
|
-
def to_lambda_literal
|
116
|
-
if type == :block && caller.type == :send && caller.receiver.nil? && caller.message == :lambda
|
117
|
-
new_source = to_source
|
118
|
-
if arguments.size > 1
|
119
|
-
new_source = new_source[0...arguments.first.loc.expression.begin_pos - 2] + new_source[arguments.last.loc.expression.end_pos + 1..-1]
|
120
|
-
new_source = new_source.sub('lambda', "->(#{arguments.map(&:to_source).join(', ')})")
|
121
|
-
else
|
122
|
-
new_source = new_source.sub('lambda', '->')
|
123
|
-
end
|
124
|
-
new_source
|
125
|
-
else
|
126
|
-
to_source
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
@@ -1,108 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Parser::AST::Node do
|
6
|
-
describe '#strip_curly_braces' do
|
7
|
-
context 'hash node' do
|
8
|
-
it 'removes curly braces' do
|
9
|
-
node = parser_parse("{ foo: 'bar' }")
|
10
|
-
expect(node.strip_curly_braces).to eq("foo: 'bar'")
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
context 'other node' do
|
15
|
-
it 'do nothing' do
|
16
|
-
node = parser_parse("'foobar'")
|
17
|
-
expect(node.strip_curly_braces).to eq("'foobar'")
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe '#wrap_curly_braces' do
|
23
|
-
context 'hash node' do
|
24
|
-
it 'adds curly braces' do
|
25
|
-
node = parser_parse("test(foo: 'bar')").arguments.first
|
26
|
-
expect(node.to_source).to eq("foo: 'bar'")
|
27
|
-
expect(node.wrap_curly_braces).to eq("{ foo: 'bar' }")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'other node' do
|
32
|
-
it 'does nothing' do
|
33
|
-
node = parser_parse("'foobar'")
|
34
|
-
expect(node.wrap_curly_braces).to eq("'foobar'")
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe '#to_single_quote' do
|
40
|
-
context 'str node' do
|
41
|
-
it 'converts double quote to single quote' do
|
42
|
-
node = parser_parse('"foobar"')
|
43
|
-
expect(node.to_source).to eq '"foobar"'
|
44
|
-
expect(node.to_single_quote).to eq "'foobar'"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context 'other node' do
|
49
|
-
it 'does nothing' do
|
50
|
-
node = parser_parse(':foobar')
|
51
|
-
expect(node.to_single_quote).to eq ':foobar'
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe '#to_symbol' do
|
57
|
-
context 'str node' do
|
58
|
-
it 'converts string to symbol' do
|
59
|
-
node = parser_parse("'foobar'")
|
60
|
-
expect(node.to_symbol).to eq ':foobar'
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
context 'other node' do
|
65
|
-
it 'does nothing' do
|
66
|
-
node = parser_parse(':foobar')
|
67
|
-
expect(node.to_symbol).to eq ':foobar'
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
describe '#to_string' do
|
73
|
-
context 'sym node' do
|
74
|
-
it 'converts symbol to string' do
|
75
|
-
node = parser_parse(':foobar')
|
76
|
-
expect(node.to_string).to eq 'foobar'
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context 'other node' do
|
81
|
-
it 'does nothing' do
|
82
|
-
node = parser_parse("'foobar'")
|
83
|
-
expect(node.to_string).to eq "'foobar'"
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
describe '#to_lambda_literal' do
|
89
|
-
context 'lambda node' do
|
90
|
-
it 'converts to lambda literal without arguments' do
|
91
|
-
node = parser_parse('lambda { foobar }')
|
92
|
-
expect(node.to_lambda_literal).to eq('-> { foobar }')
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'converts to lambda literal with arguments' do
|
96
|
-
node = parser_parse('lambda { |x, y| foobar }')
|
97
|
-
expect(node.to_lambda_literal).to eq('->(x, y) { foobar }')
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
context 'other node' do
|
102
|
-
it 'does nothing' do
|
103
|
-
node = parser_parse(':foobar')
|
104
|
-
expect(node.to_lambda_literal).to eq ':foobar'
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|