class ViewComponent::Template::File

def compiled_source

def compiled_source
  result = super
  # Strip the annotation line to maintain correct line numbers when coverage
  # is running (avoids segfault from negative lineno)
  result = result.partition(";").last if @strip_annotation_line
  result
end

def initialize(component:, details:, path:)

def initialize(component:, details:, path:)
  # If the template file has no format (e.g. .erb instead of .html.erb),
  # assume the default format (html).
  if details.format.nil?
    Kernel.warn("WARNING: Template format for #{path} is missing, defaulting to :html.")
    details = ActionView::TemplateDetails.new(details.locale, details.handler, DEFAULT_FORMAT, details.variant)
  end
  @strip_annotation_line = false
  # Rails 8.1 added a newline to compiled ERB output (rails/rails#53731).
  # Use -1 to compensate for correct line numbers in stack traces.
  # However, negative line numbers cause segfaults when Ruby's coverage
  # is enabled (bugs.ruby-lang.org/issues/19363). In that case, strip the
  # annotation line from compiled source instead.
  lineno =
    if Rails::VERSION::MAJOR >= 8 && Rails::VERSION::MINOR > 0 && details.handler == :erb
      if coverage_running?
        # Can't use negative lineno with coverage (causes segfault on Linux).
        # Strip annotation line if enabled to preserve correct line numbers.
        @strip_annotation_line = ActionView::Base.annotate_rendered_view_with_filenames
        0
      else
        -1
      end
    else
      0
    end
  super(
    component: component,
    details: details,
    path: path,
    lineno: lineno
  )
end

def source

Load file each time we look up #source in case the file has been modified
def source
  ::File.read(@path)
end

def type

def type
  :file
end