Skip to content

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

@takikawa

Description

@takikawa

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions