Skip to content

Collision between expressions and template variable / class field #65244

@CoreAngel

Description

@CoreAngel

Which @angular/* package(s) are the source of the bug?

compiler

Is this a regression?

Yes

Description

For expression, which can be a valid class field or template variable, a collision may occur when referencing it in a template, for example in or typeof.

If we create something like this:

@Component({
  template: `{{ in }}`
})
export class App {
  public in = 0;
}

in is treated as an expression instead of a class field. The solution, is to use this.in, then it refers to the field. Unfortunately, this cannot be applied to template variables. Maybe the compiler should handle these cases better and check if a collision can occur in a given context and display a better warning / error.

Bunus points :)

  1. It seems that in does not require anything before or after itself, unlike typeof which requires something after itself, for example:
{{ typeof }} // NG5002: Parser Error: Unexpected end of expression:  typeof  at the end of the expression [ typeof ]
{{ typeof 'value' }} // OK - return 'string'
{{ in }} // OK - return string 'in', but should throw error
{{ 1 in values }} // OK
  1. The documentation is missing information about support for in and typeof, for example.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw


Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 20.3.10
Node: 20.19.1
Package Manager: npm 10.8.2
OS: linux x64
    

Angular: 20.3.12
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, router

Package                      Version
------------------------------------
@angular-devkit/architect    0.2003.10
@angular-devkit/core         20.3.10
@angular-devkit/schematics   20.3.10
@angular/build               20.3.10
@angular/cli                 20.3.10
@schematics/angular          20.3.10
rxjs                         7.8.2
typescript                   5.8.2

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: compilerIssues related to `ngc`, Angular's template compilerarea: docsRelated to the documentationbreaking changescompiler: parserhelp wantedAn issue that is suitable for a community contributor (based on its complexity/scope).

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions