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

Original position lookup in an indexed source map can fail due to failure to find the right section #506

Closed
takikawa opened this issue May 7, 2024 · 0 comments

Comments

@takikawa
Copy link
Contributor

takikawa commented May 7, 2024

Here's an example test case:

// add to test/test-source-map-consumer

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();
  };
// add to test/util.js 

// 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",
      },
    },
  ],
};

Currently it would fail like this:

FAILED ./test-source-map-consumer: test a mapping at the boundary of indexed source map offset!
AssertionError [ERR_ASSERTION]: Incorrect line, expected 1, got null
    at Object.assertMapping (/home/asumu/source-map/test/util.js:322:12)
    at exports.test a mapping at the boundary of indexed source map offset (/home/asumu/source-map/test/test-source-map-consumer.js:2190:10)
    at async run (/home/asumu/source-map/test/run-tests.js:21:11)

In this test, the index map has a section at offset line 0, column 0. The section has a single mapping from 0, 0 -> 0, 0. This should behave the same as a regular source map with just that one section.

However, the test actually fails because the section lookup fails. I think this is actually due to an off-by-one error in the section lookup code, which I'll submit a PR for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants