Class: SourceMap
- Defined in:
- opal/stdlib/source_map.rb,
opal/stdlib/source_map/vlq.rb,
opal/stdlib/source_map/parser.rb,
opal/stdlib/source_map/generator.rb
Defined Under Namespace
Modules: Generator, Parser, VLQ Classes: ParserError
Instance Attribute Summary collapse
-
#file ⇒ Object
The name of the file containing the code that this SourceMap describes.
-
#mappings ⇒ Object
A list of mapping objects.
-
#names ⇒ Object
A list of names (used during parsing/generating) (default []).
-
#source_root ⇒ Object
The URL/directory that contains the original source files.
-
#sources ⇒ Object
The list of sources (used during parsing/generating) These are relative to the source_root.
-
#version ⇒ Object
The version of the SourceMap spec we're using.
Attributes included from Generator
Class Method Summary collapse
-
.from_json(json) ⇒ Object
Load a SourceMap from a Hash such as might be returned by Generator#as_json.
-
.from_s(str) ⇒ Object
Load a SourceMap from a String.
-
.load(filename) ⇒ Object
Load a SourceMap from a file.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ SourceMap
constructor
Create a new blank SourceMap.
Methods included from Parser
#parse_mapping, #parse_mappings, #undiff
Methods included from Generator
#add_generated, #add_mapping, #as_json, #save, #to_s
Constructor Details
#initialize(opts = {}) ⇒ SourceMap
Create a new blank SourceMap
Options may include:
:file => String # See #file :source_root => String # See #source_root :generated_output => IO # See SourceMap::Generator#generated_output
:sources => Array[String] # See #sources :names => Array[String] # See #names
:version => 3 # Which version of SourceMap to use (only 3 is allowed)
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'opal/stdlib/source_map.rb', line 24 def initialize(opts={}) unless (remain = opts.keys - [:generated_output, :file, :source_root, :sources, :names, :version]).empty? raise ArgumentError, "Unsupported options to SourceMap.new: #{remain.inspect}" end self.generated_output = opts[:generated_output] self.file = opts[:file] || '' self.source_root = opts[:source_root] || '' self.version = opts[:version] || 3 self.sources = opts[:sources] || [] self.names = opts[:names] || [] self.mappings = [] raise "version #{opts[:version]} not supported" if version != 3 end |
Instance Attribute Details
#file ⇒ Object
The name of the file containing the code that this SourceMap describes. (default "")
40 41 42 |
# File 'opal/stdlib/source_map.rb', line 40 def file @file end |
#mappings ⇒ Object
A list of mapping objects.
62 63 64 |
# File 'opal/stdlib/source_map.rb', line 62 def mappings @mappings end |
#names ⇒ Object
A list of names (used during parsing/generating) (default [])
59 60 61 |
# File 'opal/stdlib/source_map.rb', line 59 def names @names end |
#source_root ⇒ Object
The URL/directory that contains the original source files.
This is prefixed to the entries in 'sources'
46 47 48 |
# File 'opal/stdlib/source_map.rb', line 46 def source_root @source_root end |
#sources ⇒ Object
The list of sources (used during parsing/generating) These are relative to the source_root. (default [])
55 56 57 |
# File 'opal/stdlib/source_map.rb', line 55 def sources @sources end |
#version ⇒ Object
The version of the SourceMap spec we're using. (default 3)
50 51 52 |
# File 'opal/stdlib/source_map.rb', line 50 def version @version end |
Class Method Details
.from_json(json) ⇒ Object
Load a SourceMap from a Hash such as might be returned by SourceMap::Generator#as_json.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'opal/stdlib/source_map/parser.rb', line 8 def self.from_json(json) raise ParserError, "Cannot parse version: #{json['version']} of SourceMap" unless json['version'] == 3 map = new(:file => json['file'], :source_root => json['sourceRoot'], :sources => json['sources'], :names => json['names']) map.parse_mappings(json['mappings'] || '') map end |