|
|
|
@ -17,7 +17,7 @@ class ASTVisitor {
|
|
|
|
|
// istanbul ignore next
|
|
|
|
|
if ( ! fn ) throw new Error( `Visitor function for node type "${ node.type }" not defined` );
|
|
|
|
|
|
|
|
|
|
return fn.apply( this, arguments );
|
|
|
|
|
return fn.apply( this, arguments ); // eslint-disable-line prefer-rest-params
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -45,14 +45,13 @@ const on = ASTVisitor.on = {
|
|
|
|
|
// Visit a node that is defined as a property on another node
|
|
|
|
|
property( name ) {
|
|
|
|
|
|
|
|
|
|
return function visitProperty( node ) {
|
|
|
|
|
return function visitProperty( node, ...extraArgs ) {
|
|
|
|
|
|
|
|
|
|
const extraArgs = __slice.call( arguments, 1 );
|
|
|
|
|
const value = node[ name ];
|
|
|
|
|
|
|
|
|
|
if ( extraArgs.length )
|
|
|
|
|
|
|
|
|
|
this.visit.apply( this, [ value ].concat( extraArgs ) );
|
|
|
|
|
this.visit( value, ...extraArgs );
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
|
@ -65,13 +64,12 @@ const on = ASTVisitor.on = {
|
|
|
|
|
// Visit an array of nodes that are defined as a property on another node
|
|
|
|
|
children( name ) {
|
|
|
|
|
|
|
|
|
|
return function visitProperty( node ) {
|
|
|
|
|
return function visitProperty( node, ...extraArgs ) {
|
|
|
|
|
|
|
|
|
|
const args = __slice.call( arguments, 0 );
|
|
|
|
|
const children = node[ name ];
|
|
|
|
|
const visitor = this;
|
|
|
|
|
|
|
|
|
|
const cb = args.length < 2
|
|
|
|
|
const cb = extraArgs.length < 1
|
|
|
|
|
? function withoutArgs( child ) {
|
|
|
|
|
|
|
|
|
|
visitor.visit( child );
|
|
|
|
@ -79,8 +77,7 @@ const on = ASTVisitor.on = {
|
|
|
|
|
}
|
|
|
|
|
: function withArgs( child ) {
|
|
|
|
|
|
|
|
|
|
args[ 0 ] = child;
|
|
|
|
|
visitor.visit.apply( visitor, args );
|
|
|
|
|
visitor.visit( child, ...extraArgs );
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -99,21 +96,17 @@ const visitExpression = on.property( "expression" );
|
|
|
|
|
|
|
|
|
|
const DEFAULT_FUNCTIONS = {
|
|
|
|
|
|
|
|
|
|
grammar( node ) {
|
|
|
|
|
|
|
|
|
|
const args = [ void 0 ].concat( __slice.call( arguments, 1 ) );
|
|
|
|
|
grammar( node, ...extraArgs ) {
|
|
|
|
|
|
|
|
|
|
if ( node.initializer ) {
|
|
|
|
|
|
|
|
|
|
args[ 0 ] = node.initializer;
|
|
|
|
|
this.visit.apply( this, args );
|
|
|
|
|
this.visit( node.initializer, ...extraArgs );
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
node.rules.forEach( rule => {
|
|
|
|
|
|
|
|
|
|
args[ 0 ] = rule;
|
|
|
|
|
this.visit.apply( this, args );
|
|
|
|
|
this.visit( rule, ...extraArgs );
|
|
|
|
|
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|