synvert-core 1.4.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/main.yml +0 -1
  3. data/.gitignore +0 -5
  4. data/CHANGELOG.md +12 -0
  5. data/Gemfile +0 -3
  6. data/Gemfile.lock +101 -0
  7. data/Guardfile +0 -9
  8. data/README.md +31 -13
  9. data/Rakefile +1 -15
  10. data/lib/synvert/core/engine/erb.rb +1 -1
  11. data/lib/synvert/core/engine.rb +1 -1
  12. data/lib/synvert/core/node_ext.rb +0 -639
  13. data/lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb +20 -17
  14. data/lib/synvert/core/rewriter/condition/if_exist_condition.rb +1 -5
  15. data/lib/synvert/core/rewriter/condition/if_only_exist_condition.rb +1 -1
  16. data/lib/synvert/core/rewriter/condition/unless_exist_condition.rb +1 -5
  17. data/lib/synvert/core/rewriter/condition.rb +5 -1
  18. data/lib/synvert/core/rewriter/instance.rb +91 -140
  19. data/lib/synvert/core/rewriter/scope/query_scope.rb +8 -6
  20. data/lib/synvert/core/rewriter/scope/within_scope.rb +4 -87
  21. data/lib/synvert/core/rewriter.rb +0 -10
  22. data/lib/synvert/core/version.rb +1 -1
  23. data/lib/synvert/core.rb +4 -6
  24. data/spec/synvert/core/engine/erb_spec.rb +3 -3
  25. data/spec/synvert/core/node_ext_spec.rb +0 -965
  26. data/spec/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action_spec.rb +21 -1
  27. data/spec/synvert/core/rewriter/instance_spec.rb +64 -131
  28. data/spec/synvert/core/rewriter/scope/goto_scope_spec.rb +1 -4
  29. data/spec/synvert/core/rewriter/scope/query_scope_spec.rb +1 -16
  30. data/spec/synvert/core/rewriter/scope/within_scope_spec.rb +22 -13
  31. data/synvert-core-ruby.gemspec +5 -3
  32. metadata +46 -62
  33. data/lib/synvert/core/array_ext.rb +0 -48
  34. data/lib/synvert/core/node_query/compiler/array.rb +0 -34
  35. data/lib/synvert/core/node_query/compiler/attribute.rb +0 -39
  36. data/lib/synvert/core/node_query/compiler/attribute_list.rb +0 -24
  37. data/lib/synvert/core/node_query/compiler/basic_selector.rb +0 -28
  38. data/lib/synvert/core/node_query/compiler/boolean.rb +0 -23
  39. data/lib/synvert/core/node_query/compiler/comparable.rb +0 -86
  40. data/lib/synvert/core/node_query/compiler/dynamic_attribute.rb +0 -51
  41. data/lib/synvert/core/node_query/compiler/expression.rb +0 -41
  42. data/lib/synvert/core/node_query/compiler/float.rb +0 -23
  43. data/lib/synvert/core/node_query/compiler/identifier.rb +0 -41
  44. data/lib/synvert/core/node_query/compiler/integer.rb +0 -23
  45. data/lib/synvert/core/node_query/compiler/invalid_operator_error.rb +0 -7
  46. data/lib/synvert/core/node_query/compiler/nil.rb +0 -23
  47. data/lib/synvert/core/node_query/compiler/parse_error.rb +0 -7
  48. data/lib/synvert/core/node_query/compiler/regexp.rb +0 -37
  49. data/lib/synvert/core/node_query/compiler/selector.rb +0 -113
  50. data/lib/synvert/core/node_query/compiler/string.rb +0 -23
  51. data/lib/synvert/core/node_query/compiler/symbol.rb +0 -23
  52. data/lib/synvert/core/node_query/compiler.rb +0 -25
  53. data/lib/synvert/core/node_query/lexer.rex +0 -99
  54. data/lib/synvert/core/node_query/lexer.rex.rb +0 -299
  55. data/lib/synvert/core/node_query/parser.racc.rb +0 -306
  56. data/lib/synvert/core/node_query/parser.y +0 -60
  57. data/lib/synvert/core/node_query.rb +0 -36
  58. data/lib/synvert/core/rewriter/action/append_action.rb +0 -28
  59. data/lib/synvert/core/rewriter/action/delete_action.rb +0 -34
  60. data/lib/synvert/core/rewriter/action/insert_action.rb +0 -34
  61. data/lib/synvert/core/rewriter/action/insert_after_action.rb +0 -22
  62. data/lib/synvert/core/rewriter/action/prepend_action.rb +0 -44
  63. data/lib/synvert/core/rewriter/action/remove_action.rb +0 -56
  64. data/lib/synvert/core/rewriter/action/replace_action.rb +0 -33
  65. data/lib/synvert/core/rewriter/action/replace_with_action.rb +0 -36
  66. data/lib/synvert/core/rewriter/action/wrap_action.rb +0 -37
  67. data/lib/synvert/core/rewriter/action.rb +0 -102
  68. data/spec/synvert/core/node_query/lexer_spec.rb +0 -580
  69. data/spec/synvert/core/node_query/parser_spec.rb +0 -337
  70. data/spec/synvert/core/rewriter/action/append_action_spec.rb +0 -70
  71. data/spec/synvert/core/rewriter/action/delete_action_spec.rb +0 -26
  72. data/spec/synvert/core/rewriter/action/insert_action_spec.rb +0 -70
  73. data/spec/synvert/core/rewriter/action/insert_after_action_spec.rb +0 -26
  74. data/spec/synvert/core/rewriter/action/prepend_action_spec.rb +0 -175
  75. data/spec/synvert/core/rewriter/action/remove_action_spec.rb +0 -26
  76. data/spec/synvert/core/rewriter/action/replace_action_spec.rb +0 -28
  77. data/spec/synvert/core/rewriter/action/replace_with_action_spec.rb +0 -59
  78. data/spec/synvert/core/rewriter/action/wrap_action_spec.rb +0 -31
  79. data/spec/synvert/core/rewriter/action_spec.rb +0 -14
@@ -3,6 +3,26 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  module Synvert::Core
6
- describe Rewriter::ReplaceErbStmtWithExprAction do
6
+ RSpec.describe Rewriter::ReplaceErbStmtWithExprAction do
7
+ context 'replace with single line' do
8
+ subject {
9
+ source = "<% form_for post do |f| %>\n<% end %>"
10
+ source = Engine::Erb.encode(source)
11
+ node = Parser::CurrentRuby.parse(source).children[1]
12
+ described_class.new(node).process
13
+ }
14
+
15
+ it 'gets start' do
16
+ expect(subject.start).to eq '@output_buffer = output_buffer || ActionView::OutputBuffer.new;'.length
17
+ end
18
+
19
+ it 'gets end' do
20
+ expect(subject.end).to eq '@output_buffer = output_buffer || ActionView::OutputBuffer.new;; ; form_for post do |f| ; ;'.length
21
+ end
22
+
23
+ it 'gets new_code' do
24
+ expect(subject.new_code).to eq '@output_buffer.append= form_for post do |f| ; ;'
25
+ end
26
+ end
7
27
  end
8
28
  end
@@ -4,8 +4,6 @@ require 'spec_helper'
4
4
 
5
5
  module Synvert::Core
6
6
  describe Rewriter::Instance do
7
- before { Rewriter::Instance.reset }
8
-
9
7
  let(:instance) {
10
8
  rewriter = Rewriter.new('foo', 'bar')
11
9
  Rewriter::Instance.new(rewriter, ['file pattern'])
@@ -14,16 +12,27 @@ module Synvert::Core
14
12
  it 'parses find_node' do
15
13
  scope = double
16
14
  block = proc {}
17
- expect(Rewriter::QueryScope).to receive(:new).with(instance, '.send[message=create]', &block).and_return(scope)
15
+ expect(Rewriter::QueryScope).to receive(:new).with(instance, '.send[message=create]', {}, &block).and_return(scope)
18
16
  expect(scope).to receive(:process)
19
17
  instance.find_node('.send[message=create]', &block)
20
18
  end
21
19
 
20
+ it 'raises ParseError when parsing invalid nql' do
21
+ block = proc {}
22
+ expect {
23
+ instance.find_node('synvert', &block)
24
+ }.to raise_error(NodeQuery::Compiler::ParseError)
25
+
26
+ expect {
27
+ instance.find_node('.block <caller.arguments> .hash', &block)
28
+ }.to raise_error(NodeQuery::Compiler::ParseError)
29
+ end
30
+
22
31
  it 'parses within_node' do
23
32
  scope = double
24
33
  block = proc {}
25
34
  expect(Rewriter::WithinScope).to receive(:new)
26
- .with(instance, { type: 'send', message: 'create' }, { stop_when_match: false, direct: false }, &block)
35
+ .with(instance, { type: 'send', message: 'create' }, {}, &block)
27
36
  .and_return(scope)
28
37
  expect(scope).to receive(:process)
29
38
  instance.within_node(type: 'send', message: 'create', &block)
@@ -33,30 +42,20 @@ module Synvert::Core
33
42
  scope = double
34
43
  block = proc {}
35
44
  expect(Rewriter::WithinScope).to receive(:new)
36
- .with(instance, { type: 'send', message: 'create' }, { stop_when_match: false, direct: false }, &block)
45
+ .with(instance, { type: 'send', message: 'create' }, {}, &block)
37
46
  .and_return(scope)
38
47
  expect(scope).to receive(:process)
39
48
  instance.with_node(type: 'send', message: 'create', &block)
40
49
  end
41
50
 
42
- it 'parses within_node with stop_when_match true' do
43
- scope = double
44
- block = proc {}
45
- expect(Rewriter::WithinScope).to receive(:new)
46
- .with(instance, { type: 'send', message: 'create' }, { stop_when_match: true, direct: false }, &block)
47
- .and_return(scope)
48
- expect(scope).to receive(:process)
49
- instance.within_node({ type: 'send', message: 'create' }, { stop_when_match: true }, &block)
50
- end
51
-
52
- it 'parses within_node with direct true' do
51
+ it 'parses within_node with stop_at_first_match true' do
53
52
  scope = double
54
53
  block = proc {}
55
54
  expect(Rewriter::WithinScope).to receive(:new)
56
- .with(instance, { type: 'send', message: 'create' }, { stop_when_match: false, direct: true }, &block)
55
+ .with(instance, { type: 'send', message: 'create' }, { stop_at_first_match: true }, &block)
57
56
  .and_return(scope)
58
57
  expect(scope).to receive(:process)
59
- instance.within_node({ type: 'send', message: 'create' }, { direct: true }, &block)
58
+ instance.within_node({ type: 'send', message: 'create' }, { stop_at_first_match: true }, &block)
60
59
  end
61
60
 
62
61
  it 'parses goto_node' do
@@ -98,97 +97,83 @@ module Synvert::Core
98
97
  end
99
98
 
100
99
  it 'parses append' do
101
- action = double
102
- expect(Rewriter::AppendAction).to receive(:new).with(
103
- instance,
104
- 'include FactoryGirl::Syntax::Methods'
105
- ).and_return(action)
106
- expect(action).to receive(:process)
107
- instance.append 'include FactoryGirl::Syntax::Methods'
100
+ instance.current_mutation = double
101
+ instance.current_node = double
102
+ expect(instance.current_mutation).to receive(:append).with(instance.current_node, 'Foobar')
103
+ instance.append 'Foobar'
108
104
  end
109
105
 
110
106
  it 'parses prepend' do
111
- action = double
112
- expect(Rewriter::PrependAction).to receive(:new).with(
113
- instance,
114
- '{{arguments.first}}.include FactoryGirl::Syntax::Methods'
115
- ).and_return(action)
116
- expect(action).to receive(:process)
117
- instance.prepend '{{arguments.first}}.include FactoryGirl::Syntax::Methods'
107
+ instance.current_mutation = double
108
+ instance.current_node = double
109
+ expect(instance.current_mutation).to receive(:prepend).with(instance.current_node, 'Foobar')
110
+ instance.prepend 'Foobar'
118
111
  end
119
112
 
120
113
  it 'parses insert at end' do
121
- action = double
122
- expect(Rewriter::InsertAction).to receive(:new).with(
123
- instance,
124
- '.first',
125
- at: 'end',
126
- to: 'receiver'
127
- ).and_return(action)
128
- expect(action).to receive(:process)
129
- instance.insert '.first', to: 'receiver'
114
+ instance.current_mutation = double
115
+ instance.current_node = double
116
+ expect(instance.current_mutation).to receive(:insert).with(instance.current_node, 'Foobar', at: 'end', to: 'receiver')
117
+ instance.insert 'Foobar', to: 'receiver'
130
118
  end
131
119
 
132
120
  it 'parses insert at beginning' do
133
- action = double
134
- expect(Rewriter::InsertAction).to receive(:new).with(
135
- instance,
136
- 'URI.',
137
- at: 'beginning',
138
- to: nil
139
- ).and_return(action)
140
- expect(action).to receive(:process)
141
- instance.insert 'URI.', at: 'beginning'
121
+ instance.current_mutation = double
122
+ instance.current_node = double
123
+ expect(instance.current_mutation).to receive(:insert).with(instance.current_node, 'Foobar', at: 'beginning', to: nil)
124
+ instance.insert 'Foobar', at: 'beginning'
142
125
  end
143
126
 
144
127
  it 'parses insert_after' do
128
+ instance.current_mutation = double
129
+ instance.current_node = double
130
+ expect(instance.current_mutation).to receive(:insert_after).with(instance.current_node, 'Foobar')
131
+ instance.insert_after 'Foobar'
132
+ end
133
+
134
+ it 'parses replace_erb_stmt_with_expr' do
135
+ instance.current_mutation = double
136
+ instance.current_node = double
145
137
  action = double
146
- expect(Rewriter::InsertAfterAction).to receive(:new).with(
147
- instance,
148
- '{{arguments.first}}.include FactoryGirl::Syntax::Methods'
149
- ).and_return(action)
138
+ expect(instance.current_mutation).to receive(:actions).and_return([])
139
+ expect(Rewriter::ReplaceErbStmtWithExprAction).to receive(:new).with(instance.current_node).and_return(action)
150
140
  expect(action).to receive(:process)
151
- instance.insert_after '{{arguments.first}}.include FactoryGirl::Syntax::Methods'
141
+ instance.replace_erb_stmt_with_expr
152
142
  end
153
143
 
154
144
  it 'parses replace_with' do
155
- action = double
156
- expect(Rewriter::ReplaceWithAction).to receive(:new).with(instance, 'create {{arguments}}').and_return(action)
157
- expect(action).to receive(:process)
158
- instance.replace_with 'create {{arguments}}'
145
+ instance.current_mutation = double
146
+ instance.current_node = double
147
+ expect(instance.current_mutation).to receive(:replace_with).with(instance.current_node, 'Foobar')
148
+ instance.replace_with 'Foobar'
159
149
  end
160
150
 
161
151
  it 'parses replace with' do
162
- action = double
163
- expect(Rewriter::ReplaceAction).to receive(:new).with(instance, :message, with: 'test').and_return(action)
164
- expect(action).to receive(:process)
165
- instance.replace :message, with: 'test'
152
+ instance.current_mutation = double
153
+ instance.current_node = double
154
+ expect(instance.current_mutation).to receive(:replace).with(instance.current_node, :message, with: 'Foobar')
155
+ instance.replace :message, with: 'Foobar'
166
156
  end
167
157
 
168
158
  it 'parses remove' do
169
- action = double
170
- expect(Rewriter::RemoveAction).to receive(:new).with(instance, { and_comma: true }).and_return(action)
171
- expect(action).to receive(:process)
159
+ instance.current_mutation = double
160
+ instance.current_node = double
161
+ expect(instance.current_mutation).to receive(:remove).with(instance.current_node, and_comma: true)
172
162
  instance.remove and_comma: true
173
163
  end
174
164
 
175
- it 'parses remove' do
176
- action = double
177
- expect(Rewriter::DeleteAction).to receive(:new).with(
178
- instance,
179
- :dot,
180
- :message,
181
- { and_comma: true }
182
- ).and_return(action)
183
- expect(action).to receive(:process)
165
+ it 'parses delete' do
166
+ instance.current_mutation = double
167
+ instance.current_node = double
168
+ expect(instance.current_mutation).to receive(:delete).with(instance.current_node, :dot, :message, and_comma: true)
184
169
  instance.delete :dot, :message, and_comma: true
185
170
  end
186
171
 
187
172
  it 'parses wrap with' do
188
- action = double
189
- expect(Rewriter::WrapAction).to receive(:new).with(instance, with: 'module Foo', indent: nil).and_return(action)
190
- expect(action).to receive(:process)
191
- instance.wrap with: 'module Foo'
173
+ instance.current_mutation = double
174
+ instance.current_node = double
175
+ expect(instance.current_mutation).to receive(:wrap).with(instance.current_node, with: 'module Foobar')
176
+ instance.wrap with: 'module Foobar'
192
177
  end
193
178
 
194
179
  it 'parses warn' do
@@ -251,32 +236,6 @@ module Synvert::Core
251
236
  instance.process
252
237
  end
253
238
 
254
- it 'does not read file if already read' do
255
- instance =
256
- Rewriter::Instance.new rewriter, ['spec/spec_helper.rb'] do
257
- with_node type: 'block', caller: { receiver: 'RSpec', message: 'configure' } do
258
- unless_exist_node type: 'send', message: 'include', arguments: ['FactoryGirl::Syntax::Methods'] do
259
- insert '{{arguments.first}}.include FactoryGirl::Syntax::Methods'
260
- end
261
- end
262
- end
263
- input = <<~EOS
264
- RSpec.configure do |config|
265
- config.include FactoryGirl::Syntax::Methods
266
- end
267
- EOS
268
- output = <<~EOS
269
- RSpec.configure do |config|
270
- config.include FactoryGirl::Syntax::Methods
271
- end
272
- EOS
273
- expect(Dir).to receive(:glob).with('./spec/spec_helper.rb').and_return(['spec/spec_helper.rb']).twice
274
- expect(File).to receive(:read).with('spec/spec_helper.rb', encoding: 'UTF-8').and_return(input).once
275
- expect(File).not_to receive(:write).with('spec/spec_helper.rb', output)
276
- instance.process
277
- instance.process
278
- end
279
-
280
239
  it 'updates file_source and file_ast when writing a file' do
281
240
  instance =
282
241
  Rewriter::Instance.new rewriter, ['spec/**/*_spec.rb'] do
@@ -308,32 +267,6 @@ module Synvert::Core
308
267
  end
309
268
  end
310
269
 
311
- describe '#get_conflict_actions' do
312
- let(:rewriter) { Rewriter.new('foo', 'bar') }
313
-
314
- it 'has no conflict' do
315
- action1 = double(begin_pos: 10, end_pos: 20)
316
- action2 = double(begin_pos: 30, end_pos: 40)
317
- action3 = double(begin_pos: 50, end_pos: 60)
318
- instance = Rewriter::Instance.new rewriter, ['spec/spec_helper.rb']
319
- instance.instance_variable_set :@actions, [action1, action2, action3]
320
- conflict_actions = instance.send(:get_conflict_actions)
321
- expect(conflict_actions).to eq []
322
- expect(instance.instance_variable_get(:@actions)).to eq [action1, action2, action3]
323
- end
324
-
325
- it 'has no conflict' do
326
- action1 = double(begin_pos: 30, end_pos: 40)
327
- action2 = double(begin_pos: 50, end_pos: 60)
328
- action3 = double(begin_pos: 10, end_pos: 20)
329
- instance = Rewriter::Instance.new rewriter, ['spec/spec_helper.rb']
330
- instance.instance_variable_set :@actions, [action1, action2, action3]
331
- conflict_actions = instance.send(:get_conflict_actions)
332
- expect(conflict_actions).to eq [action2, action1]
333
- expect(instance.instance_variable_get(:@actions)).to eq [action3]
334
- end
335
- end
336
-
337
270
  describe '#process_with_node' do
338
271
  it 'resets current_node' do
339
272
  node1 = double
@@ -14,10 +14,7 @@ module Synvert::Core
14
14
  EOS
15
15
 
16
16
  let(:node) { Parser::CurrentRuby.parse(source) }
17
- before do
18
- Rewriter::Instance.reset
19
- instance.current_node = node
20
- end
17
+ before { instance.current_node = node }
21
18
 
22
19
  describe '#process' do
23
20
  it 'call block with child node' do
@@ -18,10 +18,7 @@ module Synvert::Core
18
18
 
19
19
  let(:node) { Parser::CurrentRuby.parse(source) }
20
20
 
21
- before do
22
- Rewriter::Instance.reset
23
- instance.current_node = node
24
- end
21
+ before { instance.current_node = node }
25
22
 
26
23
  describe '#process' do
27
24
  it 'not call block if no matching node' do
@@ -58,18 +55,6 @@ module Synvert::Core
58
55
  expect(block_nodes.size).to eq 2
59
56
  end
60
57
 
61
- it 'raises ParseError' do
62
- scope = described_class.new(instance, 'synvert') {}
63
- expect {
64
- scope.process
65
- }.to raise_error(NodeQuery::Compiler::ParseError)
66
-
67
- scope = described_class.new(instance, '.block <caller.arguments> .hash') {}
68
- expect {
69
- scope.process
70
- }.to raise_error(NodeQuery::Compiler::ParseError)
71
- end
72
-
73
58
  it 'raises InvalidOperatorError' do
74
59
  scope = described_class.new(instance, '.send[receiver IN FactoryGirl]') {}
75
60
  expect {
@@ -9,19 +9,18 @@ module Synvert::Core
9
9
  Rewriter::Instance.new(rewriter, 'file pattern')
10
10
  }
11
11
  let(:source) { <<~EOS }
12
- describe Post do
13
- it 'gets post' do
14
- FactoryGirl.create :post
12
+ describe User do
13
+ describe 'create' do
14
+ it 'creates user' do
15
+ FactoryGirl.create :user
16
+ end
15
17
  end
16
18
  end
17
19
  EOS
18
20
 
19
21
  let(:node) { Parser::CurrentRuby.parse(source) }
20
22
 
21
- before do
22
- Rewriter::Instance.reset
23
- instance.current_node = node
24
- end
23
+ before { instance.current_node = node }
25
24
 
26
25
  describe '#process' do
27
26
  it 'not call block if no matching node' do
@@ -42,7 +41,7 @@ module Synvert::Core
42
41
  type: 'send',
43
42
  receiver: 'FactoryGirl',
44
43
  message: 'create',
45
- arguments: [':post'] do
44
+ arguments: [':user'] do
46
45
  run = true
47
46
  type_in_scope = node.type
48
47
  end
@@ -55,27 +54,37 @@ module Synvert::Core
55
54
  it 'matches multiple block nodes' do
56
55
  block_nodes = []
57
56
  scope =
58
- Rewriter::WithinScope.new(instance, { type: 'block' }, { stop_when_match: false }) do
57
+ Rewriter::WithinScope.new(instance, { type: 'block' }) do
58
+ block_nodes << node
59
+ end
60
+ scope.process
61
+ expect(block_nodes.size).to eq 3
62
+ end
63
+
64
+ it 'matches only 2 block nodes if including_self is false' do
65
+ block_nodes = []
66
+ scope =
67
+ Rewriter::WithinScope.new(instance, { type: 'block' }, { including_self: false }) do
59
68
  block_nodes << node
60
69
  end
61
70
  scope.process
62
71
  expect(block_nodes.size).to eq 2
63
72
  end
64
73
 
65
- it 'matches only one block node if no recursive' do
74
+ it 'matches only one block node if recursive is false' do
66
75
  block_nodes = []
67
76
  scope =
68
- Rewriter::WithinScope.new(instance, { type: 'block' }, { stop_when_match: true }) do
77
+ Rewriter::WithinScope.new(instance, { type: 'block' }, { recursive: false }) do
69
78
  block_nodes << node
70
79
  end
71
80
  scope.process
72
81
  expect(block_nodes.size).to eq 1
73
82
  end
74
83
 
75
- it 'matches only one direct node' do
84
+ it 'matches only one block node if stop_at_first_match is true' do
76
85
  block_nodes = []
77
86
  scope =
78
- Rewriter::WithinScope.new(instance, { type: 'block' }, { direct: true }) do
87
+ Rewriter::WithinScope.new(instance, { type: 'block' }, { stop_at_first_match: true }) do
79
88
  block_nodes << node
80
89
  end
81
90
  scope.process
@@ -14,13 +14,15 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = "https://github.com/xinminlabs/synvert-core-ruby"
15
15
  spec.license = "MIT"
16
16
 
17
- spec.files = `git ls-files -z`.split("\x0") +
18
- %w[lib/synvert/core/node_query/lexer.rex.rb lib/synvert/core/node_query/parser.racc.rb]
17
+ spec.files = `git ls-files -z`.split("\x0")
19
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
20
  spec.require_paths = ["lib"]
22
21
 
23
- spec.add_runtime_dependency "activesupport"
22
+ spec.add_runtime_dependency "activesupport", "< 7.0.0"
24
23
  spec.add_runtime_dependency "erubis"
24
+ spec.add_runtime_dependency "node_query"
25
+ spec.add_runtime_dependency "node_mutation"
25
26
  spec.add_runtime_dependency "parser"
27
+ spec.add_runtime_dependency "parser_node_ext"
26
28
  end
metadata CHANGED
@@ -1,17 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synvert-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.6.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: 2022-05-21 00:00:00.000000000 Z
11
+ date: 2022-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "<"
18
+ - !ruby/object:Gem::Version
19
+ version: 7.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "<"
25
+ - !ruby/object:Gem::Version
26
+ version: 7.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: erubis
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - ">="
@@ -25,7 +39,21 @@ dependencies:
25
39
  - !ruby/object:Gem::Version
26
40
  version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
- name: erubis
42
+ name: node_query
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: node_mutation
29
57
  requirement: !ruby/object:Gem::Requirement
30
58
  requirements:
31
59
  - - ">="
@@ -52,6 +80,20 @@ dependencies:
52
80
  - - ">="
53
81
  - !ruby/object:Gem::Version
54
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: parser_node_ext
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
55
97
  description: convert ruby code to better syntax automatically.
56
98
  email:
57
99
  - flyerhzm@gmail.com
@@ -64,53 +106,19 @@ files:
64
106
  - ".rspec"
65
107
  - CHANGELOG.md
66
108
  - Gemfile
109
+ - Gemfile.lock
67
110
  - Guardfile
68
111
  - LICENSE.txt
69
112
  - README.md
70
113
  - Rakefile
71
114
  - lib/synvert/core.rb
72
- - lib/synvert/core/array_ext.rb
73
115
  - lib/synvert/core/configuration.rb
74
116
  - lib/synvert/core/engine.rb
75
117
  - lib/synvert/core/engine/erb.rb
76
118
  - lib/synvert/core/exceptions.rb
77
119
  - lib/synvert/core/node_ext.rb
78
- - lib/synvert/core/node_query.rb
79
- - lib/synvert/core/node_query/compiler.rb
80
- - lib/synvert/core/node_query/compiler/array.rb
81
- - lib/synvert/core/node_query/compiler/attribute.rb
82
- - lib/synvert/core/node_query/compiler/attribute_list.rb
83
- - lib/synvert/core/node_query/compiler/basic_selector.rb
84
- - lib/synvert/core/node_query/compiler/boolean.rb
85
- - lib/synvert/core/node_query/compiler/comparable.rb
86
- - lib/synvert/core/node_query/compiler/dynamic_attribute.rb
87
- - lib/synvert/core/node_query/compiler/expression.rb
88
- - lib/synvert/core/node_query/compiler/float.rb
89
- - lib/synvert/core/node_query/compiler/identifier.rb
90
- - lib/synvert/core/node_query/compiler/integer.rb
91
- - lib/synvert/core/node_query/compiler/invalid_operator_error.rb
92
- - lib/synvert/core/node_query/compiler/nil.rb
93
- - lib/synvert/core/node_query/compiler/parse_error.rb
94
- - lib/synvert/core/node_query/compiler/regexp.rb
95
- - lib/synvert/core/node_query/compiler/selector.rb
96
- - lib/synvert/core/node_query/compiler/string.rb
97
- - lib/synvert/core/node_query/compiler/symbol.rb
98
- - lib/synvert/core/node_query/lexer.rex
99
- - lib/synvert/core/node_query/lexer.rex.rb
100
- - lib/synvert/core/node_query/parser.racc.rb
101
- - lib/synvert/core/node_query/parser.y
102
120
  - lib/synvert/core/rewriter.rb
103
- - lib/synvert/core/rewriter/action.rb
104
- - lib/synvert/core/rewriter/action/append_action.rb
105
- - lib/synvert/core/rewriter/action/delete_action.rb
106
- - lib/synvert/core/rewriter/action/insert_action.rb
107
- - lib/synvert/core/rewriter/action/insert_after_action.rb
108
- - lib/synvert/core/rewriter/action/prepend_action.rb
109
- - lib/synvert/core/rewriter/action/remove_action.rb
110
- - lib/synvert/core/rewriter/action/replace_action.rb
111
121
  - lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb
112
- - lib/synvert/core/rewriter/action/replace_with_action.rb
113
- - lib/synvert/core/rewriter/action/wrap_action.rb
114
122
  - lib/synvert/core/rewriter/any_value.rb
115
123
  - lib/synvert/core/rewriter/condition.rb
116
124
  - lib/synvert/core/rewriter/condition/if_exist_condition.rb
@@ -130,19 +138,7 @@ files:
130
138
  - spec/support/parser_helper.rb
131
139
  - spec/synvert/core/engine/erb_spec.rb
132
140
  - spec/synvert/core/node_ext_spec.rb
133
- - spec/synvert/core/node_query/lexer_spec.rb
134
- - spec/synvert/core/node_query/parser_spec.rb
135
- - spec/synvert/core/rewriter/action/append_action_spec.rb
136
- - spec/synvert/core/rewriter/action/delete_action_spec.rb
137
- - spec/synvert/core/rewriter/action/insert_action_spec.rb
138
- - spec/synvert/core/rewriter/action/insert_after_action_spec.rb
139
- - spec/synvert/core/rewriter/action/prepend_action_spec.rb
140
- - spec/synvert/core/rewriter/action/remove_action_spec.rb
141
- - spec/synvert/core/rewriter/action/replace_action_spec.rb
142
141
  - spec/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action_spec.rb
143
- - spec/synvert/core/rewriter/action/replace_with_action_spec.rb
144
- - spec/synvert/core/rewriter/action/wrap_action_spec.rb
145
- - spec/synvert/core/rewriter/action_spec.rb
146
142
  - spec/synvert/core/rewriter/condition/if_exist_condition_spec.rb
147
143
  - spec/synvert/core/rewriter/condition/if_only_exist_condition_spec.rb
148
144
  - spec/synvert/core/rewriter/condition/unless_exist_condition_spec.rb
@@ -186,19 +182,7 @@ test_files:
186
182
  - spec/support/parser_helper.rb
187
183
  - spec/synvert/core/engine/erb_spec.rb
188
184
  - spec/synvert/core/node_ext_spec.rb
189
- - spec/synvert/core/node_query/lexer_spec.rb
190
- - spec/synvert/core/node_query/parser_spec.rb
191
- - spec/synvert/core/rewriter/action/append_action_spec.rb
192
- - spec/synvert/core/rewriter/action/delete_action_spec.rb
193
- - spec/synvert/core/rewriter/action/insert_action_spec.rb
194
- - spec/synvert/core/rewriter/action/insert_after_action_spec.rb
195
- - spec/synvert/core/rewriter/action/prepend_action_spec.rb
196
- - spec/synvert/core/rewriter/action/remove_action_spec.rb
197
- - spec/synvert/core/rewriter/action/replace_action_spec.rb
198
185
  - spec/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action_spec.rb
199
- - spec/synvert/core/rewriter/action/replace_with_action_spec.rb
200
- - spec/synvert/core/rewriter/action/wrap_action_spec.rb
201
- - spec/synvert/core/rewriter/action_spec.rb
202
186
  - spec/synvert/core/rewriter/condition/if_exist_condition_spec.rb
203
187
  - spec/synvert/core/rewriter/condition/if_only_exist_condition_spec.rb
204
188
  - spec/synvert/core/rewriter/condition/unless_exist_condition_spec.rb
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Extend Array.
4
- class Array
5
- # Get child node by the name.
6
- #
7
- # @param child_name [String] name of child node.
8
- # @return [Parser::AST::Node] the child node.
9
- def child_node_by_name(child_name)
10
- direct_child_name, nested_child_name = child_name.split('.', 2)
11
- child_direct_child_node = direct_child_name =~ /\A\d+\z/ ? self[direct_child_name.to_i - 1] : self.send(direct_child_name)
12
- return child_direct_child_node.child_node_by_name(nested_child_name) if nested_child_name
13
- return child_direct_child_node if child_direct_child_node
14
-
15
- raise Synvert::Core::MethodNotSupported,
16
- "child_node_by_name is not handled for #{debug_info}, child_name: #{child_name}"
17
- end
18
-
19
- # Get the source range of child node.
20
- #
21
- # @param child_name [String] name of child node.
22
- # @return [Parser::Source::Range] source range of child node.
23
- def child_node_range(child_name)
24
- direct_child_name, nested_child_name = child_name.split('.', 2)
25
- child_direct_child_node = direct_child_name =~ /\A\d+\z/ ? self[direct_child_name.to_i - 1] : self.send(direct_child_name)
26
- if nested_child_name
27
- return child_direct_child_node.child_node_range(nested_child_name)
28
- elsif child_direct_child_node
29
- return (
30
- Parser::Source::Range.new(
31
- '(string)',
32
- child_direct_child_node.loc.expression.begin_pos,
33
- child_direct_child_node.loc.expression.end_pos
34
- )
35
- )
36
- else
37
- raise Synvert::Core::MethodNotSupported,
38
- "child_node_range is not handled for #{debug_info}, child_name: #{child_name}"
39
- end
40
- end
41
-
42
- # Return the debug info.
43
- #
44
- # @return [String] file, line, source and node.
45
- def debug_info
46
- map(&:debug_info).join("\n")
47
- end
48
- end