[フレーム]

Class: SourceMap

Inherits:
Object show all
Includes:
Generator , Parser
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

Attributes included from Generator

#generated_output

Class Method Summary collapse

Instance Method Summary collapse

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

#fileObject

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

#mappingsObject

A list of mapping objects.

62
63
64
# File 'opal/stdlib/source_map.rb', line 62
def mappings
 @mappings
end

#namesObject

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_rootObject

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

#sourcesObject

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

#versionObject

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 .

Raises:

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

.from_s(str) ⇒ Object

Load a SourceMap from a String.

21
22
23
# File 'opal/stdlib/source_map/parser.rb', line 21
def self.from_s(str)
 from_json JSON .parse (str)
end

.load(filename) ⇒ Object

Load a SourceMap from a file.

26
27
28
# File 'opal/stdlib/source_map/parser.rb', line 26
def self.load(filename)
 from_s File .read(filename)
end

AltStyle によって変換されたページ (->オリジナル) /