summaryrefslogtreecommitdiff
path: root/node_modules/source-map/lib/base64-vlq.js
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2024-10-13 10:37:19 +0800
committerlittleblack111 <littleblack11111@gmail.com>2024-10-13 10:37:19 +0800
commite29b244aeab08ea36fb385c7beb2ad0560217039 (patch)
treec66b744dc29573f1acc871862937a23f1b80e6bf /node_modules/source-map/lib/base64-vlq.js
parent62c2881629e6413a8fec6d3dd092e4568e2a81dc (diff)
bump: @babel/cli 7.25.6 → 7.25.7, @babel/core 7.25.2 → 7.25.8, @babel/preset-env 7.25.4 → 7.25.8, postcss 8.4.41 → 8.4.47, swup 4.7.0 → 4.8.1
Diffstat (limited to 'node_modules/source-map/lib/base64-vlq.js')
-rw-r--r--node_modules/source-map/lib/base64-vlq.js51
1 files changed, 40 insertions, 11 deletions
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;
+};