Skip to content

mapping.source is not null even if the original is. #25

Closed

Description

@dragomirtitian

When trying to create a source map generator form a consumer that has mappings with just the generated position we get an error.

Code to reproduce:

import { SourceMapGenerator, SourceMapConsumer } from 'source-map-js';

const original = new SourceMapGenerator({
    file: "origina.min.js",
})
original.addMapping({
    generated: { line: 1, column: 1},
    original: null!,
    source: null!,
});

const consumer = new SourceMapConsumer(original.toJSON());

const fromConsumer = SourceMapGenerator.fromSourceMap(consumer);

Actual result

Error: original.line and original.column are not numbers -- you probably meant to omit the original mapping entirely and only map the generated position. If so, pass null for the original mapping instead of an object with empty or null values.

Expected result

We should be able to create a source map generator from a consumer that has mappings with only generated position.

Cause

When mappings are produced they get a source even if they did not originally have one. Code

      var mapping = mappings[i];
      var source = mapping.source === null ? null : sources.at(mapping.source);
      source = util.computeSourceURL(sourceRoot, source, sourceMapURL); 

util.computeSourceURL will return . if all components are null.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions