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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c83e3715de9de4bc244ddbcf4486f78c51bdff021735f291d797d7e2728d3369
4
- data.tar.gz: 6dae070e5a2ad3977a53c08f312ee240d3a9164b353e257d61bdaff0c492c542
3
+ metadata.gz: 1e20b2ab8c6e7c9f01e01b97dfd8b0315d6fb6e474e8176a2f83609ff4e565da
4
+ data.tar.gz: cc6bcbb6ddbb098b2dbe9090e20cb6d9b7466eea2041a6ae6a0880470e0f8d01
5
5
  SHA512:
6
- metadata.gz: b10359865b08bbb672dcdcb567f27a1de4018e12f61615cb16fb4d9406af37be3443ccafafcd2d9347a0fab48f739fffa70e170eff13ad443272542a2148cfc8
7
- data.tar.gz: 605c42f06b1b2f5d54c8714394f3874446e88f27016bcf361d2a067f36dad285db9056984fc1216d70c02237eb3e052799e16e9c065cf4e3fda14823734f0e6d
6
+ metadata.gz: 22b95e80c34f121736637a069cebc2d8e717e1e6cc9461937a9c00dff9253db473dccb945d6463edaee4a3c54df9392597fe6b65e1825a56425742f1beaf80b2
7
+ data.tar.gz: 7134108cd2d15fd4dd6a4ee73a23f31917bfff251f403297be2f636fa0e4ab580482da4971c87815c22e2b3e182ec585b39fc688963b6495f38781e764372bdf
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # NodeMutation
2
2
 
3
+ ## 1.9.3 (2023-02-15)
4
+
5
+ * Remove engine
6
+
7
+ ## 1.9.2 (2023-02-11)
8
+
9
+ * Squeeze space if end with space, newline or semicolon
10
+
3
11
  ## 1.9.1 (2023-02-10)
4
12
 
5
13
  * Make sure `tab_width` is an Integer
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- node_mutation (1.9.1)
4
+ node_mutation (1.9.3)
5
5
  erubis
6
6
 
7
7
  GEM
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class NodeMutation
4
- VERSION = "1.9.1"
4
+ VERSION = "1.9.3"
5
5
  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.1
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-10 00:00:00.000000000 Z
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.6
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
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module NodeMutation::Engine
4
- # Engine defines how to encode / decode other files (like erb).
5
- autoload :Erb, 'node_mutation/engine/erb'
6
- end