You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte/src/utils/flattenReference.js

17 lines
414 B

export default function flatten ( node ) {
const parts = [];
while ( node.type === 'MemberExpression' ) {
if ( node.computed ) return null;
parts.unshift( node.property.name );
node = node.object;
}
const name = node.type === 'Identifier' ? node.name : node.type === 'ThisExpression' ? 'this' : null;
if ( !name ) return null;
parts.unshift( name );
return { name, keypath: parts.join( '.' ) };
}