Skip to content

SourceMapGenerator.fromSourceMap does not work when mappings is empty #250

@dmurat

Description

@dmurat

With TypeScript compiler configured to use system modules, I'm getting source maps with empty mappings when original files are one liners (i.e. export * from './some/es6/module';). These source maps have their sources and sourcesContent collections filled in correctly. Chrome does not have any problems with such source maps, meaning they are used and displayed correctly.

With such source maps, SourceMapGenerator.fromSourceMap returns a generator without _sources collection set, which I presume is a bug.

To reproduce this behavior, I added following test in this project:

// in test/test-source-map-generator.js
exports['test .fromSourceMap with empty mappings'] = function (assert) {
  var map = SourceMapGenerator.fromSourceMap(
    new SourceMapConsumer(util.testMapEmptyMappings));
  util.assertEqualMaps(assert, map.toJSON(), util.testMapEmptyMappings);
};

// in test/utils.js
exports.testMapEmptyMappings = {
  version: 3,
  file: 'min.js',
  names: [],
  sources: ['one.js', 'two.js'],
  sourcesContent: [
    ' ONE.foo = 1;',
    ' TWO.inc = 2;'
  ],
  sourceRoot: '',
  mappings: ''
};

I can prepare PR with fix (and some more tests) if this is useful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions