node_mutation 1.9.1 → 1.9.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 +8 -0
- data/Gemfile.lock +1 -1
- data/lib/node_mutation/action.rb +1 -1
- data/lib/node_mutation/version.rb +1 -1
- metadata +3 -5
- 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: 1e20b2ab8c6e7c9f01e01b97dfd8b0315d6fb6e474e8176a2f83609ff4e565da
|
4
|
+
data.tar.gz: cc6bcbb6ddbb098b2dbe9090e20cb6d9b7466eea2041a6ae6a0880470e0f8d01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22b95e80c34f121736637a069cebc2d8e717e1e6cc9461937a9c00dff9253db473dccb945d6463edaee4a3c54df9392597fe6b65e1825a56425742f1beaf80b2
|
7
|
+
data.tar.gz: 7134108cd2d15fd4dd6a4ee73a23f31917bfff251f403297be2f636fa0e4ab580482da4971c87815c22e2b3e182ec585b39fc688963b6495f38781e764372bdf
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/lib/node_mutation/action.rb
CHANGED
@@ -54,7 +54,7 @@ class NodeMutation::Action
|
|
54
54
|
|
55
55
|
# Squeeze spaces from source code.
|
56
56
|
def squeeze_spaces
|
57
|
-
if file_source[@start - 1] == ' ' && file_source[@end]
|
57
|
+
if file_source[@start - 1] == ' ' && [' ', "\n", ';'].include?(file_source[@end])
|
58
58
|
@start -= 1
|
59
59
|
end
|
60
60
|
end
|
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.9.
|
4
|
+
version: 1.9.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-02-
|
11
|
+
date: 2023-02-15 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
|
@@ -82,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
80
|
- !ruby/object:Gem::Version
|
83
81
|
version: '0'
|
84
82
|
requirements: []
|
85
|
-
rubygems_version: 3.4.
|
83
|
+
rubygems_version: 3.4.1
|
86
84
|
signing_key:
|
87
85
|
specification_version: 4
|
88
86
|
summary: ast node mutation apis
|
@@ -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
|