Method: Packr::SourceMap#update

Defined in:
lib/packr/source_map.rb

#update(script) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/packr/source_map.rb', line 57

def update(script)
  return unless enabled?
  
  @segments = []
  @names = SortedSet.new
  
  tokenize(script, false).each_with_index do |token, i|
    source_token = @tokens[i]
    
    if source_token[:name] != token[:name]
      @names.add(source_token[:name])
      name = source_token[:name]
    else
      name = nil
    end
    
    @segments << {
      :line     => token[:line] + @line_offset,
      :column   => token[:column],
      :mapping  => {
        :source => source_token[:source],
        :line   => source_token[:line],
        :column => source_token[:column],
        :name   => name
      }
    }
  end
  
  if @generated_file and @base_62
    script << "\n//@ sourceURL=$$SOURCE_URL"
  end
end