Why does originalPositionFor() return null for valid location in Mozilla's source-map library

Viewed 310

I'm trying to use Mozilla's source-map library to map positions in transformed files back to their original locations. I found a situation where the source map can't find the valid location, but I don't understand why.

Here's my source file

sub main()
end sub

For the purposes of this question, I'm creating a source map that perfectly models that source file with no transformations. So, in theory any position request should return the exact same position back. However, that's now what I'm seeing in the following code snippet. In this case, {line: 2, column: 1} returns {line: null, column: null}, but {line: 2, column: 0} correctly returns {line: 2, column: 0}.

What am I doing wrong?

sourceMap.SourceMapConsumer.initialize({
  "lib/mappings.wasm": "https://unpkg.com/source-map@0.7.3/lib/mappings.wasm"
});

//create a source map
let codeAndMap = new sourceMap.SourceNode(null, null, 'main.brs', [
  new sourceMap.SourceNode(1, 0, 'main.brs', 'sub main()'), '\n',
  new sourceMap.SourceNode(2, 0, 'main.brs', 'end sub')
]).toStringWithSourceMap();

sourceMap.SourceMapConsumer.with(codeAndMap.map.toJSON(), null, (consumer) => {
  console.log('column 0', JSON.stringify(

    //returns {line: 2, column: 0}
    consumer.originalPositionFor({
      line: 2,
      column: 0,
      bias: sourceMap.SourceMapConsumer.LEAST_UPPER_BOUND
    })

  ));

  console.log('column 1', JSON.stringify(

    //returns {line: null, column: null}, but SHOULD return {line: 2, column: 1}
    consumer.originalPositionFor({
      line: 2,
      column: 1,
      bias: sourceMap.SourceMapConsumer.LEAST_UPPER_BOUND
    })

  ));

});
<script src="https://unpkg.com/source-map@0.7.3/dist/source-map.js"></script>

0 Answers
Related