MCPcopy
hub / github.com/angular/angular / ASTValidator

Class ASTValidator

packages/compiler/test/expression_parser/utils/validator.ts:43–173  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41import {unparse} from './unparser';
42
43class ASTValidator extends RecursiveAstVisitor {
44 private parentSpan: ParseSpan | undefined;
45
46 override visit(ast: AST) {
47 this.parentSpan = undefined;
48 ast.visit(this);
49 }
50
51 validate(ast: AST, cb: () => void): void {
52 if (!inSpan(ast.span, this.parentSpan)) {
53 if (this.parentSpan) {
54 const parentSpan = this.parentSpan as ParseSpan;
55 throw Error(
56 `Invalid AST span [expected (${ast.span.start}, ${ast.span.end}) to be in (${
57 parentSpan.start
58 }, ${parentSpan.end}) for ${unparse(ast)}`,
59 );
60 } else {
61 throw Error(`Invalid root AST span for ${unparse(ast)}`);
62 }
63 }
64 const oldParent = this.parentSpan;
65 this.parentSpan = ast.span;
66 cb();
67 this.parentSpan = oldParent;
68 }
69
70 override visitUnary(ast: Unary, context: any): any {
71 this.validate(ast, () => super.visitUnary(ast, context));
72 }
73
74 override visitBinary(ast: Binary, context: any): any {
75 this.validate(ast, () => super.visitBinary(ast, context));
76 }
77
78 override visitChain(ast: Chain, context: any): any {
79 this.validate(ast, () => super.visitChain(ast, context));
80 }
81
82 override visitConditional(ast: Conditional, context: any): any {
83 this.validate(ast, () => super.visitConditional(ast, context));
84 }
85
86 override visitImplicitReceiver(ast: ImplicitReceiver, context: any): any {
87 this.validate(ast, () => super.visitImplicitReceiver(ast, context));
88 }
89
90 override visitInterpolation(ast: Interpolation, context: any): any {
91 this.validate(ast, () => super.visitInterpolation(ast, context));
92 }
93
94 override visitKeyedRead(ast: KeyedRead, context: any): any {
95 this.validate(ast, () => super.visitKeyedRead(ast, context));
96 }
97
98 override visitLiteralArray(ast: LiteralArray, context: any): any {
99 this.validate(ast, () => super.visitLiteralArray(ast, context));
100 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…