You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

@atlaspack/source-map

Package Overview
Dependencies
Maintainers
3
Versions
168
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@atlaspack/source-map - npm Package Compare versions

Comparing version
3.2.11-canary.4209
to
3.2.11-canary.4210
+56
dist/vlq.js
"use strict";
/**
* Pure-JS VLQ codec for source map mappings strings.
*
* Source map VLQ encoding:
* - Each value is encoded as one or more 6-bit base64 groups.
* - Bit 5 of each group is the continuation flag; bits 4–0 are data.
* - In the very first group, bit 0 is the sign bit and bits 4–1 are value
* bits (so the effective data width of the first group is 4 bits).
* - All subsequent groups contribute 5 data bits each.
*
* Lookup tables are allocated once at module load time.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.decodeVLQ = decodeVLQ;
exports.encodeVLQ = encodeVLQ;
const BASE64_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
// Maps char-code → base64 digit value (−1 for invalid characters).
const BASE64_VALUES = new Int8Array(128).fill(-1);
for (let i = 0; i < BASE64_CHARS.length; i++) {
BASE64_VALUES[BASE64_CHARS.charCodeAt(i)] = i;
}
/**
* Decodes a single VLQ-encoded integer from `str` starting at `pos`.
* Returns the decoded value and the position of the first character after the
* encoded value (i.e. the start of the next field or segment delimiter).
*/
function decodeVLQ(str, pos) {
let result = 0;
let shift = 0;
let continuation;
do {
const digit = BASE64_VALUES[str.charCodeAt(pos++)];
continuation = (digit & 0x20) !== 0;
result |= (digit & 0x1f) << shift;
shift += 5;
} while (continuation);
const negate = (result & 1) !== 0;
result >>>= 1;
return { value: negate ? -result : result, nextPos: pos };
}
/**
* Encodes a single integer as a VLQ string.
*/
function encodeVLQ(value) {
let vlq = value < 0 ? (-value << 1) | 1 : value << 1;
let result = '';
do {
let digit = vlq & 0x1f;
vlq >>>= 5;
if (vlq > 0)
digit |= 0x20;
result += BASE64_CHARS[digit];
} while (vlq > 0);
return result;
}
/**
* Pure-JS VLQ codec for source map mappings strings.
*
* Source map VLQ encoding:
* - Each value is encoded as one or more 6-bit base64 groups.
* - Bit 5 of each group is the continuation flag; bits 4–0 are data.
* - In the very first group, bit 0 is the sign bit and bits 4–1 are value
* bits (so the effective data width of the first group is 4 bits).
* - All subsequent groups contribute 5 data bits each.
*
* Lookup tables are allocated once at module load time.
*/
export type VLQDecodeResult = {
value: number;
nextPos: number;
};
/**
* Decodes a single VLQ-encoded integer from `str` starting at `pos`.
* Returns the decoded value and the position of the first character after the
* encoded value (i.e. the start of the next field or segment delimiter).
*/
export declare function decodeVLQ(str: string, pos: number): VLQDecodeResult;
/**
* Encodes a single integer as a VLQ string.
*/
export declare function encodeVLQ(value: number): string;
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.decodeVLQ = decodeVLQ;
exports.encodeVLQ = encodeVLQ;
/**
* Pure-JS VLQ codec for source map mappings strings.
*
* Source map VLQ encoding:
* - Each value is encoded as one or more 6-bit base64 groups.
* - Bit 5 of each group is the continuation flag; bits 4–0 are data.
* - In the very first group, bit 0 is the sign bit and bits 4–1 are value
* bits (so the effective data width of the first group is 4 bits).
* - All subsequent groups contribute 5 data bits each.
*
* Lookup tables are allocated once at module load time.
*/
const BASE64_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
// Maps char-code → base64 digit value (−1 for invalid characters).
const BASE64_VALUES = new Int8Array(128).fill(-1);
for (let i = 0; i < BASE64_CHARS.length; i++) {
BASE64_VALUES[BASE64_CHARS.charCodeAt(i)] = i;
}
/**
* Decodes a single VLQ-encoded integer from `str` starting at `pos`.
* Returns the decoded value and the position of the first character after the
* encoded value (i.e. the start of the next field or segment delimiter).
*/
function decodeVLQ(str, pos) {
let result = 0;
let shift = 0;
let continuation;
do {
const digit = BASE64_VALUES[str.charCodeAt(pos++)];
continuation = (digit & 0x20) !== 0;
result |= (digit & 0x1f) << shift;
shift += 5;
} while (continuation);
const negate = (result & 1) !== 0;
result >>>= 1;
return {
value: negate ? -result : result,
nextPos: pos
};
}
/**
* Encodes a single integer as a VLQ string.
*/
function encodeVLQ(value) {
let vlq = value < 0 ? -value << 1 | 1 : value << 1;
let result = '';
do {
let digit = vlq & 0x1f;
vlq >>>= 5;
if (vlq > 0) digit |= 0x20;
result += BASE64_CHARS[digit];
} while (vlq > 0);
return result;
}
/**
* Pure-JS VLQ codec for source map mappings strings.
*
* Source map VLQ encoding:
* - Each value is encoded as one or more 6-bit base64 groups.
* - Bit 5 of each group is the continuation flag; bits 4–0 are data.
* - In the very first group, bit 0 is the sign bit and bits 4–1 are value
* bits (so the effective data width of the first group is 4 bits).
* - All subsequent groups contribute 5 data bits each.
*
* Lookup tables are allocated once at module load time.
*/
const BASE64_CHARS =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
// Maps char-code → base64 digit value (−1 for invalid characters).
const BASE64_VALUES = new Int8Array(128).fill(-1);
for (let i = 0; i < BASE64_CHARS.length; i++) {
BASE64_VALUES[BASE64_CHARS.charCodeAt(i)] = i;
}
export type VLQDecodeResult = {value: number; nextPos: number};
/**
* Decodes a single VLQ-encoded integer from `str` starting at `pos`.
* Returns the decoded value and the position of the first character after the
* encoded value (i.e. the start of the next field or segment delimiter).
*/
export function decodeVLQ(str: string, pos: number): VLQDecodeResult {
let result = 0;
let shift = 0;
let continuation: boolean;
do {
const digit = BASE64_VALUES[str.charCodeAt(pos++)];
continuation = (digit & 0x20) !== 0;
result |= (digit & 0x1f) << shift;
shift += 5;
} while (continuation);
const negate = (result & 1) !== 0;
result >>>= 1;
return {value: negate ? -result : result, nextPos: pos};
}
/**
* Encodes a single integer as a VLQ string.
*/
export function encodeVLQ(value: number): string {
let vlq = value < 0 ? (-value << 1) | 1 : value << 1;
let result = '';
do {
let digit = vlq & 0x1f;
vlq >>>= 5;
if (vlq > 0) digit |= 0x20;
result += BASE64_CHARS[digit];
} while (vlq > 0);
return result;
}
import assert from 'assert';
import {decodeVLQ, encodeVLQ} from '../src/vlq';
// Reference table of (value, expected VLQ string) pairs.
// Single-group values (abs <= 15) can be verified by hand:
// encodeVLQ(n) = BASE64_CHARS[(n << 1) | sign] (sign=1 if negative)
// Multi-group values are verified via round-trip in the round-trip suite.
const CASES: Array<[number, string]> = [
[0, 'A'],
[1, 'C'],
[-1, 'D'],
[2, 'E'],
[-2, 'F'],
[15, 'e'],
[-15, 'f'],
// Values that require two base64 groups (abs >= 16)
[16, 'gB'],
[-16, 'hB'],
[1000, 'w+B'],
[-1000, 'x+B'],
// Larger values (four groups)
[100000, 'gqjG'],
[-100000, 'hqjG'],
];
describe('VLQ codec', () => {
describe('encodeVLQ', () => {
for (const [value, expected] of CASES) {
it(`encodes ${value} as "${expected}"`, () => {
assert.strictEqual(encodeVLQ(value), expected);
});
}
it('encodes zero', () => {
assert.strictEqual(encodeVLQ(0), 'A');
});
it('encodes large positive value', () => {
// 2^20 = 1048576
const encoded = encodeVLQ(1048576);
assert.ok(encoded.length > 0);
// Round-trip must recover the original value
assert.strictEqual(decodeVLQ(encoded, 0).value, 1048576);
});
it('encodes large negative value', () => {
const encoded = encodeVLQ(-1048576);
assert.strictEqual(decodeVLQ(encoded, 0).value, -1048576);
});
});
describe('decodeVLQ', () => {
for (const [expected, encoded] of CASES) {
it(`decodes "${encoded}" as ${expected}`, () => {
const {value, nextPos} = decodeVLQ(encoded, 0);
assert.strictEqual(value, expected);
assert.strictEqual(nextPos, encoded.length);
});
}
it('returns correct nextPos when decoding from mid-string', () => {
// Encode two values back-to-back and decode the second one starting
// after the first.
const a = encodeVLQ(42);
const b = encodeVLQ(-7);
const combined = a + b;
const {value, nextPos} = decodeVLQ(combined, a.length);
assert.strictEqual(value, -7);
assert.strictEqual(nextPos, combined.length);
});
it('decodes a multi-value sequence positionally', () => {
const values = [0, 1, -1, 100, -100, 0];
const encoded = values.map(encodeVLQ).join('');
let pos = 0;
for (const expected of values) {
const {value, nextPos} = decodeVLQ(encoded, pos);
assert.strictEqual(value, expected);
pos = nextPos;
}
assert.strictEqual(pos, encoded.length);
});
});
describe('round-trip', () => {
const roundTripValues = [
0, 1, -1, 2, -2, 15, -15, 16, -16, 31, -31, 32, -32, 127, -127, 128, -128,
255, -255, 1000, -1000, 65535, -65535, 1048575, -1048575,
];
for (const value of roundTripValues) {
it(`round-trips ${value}`, () => {
const encoded = encodeVLQ(value);
const {value: decoded, nextPos} = decodeVLQ(encoded, 0);
assert.strictEqual(decoded, value);
assert.strictEqual(nextPos, encoded.length);
});
}
});
});
+4
-1

@@ -36,5 +36,8 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.init = void 0;
exports.init = exports.encodeVLQ = exports.decodeVLQ = void 0;
const SourceMap_1 = __importStar(require("./SourceMap"));
const rust_1 = require("@atlaspack/rust");
var vlq_1 = require("./vlq");
Object.defineProperty(exports, "decodeVLQ", { enumerable: true, get: function () { return vlq_1.decodeVLQ; } });
Object.defineProperty(exports, "encodeVLQ", { enumerable: true, get: function () { return vlq_1.encodeVLQ; } });
class NodeSourceMap extends SourceMap_1.default {

@@ -41,0 +44,0 @@ constructor(projectRoot = '/', buffer) {

+15
-1

@@ -6,3 +6,16 @@ "use strict";

});
exports.init = exports.default = void 0;
Object.defineProperty(exports, "decodeVLQ", {
enumerable: true,
get: function () {
return _vlq.decodeVLQ;
}
});
exports.default = void 0;
Object.defineProperty(exports, "encodeVLQ", {
enumerable: true,
get: function () {
return _vlq.encodeVLQ;
}
});
exports.init = void 0;
var _SourceMap = _interopRequireWildcard(require("./SourceMap"));

@@ -16,2 +29,3 @@ function _rust() {

}
var _vlq = require("./vlq");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }

@@ -18,0 +32,0 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }

import type { VLQMap, GenerateEmptyMapOptions } from './types';
import SourceMap from './SourceMap';
export type * from './types';
export { decodeVLQ, encodeVLQ } from './vlq';
export type { VLQDecodeResult } from './vlq';
export default class NodeSourceMap extends SourceMap {

@@ -5,0 +7,0 @@ constructor(projectRoot?: string, buffer?: Buffer);

{
"name": "@atlaspack/source-map",
"version": "3.2.11-canary.4209+3465724e6",
"version": "3.2.11-canary.4210+de388ff76",
"license": "(MIT OR Apache-2.0)",

@@ -24,5 +24,5 @@ "type": "commonjs",

"dependencies": {
"@atlaspack/rust": "3.2.1-canary.430+3465724e6"
"@atlaspack/rust": "3.2.1-canary.431+de388ff76"
},
"gitHead": "3465724e6b1f7e805f9d30828417104f40a0c2ce"
"gitHead": "de388ff76d39dece97ad475fcccdb6efb6283bfc"
}

@@ -7,2 +7,4 @@ import type {VLQMap, GenerateEmptyMapOptions} from './types';

export type * from './types';
export {decodeVLQ, encodeVLQ} from './vlq';
export type {VLQDecodeResult} from './vlq';

@@ -9,0 +11,0 @@ export default class NodeSourceMap extends SourceMap {

Sorry, the diff of this file is not supported yet