Skip to content

Commit

Permalink
Merge pull request #37 from parcel-bundler/column-offset-bugfix
Browse files Browse the repository at this point in the history
Fix bug with column offset
  • Loading branch information
DeMoorJasper authored Oct 20, 2020
2 parents 1fc437a + 5a2a3cd commit d54c72d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@parcel/source-map",
"version": "2.0.0-alpha.4.16",
"version": "2.0.0-alpha.4.17",
"main": "./dist/node.js",
"browser": "./dist/wasm-browser.js",
"license": "MIT",
Expand Down
8 changes: 8 additions & 0 deletions src/MappingContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,10 @@ void MappingContainer::addIndexedMapping(int generatedLine, int generatedColumn,

// TODO: This can be improved performance wise, by not having line stored in both MappingLine and Mapping
void MappingContainer::offsetLines(int line, int lineOffset) {
if (_generated_lines < line) {
return;
}

int lineCount = this->_mapping_lines.size();

if (lineOffset > 0) {
Expand Down Expand Up @@ -537,6 +541,10 @@ void MappingContainer::offsetLines(int line, int lineOffset) {
}

void MappingContainer::offsetColumns(int line, int column, int columnOffset) {
if (_generated_lines < line) {
return;
}

auto mappingsCount = this->_mapping_lines[line]._segments.size();
for (int i = 0; i < mappingsCount; ++i) {
if (this->_mapping_lines[line]._segments[i].generated.column < column) {
Expand Down
28 changes: 28 additions & 0 deletions test/offset-utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ describe('SourceMap - Offset Utils', () => {
});
});

it('Column offset empty map', () => {
let map = new SourceMap('/');

map.offsetColumns(1, 0, 2);
map.offsetColumns(2, 15, -4);

assert.deepEqual(map.getMap(), {
sources: [],
sourcesContent: [],
names: [],
mappings: [],
});
});

it('Positive line offset', () => {
let map = new SourceMap('/test-root');

Expand Down Expand Up @@ -236,4 +250,18 @@ describe('SourceMap - Offset Utils', () => {
],
});
});

it('Line offset empty map', () => {
let map = new SourceMap('/');

map.offsetLines(1, 2);
map.offsetLines(2, 5);

assert.deepEqual(map.getMap(), {
sources: [],
sourcesContent: [],
names: [],
mappings: [],
});
});
});

0 comments on commit d54c72d

Please sign in to comment.