synvert-core 0.4.2 → 0.4.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 +10 -3
- data/lib/synvert/core/node_ext.rb +13 -1
- data/lib/synvert/core/rewriter/action.rb +1 -1
- data/lib/synvert/core/rewriter/instance.rb +20 -3
- data/lib/synvert/core/rewriter/scope.rb +2 -12
- data/lib/synvert/core/version.rb +1 -1
- data/spec/synvert/core/node_ext_spec.rb +7 -0
- data/spec/synvert/core/rewriter/instance_spec.rb +32 -0
- data/spec/synvert/core/rewriter/scope_spec.rb +4 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bde34eb3461990b83ea42cb438131ed34dab7ff
|
4
|
+
data.tar.gz: 856cce48e98b4b1930f247125a7dd156a3c0e2b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2abd9040ab9b7f2908c1ef1f3c617bbf367fc177e0fb78a4b088b13520d60dd85cdd1afb93fb39d9bbeca20d25eabac4468dde07b99fc459a90335b1ec41df7a
|
7
|
+
data.tar.gz: 7848b2dd867efe89b7ee79207274e59cf33660ea5115a23af4ec20fff9e3400f2df27a23492e8b2e5ecc294e79453e72f021ea207040f302accfdedbda3d9e4b
|
data/CHANGELOG.md
CHANGED
@@ -1,13 +1,20 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 0.4.3
|
4
|
+
|
5
|
+
* Add parent_class for :class node
|
6
|
+
* Move process_with_node to instance
|
7
|
+
* Add Instance#process_with_other_node
|
8
|
+
* Fix indent for append action
|
9
|
+
|
3
10
|
## 0.4.2
|
4
11
|
|
5
|
-
*
|
6
|
-
*
|
12
|
+
* Do not rewrite code in {{ }} in synvert can't rewrite it
|
13
|
+
* Fix indent for replace_with action
|
7
14
|
|
8
15
|
## 0.4.1
|
9
16
|
|
10
|
-
*
|
17
|
+
* Add Rewriter::Helper module to provide common helper methods.
|
11
18
|
|
12
19
|
## 0.4.0 (2014-07-26)
|
13
20
|
|
@@ -15,6 +15,18 @@ class Parser::AST::Node
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
# Get parent_class node of :class node.
|
19
|
+
#
|
20
|
+
# @return [Parser::AST::Node] parent_class node.
|
21
|
+
# @raise [Synvert::Core::MethodNotSupported] if calls on other node.
|
22
|
+
def parent_class
|
23
|
+
if :class == self.type
|
24
|
+
self.children[1]
|
25
|
+
else
|
26
|
+
raise Synvert::Core::MethodNotSupported.new "parent_class is not handled for #{self.inspect}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
18
30
|
# Get receiver node of :send node.
|
19
31
|
#
|
20
32
|
# @return [Parser::AST::Node] receiver node.
|
@@ -266,7 +278,7 @@ class Parser::AST::Node
|
|
266
278
|
source = evaluated.first.loc.expression.source_buffer.source
|
267
279
|
source[evaluated.first.loc.expression.begin_pos...evaluated.last.loc.expression.end_pos]
|
268
280
|
end
|
269
|
-
when String
|
281
|
+
when String, Symbol
|
270
282
|
evaluated
|
271
283
|
when NilClass
|
272
284
|
'nil'
|
@@ -55,9 +55,9 @@ module Synvert::Core
|
|
55
55
|
|
56
56
|
@current_file = file_path
|
57
57
|
@current_source = source
|
58
|
-
|
59
|
-
|
60
|
-
|
58
|
+
self.process_with_node ast do
|
59
|
+
instance_eval &@block
|
60
|
+
end
|
61
61
|
|
62
62
|
@actions.sort!
|
63
63
|
check_conflict_actions
|
@@ -174,6 +174,23 @@ module Synvert::Core
|
|
174
174
|
@rewriter.add_warning Rewriter::Warning.new(self, message)
|
175
175
|
end
|
176
176
|
|
177
|
+
# Set current_node to node and process.
|
178
|
+
# @param node [Parser::AST::Node] node set to current_node
|
179
|
+
def process_with_node(node)
|
180
|
+
self.current_node = node
|
181
|
+
yield
|
182
|
+
self.current_node = node
|
183
|
+
end
|
184
|
+
|
185
|
+
# Set current_node properly, process and set current_node back to original current_node.
|
186
|
+
# @param node [Parser::AST::Node] node set to current_node
|
187
|
+
def process_with_other_node(node)
|
188
|
+
original_node = self.current_node
|
189
|
+
self.current_node = node
|
190
|
+
yield
|
191
|
+
self.current_node = original_node
|
192
|
+
end
|
193
|
+
|
177
194
|
private
|
178
195
|
|
179
196
|
# It changes source code from bottom to top, and it can change source code twice at the same time.
|
@@ -19,28 +19,18 @@ module Synvert::Core
|
|
19
19
|
def process
|
20
20
|
current_node = @instance.current_node
|
21
21
|
return unless current_node
|
22
|
-
process_with_node current_node do
|
22
|
+
@instance.process_with_node current_node do
|
23
23
|
matching_nodes = []
|
24
24
|
matching_nodes << current_node if current_node.match? @rules
|
25
25
|
current_node.recursive_children do |child_node|
|
26
26
|
matching_nodes << child_node if child_node.match? @rules
|
27
27
|
end
|
28
28
|
matching_nodes.each do |matching_node|
|
29
|
-
process_with_node matching_node do
|
29
|
+
@instance.process_with_node matching_node do
|
30
30
|
@instance.instance_eval &@block
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
# Set instance current node properly and process.
|
39
|
-
# @param node [Parser::AST::Node]
|
40
|
-
def process_with_node(node)
|
41
|
-
@instance.current_node = node
|
42
|
-
yield
|
43
|
-
@instance.current_node = node
|
44
|
-
end
|
45
35
|
end
|
46
36
|
end
|
data/lib/synvert/core/version.rb
CHANGED
@@ -26,6 +26,13 @@ describe Parser::AST::Node do
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
describe '#parent_class' do
|
30
|
+
it 'gets for class node' do
|
31
|
+
node = parse('class Post < ActiveRecord::Base; end')
|
32
|
+
expect(node.parent_class).to eq parse('ActiveRecord::Base')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
29
36
|
describe '#receiver' do
|
30
37
|
it 'gets for send node' do
|
31
38
|
node = parse('FactoryGirl.create :post')
|
@@ -191,5 +191,37 @@ end
|
|
191
191
|
end
|
192
192
|
end
|
193
193
|
end
|
194
|
+
|
195
|
+
describe '#process_with_node' do
|
196
|
+
let(:rewriter) { Rewriter.new('foobar') }
|
197
|
+
|
198
|
+
it 'resets current_node' do
|
199
|
+
instance = Rewriter::Instance.new rewriter, 'spec/**/*_spec.rb' do; end
|
200
|
+
node1 = double()
|
201
|
+
node2 = double()
|
202
|
+
instance.process_with_node(node1) do
|
203
|
+
instance.current_node = node2
|
204
|
+
expect(instance.current_node).to eq node2
|
205
|
+
end
|
206
|
+
expect(instance.current_node).to eq node1
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
describe '#process_with_other_node' do
|
211
|
+
let(:rewriter) { Rewriter.new('foobar') }
|
212
|
+
|
213
|
+
it 'resets current_node' do
|
214
|
+
instance = Rewriter::Instance.new rewriter, 'spec/**/*_spec.rb' do; end
|
215
|
+
node1 = double()
|
216
|
+
node2 = double()
|
217
|
+
node3 = double()
|
218
|
+
instance.current_node = node1
|
219
|
+
instance.process_with_other_node(node2) do
|
220
|
+
instance.current_node = node3
|
221
|
+
expect(instance.current_node).to eq node3
|
222
|
+
end
|
223
|
+
expect(instance.current_node).to eq node1
|
224
|
+
end
|
225
|
+
end
|
194
226
|
end
|
195
227
|
end
|
@@ -18,7 +18,10 @@ end
|
|
18
18
|
}
|
19
19
|
let(:node) { Parser::CurrentRuby.parse(source) }
|
20
20
|
let(:instance) { double(:current_node => node, :current_node= => node, :current_source => source) }
|
21
|
-
before
|
21
|
+
before do
|
22
|
+
allow(instance).to receive(:process_with_node).and_yield
|
23
|
+
Rewriter::Instance.current = instance
|
24
|
+
end
|
22
25
|
|
23
26
|
describe '#process' do
|
24
27
|
it 'not call block if no matching node' do
|
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.
|
4
|
+
version: 0.4.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: 2014-08-
|
11
|
+
date: 2014-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|