diff options
Diffstat (limited to 'node_modules/uglify-js/lib/minify.js')
-rw-r--r-- | node_modules/uglify-js/lib/minify.js | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/node_modules/uglify-js/lib/minify.js b/node_modules/uglify-js/lib/minify.js index 806c3aeba..d84f6825f 100644 --- a/node_modules/uglify-js/lib/minify.js +++ b/node_modules/uglify-js/lib/minify.js @@ -7,15 +7,23 @@ var to_base64 = typeof btoa == "undefined" ? function(str) { return new Buffer(str).toString("base64"); } : btoa; -function read_source_map(code) { +function read_source_map(name, code) { var match = /\n\/\/# sourceMappingURL=data:application\/json(;.*?)?;base64,(.*)/.exec(code); if (!match) { - AST_Node.warn("inline source map not found"); + AST_Node.warn("inline source map not found: " + name); return null; } return to_ascii(match[2]); } +function parse_source_map(content) { + try { + return JSON.parse(content); + } catch (ex) { + throw new Error("invalid input source map: " + content); + } +} + function set_shorthand(name, options, keys) { if (options[name]) { keys.forEach(function(key) { @@ -29,7 +37,6 @@ function set_shorthand(name, options, keys) { function init_cache(cache) { if (!cache) return; - if (!("cname" in cache)) cache.cname = -1; if (!("props" in cache)) { cache.props = new Dictionary(); } else if (!(cache.props instanceof Dictionary)) { @@ -39,7 +46,6 @@ function init_cache(cache) { function to_json(cache) { return { - cname: cache.cname, props: cache.props.toObject() }; } @@ -49,6 +55,7 @@ function minify(files, options) { try { options = defaults(options, { compress: {}, + enclose: false, ie8: false, keep_fnames: false, mangle: {}, @@ -115,7 +122,7 @@ function minify(files, options) { }; } if (timings) timings.parse = Date.now(); - var toplevel; + var source_maps, toplevel; if (files instanceof AST_Toplevel) { toplevel = files; } else { @@ -124,13 +131,23 @@ function minify(files, options) { } options.parse = options.parse || {}; options.parse.toplevel = null; + var source_map_content = options.sourceMap && options.sourceMap.content; + if (typeof source_map_content == "string" && source_map_content != "inline") { + source_map_content = parse_source_map(source_map_content); + } + source_maps = source_map_content && Object.create(null); for (var name in files) if (HOP(files, name)) { options.parse.filename = name; options.parse.toplevel = parse(files[name], options.parse); - if (options.sourceMap && options.sourceMap.content == "inline") { - if (Object.keys(files).length > 1) - throw new Error("inline source map only works with singular input"); - options.sourceMap.content = read_source_map(files[name]); + if (source_maps) { + if (source_map_content == "inline") { + var inlined_content = read_source_map(name, files[name]); + if (inlined_content) { + source_maps[name] = parse_source_map(inlined_content); + } + } else { + source_maps[name] = source_map_content; + } } } toplevel = options.parse.toplevel; @@ -141,6 +158,9 @@ function minify(files, options) { if (options.wrap) { toplevel = toplevel.wrap_commonjs(options.wrap); } + if (options.enclose) { + toplevel = toplevel.wrap_enclose(options.enclose); + } if (timings) timings.rename = Date.now(); if (options.rename) { toplevel.figure_out_scope(options.mangle); @@ -152,7 +172,6 @@ function minify(files, options) { if (options.mangle) toplevel.figure_out_scope(options.mangle); if (timings) timings.mangle = Date.now(); if (options.mangle) { - base54.reset(); toplevel.compute_char_frequency(options.mangle); toplevel.mangle_names(options.mangle); } @@ -167,12 +186,9 @@ function minify(files, options) { } if (!HOP(options.output, "code") || options.output.code) { if (options.sourceMap) { - if (typeof options.sourceMap.content == "string") { - options.sourceMap.content = JSON.parse(options.sourceMap.content); - } options.output.source_map = SourceMap({ file: options.sourceMap.filename, - orig: options.sourceMap.content, + orig: source_maps, root: options.sourceMap.root }); if (options.sourceMap.includeSources) { @@ -181,6 +197,8 @@ function minify(files, options) { } else for (var name in files) if (HOP(files, name)) { options.output.source_map.get().setSourceContent(name, files[name]); } + } else { + options.output.source_map.get()._sourcesContents = null; } } delete options.output.ast; |