Skip to content

Commit 04ba09a

Browse files
fiskerthePunderWoman
authored andcommitted
feat(compiler): support AstVisitor.visitEmptyExpr()
Add support for `AstVisitor.visitEmptyExpr()`
1 parent e66aeac commit 04ba09a

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

packages/compiler-cli/src/ngtsc/typecheck/src/expression.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,6 @@ class AstTranslator implements AstVisitor {
129129
ast = ast.ast;
130130
}
131131

132-
// The `EmptyExpr` doesn't have a dedicated method on `AstVisitor`, so it's special cased here.
133-
if (ast instanceof EmptyExpr) {
134-
const res = ts.factory.createIdentifier('undefined');
135-
addParseSpanInfo(res, ast.sourceSpan);
136-
return res;
137-
}
138-
139132
// First attempt to let any custom resolution logic provide a translation for the given node.
140133
const resolved = this.maybeResolve(ast);
141134
if (resolved !== null) {
@@ -494,6 +487,12 @@ class AstTranslator implements AstVisitor {
494487
return node;
495488
}
496489

490+
visitEmptyExpr(ast: EmptyExpr, context: any) {
491+
const node = ts.factory.createIdentifier('undefined');
492+
addParseSpanInfo(node, ast.sourceSpan);
493+
return node;
494+
}
495+
497496
private convertToSafeCall(
498497
ast: Call | SafeCall,
499498
expr: ts.Expression,

packages/compiler/src/expression_parser/ast.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export abstract class ASTWithName extends AST {
4747

4848
export class EmptyExpr extends AST {
4949
override visit(visitor: AstVisitor, context: any = null) {
50-
// do nothing
50+
return visitor.visitEmptyExpr?.(this, context);
5151
}
5252
}
5353

@@ -651,6 +651,7 @@ export interface AstVisitor {
651651
visitRegularExpressionLiteral(ast: RegularExpressionLiteral, context: any): any;
652652
visitSpreadElement(ast: SpreadElement, context: any): any;
653653
visitASTWithSource?(ast: ASTWithSource, context: any): any;
654+
visitEmptyExpr?(ast: EmptyExpr, context: any): any;
654655
/**
655656
* This function is optionally defined to allow classes that implement this
656657
* interface to selectively decide if the specified `ast` should be visited.
@@ -756,6 +757,7 @@ export class RecursiveAstVisitor implements AstVisitor {
756757
visitSpreadElement(ast: SpreadElement, context: any) {
757758
this.visit(ast.expression, context);
758759
}
760+
visitEmptyExpr(ast: EmptyExpr, context: any): any {}
759761
// This is not part of the AstVisitor interface, just a helper method
760762
visitAll(asts: AST[], context: any): any {
761763
for (const ast of asts) {

0 commit comments

Comments
 (0)