Sha256: efdd58648b9911055d0a91aa72e18e349ca37570013261708aa029a72a052bcb

Contents?: true

Size: 771 Bytes

Versions: 16

Compression:

Stored size: 771 Bytes

Contents

# frozen_string_literal: true

require 'base64'
require 'json'

module Opal::SourceMap::Map
  def to_h
    @to_h || map
  end

  def to_json
    map = to_h
    map.to_json
  rescue Encoding::UndefinedConversionError
    map[:sections].each do |i|
      i.to_json
    rescue Encoding::UndefinedConversionError
      map[:sections].delete(i)
    end
    map.to_json
  end

  def as_json(*)
    to_h
  end

  def to_s
    to_h.to_s
  end

  def to_data_uri_comment
    "//# sourceMappingURL=data:application/json;base64,#{Base64.encode64(to_json).delete("\n")}"
  end

  # Marshaling for cache shortpath
  def cache
    @to_h ||= map
    self
  end

  def marshal_dump
    [to_h, generated_code]
  end

  def marshal_load(value)
    @to_h, @generated_code = value
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
opal-1.8.3.rc1 lib/opal/source_map/map.rb
opal-1.8.2 lib/opal/source_map/map.rb
opal-1.8.1 lib/opal/source_map/map.rb
opal-1.8.0 lib/opal/source_map/map.rb
opal-1.8.0.beta1 lib/opal/source_map/map.rb
opal-1.7.4 lib/opal/source_map/map.rb
opal-1.8.0.alpha1 lib/opal/source_map/map.rb
opal-1.7.3 lib/opal/source_map/map.rb
opal-1.7.2 lib/opal/source_map/map.rb
opal-1.7.1 lib/opal/source_map/map.rb
opal-1.7.0 lib/opal/source_map/map.rb
opal-1.7.0.rc1 lib/opal/source_map/map.rb
opal-1.6.1 lib/opal/source_map/map.rb
opal-1.6.0 lib/opal/source_map/map.rb
opal-1.6.0.rc1 lib/opal/source_map/map.rb
opal-1.6.0.alpha1 lib/opal/source_map/map.rb