json-merge 1.1.2 → 7.1.1

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.
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Json
4
+ module Merge
5
+ # Extracts and tracks comments with their line numbers from JSON / JSONC
6
+ # source. The current tree-sitter JSON grammar can surface JSONC comments,
7
+ # so json-merge now uses the shared C-style comment tracker as well.
8
+ class CommentTracker < Ast::Merge::Comment::CStyleTrackerBase
9
+ # @param source [String] JSON / JSONC source code
10
+ def initialize(source)
11
+ @source = source
12
+ super(source.lines.map(&:chomp))
13
+ end
14
+
15
+ private
16
+
17
+ def owner_line_num(owner)
18
+ return owner.start_line if owner.respond_to?(:start_line) && owner.start_line
19
+ if owner.respond_to?(:key) && owner.key.respond_to?(:start_line) && owner.key.start_line
20
+ return owner.key.start_line
21
+ end
22
+
23
+ nil
24
+ end
25
+ end
26
+ end
27
+ end