Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dragomirtitian opened this issue Aug 28, 2024 · 0 comments · Fixed by #26
Closed

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

dragomirtitian opened this issue Aug 28, 2024 · 0 comments · Fixed by #26

Comments

@dragomirtitian
Copy link

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.

This was referenced Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant