Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/helpers/readMappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
* @returns {void}
*/
const readMappings = (mappings, onMapping) => {
// generatedColumn, [sourceIndex, originalLine, orignalColumn, [nameIndex]]
const currentData = new Uint32Array([0, 0, 1, 0, 0]);
// generatedColumn, [sourceIndex, originalLine, originalColumn, [nameIndex]]
const currentData = new Int32Array([0, 0, 1, 0, 0]);
let currentDataPos = 0;
// currentValue will include a sign bit at bit 0
let currentValue = 0;
Expand Down Expand Up @@ -116,5 +116,4 @@
);
}
};

module.exports = readMappings;

Check failure on line 119 in lib/helpers/readMappings.js

View workflow job for this annotation

GitHub Actions / lint

Expected blank line before this statement
76 changes: 76 additions & 0 deletions test/readMapping.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
"use strict";

const readMappings = require("../lib/helpers/readMappings");

describe("readMappings", () => {
it("should correctly decode negative VLQ deltas (backwards column references)", () => {
const mappings = [];

// Mapping with a negative column delta (backwards reference)
readMappings(
"AAKA;CAAC",
(
generatedLine,
generatedColumn,
sourceIndex,
originalLine,
originalColumn,
nameIndex,
) => {
mappings.push({
generatedLine,
generatedColumn,
sourceIndex,
originalLine,
originalColumn,
nameIndex,
});
},
);

expect(mappings).toHaveLength(2);

// First mapping: line 1, col 0, source 0, orig line 5, orig col 0
expect(mappings[0].generatedLine).toBe(1);
expect(mappings[0].generatedColumn).toBe(0);
expect(mappings[0].sourceIndex).toBe(0);
expect(mappings[0].originalLine).toBe(5);
expect(mappings[0].originalColumn).toBe(0);

// Second mapping: line 2 — negative delta on originalColumn (col goes backwards)
expect(mappings[1].generatedLine).toBe(2);
expect(mappings[1].generatedColumn).toBe(1);
expect(mappings[1].sourceIndex).toBe(1);
expect(mappings[1].originalLine).toBe(5);
expect(mappings[1].originalColumn).toBe(-1);
});

it("should handle mappings without source info", () => {
const mappings = [];

readMappings("A", (generatedLine, generatedColumn, sourceIndex) => {
mappings.push({ generatedLine, generatedColumn, sourceIndex });
});

expect(mappings).toHaveLength(1);
expect(mappings[0].generatedLine).toBe(1);
expect(mappings[0].generatedColumn).toBe(0);
expect(mappings[0].sourceIndex).toBe(-1);
});

it("should handle multiple lines", () => {
const mappings = [];

readMappings(
"AAAA;AACA;AACA",
(generatedLine, generatedColumn, sourceIndex, originalLine) => {
mappings.push({ generatedLine, generatedColumn, originalLine });
},
);

expect(mappings).toHaveLength(3);
expect(mappings[0].generatedLine).toBe(1);
expect(mappings[1].generatedLine).toBe(2);
expect(mappings[2].generatedLine).toBe(3);
});
});
Loading