fix(compiler): preserve this.$event and this.$any accesses in expressions #39323
+348
−30
Conversation
alxhub
approved these changes
Oct 29, 2020
…ions Currently expressions `$event.foo()` and `this.$event.foo()`, as well as `$any(foo)` and `this.$any(foo)`, are treated as the same expression by the compiler, because `this` is considered the same implicit receiver as when the receiver is omitted. This introduces the following issues: 1. Any time something called `$any` is used, it'll be stripped away, leaving only the first parameter. 2. If something called `$event` is used anywhere in a template, it'll be preserved as `$event`, rather than being rewritten to `ctx.$event`, causing the value to undefined at runtime. This applies to listener, property and text bindings. These changes resolve the first issue and part of the second one by preserving anything that is accessed through `this`, even if it's one of the "special" ones like `$any` or `$event`. Furthermore, these changes only expose the `$event` global variable inside event listeners, whereas previously it was available everywhere. Fixes angular#30278.
ayazhafiz
approved these changes
Oct 29, 2020
Nice change, LGTM for language service
|
@crisbeto Looks like this breaks codelyzer, so it doesn't land cleanly. While its marked as a fix here, it does modify the type of |
|
@josephperrott I've made the new method optional. Can we give it another try? |
|
Updating to |
josephperrott
added a commit
that referenced
this issue
Oct 30, 2020
…ions (#39323) Currently expressions `$event.foo()` and `this.$event.foo()`, as well as `$any(foo)` and `this.$any(foo)`, are treated as the same expression by the compiler, because `this` is considered the same implicit receiver as when the receiver is omitted. This introduces the following issues: 1. Any time something called `$any` is used, it'll be stripped away, leaving only the first parameter. 2. If something called `$event` is used anywhere in a template, it'll be preserved as `$event`, rather than being rewritten to `ctx.$event`, causing the value to undefined at runtime. This applies to listener, property and text bindings. These changes resolve the first issue and part of the second one by preserving anything that is accessed through `this`, even if it's one of the "special" ones like `$any` or `$event`. Furthermore, these changes only expose the `$event` global variable inside event listeners, whereas previously it was available everywhere. Fixes #30278. PR Close #39323
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.


Currently expressions like
$event.foo()andthis.$event.foo(), as well as$any(foo)andthis.$any(foo), are treated as the same expression by the compiler, becausethisis considered the same implicit receiver as when the receiver is omitted. This introduces the following issues:$anyis used, it'll be stripped away, leaving only the first parameter.$eventis used anywhere in a template, it'll be preserved as$event, rather than being rewritten toctx.$event, causing the value to undefined at runtime. This applies to listener, property and text bindings.These changes resolve the first issue and part of the second one by preserving anything that is accessed through
this, even if it's one of the "special" ones like$anyor$event. Furthermore, these changes only expose the$eventglobal variable inside event listeners, whereas previously it was available everywhere.Fixes #30278.
The text was updated successfully, but these errors were encountered: