1 /***********************************************************************
3 A JavaScript tokenizer / parser / beautifier / compressor.
4 https://github.com/mishoo/UglifyJS2
6 -------------------------------- (C) ---------------------------------
9 <mihai.bazon@gmail.com>
10 http://mihai.bazon.net/blog
12 Distributed under the BSD license:
14 Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
16 Redistribution and use in source and binary forms, with or without
17 modification, are permitted provided that the following conditions
20 * Redistributions of source code must retain the above
21 copyright notice, this list of conditions and the following
24 * Redistributions in binary form must reproduce the above
25 copyright notice, this list of conditions and the following
26 disclaimer in the documentation and/or other materials
27 provided with the distribution.
29 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
30 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
32 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
33 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
34 OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
35 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
36 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
38 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
39 THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 ***********************************************************************/
46 // a small wrapper around fitzgen's source-map library
47 function SourceMap(options) {
48 options = defaults(options, {
56 var generator = new MOZ_SourceMap.SourceMapGenerator({
58 sourceRoot : options.root
60 var orig_map = options.orig && new MOZ_SourceMap.SourceMapConsumer(options.orig);
62 if (orig_map && Array.isArray(options.orig.sources)) {
63 orig_map._sources.toArray().forEach(function(source) {
64 var sourceContent = orig_map.sourceContentFor(source, true);
66 generator.setSourceContent(source, sourceContent);
71 function add(source, gen_line, gen_col, orig_line, orig_col, name) {
73 var info = orig_map.originalPositionFor({
77 if (info.source === null) {
81 orig_line = info.line;
82 orig_col = info.column;
83 name = info.name || name;
85 generator.addMapping({
86 generated : { line: gen_line + options.dest_line_diff, column: gen_col },
87 original : { line: orig_line + options.orig_line_diff, column: orig_col },
94 get : function() { return generator },
95 toString : function() { return JSON.stringify(generator.toJSON()); }