node_mutation 1.9.2 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +3 -3
- data/lib/node_mutation/parser_adapter.rb +2 -0
- data/lib/node_mutation/version.rb +1 -1
- metadata +2 -4
- data/lib/node_mutation/engine/erb.rb +0 -148
- data/lib/node_mutation/engine.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da3db727f8adbdcb8e54c74e8bcb2625a3d3969af1c166734d644aeb00c33d51
|
4
|
+
data.tar.gz: ad17f467d8cd3edfd1b9ba59656a2b457cfb5c9ebcb4f4df3a10c35bef93b0d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3848188fda27a5d4f9663e664ac82e70d55bc643ddf89468925e01c29449d4015ca459b27203c0891e8052ce6ea4a134b70d2438d8f6d41c4fb89ed357bec24d
|
7
|
+
data.tar.gz: 5198f02dae89f72183a3863f2cf6f1ffa9738bdc931d8a2bd3c45d6d982f98840b047998fd2e89dc9afce00c535c98bc60a850c616d551b9e6f8a309777ea278
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# NodeMutation
|
2
2
|
|
3
|
+
## 1.10.0 (2023-03-01)
|
4
|
+
|
5
|
+
* Support `variable` of `lvasgn`, `ivasgn`, `cvasgn`, and `gvasgn` node in `child_node_range`
|
6
|
+
* Update `parser_node_ext` to 1.0.0
|
7
|
+
|
8
|
+
## 1.9.3 (2023-02-15)
|
9
|
+
|
10
|
+
* Remove engine
|
11
|
+
|
3
12
|
## 1.9.2 (2023-02-11)
|
4
13
|
|
5
14
|
* Squeeze space if end with space, newline or semicolon
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
node_mutation (1.
|
4
|
+
node_mutation (1.10.0)
|
5
5
|
erubis
|
6
6
|
|
7
7
|
GEM
|
@@ -36,9 +36,9 @@ GEM
|
|
36
36
|
notiffany (0.1.3)
|
37
37
|
nenv (~> 0.1)
|
38
38
|
shellany (~> 0.0)
|
39
|
-
parser (3.1.
|
39
|
+
parser (3.2.1.0)
|
40
40
|
ast (~> 2.4.1)
|
41
|
-
parser_node_ext (0.
|
41
|
+
parser_node_ext (1.0.0)
|
42
42
|
parser
|
43
43
|
pry (0.14.1)
|
44
44
|
coderay (~> 1.1)
|
@@ -95,6 +95,8 @@ class NodeMutation::ParserAdapter < NodeMutation::Adapter
|
|
95
95
|
OpenStruct.new(start: node.loc.operator.begin_pos, end: node.loc.operator.end_pos) if node.loc.operator
|
96
96
|
when %i[defs self]
|
97
97
|
OpenStruct.new(start: node.loc.operator.begin_pos - 'self'.length, end: node.loc.operator.begin_pos)
|
98
|
+
when %i[lvasgn variable], %i[ivasgn variable], %i[cvasgn variable], %i[gvasgn variable]
|
99
|
+
OpenStruct.new(start: node.loc.name.begin_pos, end: node.loc.name.end_pos)
|
98
100
|
when %i[send dot], %i[csend dot]
|
99
101
|
OpenStruct.new(start: node.loc.dot.begin_pos, end: node.loc.dot.end_pos) if node.loc.dot
|
100
102
|
when %i[send message], %i[csend message]
|
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.
|
4
|
+
version: 1.10.0
|
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-
|
11
|
+
date: 2023-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erubis
|
@@ -51,8 +51,6 @@ files:
|
|
51
51
|
- lib/node_mutation/action/replace_with_action.rb
|
52
52
|
- lib/node_mutation/action/wrap_action.rb
|
53
53
|
- lib/node_mutation/adapter.rb
|
54
|
-
- lib/node_mutation/engine.rb
|
55
|
-
- lib/node_mutation/engine/erb.rb
|
56
54
|
- lib/node_mutation/parser_adapter.rb
|
57
55
|
- lib/node_mutation/result.rb
|
58
56
|
- lib/node_mutation/strategy.rb
|
@@ -1,148 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'erubis'
|
4
|
-
|
5
|
-
module NodeMutation::Engine
|
6
|
-
ERUBY_EXPR_SPLITTER = '; ;'
|
7
|
-
ERUBY_STMT_SPLITTER = '; ;'
|
8
|
-
|
9
|
-
class Erb
|
10
|
-
class << self
|
11
|
-
# convert erb to ruby code.
|
12
|
-
#
|
13
|
-
# @param source [String] erb source code.
|
14
|
-
# @return [String] ruby source code.
|
15
|
-
def encode(source)
|
16
|
-
Erubis.new(source.gsub('-%>', '%>'), escape: false, trim: false).src
|
17
|
-
end
|
18
|
-
|
19
|
-
# convert ruby code to erb.
|
20
|
-
#
|
21
|
-
# @param source [String] ruby source code.
|
22
|
-
# @return [String] erb source code.
|
23
|
-
def decode(source)
|
24
|
-
source = decode_ruby_stmt(source)
|
25
|
-
source = decode_ruby_output(source)
|
26
|
-
source = decode_html_output(source)
|
27
|
-
source = remove_erubis_buf(source)
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def decode_ruby_stmt(source)
|
33
|
-
source.gsub(/#{ERUBY_STMT_SPLITTER}(.+?)#{ERUBY_STMT_SPLITTER}/mo) { "<%#{Regexp.last_match(1)}%>" }
|
34
|
-
end
|
35
|
-
|
36
|
-
def decode_ruby_output(source)
|
37
|
-
source.gsub(/@output_buffer.append=\((.+?)\);#{ERUBY_EXPR_SPLITTER}/mo) {
|
38
|
-
"<%=#{Regexp.last_match(1)}%>"
|
39
|
-
}.gsub(/@output_buffer.append= (.+?)\s+(do|\{)(\s*\|[^|]*\|)?\s*#{ERUBY_EXPR_SPLITTER}/mo) { |m|
|
40
|
-
"<%=#{m.sub('@output_buffer.append= ', '').sub(ERUBY_EXPR_SPLITTER, '')}%>"
|
41
|
-
}
|
42
|
-
end
|
43
|
-
|
44
|
-
def decode_html_output(source)
|
45
|
-
source.gsub(/@output_buffer.safe_append='(.+?)'.freeze;/m) { reverse_escape_text(Regexp.last_match(1)) }
|
46
|
-
.gsub(
|
47
|
-
/@output_buffer.safe_append=\((.+?)\);#{ERUBY_EXPR_SPLITTER}/mo
|
48
|
-
) { reverse_escape_text(Regexp.last_match(1)) }
|
49
|
-
.gsub(
|
50
|
-
/@output_buffer.safe_append=(.+?)\s+(do|\{)(\s*\|[^|]*\|)?\s*#{ERUBY_EXPR_SPLITTER}/mo
|
51
|
-
) { reverse_escape_text(Regexp.last_match(1)) }
|
52
|
-
end
|
53
|
-
|
54
|
-
def remove_erubis_buf(source)
|
55
|
-
source
|
56
|
-
.sub('@output_buffer = output_buffer || ActionView::OutputBuffer.new;', '')
|
57
|
-
.sub('@output_buffer.to_s', '')
|
58
|
-
end
|
59
|
-
|
60
|
-
def reverse_escape_text(source)
|
61
|
-
source.gsub("\\\\", "\\").gsub("\\'", "'")
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
# borrowed from rails
|
67
|
-
class Erubis < ::Erubis::Eruby
|
68
|
-
BLOCK_EXPR = /\s+(do|\{)(\s*\|[^|]*\|)?\s*\Z/
|
69
|
-
def add_preamble(src)
|
70
|
-
@newline_pending = 0
|
71
|
-
src << '@output_buffer = output_buffer || ActionView::OutputBuffer.new;'
|
72
|
-
end
|
73
|
-
|
74
|
-
def add_text(src, text)
|
75
|
-
return if text.empty?
|
76
|
-
|
77
|
-
if text == "\n"
|
78
|
-
@newline_pending += 1
|
79
|
-
else
|
80
|
-
src << "@output_buffer.safe_append='"
|
81
|
-
src << ("\n" * @newline_pending) if @newline_pending > 0
|
82
|
-
src << escape_text(text)
|
83
|
-
src << "'.freeze;"
|
84
|
-
|
85
|
-
@newline_pending = 0
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
# Erubis toggles <%= and <%== behavior when escaping is enabled.
|
90
|
-
# We override to always treat <%== as escaped.
|
91
|
-
def add_expr(src, code, indicator)
|
92
|
-
case indicator
|
93
|
-
when '=='
|
94
|
-
add_expr_escaped(src, code)
|
95
|
-
else
|
96
|
-
super
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def add_expr_literal(src, code)
|
101
|
-
flush_newline_if_pending(src)
|
102
|
-
if BLOCK_EXPR.match?(code)
|
103
|
-
src << '@output_buffer.append= ' << code << ERUBY_EXPR_SPLITTER
|
104
|
-
else
|
105
|
-
src << '@output_buffer.append=(' << code << ');' << ERUBY_EXPR_SPLITTER
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def add_expr_escaped(src, code)
|
110
|
-
flush_newline_if_pending(src)
|
111
|
-
if BLOCK_EXPR.match?(code)
|
112
|
-
src << '@output_buffer.safe_append= ' << code << ERUBY_EXPR_SPLITTER
|
113
|
-
else
|
114
|
-
src << '@output_buffer.safe_append=(' << code << ');' << ERUBY_EXPR_SPLITTER
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def add_stmt(src, code)
|
119
|
-
flush_newline_if_pending(src)
|
120
|
-
if code != "\n" && code != ''
|
121
|
-
index =
|
122
|
-
case code
|
123
|
-
when /\A(\s*)\r?\n/
|
124
|
-
Regexp.last_match(1).length
|
125
|
-
when /\A(\s+)/
|
126
|
-
Regexp.last_match(1).end_with?(' ') ? Regexp.last_match(1).length - 1 : Regexp.last_match(1).length
|
127
|
-
else
|
128
|
-
0
|
129
|
-
end
|
130
|
-
code.insert(index, ERUBY_STMT_SPLITTER)
|
131
|
-
code.insert(-1, ERUBY_STMT_SPLITTER[0...-1])
|
132
|
-
end
|
133
|
-
super
|
134
|
-
end
|
135
|
-
|
136
|
-
def add_postamble(src)
|
137
|
-
flush_newline_if_pending(src)
|
138
|
-
src << '@output_buffer.to_s'
|
139
|
-
end
|
140
|
-
|
141
|
-
def flush_newline_if_pending(src)
|
142
|
-
if @newline_pending > 0
|
143
|
-
src << "@output_buffer.safe_append='#{"\n" * @newline_pending}'.freeze;"
|
144
|
-
@newline_pending = 0
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|