Skip to content

Commit 7577ecf

Browse files
authored
Merge pull request #154 from ampproject/sourcesless-transform
Fix loading sourceless maps in array shorthand mode
2 parents 7d524ce + e63f4b5 commit 7577ecf

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/build-source-map-tree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default function buildSourceMapTree(
3131
const map = maps.pop()!;
3232

3333
for (let i = 0; i < maps.length; i++) {
34-
if (maps[i].sources.length !== 1) {
34+
if (maps[i].sources.length > 1) {
3535
throw new Error(
3636
`Transformation map ${i} must have exactly one source file.\n` +
3737
'Did you specify these with the most recent transformation maps first?'
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import remapping from '../../../src/remapping';
2+
3+
describe('source-less transform', () => {
4+
const original: any = {
5+
version: '3',
6+
sources: ['source.ts'],
7+
names: [],
8+
mappings: 'AAAA',
9+
sourcesContent: ['// hello'],
10+
};
11+
const minified: any = {
12+
version: '3',
13+
sources: [],
14+
names: [],
15+
mappings: '',
16+
};
17+
18+
test('remapping with loader generates empty sourcemap', () => {
19+
const loader = jest.fn(() => null);
20+
loader.mockReturnValueOnce(original);
21+
const remapped = remapping(minified, loader);
22+
23+
expect(loader).not.toHaveBeenCalled();
24+
expect(remapped.sources).toHaveLength(0);
25+
expect(remapped.mappings).toBe('');
26+
});
27+
28+
test('remapping with array shorthand generates empty sourcemap', () => {
29+
const loader = jest.fn(() => null);
30+
const remapped = remapping([minified, original], loader);
31+
32+
expect(loader).toHaveBeenCalledTimes(1);
33+
expect(loader).toHaveBeenCalledWith('source.ts');
34+
expect(remapped.sources).toHaveLength(0);
35+
expect(remapped.mappings).toBe('');
36+
});
37+
});

0 commit comments

Comments
 (0)