Do not use the deprecated Buffer() constructor

Refs: https://github.com/nodejs/citgm/issues/605
Refs: https://nodejs.org/api/deprecations.html#deprecations_dep0005_buffer_constructor
This commit is contained in:
Luigi Pinca 2018-10-16 08:07:20 +02:00
parent ea999b0e92
commit 8fb77eed89
2 changed files with 12 additions and 3 deletions

View File

@ -1,10 +1,16 @@
"use strict";
var to_ascii = typeof atob == "undefined" ? function(b64) {
return new Buffer(b64, "base64").toString();
var buf = Buffer.from && Buffer.from !== Uint8Array.from
? Buffer.from(b64, "base64")
: new Buffer(b64, "base64");
return buf.toString();
} : atob;
var to_base64 = typeof btoa == "undefined" ? function(str) {
return new Buffer(str).toString("base64");
var buf = Buffer.from && Buffer.from !== Uint8Array.from
? Buffer.from(str)
: new Buffer(str);
return buf.toString("base64");
} : btoa;
function read_source_map(name, code) {

View File

@ -238,7 +238,10 @@ describe("sourcemaps", function() {
assert.strictEqual(map.sourcesContent.length, 1);
assert.strictEqual(map.sourcesContent[0], code);
var encoded = result.code.slice(result.code.lastIndexOf(",") + 1);
map = JSON.parse(new Buffer(encoded, "base64").toString());
var buf = Buffer.from && Buffer.from !== Uint8Array.from
? Buffer.from(encoded, "base64")
: new Buffer(encoded, "base64");
map = JSON.parse(buf.toString());
assert.strictEqual(map.sourcesContent.length, 1);
assert.strictEqual(map.sourcesContent[0], code);
result = UglifyJS.minify(result.code, {