angular/packages/compiler-cli/test
Kristiyan Kostadinov 9cc0cbed0c refactor(compiler): generate if block instructions (#51380)
Adds the logic to generate the instructions for `if` blocks. There are two primary use cases we need to account for:

A conditional that doesn't use the `as` parameter of the `if` block. To support it we generate a nested ternary expression that evaluates to the index of the template whose condition is truthy. If the block doesn't have an `else` branch, we pass in a special `-1` value which means that no view will be rendered.

Example with an `else`:
```ts
// {#if expr}
//   ...
//   {:else if otherExpr} ...
//   {:else} ...
// {/if}

if (rf & 1) {
  ɵɵtemplate(0, App_Conditional_0_Template, 0, 0);
  ɵɵtemplate(1, App_Conditional_1_Template, 0, 0);
  ɵɵtemplate(2, App_Conditional_2_Template, 0, 0);
}
if (rf & 2) {
  ɵɵconditional(0, ctx.expr ? 0 : ctx.otherExpr ? 1 : 2);
}
```

Example without an `else`:
```ts
// {#if expr}
//   ...
//   {:else if otherExpr} ...
// {/if}

if (rf & 1) {
  ɵɵtemplate(0, App_Conditional_0_Template, 0, 0);
  ɵɵtemplate(1, App_Conditional_1_Template, 0, 0);
}
if (rf & 2) {
  ɵɵconditional(0, ctx.expr ? 0 : ctx.otherExpr ? 1 : -1);
}
```

If a conditional captures it's value in an alias (e.g. `{#if expr; as foo}`) we need to assign the value to a temporary variable before passing it along to `conditional`.

```ts
// {#if expr; as alias}...{/if}
if (rf & 1) {
  ɵɵtemplate(0, App_Conditional_0_Template, 1, 0);
}
if (rf & 2) {
  let App_contFlowTmp;
  ɵɵconditional(0, (App_contFlowTmp = ctx.expr) ? 0 : -1, App_contFlowTmp);
}
```

PR Close #51380
2023-08-18 10:01:02 -07:00
..
compliance refactor(compiler): generate if block instructions (#51380) 2023-08-18 10:01:02 -07:00
ngtsc refactor(compiler-cli): better error messages when external strings used for template and styles in local compilation mode (#51338) 2023-08-17 14:02:52 -07:00
BUILD.bazel build: ensure bootstrap transitive runfiles are made available (#48521) 2022-12-19 19:50:41 +00:00
downlevel_decorators_transform_spec.ts feat(core): support TypeScript 5.2 (#51334) 2023-08-18 07:55:16 -07:00
extract_i18n_spec.ts build: switch devmode output to es2015 (#44505) 2022-01-05 23:20:20 +00:00
mocks.ts refactor: make all imports compatible with ESM/CJS output. (#43431) 2021-10-01 18:28:45 +00:00
perform_compile_spec.ts test(compiler): add test case for merging objects in tsconfig (#49125) 2023-03-06 16:57:28 +00:00
perform_watch_spec.ts perf(compiler-cli): minimize filesystem calls when generating shims (#47682) 2022-10-07 09:10:34 -07:00
test_support.ts refactor(router): run spell check on router package (#50445) 2023-05-24 13:56:56 +00:00
typescript_support_spec.ts fix(compiler-cli): handle pre-release versions when checking version (#44109) 2021-11-09 20:54:45 +00:00
version_helpers_spec.ts refactor(compiler-cli): move version number helpers out of diagnostics subfolder (#44269) 2021-12-01 10:36:30 -08:00