UNPKG

702 BJavaScriptView Raw
1export default function isReference ( node, parent ) {
2 if ( node.type === 'MemberExpression' ) {
3 return !node.computed && isReference( node.object, node );
4 }
5
6 if ( node.type === 'Identifier' ) {
7 // TODO is this right?
8 if ( parent.type === 'MemberExpression' ) return parent.computed || node === parent.object;
9
10 // disregard the `bar` in { bar: foo }
11 if ( parent.type === 'Property' && node !== parent.value ) return false;
12
13 // disregard the `bar` in `class Foo { bar () {...} }`
14 if ( parent.type === 'MethodDefinition' ) return false;
15
16 // disregard the `bar` in `export { foo as bar }`
17 if ( parent.type === 'ExportSpecifier' && node !== parent.local ) return;
18
19 return true;
20 }
21}