diff --git a/src/build-source-map-tree.ts b/src/build-source-map-tree.ts index f12cf52..ffd0ba0 100644 --- a/src/build-source-map-tree.ts +++ b/src/build-source-map-tree.ts @@ -31,7 +31,7 @@ export default function buildSourceMapTree( const map = maps.pop()!; for (let i = 0; i < maps.length; i++) { - if (maps[i].sources.length !== 1) { + if (maps[i].sources.length > 1) { throw new Error( `Transformation map ${i} must have exactly one source file.\n` + 'Did you specify these with the most recent transformation maps first?' diff --git a/test/samples/sourceless-transform/test.ts b/test/samples/sourceless-transform/test.ts new file mode 100644 index 0000000..9318bb7 --- /dev/null +++ b/test/samples/sourceless-transform/test.ts @@ -0,0 +1,37 @@ +import remapping from '../../../src/remapping'; + +describe('source-less transform', () => { + const original: any = { + version: '3', + sources: ['source.ts'], + names: [], + mappings: 'AAAA', + sourcesContent: ['// hello'], + }; + const minified: any = { + version: '3', + sources: [], + names: [], + mappings: '', + }; + + test('remapping with loader generates empty sourcemap', () => { + const loader = jest.fn(() => null); + loader.mockReturnValueOnce(original); + const remapped = remapping(minified, loader); + + expect(loader).not.toHaveBeenCalled(); + expect(remapped.sources).toHaveLength(0); + expect(remapped.mappings).toBe(''); + }); + + test('remapping with array shorthand generates empty sourcemap', () => { + const loader = jest.fn(() => null); + const remapped = remapping([minified, original], loader); + + expect(loader).toHaveBeenCalledTimes(1); + expect(loader).toHaveBeenCalledWith('source.ts'); + expect(remapped.sources).toHaveLength(0); + expect(remapped.mappings).toBe(''); + }); +});