Skip to content

Commit cf626ff

Browse files
committed
retain binding sourcemaps to the extent possible
1 parent 92e4b7f commit cf626ff

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/utils/flattenReference.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
export default function flatten ( node ) {
22
const parts = [];
3+
const propEnd = node.end;
4+
35
while ( node.type === 'MemberExpression' ) {
46
if ( node.computed ) return null;
57
parts.unshift( node.property.name );
68

79
node = node.object;
810
}
911

12+
const propStart = node.end;
1013
const name = node.type === 'Identifier' ? node.name : node.type === 'ThisExpression' ? 'this' : null;
1114

1215
if ( !name ) return null;
1316

1417
parts.unshift( name );
15-
return { name, parts, keypath: parts.join( '.' ) };
18+
return { name, parts, keypath: `${name}[✂${propStart}-${propEnd}✂]` };
1619
}

test/sourcemaps/samples/binding/test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
export function test ({ assert, smc, locateInSource, locateInGenerated }) {
2-
const expected = locateInSource( 'foo.bar.baz' );
2+
const expected = locateInSource( 'bar.baz' );
33

44
let loc;
55
let actual;
66

7-
loc = locateInGenerated( 'foo.bar.baz' );
7+
loc = locateInGenerated( 'bar.baz' );
88

99
actual = smc.originalPositionFor({
1010
line: loc.line + 1,
@@ -18,7 +18,7 @@ export function test ({ assert, smc, locateInSource, locateInGenerated }) {
1818
column: expected.column
1919
});
2020

21-
loc = locateInGenerated( 'foo.bar.baz', loc.character + 1 );
21+
loc = locateInGenerated( 'bar.baz', loc.character + 1 );
2222

2323
actual = smc.originalPositionFor({
2424
line: loc.line + 1,

0 commit comments

Comments
 (0)