25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/sorbet_view/compiler/heredoc_extractor.rb', line 25
def self.(source, file_path)
= T.let([], T::Array[HeredocExtraction])
lines = source.lines
i = 0
while i < lines.length
line = T.must(lines[i])
match = ERB_TEMPLATE_PATTERN.match(line)
if match
delimiter = T.must(match[1])
heredoc_start = i + 1
heredoc_lines = T.let([], T::Array[String])
j = heredoc_start
while j < lines.length
heredoc_line = T.must(lines[j])
break if heredoc_line.strip == delimiter
heredoc_lines << heredoc_line
j += 1
end
erb_source, column_offset = dedent_heredoc(heredoc_lines)
class_name = class_name_from_source(source)
<< HeredocExtraction.new(
erb_source: erb_source,
line_offset: heredoc_start,
column_offset: column_offset,
class_name: class_name,
component_path: file_path
)
i = j + 1
else
i += 1
end
end
end
|