synvert-core 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -4
  3. data/CHANGELOG.md +6 -0
  4. data/Gemfile +0 -3
  5. data/Guardfile +0 -9
  6. data/README.md +30 -12
  7. data/Rakefile +1 -15
  8. data/lib/synvert/core/engine/erb.rb +1 -1
  9. data/lib/synvert/core/engine.rb +1 -1
  10. data/lib/synvert/core/node_ext.rb +0 -466
  11. data/lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb +20 -17
  12. data/lib/synvert/core/rewriter/condition/if_exist_condition.rb +1 -1
  13. data/lib/synvert/core/rewriter/condition/unless_exist_condition.rb +1 -1
  14. data/lib/synvert/core/rewriter/instance.rb +83 -133
  15. data/lib/synvert/core/rewriter/scope/query_scope.rb +2 -2
  16. data/lib/synvert/core/rewriter/scope/within_scope.rb +4 -4
  17. data/lib/synvert/core/rewriter.rb +0 -10
  18. data/lib/synvert/core/version.rb +1 -1
  19. data/lib/synvert/core.rb +4 -6
  20. data/spec/synvert/core/engine/erb_spec.rb +3 -3
  21. data/spec/synvert/core/node_ext_spec.rb +0 -795
  22. data/spec/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action_spec.rb +21 -1
  23. data/spec/synvert/core/rewriter/instance_spec.rb +47 -115
  24. data/spec/synvert/core/rewriter/scope/goto_scope_spec.rb +1 -4
  25. data/spec/synvert/core/rewriter/scope/query_scope_spec.rb +1 -4
  26. data/spec/synvert/core/rewriter/scope/within_scope_spec.rb +1 -4
  27. data/synvert-core-ruby.gemspec +4 -2
  28. metadata +44 -61
  29. data/lib/synvert/core/array_ext.rb +0 -48
  30. data/lib/synvert/core/node_query/compiler/array.rb +0 -34
  31. data/lib/synvert/core/node_query/compiler/attribute.rb +0 -39
  32. data/lib/synvert/core/node_query/compiler/attribute_list.rb +0 -24
  33. data/lib/synvert/core/node_query/compiler/basic_selector.rb +0 -28
  34. data/lib/synvert/core/node_query/compiler/boolean.rb +0 -23
  35. data/lib/synvert/core/node_query/compiler/comparable.rb +0 -86
  36. data/lib/synvert/core/node_query/compiler/dynamic_attribute.rb +0 -51
  37. data/lib/synvert/core/node_query/compiler/expression.rb +0 -41
  38. data/lib/synvert/core/node_query/compiler/float.rb +0 -23
  39. data/lib/synvert/core/node_query/compiler/identifier.rb +0 -41
  40. data/lib/synvert/core/node_query/compiler/integer.rb +0 -23
  41. data/lib/synvert/core/node_query/compiler/invalid_operator_error.rb +0 -7
  42. data/lib/synvert/core/node_query/compiler/nil.rb +0 -23
  43. data/lib/synvert/core/node_query/compiler/parse_error.rb +0 -7
  44. data/lib/synvert/core/node_query/compiler/regexp.rb +0 -37
  45. data/lib/synvert/core/node_query/compiler/selector.rb +0 -113
  46. data/lib/synvert/core/node_query/compiler/string.rb +0 -23
  47. data/lib/synvert/core/node_query/compiler/symbol.rb +0 -23
  48. data/lib/synvert/core/node_query/compiler.rb +0 -25
  49. data/lib/synvert/core/node_query/lexer.rex +0 -99
  50. data/lib/synvert/core/node_query/lexer.rex.rb +0 -299
  51. data/lib/synvert/core/node_query/parser.racc.rb +0 -306
  52. data/lib/synvert/core/node_query/parser.y +0 -60
  53. data/lib/synvert/core/node_query.rb +0 -36
  54. data/lib/synvert/core/rewriter/action/append_action.rb +0 -28
  55. data/lib/synvert/core/rewriter/action/delete_action.rb +0 -34
  56. data/lib/synvert/core/rewriter/action/insert_action.rb +0 -34
  57. data/lib/synvert/core/rewriter/action/insert_after_action.rb +0 -22
  58. data/lib/synvert/core/rewriter/action/prepend_action.rb +0 -44
  59. data/lib/synvert/core/rewriter/action/remove_action.rb +0 -56
  60. data/lib/synvert/core/rewriter/action/replace_action.rb +0 -33
  61. data/lib/synvert/core/rewriter/action/replace_with_action.rb +0 -36
  62. data/lib/synvert/core/rewriter/action/wrap_action.rb +0 -37
  63. data/lib/synvert/core/rewriter/action.rb +0 -102
  64. data/spec/synvert/core/node_query/lexer_spec.rb +0 -580
  65. data/spec/synvert/core/node_query/parser_spec.rb +0 -337
  66. data/spec/synvert/core/rewriter/action/append_action_spec.rb +0 -70
  67. data/spec/synvert/core/rewriter/action/delete_action_spec.rb +0 -26
  68. data/spec/synvert/core/rewriter/action/insert_action_spec.rb +0 -70
  69. data/spec/synvert/core/rewriter/action/insert_after_action_spec.rb +0 -26
  70. data/spec/synvert/core/rewriter/action/prepend_action_spec.rb +0 -175
  71. data/spec/synvert/core/rewriter/action/remove_action_spec.rb +0 -26
  72. data/spec/synvert/core/rewriter/action/replace_action_spec.rb +0 -28
  73. data/spec/synvert/core/rewriter/action/replace_with_action_spec.rb +0 -59
  74. data/spec/synvert/core/rewriter/action/wrap_action_spec.rb +0 -31
  75. data/spec/synvert/core/rewriter/action_spec.rb +0 -14
@@ -4,37 +4,40 @@ module Synvert::Core
4
4
  # ReplaceErbStmtWithExprAction to replace erb stmt code to expr,
5
5
  # @example
6
6
  # e.g. <% form_for ... %> => <%= form_for ... %>.
7
- class Rewriter::ReplaceErbStmtWithExprAction < Rewriter::Action
7
+ class Rewriter::ReplaceErbStmtWithExprAction < NodeMutation::Action
8
8
  # Initialize a ReplaceErbStmtWithExprAction.
9
9
  #
10
- # @param instance [Synvert::Core::Rewriter::Instance]
11
- def initialize(instance)
12
- super(instance, nil)
10
+ # @param node [Synvert::Core::Rewriter::Node]
11
+ def initialize(node)
12
+ super(node, nil)
13
13
  end
14
14
 
15
- # The rewritten erb expr code.
15
+ # The new erb expr code.
16
16
  #
17
- # @return [String] rewritten code.
18
- def rewritten_code
19
- @node.loc.expression.source_buffer.source[begin_pos...end_pos]
20
- .sub(Engine::ERUBY_STMT_SPLITTER, '@output_buffer.append= ')
21
- .sub(Engine::ERUBY_STMT_SPLITTER, Engine::ERUBY_EXPR_SPLITTER)
17
+ # @return [String] new code.
18
+ def new_code
19
+ NodeMutation.adapter.file_content(@node)[@start...@end]
20
+ .sub(Engine::ERUBY_STMT_SPLITTER, '@output_buffer.append= ')
21
+ .sub(Engine::ERUBY_STMT_SPLITTER, Engine::ERUBY_EXPR_SPLITTER)
22
22
  end
23
23
 
24
24
  private
25
25
 
26
26
  # Calculate the begin the end positions.
27
27
  def calculate_position
28
- node_begin_pos = @node.loc.expression.begin_pos
29
- while @node.loc.expression.source_buffer.source[node_begin_pos -= 1] == ' '
28
+ node_start = NodeMutation.adapter.get_start(@node)
29
+ node_source = NodeMutation.adapter.get_source(@node)
30
+ file_content = NodeMutation.adapter.file_content(@node)
31
+
32
+ whitespace_index = node_start
33
+ while file_content[whitespace_index -= 1] == ' '
30
34
  end
31
- @begin_pos = node_begin_pos - Engine::ERUBY_STMT_SPLITTER.length + 1
35
+ @start = whitespace_index - Engine::ERUBY_STMT_SPLITTER.length + 1
32
36
 
33
- node_begin_pos = @node.loc.expression.begin_pos
34
- node_begin_pos += @node.loc.expression.source.index 'do'
35
- while @node.loc.expression.source_buffer.source[node_begin_pos += 1] != '@'
37
+ at_index = node_start + node_source.index('do')
38
+ while file_content[at_index += 1] != '@'
36
39
  end
37
- @end_pos = node_begin_pos
40
+ @end = at_index
38
41
  end
39
42
  end
40
43
  end
@@ -10,7 +10,7 @@ module Synvert::Core
10
10
  # @return [Boolean]
11
11
  def match?
12
12
  match = false
13
- @instance.current_node.recursive_children do |child_node|
13
+ NodeQuery::Helper.handle_recursive_child(@instance.current_node) do |child_node|
14
14
  match ||= child_node&.match?(@rules)
15
15
  end
16
16
  match
@@ -10,7 +10,7 @@ module Synvert::Core
10
10
  # return [Boolean]
11
11
  def match?
12
12
  match = false
13
- @instance.current_node.recursive_children do |child_node|
13
+ NodeQuery::Helper.handle_recursive_child(@instance.current_node) do |child_node|
14
14
  match ||= child_node&.match?(@rules)
15
15
  end
16
16
  !match
@@ -20,66 +20,13 @@ module Synvert::Core
20
20
  rewriter.helpers.each { |helper| singleton_class.send(:define_method, helper[:name], &helper[:block]) }
21
21
  end
22
22
 
23
- class << self
24
- # Get file source.
25
- #
26
- # @param file_path [String] file path
27
- # @return [String] file source
28
- def file_source(file_path)
29
- @file_source ||= {}
30
- @file_source[file_path] ||=
31
- begin
32
- source = File.read(file_path, encoding: 'UTF-8')
33
- source = Engine::ERB.encode(source) if /\.erb$/.match?(file_path)
34
- source
35
- end
36
- end
37
-
38
- # Get file ast.
39
- #
40
- # @param file_path [String] file path
41
- # @return [String] ast node for file
42
- def file_ast(file_path)
43
- @file_ast ||= {}
44
- @file_ast[file_path] ||=
45
- begin
46
- buffer = Parser::Source::Buffer.new file_path
47
- buffer.source = file_source(file_path)
48
-
49
- parser = Parser::CurrentRuby.new
50
- parser.reset
51
- parser.parse buffer
52
- end
53
- end
54
-
55
- # Write source to file and remove cached file source and ast.
56
- #
57
- # @param file_path [String] file path
58
- # @param source [String] file source
59
- def write_file(file_path, source)
60
- source = Engine::ERB.decode(source) if /\.erb/.match?(file_path)
61
- File.write(file_path, source.gsub(/ +\n/, "\n"))
62
- @file_source[file_path] = nil
63
- @file_ast[file_path] = nil
64
- end
65
-
66
- # Reset file source and ast.
67
- def reset
68
- @file_source = {}
69
- @file_ast = {}
70
- end
71
- end
72
-
73
23
  # @!attribute [rw] current_node
74
24
  # @return current parsing node
75
25
  # @!attribute [rw] current_file
76
26
  # @return current filename
77
- attr_accessor :current_node, :current_file
78
-
79
- # Current file source
80
- def file_source
81
- self.class.file_source(current_file)
82
- end
27
+ # @!attribute [rw] current_mutation
28
+ # @return current mutation
29
+ attr_accessor :current_node, :current_file, :current_mutation
83
30
 
84
31
  # Process the instance.
85
32
  # It finds specified files, for each file, it executes the block code, rewrites the original code,
@@ -231,7 +178,7 @@ module Synvert::Core
231
178
  # end
232
179
  # @param code [String] code need to be appended.
233
180
  def append(code)
234
- @actions << Rewriter::AppendAction.new(self, code).process
181
+ @current_mutation.append(@current_node, code)
235
182
  end
236
183
 
237
184
  # Parse +prepend+ dsl, it creates a {Synvert::Core::Rewriter::PrependAction} to
@@ -250,7 +197,7 @@ module Synvert::Core
250
197
  # end
251
198
  # @param code [String] code need to be prepended.
252
199
  def prepend(code)
253
- @actions << Rewriter::PrependAction.new(self, code).process
200
+ @current_mutation.prepend(@current_node, code)
254
201
  end
255
202
 
256
203
  # Parse +insert+ dsl, it creates a {Synvert::Core::Rewriter::InsertAction} to insert code.
@@ -265,7 +212,7 @@ module Synvert::Core
265
212
  # @param at [String] insert position, beginning or end
266
213
  # @param to [String] where to insert, if it is nil, will insert to current node.
267
214
  def insert(code, at: 'end', to: nil)
268
- @actions << Rewriter::InsertAction.new(self, code, at: at, to: to).process
215
+ @current_mutation.insert(@current_node, code, at: at, to: to)
269
216
  end
270
217
 
271
218
  # Parse +insert_after+ dsl, it creates a {Synvert::Core::Rewriter::InsertAfterAction} to
@@ -280,7 +227,22 @@ module Synvert::Core
280
227
  # end
281
228
  # @param code [String] code need to be inserted.
282
229
  def insert_after(code)
283
- @actions << Rewriter::InsertAfterAction.new(self, code).process
230
+ @current_mutation.insert_after(@current_node, code)
231
+ end
232
+
233
+ # Parse +replace_erb_stmt_with_expr+ dsl, it creates a {Synvert::Core::Rewriter::ReplaceErbStmtWithExprAction} to
234
+ # replace erb stmt code to expr code.
235
+ # @example
236
+ # # <% form_for post do |f| %>
237
+ # # <% end %>
238
+ # # =>
239
+ # # <%= form_for post do |f| %>
240
+ # # <% end %>
241
+ # with_node type: 'block', caller: { type: 'send', receiver: nil, message: 'form_for' } do
242
+ # replace_erb_stmt_with_expr
243
+ # end
244
+ def replace_erb_stmt_with_expr
245
+ @current_mutation.actions << Rewriter::ReplaceErbStmtWithExprAction.new(@current_node).process
284
246
  end
285
247
 
286
248
  # Parse +replace_with+ dsl, it creates a {Synvert::Core::Rewriter::ReplaceWithAction} to
@@ -294,7 +256,7 @@ module Synvert::Core
294
256
  # end
295
257
  # @param code [String] code need to be replaced with.
296
258
  def replace_with(code)
297
- @actions << Rewriter::ReplaceWithAction.new(self, code).process
259
+ @current_mutation.replace_with(@current_node, code)
298
260
  end
299
261
 
300
262
  # Parse +replace+ dsl, it creates a {Synvert::Core::Rewriter::ReplaceAction} to
@@ -310,22 +272,7 @@ module Synvert::Core
310
272
  # @param selectors [Array<Symbol>] selector names of child node.
311
273
  # @param with [String] code need to be replaced with.
312
274
  def replace(*selectors, with:)
313
- @actions << Rewriter::ReplaceAction.new(self, *selectors, with: with).process
314
- end
315
-
316
- # Parse +replace_erb_stmt_with_expr+ dsl, it creates a {Synvert::Core::Rewriter::ReplaceErbStmtWithExprAction} to
317
- # replace erb stmt code to expr code.
318
- # @example
319
- # # <% form_for post do |f| %>
320
- # # <% end %>
321
- # # =>
322
- # # <%= form_for post do |f| %>
323
- # # <% end %>
324
- # with_node type: 'block', caller: { type: 'send', receiver: nil, message: 'form_for' } do
325
- # replace_erb_stmt_with_expr
326
- # end
327
- def replace_erb_stmt_with_expr
328
- @actions << Rewriter::ReplaceErbStmtWithExprAction.new(self).process
275
+ @current_mutation.replace(@current_node, *selectors, with: with)
329
276
  end
330
277
 
331
278
  # Parse +remove+ dsl, it creates a {Synvert::Core::Rewriter::RemoveAction} to remove current node.
@@ -336,7 +283,7 @@ module Synvert::Core
336
283
  # @param options [Hash] options.
337
284
  # @option and_comma [Boolean] delete extra comma.
338
285
  def remove(**options)
339
- @actions << Rewriter::RemoveAction.new(self, **options).process
286
+ @current_mutation.remove(@current_node, **options)
340
287
  end
341
288
 
342
289
  # Parse +delete+ dsl, it creates a {Synvert::Core::Rewriter::DeleteAction} to delete child nodes.
@@ -351,7 +298,7 @@ module Synvert::Core
351
298
  # @param options [Hash]
352
299
  # @option and_comma [Boolean] delete extra comma.
353
300
  def delete(*selectors, **options)
354
- @actions << Rewriter::DeleteAction.new(self, *selectors, **options).process
301
+ @current_mutation.delete(@current_node, *selectors, **options)
355
302
  end
356
303
 
357
304
  # Parse +wrap+ dsl, it creates a {Synvert::Core::Rewriter::WrapAction} to
@@ -368,9 +315,8 @@ module Synvert::Core
368
315
  # wrap with: 'module Synvert'
369
316
  # end
370
317
  # @param with [String] code need to be wrapped with.
371
- # @param indent [Integer, nil] number of whitespaces.
372
- def wrap(with:, indent: nil)
373
- @actions << Rewriter::WrapAction.new(self, with: with, indent: indent).process
318
+ def wrap(with:)
319
+ @current_mutation.wrap(@current_node, with: with)
374
320
  end
375
321
 
376
322
  # Parse +warn+ dsl, it creates a {Synvert::Core::Rewriter::Warning} to save warning message.
@@ -397,65 +343,69 @@ module Synvert::Core
397
343
  #
398
344
  # @param file_path [String]
399
345
  def process_file(file_path)
400
- begin
401
- puts file_path if Configuration.show_run_process
402
- conflict_actions = []
403
- source = +self.class.file_source(file_path)
404
- ast = self.class.file_ast(file_path)
405
-
406
- @current_file = file_path
407
-
408
- process_with_node(ast) do
409
- instance_eval(&@block)
410
- rescue NoMethodError
411
- puts @current_node.debug_info
412
- raise
413
- end
414
-
415
- if @actions.length > 0
416
- @actions.sort_by! { |action| [action.begin_pos, action.end_pos] }
417
- conflict_actions = get_conflict_actions
418
- @actions.reverse_each do |action|
419
- source[action.begin_pos...action.end_pos] = action.rewritten_code
346
+ puts file_path if Configuration.show_run_process
347
+
348
+ @current_file = file_path
349
+ while true
350
+ source = read_source(file_path)
351
+ @current_mutation = NodeMutation.new(source)
352
+ begin
353
+ node = parse_code(file_path, source)
354
+
355
+ process_with_node(node) do
356
+ instance_eval(&@block)
357
+ rescue NoMethodError => e
358
+ puts [
359
+ "error: #{e.message}",
360
+ "file: #{file_path}",
361
+ "source: #{source}",
362
+ "line: #{current_node.line}"
363
+ ].join("\n")
364
+ raise
420
365
  end
421
- @actions = []
422
366
 
423
- update_file(file_path, source)
367
+ result = @current_mutation.process
368
+ if result.affected?
369
+ @rewriter.add_affected_file(file_path)
370
+ write_source(file_path, result.new_source)
371
+ end
372
+ break unless result.conflicted?
373
+ rescue Parser::SyntaxError
374
+ puts "[Warn] file #{file_path} was not parsed correctly."
375
+ # do nothing, iterate next file
424
376
  end
425
- rescue Parser::SyntaxError
426
- puts "[Warn] file #{file_path} was not parsed correctly."
427
- # do nothing, iterate next file
428
- end while !conflict_actions.empty?
377
+ end
429
378
  end
430
379
 
431
- # It changes source code from bottom to top, and it can change source code twice at the same time,
432
- # So if there is an overlap between two actions, it removes the conflict actions and operate them in the next loop.
433
- def get_conflict_actions
434
- i = @actions.length - 1
435
- j = i - 1
436
- conflict_actions = []
437
- return if i < 0
438
-
439
- begin_pos = @actions[i].begin_pos
440
- while j > -1
441
- if begin_pos < @actions[j].end_pos
442
- conflict_actions << @actions.delete_at(j)
443
- else
444
- i = j
445
- begin_pos = @actions[i].begin_pos
446
- end
447
- j -= 1
448
- end
449
- conflict_actions
380
+ # Read file source.
381
+ # @param file_path [String] file path
382
+ # @return [String] file source
383
+ def read_source(file_path)
384
+ source = File.read(file_path, encoding: 'UTF-8')
385
+ source = Engine::Erb.encode(source) if /\.erb$/.match?(file_path)
386
+ source
387
+ end
388
+
389
+ # Write file source to file.
390
+ # @param file_path [String] file path
391
+ # @param source [String] file source
392
+ def write_source(file_path, source)
393
+ source = Engine::Erb.decode(source) if /\.erb/.match?(file_path)
394
+ File.write(file_path, source.gsub(/ +\n/, "\n"))
450
395
  end
451
396
 
452
- # It updates a file with new source code.
397
+ # Parse code ast node.
453
398
  #
454
- # @param file_path [String] the file path
455
- # @param source [String] the new source code
456
- def update_file(file_path, source)
457
- self.class.write_file(file_path, source)
458
- @rewriter.add_affected_file(file_path)
399
+ # @param file_path [String] file path
400
+ # @param file_path [String] file path
401
+ # @return [Node] ast node for file
402
+ def parse_code(file_path, source)
403
+ buffer = Parser::Source::Buffer.new file_path
404
+ buffer.source = source
405
+
406
+ parser = Parser::CurrentRuby.new
407
+ parser.reset
408
+ parser.parse buffer
459
409
  end
460
410
  end
461
411
  end
@@ -23,13 +23,13 @@ module Synvert::Core
23
23
  return unless current_node
24
24
 
25
25
  @instance.process_with_node(current_node) do
26
- NodeQuery::Parser.new.parse(@query_string).query_nodes(current_node).each do |node|
26
+ NodeQuery.new(@query_string).parse(current_node).each do |node|
27
27
  @instance.process_with_node(node) do
28
28
  @instance.instance_eval(&@block)
29
29
  end
30
30
  end
31
31
  end
32
- rescue NodeQuery::Lexer::ScanError, Racc::ParseError => e
32
+ rescue NodeQueryLexer::ScanError, Racc::ParseError => e
33
33
  raise NodeQuery::Compiler::ParseError, "Invalid query string: #{@query_string}"
34
34
  end
35
35
  end
@@ -69,13 +69,13 @@ module Synvert::Core
69
69
  matching_nodes = []
70
70
  if current_node.is_a?(Parser::AST::Node)
71
71
  matching_nodes << current_node if current_node.match?(@rules)
72
- current_node.recursive_children do |child_node|
72
+ NodeQuery::Helper.handle_recursive_child(current_node) do |child_node|
73
73
  matching_nodes << child_node if child_node.match?(@rules)
74
74
  end
75
75
  else
76
76
  current_node.each do |node|
77
77
  matching_nodes << node if node.match?(@rules)
78
- node.recursive_children do |child_node|
78
+ NodeQuery::Helper.handle_recursive_child(node) do |child_node|
79
79
  matching_nodes << child_node if child_node.match?(@rules)
80
80
  end
81
81
  end
@@ -93,7 +93,7 @@ module Synvert::Core
93
93
  matching_nodes << current_node
94
94
  return matching_nodes
95
95
  end
96
- current_node.recursive_children do |child_node|
96
+ NodeQuery::Helper.handle_recursive_child(current_node) do |child_node|
97
97
  if child_node.match?(@rules)
98
98
  matching_nodes << child_node
99
99
  next :stop
@@ -105,7 +105,7 @@ module Synvert::Core
105
105
  matching_nodes << node
106
106
  next
107
107
  end
108
- node.recursive_children do |child_node|
108
+ NodeQuery::Helper.handle_recursive_child(node) do |child_node|
109
109
  if child_node.match?(@rules)
110
110
  matching_nodes << child_node
111
111
  next :stop
@@ -8,17 +8,7 @@ module Synvert::Core
8
8
  # One Rewriter checks if the depndency version matches, and it can contain one or many {Synvert::Core::Rewriter::Instance},
9
9
  # which define the behavior what files and what codes to detect and rewrite to what code.
10
10
  class Rewriter
11
- autoload :Action, 'synvert/core/rewriter/action'
12
- autoload :AppendAction, 'synvert/core/rewriter/action/append_action'
13
- autoload :DeleteAction, 'synvert/core/rewriter/action/delete_action'
14
- autoload :InsertAction, 'synvert/core/rewriter/action/insert_action'
15
- autoload :InsertAfterAction, 'synvert/core/rewriter/action/insert_after_action'
16
- autoload :RemoveAction, 'synvert/core/rewriter/action/remove_action'
17
- autoload :PrependAction, 'synvert/core/rewriter/action/prepend_action'
18
- autoload :ReplaceAction, 'synvert/core/rewriter/action/replace_action'
19
11
  autoload :ReplaceErbStmtWithExprAction, 'synvert/core/rewriter/action/replace_erb_stmt_with_expr_action'
20
- autoload :ReplaceWithAction, 'synvert/core/rewriter/action/replace_with_action'
21
- autoload :WrapAction, 'synvert/core/rewriter/action/wrap_action'
22
12
 
23
13
  autoload :Warning, 'synvert/core/rewriter/warning'
24
14
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Synvert
4
4
  module Core
5
- VERSION = '1.4.0'
5
+ VERSION = '1.5.0'
6
6
  end
7
7
  end
data/lib/synvert/core.rb CHANGED
@@ -4,14 +4,13 @@ require 'synvert/core/version'
4
4
  require 'bundler'
5
5
  require 'parser'
6
6
  require 'parser/current'
7
- require 'ast'
7
+ require 'parser_node_ext'
8
+ require_relative './core/node_ext'
8
9
  require 'active_support'
9
- require 'active_support/core_ext/object'
10
- require 'active_support/core_ext/array'
11
10
  require 'erubis'
12
11
  require 'set'
13
- require 'synvert/core/array_ext'
14
- require 'synvert/core/node_ext'
12
+ require 'node_query'
13
+ require 'node_mutation'
15
14
 
16
15
  module Synvert
17
16
  module Core
@@ -20,7 +19,6 @@ module Synvert
20
19
  autoload :Engine, 'synvert/core/engine'
21
20
  autoload :RewriterNotFound, 'synvert/core/exceptions'
22
21
  autoload :MethodNotSupported, 'synvert/core/exceptions'
23
- autoload :NodeQuery, 'synvert/core/node_query'
24
22
  end
25
23
  end
26
24
 
@@ -3,7 +3,7 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  module Synvert::Core
6
- describe Engine::ERB do
6
+ describe Engine::Erb do
7
7
  it 'encodes / decodes' do
8
8
  source = <<~EOF
9
9
  <%content_for :head do%>
@@ -34,14 +34,14 @@ module Synvert::Core
34
34
  <% end %>
35
35
  <% end %>
36
36
  EOF
37
- encoded_source = Engine::ERB.encode(source)
37
+ encoded_source = Engine::Erb.encode(source)
38
38
  buffer = Parser::Source::Buffer.new '(test)'
39
39
  buffer.source = encoded_source
40
40
  parser = Parser::CurrentRuby.new
41
41
  parser.reset
42
42
  parser.parse buffer
43
43
 
44
- expect(Engine::ERB.decode(encoded_source)).to eq source
44
+ expect(Engine::Erb.decode(encoded_source)).to eq source
45
45
  end
46
46
  end
47
47
  end