more sourcemap stuff

pull/97/head
Rich Harris 8 years ago
parent 5e8a25fe65
commit 695cfd01c9

2
.gitignore vendored

@ -4,3 +4,5 @@ dist
.nyc_output
coverage
coverage.lcov
test/sourcemaps/*/output.js
test/sourcemaps/*/output.js.map

@ -514,13 +514,16 @@ export default function generate ( parsed, source, options ) {
addString( getIntro( format, options, imports ) );
// a filename is necessary for sourcemap generation
const filename = options.filename || 'SvelteComponent.html';
parts.forEach( str => {
const match = pattern.exec( str );
addString( str.replace( pattern, '' ) );
compiled.addSource({
filename: options.filename,
filename,
content: generator.code.snip( +match[1], +match[2] )
});
});
@ -531,6 +534,6 @@ export default function generate ( parsed, source, options ) {
return {
code: compiled.toString(),
map: compiled.generateMap()
map: compiled.generateMap({ includeContent: true })
};
}

@ -1,7 +1,16 @@
export function test ( assert, code, map, smc, locator ) {
console.log( `code`, code )
console.log( `map`, map )
export function test ({ assert, smc, locateInSource, locateInGenerated }) {
const expected = locateInSource( 'foo.bar.baz' );
const loc = locateInGenerated( 'foo.bar.baz' );
let loc = locator( 'foo.bar.baz' );
console.log( `loc`, loc )
const actual = smc.originalPositionFor({
line: loc.line + 1,
column: loc.column
});
assert.deepEqual( actual, {
source: 'SvelteComponent.html',
name: null,
line: expected.line,
column: expected.column
});
}

@ -481,12 +481,17 @@ describe( 'svelte', () => {
const input = fs.readFileSync( `test/sourcemaps/${dir}/input.html`, 'utf-8' ).replace( /\s+$/, '' );
const { code, map } = svelte.compile( input );
fs.writeFileSync( `test/sourcemaps/${dir}/output.js`, `${code}\n//# sourceMappingURL=output.js.map` );
fs.writeFileSync( `test/sourcemaps/${dir}/output.js.map`, JSON.stringify( map, null, ' ' ) );
const { test } = require( `./sourcemaps/${dir}/test.js` );
const smc = new SourceMapConsumer( map );
const locator = getLocator( code );
test( assert, code, map, smc, locator );
const locateInSource = getLocator( input );
const locateInGenerated = getLocator( code );
test({ assert, code, map, smc, locateInSource, locateInGenerated });
});
});
});

Loading…
Cancel
Save