Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an off-by-1 error in section lookup #507

Merged
merged 1 commit into from
May 30, 2024
Merged
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: 4 additions & 1 deletion lib/source-map-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,11 @@ class IndexedSourceMapConsumer extends SourceMapConsumer {
return cmp;
}

// The generated column is 0-based, but the section offset column is
// stored 1-based.
return (
aNeedle.generatedColumn - section.generatedOffset.generatedColumn
aNeedle.generatedColumn -
(section.generatedOffset.generatedColumn - 1)
);
}
);
Expand Down
9 changes: 9 additions & 0 deletions test/test-source-map-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2183,3 +2183,12 @@ exports["test SourceMapConsumer.with and exceptions"] = async function (
assert.equal(error, 6);
assert.equal(consumer._mappingsPtr, 0);
};

exports["test a mapping at the boundary of indexed source map offset"] =
async function (assert) {
const map = await new SourceMapConsumer(
util.indexedTestMapAtOffsetBoundary
);
util.assertMapping(1, 0, "/the/root/one.js", 1, 0, null, null, map, assert);
map.destroy();
};
25 changes: 25 additions & 0 deletions test/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,31 @@ exports.indexedTestMapColumnOffset = {
},
],
};
// This mapping is for testing a case where the mapped position is at the
// section offset.
exports.indexedTestMapAtOffsetBoundary = {
version: 3,
file: "min.js",
sections: [
{
offset: {
line: 0,
column: 0,
},
map: {
version: 3,
sources: ["one.js"],
sourcesContent: [
"ONE.foo = function (bar) {\n return baz(bar);\n };",
],
names: ["bar", "baz"],
mappings: "AAAA",
file: "min.js",
sourceRoot: "/the/root",
},
},
],
};
exports.testMapWithSourcesContent = {
version: 3,
file: "min.js",
Expand Down
Loading