private static Node getAddingRoot ( Node n ) { Node addingRoot = null ; Node ancestor = n ; crawl_ancestors : while ( null != ( ancestor = ancestor . getParent ( ) ) ) { switch ( ancestor . getToken ( ) ) { case SCRIPT : case MODULE_BODY : addingRoot = ancestor ; break crawl_ancestors ; case FUNCTION : addingRoot = ancestor . getLastChild ( ) ; break crawl_ancestors ; default : continue crawl_ancestors ; } } // make sure that the adding root looks ok checkState ( addingRoot . isBlock ( ) || addingRoot . isModuleBody ( ) || addingRoot . isScript ( ) ) ; checkState ( ! addingRoot . hasChildren ( ) || ! addingRoot . getFirstChild ( ) . isScript ( ) ) ; return addingRoot ; }
Gets a Node at the top of the current scope where we can add new var declarations as children .