diff --git a/src/compiler/preprocess/index.ts b/src/compiler/preprocess/index.ts index 27c1c471c1..3e2bf99c7c 100644 --- a/src/compiler/preprocess/index.ts +++ b/src/compiler/preprocess/index.ts @@ -104,8 +104,9 @@ function get_replacement( let decoded_map: DecodedSourceMap; if (processed.map) { decoded_map = typeof processed.map === 'string' ? JSON.parse(processed.map) : processed.map; - if (typeof(decoded_map.mappings) === 'string') + if (typeof(decoded_map.mappings) === 'string') { decoded_map.mappings = decode_mappings(decoded_map.mappings); + } sourcemap_add_offset(decoded_map, get_location(offset + prefix.length)); } const processed_with_map = StringWithSourcemap.from_processed(processed.code, decoded_map); @@ -146,12 +147,13 @@ export default async function preprocess( if (processed && processed.dependencies) dependencies.push(...processed.dependencies); source = processed ? processed.code : source; - if (processed && processed.map) + if (processed && processed.map) { sourcemap_list.unshift( typeof(processed.map) === 'string' ? JSON.parse(processed.map) : processed.map ); + } } for (const fn of script) { diff --git a/src/compiler/utils/string_with_sourcemap.ts b/src/compiler/utils/string_with_sourcemap.ts index 845d46ec7d..ebd44221e1 100644 --- a/src/compiler/utils/string_with_sourcemap.ts +++ b/src/compiler/utils/string_with_sourcemap.ts @@ -59,8 +59,9 @@ function merge_tables(this_table: T[], other_table): [T[], number[], boolean, } function pushArray(_this: T[], other: T[]) { - for (let i = 0; i < other.length; i++) + for (let i = 0; i < other.length; i++) { _this.push(other[i]); + } } export class StringWithSourcemap { @@ -69,15 +70,16 @@ export class StringWithSourcemap { constructor(string = '', map = null) { this.string = string; - if (map) + if (map) { this.map = map as DecodedSourceMap; - else + } else { this.map = { version: 3, mappings: [], sources: [], names: [] }; + } } // concat in-place (mutable), return this (chainable)