Consume sourcemaps

pull/1863/head
Timothy Johnson 7 years ago
parent 00a14486f6
commit f2cbf11cc2

@ -107,6 +107,7 @@ function compileFile(input, output, options) {
let compiled; let compiled;
try { try {
delete options.sourceMap; // compiler doesn't use this option
compiled = svelte.compile(source, options); compiled = svelte.compile(source, options);
} catch (err) { } catch (err) {
error(err); error(err);

@ -1,3 +1,4 @@
import { SourceMapGenerator, SourceMapConsumer } from 'source-map';
import { assign } from '../shared'; import { assign } from '../shared';
import Stats from '../Stats'; import Stats from '../Stats';
import parse from '../parse/index'; import parse from '../parse/index';
@ -89,7 +90,21 @@ export default function compile(source: string, options: CompileOptions = {}) {
return renderSSR(component, options); return renderSSR(component, options);
} }
return renderDOM(component, options); const result = renderDOM(component, options);
if (options.sourceMap) {
const inputConsumer = new SourceMapConsumer(options.sourceMap);
const jsSourceMap = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(result.js.map));
jsSourceMap.applySourceMap(inputConsumer);
result.js.map = jsSourceMap.toJSON();
const cssSourceMap = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(result.css.map));
cssSourceMap.applySourceMap(inputConsumer);
result.css.map = cssSourceMap.toJSON();
}
return result;
} catch (err) { } catch (err) {
onerror(err); onerror(err);
} }

@ -57,6 +57,7 @@ export interface CompileOptions {
legacy?: boolean; legacy?: boolean;
customElement?: CustomElementOptions | true; customElement?: CustomElementOptions | true;
css?: boolean; css?: boolean;
sourceMap?: string | object;
preserveComments?: boolean | false; preserveComments?: boolean | false;

Loading…
Cancel
Save