class Opal::SourceMap::Index

def initialize(source_maps, join: nil)

Parameters:
  • join: () -- the string used to join the sources, empty by default, Opal::Builder uses "\n"
  • source_maps (Opal::SourceMap::File) --
def initialize(source_maps, join: nil)
  @source_maps = source_maps
  @join = join
end

def map


may not overlap.
The sections must be sorted by starting position and the represented sections

values from the containing index map.
embedded complete source map object. An embedded map does not inherit any
same way as the “sources” fields in the standard map. A “map” entry must be an
where a source map can be found for this section and the url is resolved in the
The other field must be either “url” or “map”. A “url” entry must be a URL

referenced source map represents.
“line” and “column”, that represent the offset into generated code that the
“offset” and a source map reference. “offset” is an object with two fields,
The “sections” field is an array of JSON objects that itself has two fields

Line 4: The sections field.
Line 3: The name field. See the description of the standard map.
Line 2: The version field. See the description of the standard map.
Line 1: The entire file is an JSON object.

The index map follow the form of the standard map

16: }
15: ],
14: }
13: }
12: mappings: "AAAA,E;;ABCDE;"
11: names: ["src", "maps", "are", "fun"],
10: sources: ["foo.js", "bar.js"],
9: file: “section.js”,
8: version : 3,
7: {
6: { offset: {line:100, column:10}, map:
5: { offset: {line:0, column:0}, url: “url_for_part1.map” }
4: sections: [
3: file: “app.js”,
2: version : 3,
1: {

alternate representation of a map is supported:
To support concatenating generated code and other common post processing, an
def map
  offset_line = 0
  offset_column = 0
  {
    version: 3,
    # file: "app.js",
    sections: @source_maps.map do |source_map|
      map = {
        offset: {
          line: offset_line,
          column: offset_column,
        },
        map: source_map.to_h,
      }
      generated_code  = source_map.generated_code
      generated_code += @join if @join
      new_lines_count = generated_code.count("\n")
      last_line       = generated_code[generated_code.rindex("\n") + 1..-1]
      offset_line    += new_lines_count
      offset_column  += last_line.size
      map
    end
  }
end