fix: invalid filenames in sources of source maps

When the parsed files have no associated filenames (eg: a string or array of strings was passed to the `minify` function), the `sources` array of the generated sourcemap must only contain null values.

Currently, it contains the stringified indexes of the array. For example, passing a string to `minify` results in a `sources` array of `["0"]`, which breaks the sourcemap.

Also, this PR adds the `sourceMap.json` option. When explicitly set to `false`, the sourcemap is *not* stringified.
This commit is contained in:
aleclarson 2018-06-08 14:58:18 -04:00
parent 9e19e63551
commit 2aa8b944f6

View File

@ -111,6 +111,7 @@ function minify(files, options) {
content: null,
filename: null,
includeSources: false,
json: true,
root: null,
url: null,
}, true);
@ -207,7 +208,13 @@ function minify(files, options) {
toplevel.print(stream);
result.code = stream.get();
if (options.sourceMap) {
result.map = options.output.source_map.toString();
result.map = options.output.source_map.get().toJSON();
if (Array.isArray(files)) {
result.map.sources = [null];
}
if (options.sourceMap.json !== false) {
result.map = JSON.stringify(result.map);
}
if (options.sourceMap.url == "inline") {
result.code += "\n//# sourceMappingURL=data:application/json;charset=utf-8;base64," + to_base64(result.map);
} else if (options.sourceMap.url) {