Skip to content

Commit

Permalink
Fix handling of sectioned source maps missing 'names' array (#29)
Browse files Browse the repository at this point in the history
Even though the 'names' array is seen as required, normalize it to an
empty array if omitted

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 authored Oct 11, 2023
1 parent 5ccfcfe commit 5a8583c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 2 deletions.
2 changes: 1 addition & 1 deletion src/trace-mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export class TraceMap implements SourceMap {
const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
this.version = version;
this.file = file;
this.names = names;
this.names = names || [];
this.sourceRoot = sourceRoot;
this.sources = sources;
this.sourcesContent = sourcesContent;
Expand Down
1 change: 0 additions & 1 deletion test/any-map.test.ts
Original file line number Diff line number Diff line change
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 5a8583c

Please sign in to comment.