feat(ivy): record absolute position of template expressions (#31391)
Currently, template expressions and statements have their location recorded relative to the HTML element they are in, with no handle to absolute location in a source file except for a line/column location. However, the line/column location is also not entirely accurate, as it points an entire semantic expression, and not necessarily the start of an expression recorded by the expression parser. To support record of the source code expressions originate from, add a new `sourceSpan` field to `ASTWithSource` that records the absolute byte offset of an expression within a source code. Implement part 2 of [refactoring template parsing for stability](https://hackmd.io/@X3ECPVy-RCuVfba-pnvIpw/BkDUxaW84/%2FMA1oxh6jRXqSmZBcLfYdyw?type=book). PR Close #31391
This commit is contained in:
@ -203,11 +203,21 @@ export class FunctionCall extends AST {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Records the absolute position of a text span in a source file, where `start` and `end` are the
|
||||
* starting and ending byte offsets, respectively, of the text span in a source file.
|
||||
*/
|
||||
export class AbsoluteSourceSpan {
|
||||
constructor(public start: number, public end: number) {}
|
||||
}
|
||||
|
||||
export class ASTWithSource extends AST {
|
||||
public sourceSpan: AbsoluteSourceSpan;
|
||||
constructor(
|
||||
public ast: AST, public source: string|null, public location: string,
|
||||
public ast: AST, public source: string|null, public location: string, absoluteOffset: number,
|
||||
public errors: ParserError[]) {
|
||||
super(new ParseSpan(0, source == null ? 0 : source.length));
|
||||
this.sourceSpan = new AbsoluteSourceSpan(absoluteOffset, absoluteOffset + this.span.end);
|
||||
}
|
||||
visit(visitor: AstVisitor, context: any = null): any {
|
||||
if (visitor.visitASTWithSource) {
|
||||
|
Reference in New Issue
Block a user