Skip to content

Commit

Permalink
Fix handling of sectioned source maps missing 'names' array
Browse files Browse the repository at this point in the history
AFAIK just like for regular source maps, the 'names' array can be
omitted for maps in sectioned/index source maps.

Currently, trace-mapping will throw with an exception
"Cannot read properties of undefined (reading 'length')"
in case no 'names' array is provided.
  • Loading branch information
RandomByte committed Oct 10, 2023
1 parent 5ccfcfe commit f60214e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/any-map.ts
Expand Up @@ -111,7 +111,9 @@ function addSection(
const { resolvedSources, sourcesContent: contents } = map;

append(sources, resolvedSources);
append(names, map.names);
if (map.names) {
append(names, map.names);
}
if (contents) append(sourcesContent, contents);
else for (let i = 0; i < resolvedSources.length; i++) sourcesContent.push(null);

Expand Down
1 change: 0 additions & 1 deletion test/any-map.test.ts
Expand Up @@ -58,7 +58,6 @@ describe('AnyMap', () => {
offset: { line: 0, column: 1 },
map: {
version: 3,
names: [],
sources: ['fourth.js'],
sourcesContent: ['fourthsource'],
mappings: 'AAAA',
Expand Down

0 comments on commit f60214e

Please sign in to comment.