From 5a8583c2005a8ea9fdfd12bdf36d9bd73351cf2c Mon Sep 17 00:00:00 2001 From: Merlin Beutlberger Date: Wed, 11 Oct 2023 20:02:23 +0200 Subject: [PATCH] Fix handling of sectioned source maps missing 'names' array (#29) 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. --- src/trace-mapping.ts | 2 +- test/any-map.test.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/trace-mapping.ts b/src/trace-mapping.ts index dca6062..d99a85f 100644 --- a/src/trace-mapping.ts +++ b/src/trace-mapping.ts @@ -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; diff --git a/test/any-map.test.ts b/test/any-map.test.ts index 2169115..a68a650 100644 --- a/test/any-map.test.ts +++ b/test/any-map.test.ts @@ -58,7 +58,6 @@ describe('AnyMap', () => { offset: { line: 0, column: 1 }, map: { version: 3, - names: [], sources: ['fourth.js'], sourcesContent: ['fourthsource'], mappings: 'AAAA',