diff --git a/src/autoProcess.ts b/src/autoProcess.ts index ef2e5ae4..d8d4d678 100644 --- a/src/autoProcess.ts +++ b/src/autoProcess.ts @@ -127,9 +127,23 @@ export function sveltePreprocess( } if (sourceMap && name in SOURCE_MAP_PROP_MAP) { - const [propName, value] = SOURCE_MAP_PROP_MAP[name]; + const [propPath, value] = SOURCE_MAP_PROP_MAP[name]; + const pathParts = propPath.split('.'); + let parentObj = opts; - opts[propName] = value; + for (let i = 0; i < pathParts.length - 1; i++) { + const propName = pathParts[i]; + + if (typeof parentObj[propName] !== 'object') { + parentObj[propName] = {}; + } + + parentObj = parentObj[propName]; + } + + const propName = pathParts[pathParts.length - 1]; + + parentObj[propName] = value; } return opts; diff --git a/src/modules/language.ts b/src/modules/language.ts index ae1fbe35..e53ef05f 100644 --- a/src/modules/language.ts +++ b/src/modules/language.ts @@ -38,7 +38,7 @@ export function getLanguageDefaults(lang: string): null | Record { export const SOURCE_MAP_PROP_MAP: Record = { babel: ['sourceMaps', true], - typescript: ['sourceMap', true], + typescript: ['compilerOptions.sourceMap', true], scss: ['sourceMap', true], less: ['sourceMap', {}], stylus: ['sourcemap', true], diff --git a/test/autoProcess/sourceMaps.test.ts b/test/autoProcess/sourceMaps.test.ts index e24b1ba1..3efcc243 100644 --- a/test/autoProcess/sourceMaps.test.ts +++ b/test/autoProcess/sourceMaps.test.ts @@ -84,13 +84,27 @@ describe(`sourcemap generation`, () => { [transformerName]: true, }); - const [key, val] = SOURCE_MAP_PROP_MAP[transformerName]; + const [propPath, value] = SOURCE_MAP_PROP_MAP[transformerName]; + const expectedOptions = {}; + const pathParts = propPath.split('.'); + let parentObj = expectedOptions; + + for (let i = 0; i < pathParts.length - 1; i++) { + const propName = pathParts[i]; + + parentObj[propName] = {}; + parentObj = parentObj[propName]; + } + + const propName = pathParts[pathParts.length - 1]; + + parentObj[propName] = value; await preprocess(template, opts); expect(transformer).toHaveBeenCalledWith( expect.objectContaining({ - options: expect.objectContaining({ [key]: val }), + options: expect.objectContaining(expectedOptions), }), ); });