Class: Opal::Fragment
- Inherits:
- 
      Object
      
        - Object
- Opal::Fragment
 
- Defined in:
- opal/lib/opal/fragment.rb
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, scope, 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. 
- #source_map_name ⇒ Object
Constructor Details
#initialize(code, scope, sexp = nil) ⇒ Fragment
Create fragment with javascript code and optional original [Opal::Sexp].
| 20 21 22 23 24 | # File 'opal/lib/opal/fragment.rb', line 20 def initialize(code, scope, sexp = nil) @code = code.to_s @sexp = sexp @scope = scope end | 
Instance Attribute Details
#code ⇒ String (readonly)
String of javascript this fragment holds
| 14 15 16 | # File 'opal/lib/opal/fragment.rb', line 14 def code @code end | 
Instance Method Details
#column ⇒ Integer?
Original column this fragment was created from
| 64 65 66 | # File 'opal/lib/opal/fragment.rb', line 64 def column @sexp.column if @sexp end | 
#inspect ⇒ Object
Inspect the contents of this fragment, f("fooo")
| 27 28 29 | # File 'opal/lib/opal/fragment.rb', line 27 def inspect "f(#{@code.inspect})" end | 
#line ⇒ Integer?
Original line this fragment was created from
| 58 59 60 | # File 'opal/lib/opal/fragment.rb', line 58 def line @sexp.line if @sexp end | 
#source_map_name ⇒ Object
| 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | # File 'opal/lib/opal/fragment.rb', line 31 def source_map_name case @sexp.type when :top, :begin, :newline, :js_return nil when :self 'self' when :module 'module' when :class 'class' when :int @sexp.children.first when :def @sexp.children.first when :defs @sexp.children[1] when :send @sexp.children[1] when :lvar, :lvasgn, :lvdeclare, :ivar, :ivasgn, :gvar, :cvar, :cvasgn, :gvars, :gvasgn @sexp.children.first else # nil end end |