Skip to content

Commit

Permalink
Merge pull request #154 from ampproject/sourcesless-transform
Browse files Browse the repository at this point in the history
Fix loading sourceless maps in array shorthand mode
  • Loading branch information
jridgewell authored Dec 1, 2021
2 parents 7d524ce + e63f4b5 commit 7577ecf
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/build-source-map-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?'
Expand Down
37 changes: 37 additions & 0 deletions test/samples/sourceless-transform/test.ts
Original file line number Diff line number Diff line change
@@ -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('');
});
});

0 comments on commit 7577ecf

Please sign in to comment.