From 0c3e2763cdc35b5fa8ae9889d5a0c83f6c633b70 Mon Sep 17 00:00:00 2001 From: dominikg Date: Mon, 17 Nov 2025 15:20:54 +0100 Subject: [PATCH 1/2] add check for negative idx to sourcemaps test --- packages/svelte/tests/sourcemaps/test.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/svelte/tests/sourcemaps/test.ts b/packages/svelte/tests/sourcemaps/test.ts index c654258b34fd..e534146a3a3a 100644 --- a/packages/svelte/tests/sourcemaps/test.ts +++ b/packages/svelte/tests/sourcemaps/test.ts @@ -96,6 +96,18 @@ const { test, run } = suite(async (config, cwd) => { const decoded = decode(map.mappings); + /* + Decoded sourcemap mappings contain absolute line/column numbers. + Negative values are invalid and can cause errors in downstream processing + */ + for(let l = 0; l < decoded.length; l++) { + for(let m of decoded[l]) { + if(m.find(i => i < 0)) { + throw new Error(`Invalid mapping with negative value ${JSON.stringify(m)} at line ${l} of the decoded mappings of ${info} sourcemap\n${JSON.stringify(map)}`) + } + } + } + try { for (let entry of entries) { entry = typeof entry === 'string' ? { str: entry } : entry; From cc9219ad39d02df8c9b00bce98395b1e9eef9acb Mon Sep 17 00:00:00 2001 From: dominikg Date: Mon, 17 Nov 2025 15:36:45 +0100 Subject: [PATCH 2/2] fix: format --- packages/svelte/tests/sourcemaps/test.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/svelte/tests/sourcemaps/test.ts b/packages/svelte/tests/sourcemaps/test.ts index e534146a3a3a..ed5375ed5593 100644 --- a/packages/svelte/tests/sourcemaps/test.ts +++ b/packages/svelte/tests/sourcemaps/test.ts @@ -100,10 +100,12 @@ const { test, run } = suite(async (config, cwd) => { Decoded sourcemap mappings contain absolute line/column numbers. Negative values are invalid and can cause errors in downstream processing */ - for(let l = 0; l < decoded.length; l++) { - for(let m of decoded[l]) { - if(m.find(i => i < 0)) { - throw new Error(`Invalid mapping with negative value ${JSON.stringify(m)} at line ${l} of the decoded mappings of ${info} sourcemap\n${JSON.stringify(map)}`) + for (let l = 0; l < decoded.length; l++) { + for (let m of decoded[l]) { + if (m.find((i) => i < 0)) { + throw new Error( + `Invalid mapping with negative value ${JSON.stringify(m)} at line ${l} of the decoded mappings of ${info} sourcemap\n${JSON.stringify(map)}` + ); } } }