angular/packages/compiler-cli/test
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
..
compliance fix(compiler): generate correct code for safe method calls (#44088) 2021-11-08 17:31:36 +00:00
diagnostics build: rename "no-ivy-aot" tag to "view-engine-only" (#43862) 2021-10-19 10:06:55 -07:00
metadata refactor: make all imports compatible with ESM/CJS output. (#43431) 2021-10-01 18:28:45 +00:00
ngtsc fix(compiler): do not error if $any is used inside a listener (#43866) 2021-10-18 10:43:03 -07:00
transformers build: rename "no-ivy-aot" tag to "view-engine-only" (#43862) 2021-10-19 10:06:55 -07:00
BUILD.bazel test(compiler-cli): run i18n extraction tests using Ivy compiler (#43893) 2021-10-19 16:26:21 -07:00
extract_i18n_spec.ts test(compiler-cli): run i18n extraction tests using Ivy compiler (#43893) 2021-10-19 16:26:21 -07:00
mocks.ts refactor: make all imports compatible with ESM/CJS output. (#43431) 2021-10-01 18:28:45 +00:00
ngc_spec.ts refactor: remove remaining dynamic require usages in package output (#43431) 2021-10-01 18:28:45 +00:00
perform_compile_spec.ts refactor: make all imports compatible with ESM/CJS output. (#43431) 2021-10-01 18:28:45 +00:00
perform_watch_spec.ts test(compiler-cli): run watch mode tests using Ivy compiler (#43893) 2021-10-19 16:26:21 -07:00
test_support.ts test(compiler-cli): run watch mode tests using Ivy compiler (#43893) 2021-10-19 16:26:21 -07:00
typescript_support_spec.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00