public static Node getDeclaringParent ( Node targetNode ) { Node rootTarget = getRootTarget ( targetNode ) ; Node parent = rootTarget . getParent ( ) ; if ( parent . isRest ( ) || parent . isDefaultValue ( ) ) { // e.g. `function foo(targetNode1 = default, ...targetNode2) {}` parent = parent . getParent ( ) ; checkState ( parent . isParamList ( ) , parent ) ; } else if ( parent . isDestructuringLhs ( ) ) { // e.g. `let [a, b] = something;` targetNode is `[a, b]` parent = parent . getParent ( ) ; checkState ( isNameDeclaration ( parent ) , parent ) ; } else if ( parent . isClass ( ) || parent . isFunction ( ) ) { // e.g. `function targetNode() {}` // e.g. `class targetNode {}` checkState ( targetNode == parent . getFirstChild ( ) , targetNode ) ; } else if ( parent . isImportSpec ( ) ) { // e.g. `import {foo as targetNode} from './foo'; checkState ( targetNode == parent . getSecondChild ( ) , targetNode ) ; // import -> import_specs -> import_spec // we want import parent = parent . getGrandparent ( ) ; checkState ( parent . isImport ( ) , parent ) ; } else { // e.g. `function foo(targetNode) {};` // e.g. `let targetNode = something;` // e.g. `import targetNode from './foo'; // e.g. `} catch (foo) {` checkState ( parent . isParamList ( ) || isNameDeclaration ( parent ) || parent . isImport ( ) || parent . isCatch ( ) , parent ) ; } return parent ; }
Returns the node that is effectively declaring the given target .