From e99f950f5018cfe737c0d1150e50d97c6e6a4823 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Wed, 1 Nov 2023 20:49:36 +0800 Subject: update --- node_modules/source-map/lib/base64-vlq.js | 51 ++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 11 deletions(-) (limited to 'node_modules/source-map/lib/base64-vlq.js') diff --git a/node_modules/source-map/lib/base64-vlq.js b/node_modules/source-map/lib/base64-vlq.js index fc1049c8..612b4040 100644 --- a/node_modules/source-map/lib/base64-vlq.js +++ b/node_modules/source-map/lib/base64-vlq.js @@ -35,7 +35,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -const base64 = require("./base64"); +var base64 = require('./base64'); // A single base 64 digit can contain 6 bits of data. For the base 64 variable // length quantities we use in the source map spec, the first bit is the sign, @@ -49,16 +49,16 @@ const base64 = require("./base64"); // V V // 101011 -const VLQ_BASE_SHIFT = 5; +var VLQ_BASE_SHIFT = 5; // binary: 100000 -const VLQ_BASE = 1 << VLQ_BASE_SHIFT; +var VLQ_BASE = 1 << VLQ_BASE_SHIFT; // binary: 011111 -const VLQ_BASE_MASK = VLQ_BASE - 1; +var VLQ_BASE_MASK = VLQ_BASE - 1; // binary: 100000 -const VLQ_CONTINUATION_BIT = VLQ_BASE; +var VLQ_CONTINUATION_BIT = VLQ_BASE; /** * Converts from a two-complement value to a value where the sign bit is @@ -78,10 +78,9 @@ function toVLQSigned(aValue) { * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1 * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2 */ -// eslint-disable-next-line no-unused-vars function fromVLQSigned(aValue) { - const isNegative = (aValue & 1) === 1; - const shifted = aValue >> 1; + var isNegative = (aValue & 1) === 1; + var shifted = aValue >> 1; return isNegative ? -shifted : shifted; @@ -91,10 +90,10 @@ function fromVLQSigned(aValue) { * Returns the base 64 VLQ encoded value. */ exports.encode = function base64VLQ_encode(aValue) { - let encoded = ""; - let digit; + var encoded = ""; + var digit; - let vlq = toVLQSigned(aValue); + var vlq = toVLQSigned(aValue); do { digit = vlq & VLQ_BASE_MASK; @@ -109,3 +108,33 @@ exports.encode = function base64VLQ_encode(aValue) { return encoded; }; + +/** + * Decodes the next base 64 VLQ value from the given string and returns the + * value and the rest of the string via the out parameter. + */ +exports.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) { + var strLen = aStr.length; + var result = 0; + var shift = 0; + var continuation, digit; + + do { + if (aIndex >= strLen) { + throw new Error("Expected more digits in base 64 VLQ value."); + } + + digit = base64.decode(aStr.charCodeAt(aIndex++)); + if (digit === -1) { + throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1)); + } + + continuation = !!(digit & VLQ_CONTINUATION_BIT); + digit &= VLQ_BASE_MASK; + result = result + (digit << shift); + shift += VLQ_BASE_SHIFT; + } while (continuation); + + aOutParam.value = fromVLQSigned(result); + aOutParam.rest = aIndex; +}; -- cgit v1.2.3