|
|
@ -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}✂]` };
|
|
|
|
}
|
|
|
|
}
|
|
|
|