Error creating a SourceMapGenerator from a SourceMapConsumer of an index map (part 2)
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- javascript
- Domain
- tooling
Research direction
Start in lib/source-map-consumer.js around the sourceContentFor implementation and trace how lib/source-map-generator.js calls it from fromSourceMap. Run the provided index-map reproducer and confirm that an empty sourcesContent entry is preserved rather than treated as missing, without changing the behavior for null or undefined content.
Written by the indexing model from the issue text.
Description
;(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:
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 https://github.com/mozilla/source-map/issues/345, so tagging it just in case
- Dominant language
- JavaScript
- Stars
- 3.7k
- Forks
- 370
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from mozilla/source-map
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
mozilla/source-map#530 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
mozilla/source-map#527 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
mozilla/source-map#524 · 6 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
mozilla/source-map#516 ·
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
mozilla/source-map#510 · 1 reaction ·
All issues in mozilla/source-map
Similar issues
-
Difficulty 1/5 1-3 hours Newbie friendliness 78/100
Mintplex-Labs/anything-llm#6490 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
[quality] workflow-scripts guard reads test:unit:coverage as skipping the unit suite, blocking #632 Openagent/quality hive/hosted-available-lke648397-260827-5n31 quality testing
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
area-clientside-dartpad
Difficulty 2/5 1-3 hours Newbie friendliness 62/100