Extract visitor

This commit is contained in:
abalone0204 2016-04-26 14:31:44 +08:00
parent 762ed6b5e1
commit c2c1a6f9ff

View File

@ -778,8 +778,8 @@ function transformer(ast) {
ast._context = newAst.body; ast._context = newAst.body;
// We'll start by calling the traverser function with our ast and a visitor. // We'll start by calling the traverser function with our ast and a visitor.
traverser(ast, {
var visitor = {
// The first visitor method accepts `NumberLiterals` // The first visitor method accepts `NumberLiterals`
NumberLiteral: function(node, parent) { NumberLiteral: function(node, parent) {
// We'll create a new node also named `NumberLiteral` that we will push to // We'll create a new node also named `NumberLiteral` that we will push to
@ -826,7 +826,8 @@ function transformer(ast) {
// `context`. // `context`.
parent._context.push(expression); parent._context.push(expression);
} }
}); };
traverser(ast, visitor);
// At the end of our transformer function we'll return the new ast that we // At the end of our transformer function we'll return the new ast that we
// just created. // just created.