refactor(ivy): use absolute source spans in type checker (#34417)

Previously, the type checker would compute an absolute source span by
combining an expression AST node's `ParseSpan` (relative to the start of
the expression) together with the absolute offset of the expression as
represented in a `ParseSourceSpan`, to arrive at a span relative to the
start of the file. This information is now directly available on an
expression AST node in the `AST.sourceSpan` property, which can be used
instead.

PR Close #34417
This commit is contained in:
JoostK
2019-12-15 14:28:51 +01:00
committed by Kara Erickson
parent 76219f6e4b
commit 3e695da964
7 changed files with 75 additions and 121 deletions

View File

@ -30,7 +30,7 @@ export class AST {
/**
* Absolute location of the expression AST in a source code file.
*/
public sourceSpan: Readonly<AbsoluteSourceSpan>) {}
public sourceSpan: AbsoluteSourceSpan) {}
visit(visitor: AstVisitor, context: any = null): any { return null; }
toString(): string { return 'AST'; }
}
@ -145,7 +145,7 @@ export class KeyedWrite extends AST {
export class BindingPipe extends AST {
constructor(
span: ParseSpan, sourceSpan: AbsoluteSourceSpan, public exp: AST, public name: string,
public args: any[], public nameSpan: ParseSpan) {
public args: any[], public nameSpan: AbsoluteSourceSpan) {
super(span, sourceSpan);
}
visit(visitor: AstVisitor, context: any = null): any { return visitor.visitPipe(this, context); }

View File

@ -359,7 +359,7 @@ export class _ParseAST {
do {
const nameStart = this.inputIndex;
const name = this.expectIdentifierOrKeyword();
const nameSpan = this.span(nameStart);
const nameSpan = this.sourceSpan(nameStart);
const args: AST[] = [];
while (this.optionalCharacter(chars.$COLON)) {
args.push(this.parseExpression());