node_mutation 1.15.1 → 1.15.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 382d91776358172b2310f5281edc413bf6066da9e333e150fa14a068219058bf
4
- data.tar.gz: 5bdeef13cc69a5f4e6b9abef45ed95eeab57b13e95bed01a8fb0f25b02788140
3
+ metadata.gz: e184fa98da9cbfac3645ec4e89ac2201cdbbfd958c511a03050443a66c79b322
4
+ data.tar.gz: 7c7693df11e9cd74df33d5ef6949bc800ab3a6c4367836c799b76073800586d5
5
5
  SHA512:
6
- metadata.gz: b35c57db840700ed2a53ea3f0b1713185da7c36b4759537709ce726cf1094f862dcdd9cc2e5a19cdb99b0ef34ebe1436414e17c35915f6694b3c7ee66bf4a163
7
- data.tar.gz: 2ad6b1ec1f27bad428cc299ffb95f3fce4bd57338365a60707736ae9936aaf15f445d89d8cf339224f4994391907a9df6d3e7ee2dfb2cc394782c2b83261645f
6
+ metadata.gz: 17c9a5065bb703331ccf1996bb3895ff833336b768aca74751c52b885c0651c9c4bb19b989d026aa39b10cdf03b61ab43ddf3e5e1fe742aa837527b8e680279e
7
+ data.tar.gz: ba34afa52b6dacf07f5a9b736a31e2b1ad0c37e3a0717690d302f1a1e91ab366705d7ac840a903ada796d182731731823a7cf438e3d1de6c07ee1fcdb2ae5861
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # NodeMutation
2
2
 
3
+ ## 1.15.3 (2023-04-18)
4
+
5
+ * Add `type` to `Action`
6
+
7
+ ## 1.15.2 (2023-04-17)
8
+
9
+ * Support `const` `double_colon` in child_node_range
10
+
3
11
  ## 1.15.1 (2023-04-17)
4
12
 
5
13
  * Fix `wrap` code for newline
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- node_mutation (1.15.1)
4
+ node_mutation (1.15.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -2,6 +2,11 @@
2
2
 
3
3
  # AppendAction appends code to the bottom of node body.
4
4
  class NodeMutation::AppendAction < NodeMutation::Action
5
+ def initialize(node, code)
6
+ super(node, code)
7
+ @type = :insert
8
+ end
9
+
5
10
  private
6
11
 
7
12
  END_LENGTH = "\nend".length
@@ -11,6 +11,7 @@ class NodeMutation::DeleteAction < NodeMutation::Action
11
11
  super(node, nil)
12
12
  @selectors = selectors
13
13
  @and_comma = and_comma
14
+ @type = :delete
14
15
  end
15
16
 
16
17
  # The rewritten code, always empty string.
@@ -9,6 +9,7 @@ class NodeMutation::IndentAction < NodeMutation::Action
9
9
  def initialize(node, tab_size = 1)
10
10
  super(node, nil)
11
11
  @tab_size = tab_size
12
+ @type = :replace
12
13
  end
13
14
 
14
15
  # The rewritten source code with proper indent.
@@ -14,6 +14,7 @@ class NodeMutation::InsertAction < NodeMutation::Action
14
14
  @at = at
15
15
  @to = to
16
16
  @and_comma = and_comma
17
+ @type = :insert
17
18
  end
18
19
 
19
20
  # The rewritten source code.
@@ -2,6 +2,11 @@
2
2
 
3
3
  # PrependAction to prepend code to the top of node body.
4
4
  class NodeMutation::PrependAction < NodeMutation::Action
5
+ def initialize(node, code)
6
+ super(node, code)
7
+ @type = :insert
8
+ end
9
+
5
10
  private
6
11
 
7
12
  DO_LENGTH = ' do'.length
@@ -10,6 +10,7 @@ class NodeMutation::RemoveAction < NodeMutation::Action
10
10
  def initialize(node, and_comma: false)
11
11
  super(node, nil)
12
12
  @and_comma = and_comma
13
+ @type = :delete
13
14
  end
14
15
 
15
16
  # The rewritten code, always empty string.
@@ -10,6 +10,7 @@ class NodeMutation::ReplaceAction < NodeMutation::Action
10
10
  def initialize(node, *selectors, with:)
11
11
  super(node, with)
12
12
  @selectors = selectors
13
+ @type = :replace
13
14
  end
14
15
 
15
16
  # The rewritten source code.
@@ -2,6 +2,11 @@
2
2
 
3
3
  # ReplaceWithAction to replace code.
4
4
  class NodeMutation::ReplaceWithAction < NodeMutation::Action
5
+ def initialize(node, code)
6
+ super(node, code)
7
+ @type = :replace
8
+ end
9
+
5
10
  # The rewritten source code with proper indent.
6
11
  #
7
12
  # @return [String] rewritten code.
@@ -6,7 +6,9 @@ class NodeMutation::Action
6
6
  # @return [Integer] start position
7
7
  # @!attribute [rw] end
8
8
  # @return [Integer] end position
9
- attr_accessor :start, :end
9
+ # @!attribute [rw] type
10
+ # @return [Symbol] action type, :insert, :replace or :delete
11
+ attr_accessor :start, :end, :type
10
12
 
11
13
  # Initialize an action.
12
14
  #
@@ -90,6 +90,8 @@ class NodeMutation::ParserAdapter < NodeMutation::Adapter
90
90
  )
91
91
  when %i[class name], %i[const name], %i[cvar name], %i[def name], %i[defs name], %i[gvar name], %i[ivar name], %i[lvar name]
92
92
  NodeMutation::Struct::Range.new(node.loc.name.begin_pos, node.loc.name.end_pos)
93
+ when %i[const double_colon]
94
+ NodeMutation::Struct::Range.new(node.loc.double_colon.begin_pos, node.loc.double_colon.end_pos)
93
95
  when %i[defs dot]
94
96
  NodeMutation::Struct::Range.new(node.loc.operator.begin_pos, node.loc.operator.end_pos) if node.loc.operator
95
97
  when %i[defs self]
@@ -19,7 +19,7 @@ class NodeMutation::Result
19
19
  end
20
20
 
21
21
  def actions=(actions)
22
- @actions = actions.map { |action| NodeMutation::Struct::Action.new(action.start, action.end, action.new_code) }
22
+ @actions = actions.map { |action| NodeMutation::Struct::Action.new(action.type, action.start, action.end, action.new_code) }
23
23
  end
24
24
 
25
25
  def to_json(*args)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class NodeMutation::Struct
4
- Action = Struct.new(:start, :end, :new_code)
4
+ Action = Struct.new(:type, :start, :end, :new_code)
5
5
  Location = Struct.new(:line, :column)
6
6
  Range = Struct.new(:start, :end)
7
7
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class NodeMutation
4
- VERSION = "1.15.1"
4
+ VERSION = "1.15.3"
5
5
  end
@@ -1,5 +1,6 @@
1
1
  class NodeMutation::Struct
2
2
  class Action < ::Struct
3
+ prop :type, Symbol
3
4
  prop :start, Integer
4
5
  prop :end, Integer
5
6
  prop :new_code, String
@@ -23,6 +23,8 @@ module NodeMutation[T]
23
23
 
24
24
  def delete: (node: T, *selectors: Array[String], **options: { and_comma: bool }) -> void
25
25
 
26
+ def indent: (node: T, ?tab_size: Integer) -> void
27
+
26
28
  def insert: (node: T, code: String, ?at: "beginning" | "end", ?to: nil | String) -> void
27
29
 
28
30
  def prepend: (node: T, code: String) -> void
@@ -33,7 +35,7 @@ module NodeMutation[T]
33
35
 
34
36
  def replace_with: (node: T, code: String) -> void
35
37
 
36
- def wrap: (node: T, prefix: String, suffix: String, newline: bool) -> void
38
+ def wrap: (node: T, prefix: String, suffix: String, ?newline: bool) -> void
37
39
 
38
40
  def noop: (node: T) -> void
39
41
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: node_mutation
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.15.1
4
+ version: 1.15.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-17 00:00:00.000000000 Z
11
+ date: 2023-04-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ast node mutation apis
14
14
  email: