retain binding sourcemaps to the extent possible

pull/432/head
Rich-Harris 8 years ago
parent 92e4b7f813
commit cf626ff880

@ -1,5 +1,7 @@
export default function flatten ( node ) { export default function flatten ( node ) {
const parts = []; const parts = [];
const propEnd = node.end;
while ( node.type === 'MemberExpression' ) { while ( node.type === 'MemberExpression' ) {
if ( node.computed ) return null; if ( node.computed ) return null;
parts.unshift( node.property.name ); parts.unshift( node.property.name );
@ -7,10 +9,11 @@ export default function flatten ( node ) {
node = node.object; node = node.object;
} }
const propStart = node.end;
const name = node.type === 'Identifier' ? node.name : node.type === 'ThisExpression' ? 'this' : null; const name = node.type === 'Identifier' ? node.name : node.type === 'ThisExpression' ? 'this' : null;
if ( !name ) return null; if ( !name ) return null;
parts.unshift( name ); parts.unshift( name );
return { name, parts, keypath: parts.join( '.' ) }; return { name, parts, keypath: `${name}[✂${propStart}-${propEnd}✂]` };
} }

@ -1,10 +1,10 @@
export function test ({ assert, smc, locateInSource, locateInGenerated }) { export function test ({ assert, smc, locateInSource, locateInGenerated }) {
const expected = locateInSource( 'foo.bar.baz' ); const expected = locateInSource( 'bar.baz' );
let loc; let loc;
let actual; let actual;
loc = locateInGenerated( 'foo.bar.baz' ); loc = locateInGenerated( 'bar.baz' );
actual = smc.originalPositionFor({ actual = smc.originalPositionFor({
line: loc.line + 1, line: loc.line + 1,
@ -18,7 +18,7 @@ export function test ({ assert, smc, locateInSource, locateInGenerated }) {
column: expected.column column: expected.column
}); });
loc = locateInGenerated( 'foo.bar.baz', loc.character + 1 ); loc = locateInGenerated( 'bar.baz', loc.character + 1 );
actual = smc.originalPositionFor({ actual = smc.originalPositionFor({
line: loc.line + 1, line: loc.line + 1,

Loading…
Cancel
Save