| | |
| | | } |
| | | |
| | | function create_array_map() { |
| | | var map = Object.create(null); |
| | | var map = new Dictionary(); |
| | | var array = []; |
| | | array.index = function(name) { |
| | | if (!HOP(map, name)) { |
| | | map[name] = array.length; |
| | | var index = map.get(name); |
| | | if (!(index >= 0)) { |
| | | index = array.length; |
| | | array.push(name); |
| | | map.set(name, index); |
| | | } |
| | | return map[name]; |
| | | return index; |
| | | }; |
| | | return array; |
| | | } |
| | | |
| | | function SourceMap(options) { |
| | | var sources = create_array_map(); |
| | | var sources_content = options.includeSources && Object.create(null); |
| | | var sources_content = options.includeSources && new Dictionary(); |
| | | var names = create_array_map(); |
| | | var mappings = ""; |
| | | if (options.orig) Object.keys(options.orig).forEach(function(name) { |
| | |
| | | if (!sources_content || !map.sourcesContent) return; |
| | | for (var i = 0; i < map.sources.length; i++) { |
| | | var content = map.sourcesContent[i]; |
| | | if (content) sources_content[map.sources[i]] = content; |
| | | if (content) sources_content.set(map.sources[i], content); |
| | | } |
| | | }); |
| | | var prev_source; |
| | |
| | | add(source, gen_line, gen_col, orig_line, orig_col, name); |
| | | } : add, |
| | | setSourceContent: sources_content ? function(source, content) { |
| | | if (!(source in sources_content)) { |
| | | sources_content[source] = content; |
| | | if (!sources_content.has(source)) { |
| | | sources_content.set(source, content); |
| | | } |
| | | } : noop, |
| | | toString: function() { |
| | |
| | | sourceRoot: options.root || undefined, |
| | | sources: sources, |
| | | sourcesContent: sources_content ? sources.map(function(source) { |
| | | return sources_content[source] || null; |
| | | return sources_content.get(source) || null; |
| | | }) : undefined, |
| | | names: names, |
| | | mappings: mappings, |