From 5e9382c1f8a19fcd582d98a2033363e2a929fecc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=99=E8=85=BE=E9=81=93?= Date: Mon, 12 Nov 2018 10:57:22 +0800 Subject: [PATCH] fix read_source_map bug 1. `new Buffer` can cause a global `DeprecationWarning` in `Node.js` nowadays. Fix it as `Buffer.from ? Buffer.from : new Buffer`. 2. A) The previous regExp may match a map-like string or otherthings before the real inline map, which must in the end of the file. B) And, the eol in javascript is not only `\n`, but also `\r` `\u2028` `\u2029`. --- lib/minify.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/minify.js b/lib/minify.js index d84f6825..113d64bb 100644 --- a/lib/minify.js +++ b/lib/minify.js @@ -1,14 +1,14 @@ "use strict"; var to_ascii = typeof atob == "undefined" ? function(b64) { - return new Buffer(b64, "base64").toString(); + return ( Buffer.from ? Buffer.from(b64, "base64") : new Buffer(b64, "base64") ).toString(); } : atob; var to_base64 = typeof btoa == "undefined" ? function(str) { - return new Buffer(str).toString("base64"); + return ( Buffer.from ? Buffer.from(str) : new Buffer(str) ).toString("base64"); } : btoa; function read_source_map(name, code) { - var match = /\n\/\/# sourceMappingURL=data:application\/json(;.*?)?;base64,(.*)/.exec(code); + var match = /(?:^|[^.])\/\/# sourceMappingURL=data:application\/json(;.*?)?;base64,(.*)\s*$/.exec(code); if (!match) { AST_Node.warn("inline source map not found: " + name); return null;