diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2019-05-04 20:08:57 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-04 20:08:57 +0800 |
commit | 11cdab745d29313a4e1799c65d13f7d6d5a45938 (patch) | |
tree | 336375b5eac05211b5ea2c77aecc37069a3753ba /lib | |
parent | a89d424a0bd85c80a6b49b6585143ff723a243ca (diff) | |
download | tracifyjs-11cdab745d29313a4e1799c65d13f7d6d5a45938.tar.gz tracifyjs-11cdab745d29313a4e1799c65d13f7d6d5a45938.zip |
fix corner cases in `sourceMap` (#3397)
fixes #3255
fixes #3294
Diffstat (limited to 'lib')
-rw-r--r-- | lib/minify.js | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/minify.js b/lib/minify.js index 5f865c63..1bb6309c 100644 --- a/lib/minify.js +++ b/lib/minify.js @@ -8,7 +8,7 @@ var to_base64 = typeof btoa == "undefined" ? function(str) { } : btoa; function read_source_map(name, code) { - var match = /\n\/\/# sourceMappingURL=data:application\/json(;.*?)?;base64,(.*)/.exec(code); + var match = /\n\/\/# sourceMappingURL=data:application\/json(;.*?)?;base64,(\S+)\s*$/.exec(code); if (!match) { AST_Node.warn("inline source map not found: " + name); return null; @@ -204,10 +204,14 @@ function minify(files, options) { result.code = stream.get(); if (options.sourceMap) { result.map = options.output.source_map.toString(); - 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) { - result.code += "\n//# sourceMappingURL=" + options.sourceMap.url; + var url = options.sourceMap.url; + if (url) { + result.code = result.code.replace(/\n\/\/# sourceMappingURL=\S+\s*$/, ""); + if (url == "inline") { + result.code += "\n//# sourceMappingURL=data:application/json;charset=utf-8;base64," + to_base64(result.map); + } else { + result.code += "\n//# sourceMappingURL=" + url; + } } } } |