Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup! feat(compiler): add support for the typeof keyword in templa…
…te expressions.
  • Loading branch information
JeanMeche committed Oct 14, 2024
commit 992769fdead4f727c59cf7fcdf3a0ee7c4b67cef
6 changes: 3 additions & 3 deletions packages/compiler-cli/src/ngtsc/typecheck/src/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
LiteralPrimitive,
NonNullAssert,
PrefixNot,
PrefixTypeof,
TypeofExpression,
PropertyRead,
PropertyWrite,
SafeCall,
Expand Down Expand Up @@ -276,7 +276,7 @@ class AstTranslator implements AstVisitor {
return node;
}

visitPrefixTypeof(ast: PrefixTypeof): ts.Expression {
visitTypeofExpresion(ast: TypeofExpression): ts.Expression {
const expression = wrapForDiagnostics(this.translate(ast.expression));
const node = ts.factory.createTypeOfExpression(expression);
addParseSpanInfo(node, ast.sourceSpan);
Expand Down Expand Up @@ -549,7 +549,7 @@ class VeSafeLhsInferenceBugDetector implements AstVisitor {
visitPrefixNot(ast: PrefixNot): boolean {
return ast.expression.visit(this);
}
visitPrefixTypeof(ast: PrefixNot): boolean {
visitTypeofExpresion(ast: PrefixNot): boolean {
return ast.expression.visit(this);
}
visitNonNullAssert(ast: PrefixNot): boolean {
Expand Down
16 changes: 8 additions & 8 deletions packages/compiler/src/expression_parser/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ export class PrefixNot extends AST {
}
}

export class PrefixTypeof extends AST {
export class TypeofExpression extends AST {
constructor(
span: ParseSpan,
sourceSpan: AbsoluteSourceSpan,
Expand All @@ -382,7 +382,7 @@ export class PrefixTypeof extends AST {
super(span, sourceSpan);
}
override visit(visitor: AstVisitor, context: any = null): any {
return visitor.visitPrefixTypeof(this, context);
return visitor.visitTypeofExpresion(this, context);
}
}

Expand Down Expand Up @@ -547,7 +547,7 @@ export interface AstVisitor {
visitLiteralPrimitive(ast: LiteralPrimitive, context: any): any;
visitPipe(ast: BindingPipe, context: any): any;
visitPrefixNot(ast: PrefixNot, context: any): any;
visitPrefixTypeof(ast: PrefixTypeof, context: any): any;
visitTypeofExpresion(ast: TypeofExpression, context: any): any;
visitNonNullAssert(ast: NonNullAssert, context: any): any;
visitPropertyRead(ast: PropertyRead, context: any): any;
visitPropertyWrite(ast: PropertyWrite, context: any): any;
Expand Down Expand Up @@ -615,7 +615,7 @@ export class RecursiveAstVisitor implements AstVisitor {
visitPrefixNot(ast: PrefixNot, context: any): any {
this.visit(ast.expression, context);
}
visitPrefixTypeof(ast: PrefixTypeof, context: any) {
visitTypeofExpresion(ast: TypeofExpression, context: any) {
this.visit(ast.expression, context);
}
visitNonNullAssert(ast: NonNullAssert, context: any): any {
Expand Down Expand Up @@ -732,8 +732,8 @@ export class AstTransformer implements AstVisitor {
return new PrefixNot(ast.span, ast.sourceSpan, ast.expression.visit(this));
}

visitPrefixTypeof(ast: PrefixNot, context: any): AST {
return new PrefixTypeof(ast.span, ast.sourceSpan, ast.expression.visit(this));
visitTypeofExpresion(ast: PrefixNot, context: any): AST {
Comment thread
JeanMeche marked this conversation as resolved.
Outdated
return new TypeofExpression(ast.span, ast.sourceSpan, ast.expression.visit(this));
}

visitNonNullAssert(ast: NonNullAssert, context: any): AST {
Expand Down Expand Up @@ -912,10 +912,10 @@ export class AstMemoryEfficientTransformer implements AstVisitor {
return ast;
}

visitPrefixTypeof(ast: PrefixTypeof, context: any): AST {
visitTypeofExpresion(ast: TypeofExpression, context: any): AST {
const expression = ast.expression.visit(this);
if (expression !== ast.expression) {
return new PrefixTypeof(ast.span, ast.sourceSpan, expression);
return new TypeofExpression(ast.span, ast.sourceSpan, expression);
}
return ast;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/src/expression_parser/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class Token {
}

isKeywordTypeof(): boolean {
return this.type == TokenType.Keyword && this.strValue == 'typeof';
return this.type === TokenType.Keyword && this.strValue === 'typeof';
}

isError(): boolean {
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler/src/expression_parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
ParserError,
ParseSpan,
PrefixNot,
PrefixTypeof,
TypeofExpression,
PropertyRead,
PropertyWrite,
RecursiveAstVisitor,
Expand Down Expand Up @@ -965,7 +965,7 @@ class _ParseAST {
this.advance();
const start = this.inputIndex;
let result = this.parsePrefix();
return new PrefixTypeof(this.span(start), this.sourceSpan(start), result);
return new TypeofExpression(this.span(start), this.sourceSpan(start), result);
}
return this.parseCallChain();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/src/template/pipeline/src/ingest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ function convertAst(
convertAst(ast.expression, job, baseSourceSpan),
convertSourceSpan(ast.span, baseSourceSpan),
);
} else if (ast instanceof e.PrefixTypeof) {
} else if (ast instanceof e.TypeofExpression) {
return o.typeofExpr(convertAst(ast.expression, job, baseSourceSpan));
} else {
throw new Error(
Expand Down
1 change: 1 addition & 0 deletions packages/compiler/test/expression_parser/parser_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ describe('parser', () => {

it('should parse typeof expression', () => {
Comment thread
crisbeto marked this conversation as resolved.
Outdated
checkAction(`typeof {} === "object"`);
checkAction('(!(typeof {} === "number"))', '!typeof {} === "number"');
});

it('should parse grouped expressions', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/compiler/test/expression_parser/utils/unparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
LiteralPrimitive,
NonNullAssert,
PrefixNot,
TypeofExpression,
PropertyRead,
PropertyWrite,
RecursiveAstVisitor,
Expand Down Expand Up @@ -192,7 +193,7 @@ class Unparser implements AstVisitor {
this._visit(ast.expression);
}

visitPrefixTypeof(ast: PrefixNot, context: any) {
visitTypeofExpresion(ast: TypeofExpression, context: any) {
this._expression += 'typeof ';
this._visit(ast.expression);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/compiler/test/expression_parser/utils/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
LiteralPrimitive,
ParseSpan,
PrefixNot,
PrefixTypeof,
TypeofExpression,
PropertyRead,
PropertyWrite,
RecursiveAstVisitor,
Expand Down Expand Up @@ -113,8 +113,8 @@ class ASTValidator extends RecursiveAstVisitor {
this.validate(ast, () => super.visitPrefixNot(ast, context));
}

override visitPrefixTypeof(ast: PrefixTypeof, context: any): any {
this.validate(ast, () => super.visitPrefixTypeof(ast, context));
override visitTypeofExpresion(ast: TypeofExpression, context: any): any {
this.validate(ast, () => super.visitTypeofExpresion(ast, context));
}

override visitPropertyRead(ast: PropertyRead, context: any): any {
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler/test/render3/util/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ class ExpressionSourceHumanizer extends e.RecursiveAstVisitor implements t.Visit
this.recordAst(ast);
super.visitPrefixNot(ast, null);
}
override visitPrefixTypeof(ast: e.PrefixTypeof) {
override visitTypeofExpresion(ast: e.TypeofExpression) {
this.recordAst(ast);
super.visitPrefixTypeof(ast, null);
super.visitTypeofExpresion(ast, null);
}
override visitPropertyRead(ast: e.PropertyRead) {
this.recordAst(ast);
Expand Down