Class: Svelte::Errors::CompilerError

Inherits:
ActiveSupport::SyntaxErrorProxy
  • Object
show all
Defined in:
lib/svelte/errors.rb

Overview

steep:ignore UnknownConstant

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error) ⇒ CompilerError

Returns a new instance of CompilerError.



8
9
10
11
12
13
14
15
# File 'lib/svelte/errors.rb', line 8

def initialize(error)
  @file = error[:id]
  @line = error.dig(:start, :line)
  @sugggestion = error.dig(:suggestion) || ""
  # steep:ignore:start
  super(error[:pluginCode]) # : self
  # steep:ignore:end
end

Instance Attribute Details

#locationObject

Returns the value of attribute location.



6
7
8
# File 'lib/svelte/errors.rb', line 6

def location
  @location
end

#suggestionObject

Returns the value of attribute suggestion.



6
7
8
# File 'lib/svelte/errors.rb', line 6

def suggestion
  @suggestion
end

#templateObject

Returns the value of attribute template.



6
7
8
# File 'lib/svelte/errors.rb', line 6

def template
  @template
end

Instance Method Details

#annotated_source_codeObject



46
47
48
49
50
51
# File 'lib/svelte/errors.rb', line 46

def annotated_source_code
  location[:lineText].split("\n").map.with_index(1) { |line, index|
    indentation = " " * 4
    "#{index}:#{indentation}#{line}"
  }
end

#backtraceObject



21
22
23
24
25
26
27
# File 'lib/svelte/errors.rb', line 21

def backtrace
  if suggestion
    ["#{Rails.root.join @file}:#{@line}:#{message}, #{suggestion}"] + caller
  else
    ["#{Rails.root.join @file}:#{@line}:#{message}"] + caller
  end
end

#backtrace_locationsObject



37
38
39
40
41
42
43
44
# File 'lib/svelte/errors.rb', line 37

def backtrace_locations
  traces = backtrace.map { |trace|
    file, line = trace.match(/^(.+?):(\d+).*$/, &:captures) || trace
    ActiveSupport::SyntaxErrorProxy::BacktraceLocation.new(file, line.to_i, trace) # steep:ignore UnknownConstant
  }

  traces.map { |loc| ActiveSupport::SyntaxErrorProxy::BacktraceLocationProxy.new(loc, self) } # steep:ignore UnknownConstant
end

#bindingsObject



33
34
35
# File 'lib/svelte/errors.rb', line 33

def bindings
  [template.send(:binding)]
end

#causeObject



29
30
31
# File 'lib/svelte/errors.rb', line 29

def cause
  nil
end

#messageObject



17
18
19
# File 'lib/svelte/errors.rb', line 17

def message
  to_s
end