fix(compiler): give ASTWithSource its own visit method (#31347)

ASTWithSource contains more information that AST and should have its own
visit method, if desired. This implements that.

PR Close #31347
This commit is contained in:
Ayaz Hafiz
2019-06-28 15:59:21 -07:00
committed by Jason Aden
parent 50c4ec6687
commit 6aaca21c27
2 changed files with 96 additions and 87 deletions

View File

@ -209,7 +209,12 @@ export class ASTWithSource extends AST {
public errors: ParserError[]) {
super(new ParseSpan(0, source == null ? 0 : source.length));
}
visit(visitor: AstVisitor, context: any = null): any { return this.ast.visit(visitor, context); }
visit(visitor: AstVisitor, context: any = null): any {
if (visitor.visitASTWithSource) {
return visitor.visitASTWithSource(this, context);
}
return this.ast.visit(visitor, context);
}
toString(): string { return `${this.source} in ${this.location}`; }
}
@ -240,6 +245,7 @@ export interface AstVisitor {
visitQuote(ast: Quote, context: any): any;
visitSafeMethodCall(ast: SafeMethodCall, context: any): any;
visitSafePropertyRead(ast: SafePropertyRead, context: any): any;
visitASTWithSource?(ast: ASTWithSource, context: any): any;
visit?(ast: AST, context?: any): any;
}