synvert-core 1.3.0 → 1.3.1
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 +4 -0
- data/lib/synvert/core/node_query/lexer.rex.rb +1 -0
- data/lib/synvert/core/node_query/parser.racc.rb +1 -0
- data/lib/synvert/core/rewriter/action/delete_action.rb +4 -2
- data/lib/synvert/core/rewriter/action/remove_action.rb +5 -2
- data/lib/synvert/core/rewriter/instance.rb +8 -4
- data/lib/synvert/core/version.rb +1 -1
- data/spec/synvert/core/rewriter/instance_spec.rb +9 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51aff3b9c1c43ab2e6b3c093b65a42cb97536b900cf0aa8d0081e7e8716346f0
|
4
|
+
data.tar.gz: 6902ad17b6fa2d1ab2a5d5294f3bb1f29903a12c7ad8dd15cc7dae56173a440a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74cc5bb2cf144fba8bbd8ad647971efeba9473138d1cc5b416b45aa940c22f8929cefdd32b5e692c0dc1a9c9786d49dd8b441f1949a58256cec015a9697f2a43
|
7
|
+
data.tar.gz: c08abee0bf9fd0cba7cd5248f9020c4c30dadc25c06c5b358a122ccb09e7171878eae85cd498a0fb788aa2987fcf0302916c49cca0f9eaabc77b55e3a43d6a3a
|
data/CHANGELOG.md
CHANGED
@@ -7,9 +7,11 @@ module Synvert::Core
|
|
7
7
|
#
|
8
8
|
# @param instance [Synvert::Core::Rewriter::Instance]
|
9
9
|
# @param selectors [Array<Symbol, String>] used to select child nodes
|
10
|
-
|
10
|
+
# @option and_comma [Boolean] delete extra comma.
|
11
|
+
def initialize(instance, *selectors, and_comma: false)
|
11
12
|
super(instance, nil)
|
12
13
|
@selectors = selectors
|
14
|
+
@and_comma = and_comma
|
13
15
|
end
|
14
16
|
|
15
17
|
# The rewritten code, always empty string.
|
@@ -26,7 +28,7 @@ module Synvert::Core
|
|
26
28
|
@end_pos = @selectors.map { |selector| @node.child_node_range(selector) }
|
27
29
|
.compact.map(&:end_pos).max
|
28
30
|
squeeze_spaces
|
29
|
-
remove_comma
|
31
|
+
remove_comma if @and_comma
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
@@ -6,8 +6,11 @@ module Synvert::Core
|
|
6
6
|
# Initialize a RemoveAction.
|
7
7
|
#
|
8
8
|
# @param instance [Synvert::Core::Rewriter::RemoveAction]
|
9
|
-
|
9
|
+
# @param options [Hash] options.
|
10
|
+
# @option and_comma [Boolean] delete extra comma.
|
11
|
+
def initialize(instance, and_comma: false)
|
10
12
|
super(instance, nil)
|
13
|
+
@and_comma = and_comma
|
11
14
|
end
|
12
15
|
|
13
16
|
# The rewritten code, always empty string.
|
@@ -27,7 +30,7 @@ module Synvert::Core
|
|
27
30
|
@begin_pos = @node.loc.expression.begin_pos
|
28
31
|
@end_pos = @node.loc.expression.end_pos
|
29
32
|
squeeze_spaces
|
30
|
-
remove_comma
|
33
|
+
remove_comma if @and_command
|
31
34
|
end
|
32
35
|
end
|
33
36
|
|
@@ -333,8 +333,10 @@ module Synvert::Core
|
|
333
333
|
# with_node type: 'send', message: { in: %w[puts p] } do
|
334
334
|
# remove
|
335
335
|
# end
|
336
|
-
|
337
|
-
|
336
|
+
# @param options [Hash] options.
|
337
|
+
# @option and_comma [Boolean] delete extra comma.
|
338
|
+
def remove(**options)
|
339
|
+
@actions << Rewriter::RemoveAction.new(self, **options).process
|
338
340
|
end
|
339
341
|
|
340
342
|
# Parse +delete+ dsl, it creates a {Synvert::Core::Rewriter::DeleteAction} to delete child nodes.
|
@@ -346,8 +348,10 @@ module Synvert::Core
|
|
346
348
|
# delete :receiver, :dot
|
347
349
|
# end
|
348
350
|
# @param selectors [Array<Symbol>] selector names of child node.
|
349
|
-
|
350
|
-
|
351
|
+
# @param options [Hash]
|
352
|
+
# @option and_comma [Boolean] delete extra comma.
|
353
|
+
def delete(*selectors, **options)
|
354
|
+
@actions << Rewriter::DeleteAction.new(self, *selectors, **options).process
|
351
355
|
end
|
352
356
|
|
353
357
|
# Parse +wrap+ dsl, it creates a {Synvert::Core::Rewriter::WrapAction} to
|
data/lib/synvert/core/version.rb
CHANGED
@@ -167,16 +167,21 @@ module Synvert::Core
|
|
167
167
|
|
168
168
|
it 'parses remove' do
|
169
169
|
action = double
|
170
|
-
expect(Rewriter::RemoveAction).to receive(:new).with(instance).and_return(action)
|
170
|
+
expect(Rewriter::RemoveAction).to receive(:new).with(instance, { and_comma: true }).and_return(action)
|
171
171
|
expect(action).to receive(:process)
|
172
|
-
instance.remove
|
172
|
+
instance.remove and_comma: true
|
173
173
|
end
|
174
174
|
|
175
175
|
it 'parses remove' do
|
176
176
|
action = double
|
177
|
-
expect(Rewriter::DeleteAction).to receive(:new).with(
|
177
|
+
expect(Rewriter::DeleteAction).to receive(:new).with(
|
178
|
+
instance,
|
179
|
+
:dot,
|
180
|
+
:message,
|
181
|
+
{ and_comma: true }
|
182
|
+
).and_return(action)
|
178
183
|
expect(action).to receive(:process)
|
179
|
-
instance.delete :dot, :message
|
184
|
+
instance.delete :dot, :message, and_comma: true
|
180
185
|
end
|
181
186
|
|
182
187
|
it 'parses wrap with' 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: 1.3.
|
4
|
+
version: 1.3.1
|
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-
|
11
|
+
date: 2022-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|