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.
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:
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. Codeutil.computeSourceURL
will return.
if all components are null.