mirror of
https://github.com/jamiebuilds/the-super-tiny-compiler.git
synced 2024-10-27 20:34:08 +00:00
Extract visitor
This commit is contained in:
parent
762ed6b5e1
commit
c2c1a6f9ff
@ -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.
|
||||||
|
Loading…
Reference in New Issue
Block a user