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:
parent
9e19e63551
commit
2aa8b944f6
|
|
@ -111,6 +111,7 @@ function minify(files, options) {
|
||||||
content: null,
|
content: null,
|
||||||
filename: null,
|
filename: null,
|
||||||
includeSources: false,
|
includeSources: false,
|
||||||
|
json: true,
|
||||||
root: null,
|
root: null,
|
||||||
url: null,
|
url: null,
|
||||||
}, true);
|
}, true);
|
||||||
|
|
@ -207,7 +208,13 @@ function minify(files, options) {
|
||||||
toplevel.print(stream);
|
toplevel.print(stream);
|
||||||
result.code = stream.get();
|
result.code = stream.get();
|
||||||
if (options.sourceMap) {
|
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") {
|
if (options.sourceMap.url == "inline") {
|
||||||
result.code += "\n//# sourceMappingURL=data:application/json;charset=utf-8;base64," + to_base64(result.map);
|
result.code += "\n//# sourceMappingURL=data:application/json;charset=utf-8;base64," + to_base64(result.map);
|
||||||
} else if (options.sourceMap.url) {
|
} else if (options.sourceMap.url) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user