Skip to content

toStringWithSourceMap behaves incorrectly if SourceNodes source is null or is an empty string #444

Description

@Mingun

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions