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

Error creating a SourceMapGenerator from a SourceMapConsumer of an index map (part 2) #420

Open
rlidwka opened this issue Sep 3, 2020 · 0 comments
Labels
needs-triage Unconfirmed issues

Comments

@rlidwka
Copy link

rlidwka commented Sep 3, 2020

;(async () => {
  let mozilla = require('source-map')
  let map;

  map = {
    version: 3,
    sections: [
      {
        offset: { line: 0, column: 0 },
        map: {
          version: 3,
          sources: ['123', '456'],
          sourcesContent: ['a\nb\nc\n', ''],
          mappings: 'AAAA;AACA;AACA;'
        }
      }
    ]
  }

  // this map works for some reason
  /*map = {
    version: 3,
    sources: ['123', '456'],
    sourcesContent: ['a\nb\nc\n', ''],
    mappings: 'AAAA;AACA;AACA;'
  }*/

  let consumer = await new mozilla.SourceMapConsumer(map)
  consumer.sourceRoot = null; // https://github.com/mozilla/source-map/issues/345
  let generator = mozilla.SourceMapGenerator.fromSourceMap(consumer)
  console.log(generator.toJSON())

})().catch(console.log)

This errors out:

Error: "456" is not in the SourceMap.
    at IndexedSourceMapConsumer.sourceContentFor (/tmp/node_modules/source-map/lib/source-map-consumer.js:840:11)
    at /tmp/node_modules/source-map/lib/source-map-generator.js:82:42
    at Array.forEach (<anonymous>)
    at Function.fromSourceMap (/tmp/node_modules/source-map/lib/source-map-generator.js:72:32)
    at /tmp/123/test.js:29:46

The issue is in here somewhere:

if (content) {

Content is empty - '' - but it is still in the sourcemap. I believe it should be if (content == null) { check, i.e. null or undefined, letting empty string pass along.

this may be related to #345, so tagging it just in case

@jkrems jkrems added the needs-triage Unconfirmed issues label Apr 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage Unconfirmed issues
Projects
None yet
Development

No branches or pull requests

2 participants