Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / handlebars / node_modules / uglify-js / lib / sourcemap.js
1 /***********************************************************************
2
3   A JavaScript tokenizer / parser / beautifier / compressor.
4   https://github.com/mishoo/UglifyJS2
5
6   -------------------------------- (C) ---------------------------------
7
8                            Author: Mihai Bazon
9                          <mihai.bazon@gmail.com>
10                        http://mihai.bazon.net/blog
11
12   Distributed under the BSD license:
13
14     Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
15
16     Redistribution and use in source and binary forms, with or without
17     modification, are permitted provided that the following conditions
18     are met:
19
20         * Redistributions of source code must retain the above
21           copyright notice, this list of conditions and the following
22           disclaimer.
23
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.
28
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
40     SUCH DAMAGE.
41
42  ***********************************************************************/
43
44 "use strict";
45
46 // a small wrapper around fitzgen's source-map library
47 function SourceMap(options) {
48     options = defaults(options, {
49         file : null,
50         root : null,
51         orig : null,
52
53         orig_line_diff : 0,
54         dest_line_diff : 0,
55     });
56     var generator = new MOZ_SourceMap.SourceMapGenerator({
57         file       : options.file,
58         sourceRoot : options.root
59     });
60     var orig_map = options.orig && new MOZ_SourceMap.SourceMapConsumer(options.orig);
61
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);
65             if (sourceContent) {
66                 generator.setSourceContent(source, sourceContent);
67             }
68         });
69     }
70
71     function add(source, gen_line, gen_col, orig_line, orig_col, name) {
72         if (orig_map) {
73             var info = orig_map.originalPositionFor({
74                 line: orig_line,
75                 column: orig_col
76             });
77             if (info.source === null) {
78                 return;
79             }
80             source = info.source;
81             orig_line = info.line;
82             orig_col = info.column;
83             name = info.name || name;
84         }
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 },
88             source    : source,
89             name      : name
90         });
91     };
92     return {
93         add        : add,
94         get        : function() { return generator },
95         toString   : function() { return JSON.stringify(generator.toJSON()); }
96     };
97 };