add outputFilename option for sourcemap generation

pull/295/head
Rich Harris 8 years ago
parent f3afc4ad88
commit c1ba7638ce

@ -168,7 +168,7 @@ export default class Generator {
return { return {
code: compiled.toString(), code: compiled.toString(),
map: compiled.generateMap({ includeContent: true }) map: compiled.generateMap({ includeContent: true, file: options.outputFilename })
}; };
} }

@ -1,4 +1,5 @@
import * as fs from 'fs'; import * as fs from 'fs';
import * as path from 'path';
import assert from 'assert'; import assert from 'assert';
import { svelte, exists } from './helpers.js'; import { svelte, exists } from './helpers.js';
import { SourceMapConsumer } from 'source-map'; import { SourceMapConsumer } from 'source-map';
@ -15,11 +16,19 @@ describe( 'sourcemaps', () => {
} }
( solo ? it.only : it )( dir, () => { ( solo ? it.only : it )( dir, () => {
const input = fs.readFileSync( `test/sourcemaps/${dir}/input.html`, 'utf-8' ).replace( /\s+$/, '' ); const filename = path.resolve( `test/sourcemaps/${dir}/input.html` );
const { code, map } = svelte.compile( input ); const outputFilename = path.resolve( `test/sourcemaps/${dir}/output.js` );
fs.writeFileSync( `test/sourcemaps/${dir}/output.js`, `${code}\n//# sourceMappingURL=output.js.map` ); const input = fs.readFileSync( filename, 'utf-8' ).replace( /\s+$/, '' );
fs.writeFileSync( `test/sourcemaps/${dir}/output.js.map`, JSON.stringify( map, null, ' ' ) ); const { code, map } = svelte.compile( input, {
filename,
outputFilename
});
fs.writeFileSync( outputFilename, `${code}\n//# sourceMappingURL=output.js.map` );
fs.writeFileSync( `${outputFilename}.map`, JSON.stringify( map, null, ' ' ) );
assert.deepEqual( map.sources, [ 'input.html' ]);
const { test } = require( `./sourcemaps/${dir}/test.js` ); const { test } = require( `./sourcemaps/${dir}/test.js` );

@ -12,7 +12,7 @@ export function test ({ assert, smc, locateInSource, locateInGenerated }) {
}); });
assert.deepEqual( actual, { assert.deepEqual( actual, {
source: 'SvelteComponent.html', source: 'input.html',
name: null, name: null,
line: expected.line + 1, line: expected.line + 1,
column: expected.column column: expected.column
@ -26,7 +26,7 @@ export function test ({ assert, smc, locateInSource, locateInGenerated }) {
}); });
assert.deepEqual( actual, { assert.deepEqual( actual, {
source: 'SvelteComponent.html', source: 'input.html',
name: null, name: null,
line: expected.line + 1, line: expected.line + 1,
column: expected.column column: expected.column

@ -8,7 +8,7 @@ export function test ({ assert, smc, locateInSource, locateInGenerated }) {
}); });
assert.deepEqual( actual, { assert.deepEqual( actual, {
source: 'SvelteComponent.html', source: 'input.html',
name: null, name: null,
line: expected.line + 1, line: expected.line + 1,
column: expected.column column: expected.column

Loading…
Cancel
Save