Class: Oxc::TransformResult

Inherits:
Result
  • Object
show all
Defined in:
lib/oxc/transform_result.rb,
sig/oxc/transform_result.rbs

Instance Attribute Summary collapse

Attributes inherited from Result

#code, #diagnostics, #legal_comments, #map

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Result

#inspect, #to_s, #validate!

Methods included from Diagnosed

#errors, #errors?, #panicked?, #warnings, #warnings?

Constructor Details

#initialize(declaration: nil, declaration_map: nil, helpers_used: {}) ⇒ TransformResult

: (code: String, diagnostics: Array, ?map: String?, ?declaration: String?, ?declaration_map: String?, ?legal_comments: Array, ?helpers_used: Hash[String, String], ?panicked: bool) -> void

Parameters:

  • code: (String)
  • diagnostics: (Array[Oxc::Diagnostic])
  • map: (String, nil)
  • declaration: (String, nil) (defaults to: nil)
  • declaration_map: (String, nil) (defaults to: nil)
  • legal_comments: (Array[String])
  • helpers_used: (Hash[String, String]) (defaults to: {})
  • panicked: (Boolean)


26
27
28
29
30
31
32
33
34
# File 'lib/oxc/transform_result.rb', line 26

def initialize(declaration: nil, declaration_map: nil, helpers_used: {}, **)
  super(**)

  @declaration = declaration
  @declaration_map = declaration_map
  @helpers_used = helpers_used.freeze

  freeze
end

Instance Attribute Details

#declarationString? (readonly)

Signature:

  • String?

Returns:

  • (String, nil)


5
6
7
# File 'lib/oxc/transform_result.rb', line 5

def declaration
  @declaration
end

#declaration_mapString? (readonly)

Signature:

  • String?

Returns:

  • (String, nil)


6
7
8
# File 'lib/oxc/transform_result.rb', line 6

def declaration_map
  @declaration_map
end

#helpers_usedHash[String, String] (readonly)

Signature:

  • Hash[String, String]

Returns:

  • (Hash[String, String])


7
8
9
# File 'lib/oxc/transform_result.rb', line 7

def helpers_used
  @helpers_used
end

Class Method Details

.from_json(payload) ⇒ Oxc::TransformResult

: (String) -> Oxc::TransformResult

Parameters:

  • (String)

Returns:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/oxc/transform_result.rb', line 10

def self.from_json(payload)
  parsed = JSON.parse(payload)

  new(
    code: parsed.fetch("code"),
    map: parsed["map"],
    declaration: parsed["declaration"],
    declaration_map: parsed["declaration_map"],
    legal_comments: parsed.fetch("legal_comments"),
    helpers_used: parsed.fetch("helpers_used"),
    diagnostics: parsed.fetch("errors").map { |diagnostic| Diagnostic.from_hash(diagnostic) },
    panicked: parsed.fetch("panicked")
  )
end

Instance Method Details

#partsArray[String]

: () -> Array

Returns:

  • (Array[String])


39
40
41
42
43
44
45
# File 'lib/oxc/transform_result.rb', line 39

def parts
  parts = super
  parts << "declaration=#{declaration.length} bytes" if declaration
  parts << "helpers_used=#{helpers_used.length}" unless helpers_used.empty?

  parts
end