`toStringWithSourceMap` behaves incorrectly if `SourceNode`s source is `null` or is an empty string
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 3.7k
- Forks
- 370
- PR merge metrics
- No merged PRs in 30d
Description
When source set to null, mapping does not generated.
When source set to empty string there is an error during mapping calculation (not during SourceNode creation as expected if empty string is forbidden).
This code snippet demonstrates both problems: https://runkit.com/embed/47lduu6k2173
Source code of the snippet:
let SourceNode = require('source-map').SourceNode;
function test(source) {
let node = new SourceNode(
null,
null,
source,
[
'prefix',
new SourceNode(1, 0, source, 'code'),
'suffix',
]
);
let { code, map } = node.toStringWithSourceMap();
console.log(map.toJSON(), code);
}
// {version: 3, sources: ["source"], names: [], mappings: "MAAA,I"}
test("source");// OK
// {version: 3, sources: [], names: [], mappings: ""}
test(null); // Empty mapping
// Error: Invalid mapping: {"generated":{"line":1,"column":6},"source":"","original":{"line":1,"column":0},"name":null}
test(""); // Error
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.
Research direction
The entry point is SourceNode.toStringWithSourceMap; first reproduce the null and empty-string cases from the issue snippet and trace how each source reaches mapping generation. Done means both inputs have intentional, consistent behavior without silently losing mappings or failing later with an invalid-mapping error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100