Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

`toStringWithSourceMap` behaves incorrectly if `SourceNode`s source is `null` or is an empty string

Open
#444 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript
Domain
devtools

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.

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
Dominant language
JavaScript
Stars
3.7k
Forks
370
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from mozilla/source-map

All issues in mozilla/source-map

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.