Class: Oxc::Result
- Inherits:
-
Object
- Object
- Oxc::Result
- Includes:
- Diagnosed
- Defined in:
- lib/oxc/result.rb,
sig/oxc/result.rbs
Direct Known Subclasses
Instance Attribute Summary collapse
- #code ⇒ String readonly
- #diagnostics ⇒ Array[Oxc::Diagnostic] readonly
- #legal_comments ⇒ Array[String] readonly
- #map ⇒ String? readonly
Instance Method Summary collapse
- #initialize(code:, diagnostics:, map: nil, legal_comments: [], panicked: false) ⇒ Result constructor
-
#inspect ⇒ String
: () -> String.
-
#parts ⇒ Array[String]
: () -> Array.
-
#to_s ⇒ String
: () -> String.
-
#validate!(strict: false) ⇒ self
: (?strict: bool?) -> self.
Methods included from Diagnosed
#errors, #errors?, #panicked?, #warnings, #warnings?
Constructor Details
#initialize(code:, diagnostics:, map: nil, legal_comments: [], panicked: false) ⇒ Result
13 14 15 16 17 18 19 |
# File 'lib/oxc/result.rb', line 13 def initialize(code:, diagnostics:, map: nil, legal_comments: [], panicked: false) @code = code @map = map @legal_comments = legal_comments.freeze @diagnostics = diagnostics.freeze @panicked = panicked end |
Instance Attribute Details
#code ⇒ String (readonly)
7 8 9 |
# File 'lib/oxc/result.rb', line 7 def code @code end |
#diagnostics ⇒ Array[Oxc::Diagnostic] (readonly)
10 11 12 |
# File 'lib/oxc/result.rb', line 10 def diagnostics @diagnostics end |
#legal_comments ⇒ Array[String] (readonly)
9 10 11 |
# File 'lib/oxc/result.rb', line 9 def legal_comments @legal_comments end |
#map ⇒ String? (readonly)
8 9 10 |
# File 'lib/oxc/result.rb', line 8 def map @map end |
Instance Method Details
#inspect ⇒ String
: () -> String
35 36 37 |
# File 'lib/oxc/result.rb', line 35 def inspect "#<#{self.class.name} #{parts.join(" ")}>" end |
#parts ⇒ Array[String]
: () -> Array
42 43 44 45 46 47 48 49 |
# File 'lib/oxc/result.rb', line 42 def parts parts = ["code=#{code.inspect}"] #: Array[String] parts << "map=#{map.length} bytes" if map parts << "legal_comments=#{legal_comments.inspect}" unless legal_comments.empty? parts << "diagnostics=#{diagnostics.length}" unless diagnostics.empty? parts end |
#to_s ⇒ String
: () -> String
30 31 32 |
# File 'lib/oxc/result.rb', line 30 def to_s code end |
#validate!(strict: false) ⇒ self
: (?strict: bool?) -> self
22 23 24 25 26 27 |
# File 'lib/oxc/result.rb', line 22 def validate!(strict: false) return self unless errors? || panicked? return self unless strict || panicked? || code.empty? raise SyntaxError.new(errors.first&. || "oxc could not read the source", self) end |