From c2c1a6f9fff84c6f37d4e98549ba131006a64bb4 Mon Sep 17 00:00:00 2001 From: abalone0204 Date: Tue, 26 Apr 2016 14:31:44 +0800 Subject: [PATCH] Extract visitor --- super-tiny-compiler.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/super-tiny-compiler.js b/super-tiny-compiler.js index 0cd203e..7d27dad 100644 --- a/super-tiny-compiler.js +++ b/super-tiny-compiler.js @@ -778,8 +778,8 @@ function transformer(ast) { ast._context = newAst.body; // We'll start by calling the traverser function with our ast and a visitor. - traverser(ast, { + var visitor = { // The first visitor method accepts `NumberLiterals` NumberLiteral: function(node, parent) { // We'll create a new node also named `NumberLiteral` that we will push to @@ -826,7 +826,8 @@ function transformer(ast) { // `context`. parent._context.push(expression); } - }); + }; + traverser(ast, visitor); // At the end of our transformer function we'll return the new ast that we // just created.