From d061210551d4646448810388b8aecbcbe03a8422 Mon Sep 17 00:00:00 2001 From: Benedikt Meurer Date: Fri, 17 Feb 2023 20:43:05 +0100 Subject: [PATCH] fix: `null` is invalid for `sources` and `file` This fixes `generateDecodedMap()` to avoid putting `null` into the `sources` array (which is supposed to contain only strings), and also don't assign `null` to the `file` field (which can be either a string or absent - indicated by `undefined`). --- src/Bundle.js | 2 +- src/MagicString.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Bundle.js b/src/Bundle.js index e682fb5..04d6f20 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -144,7 +144,7 @@ export default class Bundle { }); return { - file: options.file ? options.file.split(/[/\\]/).pop() : null, + file: options.file ? options.file.split(/[/\\]/).pop() : undefined, sources: this.uniqueSources.map((source) => { return options.file ? getRelativePath(options.file, source.filename) : source.filename; }), diff --git a/src/MagicString.js b/src/MagicString.js index ea85160..f8bfad0 100644 --- a/src/MagicString.js +++ b/src/MagicString.js @@ -163,9 +163,9 @@ export default class MagicString { }); return { - file: options.file ? options.file.split(/[/\\]/).pop() : null, - sources: [options.source ? getRelativePath(options.file || '', options.source) : null], - sourcesContent: options.includeContent ? [this.original] : [null], + file: options.file ? options.file.split(/[/\\]/).pop() : undefined, + sources: [options.source ? getRelativePath(options.file || '', options.source) : (options.file || '')], + sourcesContent: options.includeContent ? [this.original] : undefined, names, mappings: mappings.raw, };