8000 bug(compiler): this.$event and this.$any() should not be allowed in template · Issue #30278 · angular/angular · GitHub
[go: up one dir, main page]

Skip to content
bug(compiler): this.$event and this.$any() should not be allowed in template #30278
@trotyl

Description

@trotyl

🐞 bug report

Affected Package

The issue is caused by package @angular/compiler

Is this a regression?

No

Description

Currently $event and $any are treated as property read of ImplicitReceiver(this), and expanded to this.$event/this.$any by parser. Which means that user could manually write this.$event to access to $event object.

So the the following code are totally valid:

<button (click)="onClick(this.$any(this.$event))">Click Me!</button>

It's a really terrible pattern in template usage, gives the impression that these magical properties being assigned to component instance.

Instead, the parser should treat them as lexical identifier in the first place and forbid this. usage. It also applies to template reference.

🔬 Minimal Reproduction

https://stackblitz.com/edit/angular-mgjryy?file=src%2Fapp%2Fapp.component.html

🔥 Exception or Error

N/A

🌍 Your Environment

Angular Version:

7.2.5 now but doesn't matter

Anything else relevant?

This should be easy to implement once #30277 landed.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0