From b739bdbe192becb3fd3ea2d85d295df7e32d6cb1 Mon Sep 17 00:00:00 2001 From: Milan Hauth Date: Fri, 25 Sep 2020 09:44:34 +0200 Subject: [PATCH] optimize merge_tables, verbose remapper error --- src/compiler/preprocess/index.ts | 19 +++++++++++++++---- src/compiler/utils/string_with_sourcemap.ts | 6 ++++++ .../samples/sourcemap-sources/test.js | 8 ++++---- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/compiler/preprocess/index.ts b/src/compiler/preprocess/index.ts index b4e956aab5..4a7578452d 100644 --- a/src/compiler/preprocess/index.ts +++ b/src/compiler/preprocess/index.ts @@ -217,10 +217,21 @@ export default async function preprocess( // remapper can throw error // `Transformation map ${i} must have exactly one source file.` // for 0 <= i <= (sourcemap_list.length - 2) - const map: ReturnType = - sourcemap_list.length == 0 - ? null - : remapper(sourcemap_list as any, () => null, true); // true: skip optional field `sourcesContent` + + let map: ReturnType; + try { + map = + sourcemap_list.length == 0 + ? null + : remapper(sourcemap_list as any, () => null, true); // true: skip optional field `sourcesContent` + } catch (error) { + throw { ...error, message: error.message + + '\n\ncould not combine sourcemaps:\n' + + JSON.stringify((sourcemap_list as any).map(m => { + return { ...m, mappings: JSON.stringify(m.mappings).slice(0, 100)+' ....'}; + }), null, 2) + }; + } if (map && !map.file) delete map.file; // skip optional field `file` diff --git a/src/compiler/utils/string_with_sourcemap.ts b/src/compiler/utils/string_with_sourcemap.ts index 1b2c72f0e6..a8a978acdb 100644 --- a/src/compiler/utils/string_with_sourcemap.ts +++ b/src/compiler/utils/string_with_sourcemap.ts @@ -53,6 +53,12 @@ function merge_tables(this_table: T[], other_table): [T[], number[], boolean] has_changed = true; } } + if (has_changed) { + if (idx_map.find((val, idx) => val != idx) === undefined) { + // idx_map is identity map [0, 1, 2, 3, 4, ....] + has_changed = false; + } + } return [new_table, idx_map, has_changed]; } diff --git a/test/sourcemaps/samples/sourcemap-sources/test.js b/test/sourcemaps/samples/sourcemap-sources/test.js index 0887afddd0..e35618e18a 100644 --- a/test/sourcemaps/samples/sourcemap-sources/test.js +++ b/test/sourcemaps/samples/sourcemap-sources/test.js @@ -1,12 +1,12 @@ export function test({ assert, preprocessed, js, css }) { - const msg_expected = 'Transformation map 0 must have exactly one source file.'; + assert.notEqual(preprocessed.error, undefined, 'expected preprocessed.error'); - assert.notEqual(preprocessed.error, undefined, 'expected preprocessed.error'); + const msg_expected_prefix = 'Transformation map 0 must have exactly one source file.'; assert.equal( - preprocessed.error.message.slice(0, msg_expected.length), - msg_expected + preprocessed.error.message.slice(0, msg_expected_prefix.length), + msg_expected_prefix ); }