Skip to content

Commit b739bdb

Browse files
committed
optimize merge_tables, verbose remapper error
1 parent 47ffc05 commit b739bdb

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

src/compiler/preprocess/index.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,21 @@ export default async function preprocess(
217217
// remapper can throw error
218218
// `Transformation map ${i} must have exactly one source file.`
219219
// for 0 <= i <= (sourcemap_list.length - 2)
220-
const map: ReturnType<typeof remapper> =
221-
sourcemap_list.length == 0
222-
? null
223-
: remapper(sourcemap_list as any, () => null, true); // true: skip optional field `sourcesContent`
220+
221+
let map: ReturnType<typeof remapper>;
222+
try {
223+
map =
224+
sourcemap_list.length == 0
225+
? null
226+
: remapper(sourcemap_list as any, () => null, true); // true: skip optional field `sourcesContent`
227+
} catch (error) {
228+
throw { ...error, message: error.message +
229+
'\n\ncould not combine sourcemaps:\n' +
230+
JSON.stringify((sourcemap_list as any).map(m => {
231+
return { ...m, mappings: JSON.stringify(m.mappings).slice(0, 100)+' ....'};
232+
}), null, 2)
233+
};
234+
}
224235

225236
if (map && !map.file) delete map.file; // skip optional field `file`
226237

src/compiler/utils/string_with_sourcemap.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ function merge_tables<T>(this_table: T[], other_table): [T[], number[], boolean]
5353
has_changed = true;
5454
}
5555
}
56+
if (has_changed) {
57+
if (idx_map.find((val, idx) => val != idx) === undefined) {
58+
// idx_map is identity map [0, 1, 2, 3, 4, ....]
59+
has_changed = false;
60+
}
61+
}
5662
return [new_table, idx_map, has_changed];
5763
}
5864

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
export function test({ assert, preprocessed, js, css }) {
22

3-
const msg_expected = 'Transformation map 0 must have exactly one source file.';
3+
assert.notEqual(preprocessed.error, undefined, 'expected preprocessed.error');
44

5-
assert.notEqual(preprocessed.error, undefined, 'expected preprocessed.error');
5+
const msg_expected_prefix = 'Transformation map 0 must have exactly one source file.';
66

77
assert.equal(
8-
preprocessed.error.message.slice(0, msg_expected.length),
9-
msg_expected
8+
preprocessed.error.message.slice(0, msg_expected_prefix.length),
9+
msg_expected_prefix
1010
);
1111

1212
}

0 commit comments

Comments
 (0)