From 83f42ede367316193205572a04959098b45e711d Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Fri, 17 Apr 2020 00:20:48 +0100 Subject: support optional output of `names` in source maps (#3784) --- lib/minify.js | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'lib/minify.js') diff --git a/lib/minify.js b/lib/minify.js index ab397f5e..2182d653 100644 --- a/lib/minify.js +++ b/lib/minify.js @@ -129,6 +129,7 @@ function minify(files, options) { content: null, filename: null, includeSources: false, + names: true, root: null, url: null, }, true); @@ -138,7 +139,7 @@ function minify(files, options) { warnings.push(warning); }, options.warnings == "verbose"); if (timings) timings.parse = Date.now(); - var source_maps, toplevel; + var toplevel; if (files instanceof AST_Toplevel) { toplevel = files; } else { @@ -151,19 +152,17 @@ function minify(files, options) { 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); + if (source_map_content) options.sourceMap.orig = Object.create(null); for (var name in files) if (HOP(files, name)) { options.parse.filename = name; options.parse.toplevel = toplevel = parse(files[name], options.parse); - if (source_maps) { - if (source_map_content == "inline") { - var inlined_content = read_source_map(name, toplevel); - if (inlined_content) { - source_maps[name] = parse_source_map(inlined_content); - } - } else { - source_maps[name] = source_map_content; + if (source_map_content == "inline") { + var inlined_content = read_source_map(name, toplevel); + if (inlined_content) { + options.sourceMap.orig[name] = parse_source_map(inlined_content); } + } else if (source_map_content) { + options.sourceMap.orig[name] = source_map_content; } } } @@ -202,12 +201,7 @@ function minify(files, options) { } if (!HOP(options.output, "code") || options.output.code) { if (options.sourceMap) { - options.output.source_map = SourceMap({ - content: options.sourceMap.includeSources, - file: options.sourceMap.filename, - orig: source_maps, - root: options.sourceMap.root - }); + options.output.source_map = SourceMap(options.sourceMap); if (options.sourceMap.includeSources) { if (files instanceof AST_Toplevel) { throw new Error("original source content unavailable"); -- cgit v1.2.3