Estraverse (\href{http://github.com/estools/estraverse}{\texttt{ estraverse}}) is \href{http://www.ecma-international.org/publications/standards/Ecma-262.htm}{\texttt{ ECMAScript}} traversal functions from \href{http://github.com/estools/esmangle}{\texttt{ esmangle project}}.\hypertarget{md_sfcode_node_modules_estraverse_README_autotoc_md9231}{}\doxysubsection{Documentation}\label{md_sfcode_node_modules_estraverse_README_autotoc_md9231}
You can find usage docs at \href{https://github.com/estools/estraverse/wiki/Usage}{\texttt{ wiki page}}.\hypertarget{md_sfcode_node_modules_estraverse_README_autotoc_md9232}{}\doxysubsection{Example Usage}\label{md_sfcode_node_modules_estraverse_README_autotoc_md9232}
The following code will output all variables declared at the root of a file.


\begin{DoxyCode}{0}
\DoxyCodeLine{estraverse.traverse(ast, \{}
\DoxyCodeLine{    enter: function (node, parent) \{}
\DoxyCodeLine{        if (node.type == 'FunctionExpression' || node.type == 'FunctionDeclaration')}
\DoxyCodeLine{            return estraverse.VisitorOption.Skip;}
\DoxyCodeLine{    \},}
\DoxyCodeLine{    leave: function (node, parent) \{}
\DoxyCodeLine{        if (node.type == 'VariableDeclarator')}
\DoxyCodeLine{          console.log(node.id.name);}
\DoxyCodeLine{    \}}
\DoxyCodeLine{\}); }

\end{DoxyCode}


We can use {\ttfamily this.\+skip}, {\ttfamily this.\+remove} and {\ttfamily this.\+break} functions instead of using Skip, Remove and Break.


\begin{DoxyCode}{0}
\DoxyCodeLine{estraverse.traverse(ast, \{}
\DoxyCodeLine{    enter: function (node) \{}
\DoxyCodeLine{        this.break();}
\DoxyCodeLine{    \}}
\DoxyCodeLine{\}); }

\end{DoxyCode}


And estraverse provides {\ttfamily estraverse.\+replace} function. When returning node from {\ttfamily enter}/{\ttfamily leave}, current node is replaced with it.


\begin{DoxyCode}{0}
\DoxyCodeLine{result = estraverse.replace(tree, \{}
\DoxyCodeLine{    enter: function (node) \{}
\DoxyCodeLine{        // Replace it with replaced.}
\DoxyCodeLine{        if (node.type === 'Literal')}
\DoxyCodeLine{            return replaced;}
\DoxyCodeLine{    \}}
\DoxyCodeLine{\}); }

\end{DoxyCode}


By passing {\ttfamily visitor.\+keys} mapping, we can extend estraverse traversing functionality.


\begin{DoxyCode}{0}
\DoxyCodeLine{// This tree contains a user-\/defined `TestExpression` node.}
\DoxyCodeLine{var tree = \{}
\DoxyCodeLine{    type: 'TestExpression',}
\DoxyCodeLine{}
\DoxyCodeLine{    // This 'argument' is the property containing the other **node**.}
\DoxyCodeLine{    argument: \{}
\DoxyCodeLine{        type: 'Literal',}
\DoxyCodeLine{        value: 20}
\DoxyCodeLine{    \},}
\DoxyCodeLine{}
\DoxyCodeLine{    // This 'extended' is the property not containing the other **node**.}
\DoxyCodeLine{    extended: true}
\DoxyCodeLine{\};}
\DoxyCodeLine{estraverse.traverse(tree, \{}
\DoxyCodeLine{    enter: function (node) \{ \},}
\DoxyCodeLine{}
\DoxyCodeLine{    // Extending the existing traversing rules.}
\DoxyCodeLine{    keys: \{}
\DoxyCodeLine{        // TargetNodeName: [ 'keys', 'containing', 'the', 'other', '**node**' ]}
\DoxyCodeLine{        TestExpression: ['argument']}
\DoxyCodeLine{    \}}
\DoxyCodeLine{\}); }

\end{DoxyCode}


By passing {\ttfamily visitor.\+fallback} option, we can control the behavior when encountering unknown nodes.


\begin{DoxyCode}{0}
\DoxyCodeLine{// This tree contains a user-\/defined `TestExpression` node.}
\DoxyCodeLine{var tree = \{}
\DoxyCodeLine{    type: 'TestExpression',}
\DoxyCodeLine{}
\DoxyCodeLine{    // This 'argument' is the property containing the other **node**.}
\DoxyCodeLine{    argument: \{}
\DoxyCodeLine{        type: 'Literal',}
\DoxyCodeLine{        value: 20}
\DoxyCodeLine{    \},}
\DoxyCodeLine{}
\DoxyCodeLine{    // This 'extended' is the property not containing the other **node**.}
\DoxyCodeLine{    extended: true}
\DoxyCodeLine{\};}
\DoxyCodeLine{estraverse.traverse(tree, \{}
\DoxyCodeLine{    enter: function (node) \{ \},}
\DoxyCodeLine{}
\DoxyCodeLine{    // Iterating the child **nodes** of unknown nodes.}
\DoxyCodeLine{    fallback: 'iteration'}
\DoxyCodeLine{\}); }

\end{DoxyCode}


When {\ttfamily visitor.\+fallback} is a function, we can determine which keys to visit on each node.


\begin{DoxyCode}{0}
\DoxyCodeLine{// This tree contains a user-\/defined `TestExpression` node.}
\DoxyCodeLine{var tree = \{}
\DoxyCodeLine{    type: 'TestExpression',}
\DoxyCodeLine{}
\DoxyCodeLine{    // This 'argument' is the property containing the other **node**.}
\DoxyCodeLine{    argument: \{}
\DoxyCodeLine{        type: 'Literal',}
\DoxyCodeLine{        value: 20}
\DoxyCodeLine{    \},}
\DoxyCodeLine{}
\DoxyCodeLine{    // This 'extended' is the property not containing the other **node**.}
\DoxyCodeLine{    extended: true}
\DoxyCodeLine{\};}
\DoxyCodeLine{estraverse.traverse(tree, \{}
\DoxyCodeLine{    enter: function (node) \{ \},}
\DoxyCodeLine{}
\DoxyCodeLine{    // Skip the `argument` property of each node}
\DoxyCodeLine{    fallback: function(node) \{}
\DoxyCodeLine{        return Object.keys(node).filter(function(key) \{}
\DoxyCodeLine{            return key !== 'argument';}
\DoxyCodeLine{        \});}
\DoxyCodeLine{    \}}
\DoxyCodeLine{\}); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_estraverse_README_autotoc_md9233}{}\doxysubsection{License}\label{md_sfcode_node_modules_estraverse_README_autotoc_md9233}
Copyright (C) 2012-\/2016 \href{http://github.com/Constellation}{\texttt{ Yusuke Suzuki}} (twitter\+: \href{http://twitter.com/Constellation}{\texttt{ @\+Constellation}}) and other contributors.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met\+:


\begin{DoxyItemize}
\item Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
\item Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
\end{DoxyItemize}

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \char`\"{}\+AS IS\char`\"{} AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL $<$\+COPYRIGHT HOLDER$>$ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 