prism-merge 1.1.4 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd04362b7a3dcb058e1ddf48683905944ba9cd11bf2a3e16ffc977a286cbf707
4
- data.tar.gz: 9cee5de60fd6c3d1e28737135d5003cf6c7604780906efed2c2b861a9559e46c
3
+ metadata.gz: 34ca6071c4cec046f0e1b8b16298c1f11ac5164271ef37a51119d975e699aac6
4
+ data.tar.gz: 8dcef50c1a8cd597cf471d148a15e2fec5412c6ecdcc20ba6788ea979ff23233
5
5
  SHA512:
6
- metadata.gz: 2ba7baf55a05e4512c81a5ac78aa0c26eab48576de335659dbffd46fd9b235197132eb85f056591a8b7d7e4bbffa50142c5027ced44db2aca9e320de613ca977
7
- data.tar.gz: 495250d6a19a1f0d5893afa191e9ecf1bc8e499f66a401efa93cf6f8efc045d207ceefebf7d889bfe97cbe844f441da6867bec0405aefe303a0bd6974e067703
6
+ metadata.gz: d1faf2b8c9c7ee00902e65e6d559c931f934293764fcc8b85501b419cf2e2144e9f141d0feba0d4427018cc1f470ed5861ee9a1b06b5f2d0609a5ee39dceb94e
7
+ data.tar.gz: 67fa40303034e480ce93b5ad4286d5061fbc77afa418364f2689f7667b08779a5394a898bf6df80ee00f165a8ef2ec95818759036b27eb10b5722a5d1fb39f50
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -30,6 +30,22 @@ Please file a bug if you notice a violation of semantic versioning.
30
30
 
31
31
  ### Security
32
32
 
33
+ ## [1.1.5] - 2025-12-04
34
+
35
+ - TAG: [v1.1.5][1.1.5t]
36
+ - COVERAGE: 98.26% -- 906/922 lines in 9 files
37
+ - BRANCH COVERAGE: 87.27% -- 384/440 branches in 9 files
38
+ - 100.00% documented
39
+
40
+ ### Changed
41
+
42
+ - **Recursive merge now preserves freeze blocks**: When recursively merging nested block bodies (e.g., `Gem::Specification.new do ... end`), freeze blocks inside the body are now properly preserved. Previously, nested mergers were created with `freeze_token: nil`, causing freeze blocks to be lost.
43
+
44
+ ### Fixed
45
+
46
+ - **Fixed freeze blocks lost in nested block bodies**: Freeze blocks inside class, module, or call-with-block bodies were being lost during recursive merge. The fix passes `freeze_token` to nested mergers and ensures `extract_node_body` includes leading comments/freeze markers that appear between the node's opening line and the first statement.
47
+ - **Fixed duplicate freeze markers in output**: Freeze/unfreeze marker comments were incorrectly attached as leading comments to subsequent nodes, causing duplicate markers in merged output. These markers are now filtered from leading comments since they belong to FreezeNode boundaries.
48
+
33
49
  ## [1.1.4] - 2025-12-04
34
50
 
35
51
  - TAG: [v1.1.4][1.1.4t]
@@ -207,7 +223,9 @@ Please file a bug if you notice a violation of semantic versioning.
207
223
 
208
224
  - Initial release
209
225
 
210
- [Unreleased]: https://github.com/kettle-rb/prism-merge/compare/v1.1.4...HEAD
226
+ [Unreleased]: https://github.com/kettle-rb/prism-merge/compare/v1.1.5...HEAD
227
+ [1.1.5]: https://github.com/kettle-rb/prism-merge/compare/v1.1.4...v1.1.5
228
+ [1.1.5t]: https://github.com/kettle-rb/prism-merge/releases/tag/v1.1.5
211
229
  [1.1.4]: https://github.com/kettle-rb/prism-merge/compare/v1.1.3...v1.1.4
212
230
  [1.1.4t]: https://github.com/kettle-rb/prism-merge/releases/tag/v1.1.4
213
231
  [1.1.3]: https://github.com/kettle-rb/prism-merge/compare/v1.1.2...v1.1.3
data/README.md CHANGED
@@ -1194,7 +1194,7 @@ Thanks for RTFM. ☺️
1194
1194
  [📌gitmoji]: https://gitmoji.dev
1195
1195
  [📌gitmoji-img]: https://img.shields.io/badge/gitmoji_commits-%20%F0%9F%98%9C%20%F0%9F%98%8D-34495e.svg?style=flat-square
1196
1196
  [🧮kloc]: https://www.youtube.com/watch?v=dQw4w9WgXcQ
1197
- [🧮kloc-img]: https://img.shields.io/badge/KLOC-0.918-FFDD67.svg?style=for-the-badge&logo=YouTube&logoColor=blue
1197
+ [🧮kloc-img]: https://img.shields.io/badge/KLOC-0.922-FFDD67.svg?style=for-the-badge&logo=YouTube&logoColor=blue
1198
1198
  [🔐security]: SECURITY.md
1199
1199
  [🔐security-img]: https://img.shields.io/badge/security-policy-259D6C.svg?style=flat
1200
1200
  [📄copyright-notice-explainer]: https://opensource.stackexchange.com/questions/5778/why-do-licenses-such-as-the-mit-license-specify-a-single-year
@@ -325,6 +325,11 @@ module Prism
325
325
  def extract_nodes_with_comments
326
326
  return [] unless valid?
327
327
 
328
+ # Build pattern to filter out freeze/unfreeze markers from leading comments
329
+ freeze_marker_pattern = if @freeze_token
330
+ /#\s*#{Regexp.escape(@freeze_token)}:(freeze|unfreeze)/i
331
+ end
332
+
328
333
  statements.map.with_index do |stmt, idx|
329
334
  # FreezeNode doesn't have Prism location with comments
330
335
  # It's a wrapper with custom Location struct
@@ -338,10 +343,18 @@ module Prism
338
343
  line_range: stmt.location.start_line..stmt.location.end_line,
339
344
  }
340
345
  else
346
+ # Filter out freeze/unfreeze marker comments from leading comments
347
+ # These markers are part of FreezeNode boundaries and should not be
348
+ # attached to subsequent nodes
349
+ leading = stmt.location.leading_comments
350
+ if freeze_marker_pattern
351
+ leading = leading.reject { |c| c.slice.match?(freeze_marker_pattern) }
352
+ end
353
+
341
354
  {
342
355
  node: stmt,
343
356
  index: idx,
344
- leading_comments: stmt.location.leading_comments, # Prism native!
357
+ leading_comments: leading,
345
358
  inline_comments: stmt.location.trailing_comments, # Prism native!
346
359
  signature: generate_signature(stmt),
347
360
  line_range: stmt.location.start_line..stmt.location.end_line,
@@ -474,11 +474,6 @@ module Prism
474
474
 
475
475
  return false unless can_merge_recursively
476
476
 
477
- # Don't recursively merge if either node contains freeze blocks
478
- # (they would be lost in the nested merge since we pass freeze_token: nil)
479
- return false if node_contains_freeze_blocks?(template_node)
480
- return false if node_contains_freeze_blocks?(dest_node)
481
-
482
477
  true
483
478
  end
484
479
 
@@ -524,9 +519,10 @@ module Prism
524
519
  # Check if a node's body contains freeze block markers.
525
520
  #
526
521
  # @param node [Prism::Node] The node to check
522
+ # @param analysis [FileAnalysis] The analysis for the file containing this node
527
523
  # @return [Boolean] true if the node's body contains freeze block comments
528
524
  # @api private
529
- def node_contains_freeze_blocks?(node)
525
+ def node_contains_freeze_blocks?(node, analysis)
530
526
  return false unless @freeze_token
531
527
 
532
528
  # Check if node has nested content that could contain freeze blocks
@@ -550,15 +546,13 @@ module Prism
550
546
  return false unless has_content
551
547
 
552
548
  # Check if any comments in the node's range contain freeze markers
549
+ # Only check comments from the analysis that owns this node
553
550
  freeze_pattern = /#\s*#{Regexp.escape(@freeze_token)}:(freeze|unfreeze)/i
554
551
 
555
552
  node_start = node.location.start_line
556
553
  node_end = node.location.end_line
557
554
 
558
- @template_analysis.parse_result.comments.any? do |comment|
559
- comment_line = comment.location.start_line
560
- comment_line > node_start && comment_line < node_end && comment.slice.match?(freeze_pattern)
561
- end || @dest_analysis.parse_result.comments.any? do |comment|
555
+ analysis.parse_result.comments.any? do |comment|
562
556
  comment_line = comment.location.start_line
563
557
  comment_line > node_start && comment_line < node_end && comment.slice.match?(freeze_pattern)
564
558
  end
@@ -575,8 +569,7 @@ module Prism
575
569
  # @param anchor [FileAligner::Anchor] The anchor representing this match
576
570
  #
577
571
  # @note The nested merger is configured with:
578
- # - Same signature_generator, signature_match_preference, and add_template_only_nodes
579
- # - freeze_token: nil (freeze blocks not processed in nested context)
572
+ # - Same signature_generator, signature_match_preference, add_template_only_nodes, and freeze_token
580
573
  # - Incremented current_depth to track recursion level
581
574
  #
582
575
  # @api private
@@ -586,13 +579,14 @@ module Prism
586
579
  dest_body = extract_node_body(dest_node, @dest_analysis)
587
580
 
588
581
  # Recursively merge the bodies with incremented depth
582
+ # Pass freeze_token so freeze blocks inside nested bodies are preserved
589
583
  body_merger = SmartMerger.new(
590
584
  template_body,
591
585
  dest_body,
592
586
  signature_generator: @template_analysis.instance_variable_get(:@signature_generator),
593
587
  signature_match_preference: @signature_match_preference,
594
588
  add_template_only_nodes: @add_template_only_nodes,
595
- freeze_token: nil, # Don't process freeze blocks in nested context
589
+ freeze_token: @freeze_token,
596
590
  max_recursion_depth: @max_recursion_depth,
597
591
  current_depth: @current_depth + 1,
598
592
  )
@@ -712,13 +706,25 @@ module Prism
712
706
  body_statements = statements_node.body
713
707
  return "" if body_statements.empty?
714
708
 
715
- # Get the line range of the body (between opening line and end)
716
- first_stmt_line = body_statements.first.location.start_line
709
+ # Get the line range of the body
710
+ # Start from line after node opening (to include any leading comments/freeze markers)
711
+ # For nodes with blocks, the body starts after the block opening
712
+ body_start_line = case node
713
+ when Prism::CallNode
714
+ # Block body starts on line after the `do` or `{`
715
+ node.block.opening_loc ? node.block.opening_loc.start_line + 1 : body_statements.first.location.start_line
716
+ when Prism::ClassNode, Prism::ModuleNode, Prism::SingletonClassNode
717
+ # Body starts on line after class/module declaration
718
+ node.location.start_line + 1
719
+ else
720
+ body_statements.first.location.start_line
721
+ end
722
+
717
723
  last_stmt_line = body_statements.last.location.end_line
718
724
 
719
725
  # Extract the source lines for the body
720
726
  lines = []
721
- (first_stmt_line..last_stmt_line).each do |line_num|
727
+ (body_start_line..last_stmt_line).each do |line_num|
722
728
  lines << analysis.line_at(line_num).chomp
723
729
  end
724
730
  lines.join("\n") + "\n"
@@ -5,7 +5,7 @@ module Prism
5
5
  # Version information for Prism::Merge
6
6
  module Version
7
7
  # Current version of the prism-merge gem
8
- VERSION = "1.1.4"
8
+ VERSION = "1.1.5"
9
9
  end
10
10
  VERSION = Version::VERSION # traditional location
11
11
  end
data/sig/prism/merge.rbs CHANGED
@@ -383,7 +383,9 @@ module Prism
383
383
  def mergeable_statement?: (untyped node) -> bool
384
384
 
385
385
  # Check if a node's body contains freeze block markers
386
- def node_contains_freeze_blocks?: (untyped node) -> bool
386
+ # @param node The node to check for freeze markers
387
+ # @param analysis The FileAnalysis for the file containing the node
388
+ def node_contains_freeze_blocks?: (untyped node, FileAnalysis analysis) -> bool
387
389
 
388
390
  # Recursively merge the body of matching class, module, or call-with-block nodes
389
391
  def merge_node_body_recursively: (untyped template_node, untyped dest_node, FileAligner::Anchor anchor) -> void
data.tar.gz.sig CHANGED
@@ -1,3 +1,2 @@
1
- ��'���ӾP5t#9ġ_�$`�Z:JH)M���Te���4��͓���V�zLY9�`�)�{�MAȴN2�o�Y�[�n���X
2
- -CRjfa��� ���
3
- �ܐ_S]VƑ����bq�D�}�J��<����B��U�Z�=�VBb ��]y�ӟP�sN�Xn���y��d� ���g]�������}���]�1&���"rX������;����M��X{�t)E���)Ά�IM�^P�̓G'v���pKzQW �m�r��bYr#���iGZ_��o���Նݼ1��OJ s��#��ʳ`_��q��Y�w���'ӮW��D9S|���>��Huu]�-�C��d/3dR�A�i#���s�s��2p�
1
+ %Ϭ0)�촫՟S`�'�WCJ~�8����m:�;��@D��CA��Q(߸��<�|>r�����������ճ�˒*!U �� ėV6�{���7ݏ=�G��n���ί=ơ��
2
+ �^It��*��R����t/��lB+_�ŜFމ�3Vc x'O���K0�q4vv����,�g���7���e_���׈��,A։_xI�q+:���N���!D���\k�O�F�+�_YM�nᬹ'"�ʃ�ߍ����^Aŵ&�:z �Pk}{v���S/lR�6�'1��O�S�(?xΏse�Гu��9�^�\WR�Ś�"4l��gOV-)@y�CC��}��SN+�B)�����y[.�h��S��<ҩ/��~G���7��
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prism-merge
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter H. Boling
@@ -265,10 +265,10 @@ licenses:
265
265
  - MIT
266
266
  metadata:
267
267
  homepage_uri: https://prism-merge.galtzo.com/
268
- source_code_uri: https://github.com/kettle-rb/prism-merge/tree/v1.1.4
269
- changelog_uri: https://github.com/kettle-rb/prism-merge/blob/v1.1.4/CHANGELOG.md
268
+ source_code_uri: https://github.com/kettle-rb/prism-merge/tree/v1.1.5
269
+ changelog_uri: https://github.com/kettle-rb/prism-merge/blob/v1.1.5/CHANGELOG.md
270
270
  bug_tracker_uri: https://github.com/kettle-rb/prism-merge/issues
271
- documentation_uri: https://www.rubydoc.info/gems/prism-merge/1.1.4
271
+ documentation_uri: https://www.rubydoc.info/gems/prism-merge/1.1.5
272
272
  funding_uri: https://github.com/sponsors/pboling
273
273
  wiki_uri: https://github.com/kettle-rb/prism-merge/wiki
274
274
  news_uri: https://www.railsbling.com/tags/prism-merge
metadata.gz.sig CHANGED
Binary file