angular/packages/core
JoostK b249e24979 fix(compiler): generate correct code for safe method calls (#44088)
When a safe method call such as `person?.getName()` is used, the
compiler would generate invalid code if the argument list also contained
a safe method call. For example, the following code:

```
person?.getName(config?.get('title').enabled)
```

would generate

```
let tmp;
ctx.person == null ? null : ctx.person.getName((tmp = tmp) == null ?
null : tmp.enabled)
```

Notice how the call to `config.get('title')` has completely disappeared,
with `(tmp = tmp)` having taken its place.

The issue occurred due to how the argument list would be converted
from expression AST to output AST twice. First, the outer safe method
call would first convert its arguments list. This resulted in a
temporary being allocated for `config.get('title')`, which was stored in
the internal `_resultMap`. Only after the argument list has been
converted would the outer safe method call realize that it should be
guarded by a safe access of `person`, entering the `convertSafeAccess`
procedure to convert itself. This would convert the argument list once
again, but this time the `_resultMap` would already contain the
temporary `tmp` for `config?.get('title')`. Consequently, the safe
method in the argument list would be emitted as `tmp`.

This commit fixes the issue by ensuring that nodes are only converted
once.

Closes #44069

PR Close #44088
2021-11-08 17:31:36 +00:00
..
global build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
schematics refactor(core): set up structure for google3 usage of migration schematics (#43980) 2021-11-04 11:23:12 -07:00
src refactor(core): correct typing when getting the Nearest LContainer (#44087) 2021-11-05 21:31:49 +00:00
test fix(compiler): generate correct code for safe method calls (#44088) 2021-11-08 17:31:36 +00:00
testing fix(core): don't rethrow errors if test teardown has been disabled (#43635) 2021-10-04 17:31:26 -07:00
BUILD.bazel refactor: remove entry_point attribute from ng_package targets (#43431) 2021-10-01 18:28:42 +00:00
index.ts refactor(core): made comment structure consistent in index.ts (#43684) 2021-10-21 18:39:58 +00:00
package.json refactor(compiler-cli): update peerDependencies to require rxjs ^7.4.0 (#43748) 2021-10-06 15:57:59 -07:00
PACKAGE.md docs: add package doc files (#26047) 2018-10-05 15:42:14 -07:00
public_api.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00