diff --git a/package.json b/package.json index d5acce58..adc95abd 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/MappingContainer.cpp b/src/MappingContainer.cpp index f7cb47a6..0378606c 100644 --- a/src/MappingContainer.cpp +++ b/src/MappingContainer.cpp @@ -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) { @@ -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) { diff --git a/test/offset-utils.test.js b/test/offset-utils.test.js index 0bdb99a9..7baf6341 100644 --- a/test/offset-utils.test.js +++ b/test/offset-utils.test.js @@ -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'); @@ -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: [], + }); + }); });