diff --git a/src/utils/flattenReference.js b/src/utils/flattenReference.js index da92d5588f..c4b46e914f 100644 --- a/src/utils/flattenReference.js +++ b/src/utils/flattenReference.js @@ -1,5 +1,7 @@ export default function flatten ( node ) { const parts = []; + const propEnd = node.end; + while ( node.type === 'MemberExpression' ) { if ( node.computed ) return null; parts.unshift( node.property.name ); @@ -7,10 +9,11 @@ export default function flatten ( node ) { node = node.object; } + const propStart = node.end; const name = node.type === 'Identifier' ? node.name : node.type === 'ThisExpression' ? 'this' : null; if ( !name ) return null; parts.unshift( name ); - return { name, parts, keypath: parts.join( '.' ) }; + return { name, parts, keypath: `${name}[✂${propStart}-${propEnd}✂]` }; } diff --git a/test/sourcemaps/samples/binding/test.js b/test/sourcemaps/samples/binding/test.js index a8803c0063..8737930371 100644 --- a/test/sourcemaps/samples/binding/test.js +++ b/test/sourcemaps/samples/binding/test.js @@ -1,10 +1,10 @@ export function test ({ assert, smc, locateInSource, locateInGenerated }) { - const expected = locateInSource( 'foo.bar.baz' ); + const expected = locateInSource( 'bar.baz' ); let loc; let actual; - loc = locateInGenerated( 'foo.bar.baz' ); + loc = locateInGenerated( 'bar.baz' ); actual = smc.originalPositionFor({ line: loc.line + 1, @@ -18,7 +18,7 @@ export function test ({ assert, smc, locateInSource, locateInGenerated }) { column: expected.column }); - loc = locateInGenerated( 'foo.bar.baz', loc.character + 1 ); + loc = locateInGenerated( 'bar.baz', loc.character + 1 ); actual = smc.originalPositionFor({ line: loc.line + 1,