Class: Opal::Fragment
Overview
A fragment holds a string of generated javascript that will be written to the destination. It also keeps hold of the original sexp from which it was generated. Using this sexp, when writing fragments in order, a mapping can be created of the original location => target location, aka, source-maps!
These are generated by nodes, so will not have to create directly.
Instance Attribute Summary collapse
-
#code ⇒ String
readonly
String of javascript this fragment holds.
Instance Method Summary collapse
-
#column ⇒ Integer?
Original column this fragment was created from.
-
#initialize(code, sexp = nil) ⇒ Fragment
constructor
Create fragment with javascript code and optional original [Opal::Sexp].
-
#inspect ⇒ Object
Inspect the contents of this fragment, f("fooo").
-
#line ⇒ Integer?
Original line this fragment was created from.
- #to_code ⇒ Object deprecated Deprecated.
Constructor Details
#initialize(code, sexp = nil) ⇒ Fragment
Create fragment with javascript code and optional original [Opal::Sexp].
18 19 20 21 |
# File 'opal/lib/opal/fragment.rb', line 18 def initialize(code, sexp = nil) @code = code.to_s @sexp = sexp end |
Instance Attribute Details
#code ⇒ String (readonly)
String of javascript this fragment holds
12 13 14 |
# File 'opal/lib/opal/fragment.rb', line 12 def code @code end |
Instance Method Details
#column ⇒ Integer?
Original column this fragment was created from
49 50 51 |
# File 'opal/lib/opal/fragment.rb', line 49 def column @sexp.column if @sexp end |
#inspect ⇒ Object
Inspect the contents of this fragment, f("fooo")
37 38 39 |
# File 'opal/lib/opal/fragment.rb', line 37 def inspect "f(#{@code.inspect})" end |
#line ⇒ Integer?
Original line this fragment was created from
43 44 45 |
# File 'opal/lib/opal/fragment.rb', line 43 def line @sexp.line if @sexp end |
#to_code ⇒ Object
In debug mode we may wish to include the original line and comment in a javascript comment.
28 29 30 31 32 33 34 |
# File 'opal/lib/opal/fragment.rb', line 28 def to_code if @sexp "/*:#{@sexp.line}:#{@sexp.column}*/#{@code}" else @code end end |