Class: LightningCSS::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/lightningcss/result.rb,
sig/lightningcss/result.rbs

Overview

What a transform produced.

exports is only filled in when the stylesheet was compiled as a CSS module, and maps every name as it was written to the name it was compiled to. A transform that was not asked for a CSS module has none, and neither does a style attribute, which has no names to compile.

warnings holds what Lightning CSS understood well enough to keep but not well enough to act on, which is everything it would otherwise have dropped without saying so.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code:, warnings:, exports: nil) ⇒ Result

: (code: String, warnings: Array, ?exports: Hash[String, String]?) -> void

Parameters:

  • code: (String)
  • warnings: (Array[String])
  • exports: (Hash[String, String], nil) (defaults to: nil)


30
31
32
33
34
35
36
# File 'lib/lightningcss/result.rb', line 30

def initialize(code:, warnings:, exports: nil)
  @code = code
  @exports = exports
  @warnings = warnings.freeze

  freeze
end

Instance Attribute Details

#codeString (readonly)

Signature:

  • String

Returns:

  • (String)


14
15
16
# File 'lib/lightningcss/result.rb', line 14

def code
  @code
end

#exportsHash[String, String]? (readonly)

Signature:

  • Hash[String, String]?

Returns:

  • (Hash[String, String], nil)


15
16
17
# File 'lib/lightningcss/result.rb', line 15

def exports
  @exports
end

#warningsArray[String] (readonly)

Signature:

  • Array[String]

Returns:

  • (Array[String])


16
17
18
# File 'lib/lightningcss/result.rb', line 16

def warnings
  @warnings
end

Class Method Details

.from_json(payload) ⇒ LightningCSS::Result

: (String) -> LightningCSS::Result

Parameters:

  • (String)

Returns:



19
20
21
22
23
24
25
26
27
# File 'lib/lightningcss/result.rb', line 19

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

  new(
    code: parsed.fetch("code"),
    exports: parsed["exports"],
    warnings: parsed.fetch("warnings")
  )
end

Instance Method Details

#inspectString

: () -> String

Returns:

  • (String)


49
50
51
52
53
54
55
# File 'lib/lightningcss/result.rb', line 49

def inspect
  parts = ["code=#{code.inspect}"]
  parts << "exports=#{exports.inspect}" if exports
  parts << "warnings=#{warnings.inspect}" if warnings?

  "#<#{self.class.name} #{parts.join(" ")}>"
end

#to_sString

: () -> String

Returns:

  • (String)


44
45
46
# File 'lib/lightningcss/result.rb', line 44

def to_s
  code
end

#warnings?Boolean

: () -> bool

Returns:

  • (Boolean)


39
40
41
# File 'lib/lightningcss/result.rb', line 39

def warnings?
  !warnings.empty?
end