Commit graph

10231 commits

Author SHA1 Message Date
Pawel Kozlowski
cdcfa09ab3 refactor(core): built-in control flow - repeaters (#51422)
Draft of the runtime implementation for the built-in repeaters.

PR Close #51422
2023-08-28 20:49:18 +00:00
Miles Malerba
88fcd27c6d refactor(compiler): add a pointer to the const array in i18nStart (#51353)
Adds a pointer to the const array index containing the i18n message to
the i18nStart instruction.

PR Close #51353
2023-08-28 18:57:08 +00:00
Miles Malerba
5f02b5810b refactor(compiler): resolve element placeholders in i18n messages (#51353)
Adds a new phase to resolve element placeholders in i18n messages.
This requires adding the i18n message to element ops, which means the
creation of i18n start/end ops can now be done in a separate phase
instead of during ingestion.

PR Close #51353
2023-08-28 18:57:08 +00:00
Miles Malerba
b064b29776 refactor(compiler): use correct closure variable naming (#51353)
Updates the closure variable naming for i18n variables to match those
generated by TemplateDefinitionBuilder

PR Close #51353
2023-08-28 18:57:08 +00:00
Miles Malerba
99f94747e4 refactor(compiler): extract text nodes in i18n blocks (#51353)
Removes text nodes from i18n blocks, since the text is already captured
in the i18n message.

PR Close #51353
2023-08-28 18:57:08 +00:00
Miles Malerba
d13a2ee064 refactor(compiler): support i18n messages in the consts array (#51353)
Creates a new `ExtractedMessageOp` which is consumed by the const
collection pahse to serialize the i18n message into the consts array.
Also adds support to the consts array for initialization statements.

PR Close #51353
2023-08-28 18:57:08 +00:00
Alex Rickabaugh
575a5588f8 refactor(compiler): initial implementation of i18n blocks (#51353)
Adds i18n block start & end ops, as well as a new phase to construct the
i18n message variable to be added to the consts array.

Co-authored-by: Alex Rickabaugh <alx+alxhub@alxandria.net>
Co-authored-by: Dylan Hunn <dylhunn@gmail.com>

PR Close #51353
2023-08-28 18:57:08 +00:00
Andrew Kushnir
c4deaac5b0 refactor(core): initial implementation of {#defer} block runtime (#51347)
This commit adds an initial implementation of the `{#defer}` block runtime, which supports the `when` conditions. More conditions and basic prefetching support will be added in followup PRs.

PR Close #51347
2023-08-28 17:09:52 +00:00
Kristiyan Kostadinov
bf9663847d build: update type TypeScript 5.2 final (#51503)
Bumps up the repo to the stable version of TypeScript 5.2.

PR Close #51503
2023-08-28 17:02:30 +00:00
Kristiyan Kostadinov
fa72384ec5 refactor(compiler): introduce AST for outputting arrow functions (#51436)
Extends the compiler to add support for generating arrow functions in the output AST. This will be required for the `for` control flow block and we can potentially leverage it in other places to reduces the amount of generated code.

PR Close #51436
2023-08-23 14:45:33 -07:00
Kristiyan Kostadinov
36663e6ef6 refactor(compiler): parse let parameters in for loop (#51398)
Adds the logic to parse `let` parameters of a `for` loop block which was missed in #51299.

PR Close #51398
2023-08-22 10:40:17 -07:00
Kristiyan Kostadinov
9f6b565abd refactor(compiler): parse for loop track as an expression (#51398)
Adds some logic to store the `track` parameter of a `for` loop block as an expression AST instead of a string.

PR Close #51398
2023-08-22 10:40:17 -07:00
Kristiyan Kostadinov
eb1faa8f87 refactor(compiler): don't allow as expressions in else if blocks (#51398)
Based on some discussions, these changes remove the ability to have an `as` expression on an `else if` block.

PR Close #51398
2023-08-22 10:40:17 -07:00
Andrew Scott
2aae92b05f refactor(router): Have router subscribe to transition events to update state (#48427)
Rather than the navigation transitions managing Router state, this
commit updates the Router to manage its own state based on ongoing
transition events. In the future, this can be abstracted even further to
have a totally separate class that manages the Router state. This would
allow the potential for swapping state manager implementations rather
than having to implement all types of state management in a single place.

One finding during tests was that unexpected errors thrown by the state management code moved
to the Router here will no longer be caught by the transition pipe's `catchError`.
This only includes calls to the following public Api methods:

* `go`, `replaceState`, `historyGo`, `isCurrentPathEqualTo` on `Location`
* `UrlSerializer.serialize`
* `UrlHandlingStrategy.merge`.

None of these methods should throw if the router is expected to function.
These might throw when tests include incomplete mocks, which is not
supported, or in cases where the actual browser methods like
`replaceState` would throw. This will already result in unexpected/unsupported
behavior. The failure case here is now arguably better - the navigation
itself still completes but the state update (either updating Router
internal state or updating the browser URL) fails separately and is
unhandled.

PR Close #48427
2023-08-22 08:04:00 -07:00
Andrew Scott
96d94ad130 fix(router): Ensure canceledNavigationResolution: 'computed' works on first page (#51441)
Setting the page ID is currently broken for the first page because the
helper method's second parameter is optional, which allowed the initally
`undefined` page ID to be used again when the router performs its
initial navigation.

fixes #50983

PR Close #51441
2023-08-21 13:01:58 -07:00
Matthieu Riegler
a9b3c006f8 fix(core): guard the jasmine hooks (#51394)
This commit fixes a regression introduced in #50063

Fixes #51382

PR Close #51394
2023-08-21 08:14:53 -07:00
Kristiyan Kostadinov
9152de1387 test(core): remove manually-written control flow instructions (#51380)
Updates the control flow tests to use the compiler instead of manually-written instructions. Also adds a couple of tests that I was using along the way to verify that things work as expected.

PR Close #51380
2023-08-18 10:01:02 -07:00
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
Kristiyan Kostadinov
0c4c773fca refactor(compiler): generate switch block instructions (#51380)
Adds the logic to generate the instructions for `switch` instructions. For the following block:

```html
{#switch value()}
  {:case 0} case 0
  {:case 1} case 1
  {:case 2} case 2
  {:default} default
{/switch}
```

The compiler will produce the following output:

```ts
function App_Template(rf, ctx) {
  if (rf & 1) {
    ɵɵtemplate(0, App_Case_0_Template, 1, 0);
    ɵɵtemplate(1, App_Case_1_Template, 1, 0);
    ɵɵtemplate(2, App_Case_2_Template, 1, 0);
    ɵɵtemplate(3, App_Case_3_Template, 1, 0);
  }
  if (rf & 2) {
    let App_contFlowTmp;
    ɵɵconditional(0, (App_contFlowTmp = ctx.value()) === 0 ? 0 : App_contFlowTmp === 1 ? 1 : App_contFlowTmp === 2 ? 2 : 3);
  }
}
```

PR Close #51380
2023-08-18 10:01:02 -07:00
JoostK
5bd9fbd2c3 fix(compiler-cli): enforce a minimum version to be used when a library uses input transform (#51413)
Angular 16.1 introduced the input transform feature, requiring the partial compilation output to be extended
with a reference to the input transform function. This has resulted in a subtle breaking change, where older
versions of the Angular linker can no longer consume libraries that have started to use this feature.

We do try to support using a 16.1 library from an Angular 16.0 application, but if a library actually
adopts a new feature then this is no longer possible. In such cases, it is desirable to report a message
telling the user that their version of the Angular compiler is too old, as determined by the `"minVersion"`
property that is present in each partial declaration. This version would still indicate that the declaration
required at least Angular 14.0 to be compiled, but this is not accurate once input transforms are being
used. Consequently, this error would not be reported, causing a less informative error once the input transform
was being observed.

Fixes #51411

PR Close #51413
2023-08-18 07:58:53 -07:00
Matthieu Riegler
4663a33a0d refactor(platform-browser-dynamic): remove reexport of MetadataOverrider (#51412)
this commit removes an unnecessary re-export

PR Close #51412
2023-08-18 07:57:34 -07:00
Matthieu Riegler
de3be98417 docs: fix links in UpgradeAdapter (#51395)
PR Close #51395
2023-08-18 07:56:41 -07:00
Kristiyan Kostadinov
9cc52b9b85 feat(core): support TypeScript 5.2 (#51334)
Updates the project to support TypeScript 5.2.

PR Close #51334
2023-08-18 07:55:16 -07:00
Payam Valadkhan
0b901a814b refactor(compiler-cli): better error messages when external strings used for template and styles in local compilation mode (#51338)
In local compilation mode it is not possible to use an imported string for component's template or styles as it cannot be resolved statically in compile time. There are some such use cases in g3 and potentially devs might incorporate such pattern. At the moment such pattern will cause the local compilation fail with generic error messages (e.g., so and so at position 1 is not a reference, etc). This change makes specific error messages with helpful hints for such cases. These new error messages can help devs to quickly resolve the issue as well as make it possible to identify existing issues in g3.

PR Close #51338
2023-08-17 14:02:52 -07:00
Payam Valadkhan
8798abb744 refactor(core): implement runtime logic to compute component dependencies in local compilation mode (#51377)
The runtime `ɵɵsetNgModuleScope` is modified to accept raw scope info as passed to it in local compilation mode. The runtime further registers the ng-module in the deps tracker. Then the runtime `ɵɵgetComponentDepsFactory` is implemented to use the deps tracker to get the component dependencies which leads to a valid and working Angular code.

PR Close #51377
2023-08-17 14:01:51 -07:00
Payam Valadkhan
e69e41ecf8 refactor(core): more accurate types for standalone component imports in deps tracker (#51377)
The standalone components import as passed to the deps tracker will be the raw import, i.e., it is either a Type or a module with providers or a factory of these. So we use the existing type `RawScopeInfoFromDecorator` for these imports instead of the current one to be more realistic.

PR Close #51377
2023-08-17 14:01:51 -07:00
Payam Valadkhan
56e0b8526a refactor(core): allow empty raw import info for standalone components in the runtime deps tracker (#51377)
The current logic requires that standalone component always provide an array of raw imports. But such array could be dropped from the downstream tools if the component has no imports. So it is more natural to allow undefined raw imports for standalone components and treat it as empty array.

PR Close #51377
2023-08-17 14:01:51 -07:00
Payam Valadkhan
8b431a0164 refactor(core): kill circular deps by moving scope runtime functions to a new scope.ts file (#51377)
This refactoring is needed for next commit not to produce circular deps as we start using the `depsTracker` inside `ɵɵsetNgModuleScope`. The runtime `ɵɵsetComponentScope` is not needed to move but it moved to the new file just for consistency sake.

PR Close #51377
2023-08-17 14:01:51 -07:00
Paul Gschwendtner
552ea77854 refactor(compiler-cli): drop tsickle code paths (#50602)
`tsickle` is not used in any code paths in 3P and we can remove
this complexity. The `tsickle` npm package has not been released
in a while and we are risking breakages with e.g. future TypeScript
versions.

Note that the `ng_module` rule was updated to not emit through
tsickle at all. The tsickle in 1P is done directly by `tsc_wrapped`
and our code path in `compiler-cli` is not needed at all.

PR Close #50602
2023-08-17 10:23:49 -07:00
Alex Castle
d910bf8a84 fix(common): Allow safeUrl for ngSrc in NgOptimizedImage (#51351)
Allow safeUrl and add transformer to immediately convert ngSrc to string

PR Close #51351
2023-08-17 10:20:35 -07:00
Matthieu Riegler
e6503930f1 docs: fix see also links. (#51379)
These were all the @see with no links.

PR Close #51379
2023-08-17 10:18:33 -07:00
Gerald Monaco
6145cc1c0a refactor(core): Ensure hydration cleanup runs in the Angular zone (#51321)
Hydration cleanup needs to run in the Angular zone so that change detection will run.

PR Close #51321
2023-08-15 16:02:06 -07:00
Andrew Kushnir
bcc3c43fca refactor(core): update TestBed to handle async component metadata (#51182)
This commit updates TestBed to wait for async component metadata resolution before compiling components.
Async metadata is added by the compiler in case a component uses defer blocks, which contain deferrable
symbols.

PR Close #51182
2023-08-15 11:32:09 -07:00
Andrew Kushnir
c41a1950fd refactor(compiler): apply component metadata asynchronously when defer blocks are present (#51182)
This commit updates compiler logic to generate the `setClassMetadataAsync` calls for components that used defer blocks. The `setClassMetadataAsync` function loads deferrable dependencies and invokes the `setClassMetadata` synchronously once everything is loaded. This change is needed to avoid eager references to deferrable symbols in component metadata in generated code.

PR Close #51182
2023-08-15 11:32:09 -07:00
Luis Castro
328b3613b8 docs(common): revert format date_pipe (#51359)
PR Close #51359
2023-08-15 10:06:47 -07:00
Luis Castro
200a264fab docs(common): add new date format example to documentation (#51359)
PR Close #51359
2023-08-15 10:06:47 -07:00
Kristiyan Kostadinov
422d0d5ca3 refactor(compiler): handle deferred when trigger with a pipe (#51368)
Fixes that we weren't processing `when` conditions correctly which led to a compilation error when a pipe is used inside the expression.

PR Close #51368
2023-08-15 10:03:59 -07:00
Matthieu Riegler
17c6ad7775 docs: Add usage information to HttpInterceptorFn (#51236)
Simple doc addendum

PR Close #51236
2023-08-15 10:02:43 -07:00
Matthieu Riegler
83b708203e docs: Improve host binding docs (#51326)
This commit adds the mention of the support of styles/classes/attributes in host bindings.

fixes # 44296

PR Close #51326
2023-08-15 09:54:14 -07:00
Matthieu Riegler
3348f8820b docs: Add precisions about static/dynamic queries. (#51146)
The table is mostly copied from guide/migration-dynamic-flag.

Fixes #51142

PR Close #51146
2023-08-15 09:52:04 -07:00
Jeremy Mowery
be3edad60e refactor: add readonly to public InjectionToken types (#51125)
We enabled a lint rule internally to require that multi-provided
`InjectionToken`s have a `readonly` array type, the tokens in this
PR do not follow this rule and are causing lint violations.

Fixes #51124

PR Close #51125
2023-08-14 17:17:35 -07:00
Pawel Kozlowski
93675dc797 feat(core): conditional built-in control flow (#51346)
Initial PoC of the built-in control flow support. The goal is to
unblock compiler work.

PR Close #51346
2023-08-14 17:16:39 -07:00
Matthieu Riegler
3b1c1b91a2 docs: Add Missing SSR integrity marker error doc page (#51340)
This commit adds an error doc page for error 507 : Missing SSR content integrity marker.

PR Close #51340
2023-08-14 14:39:25 -07:00
Pawel Kozlowski
ebd217d393 Revert "refactor(core): remove class type check when clearing cache in deps tracker (#51293)" (#51358)
This reverts commit a9f609e75c.

PR Close #51358
2023-08-14 13:48:47 -07:00
Pawel Kozlowski
b1f0fc9129 Revert "refactor(core): enabled using deps tracker in JIT compilation (#51293)" (#51358)
This reverts commit bc55d82eb9.

PR Close #51358
2023-08-14 13:48:47 -07:00
Pawel Kozlowski
b0ea81d562 Revert "refactor(core): kill circular deps by moving scope runtime functions to a new scope.ts file (#51309)" (#51358)
This reverts commit 45105555da.

PR Close #51358
2023-08-14 13:48:47 -07:00
Pawel Kozlowski
b297ea7966 Revert "refactor(core): allow empty raw import info for standalone components in the runtime deps tracker (#51309)" (#51358)
This reverts commit 8156128863.

PR Close #51358
2023-08-14 13:48:47 -07:00
Pawel Kozlowski
32d30f26a7 Revert "refactor(core): more accurate types for standalone component imports in deps tracker (#51309)" (#51358)
This reverts commit e7ea016e00.

PR Close #51358
2023-08-14 13:48:47 -07:00
Pawel Kozlowski
ee73d180fd Revert "refactor(core): implement runtime logic to compute component dependencies in local compilation mode (#51309)" (#51358)
This reverts commit f7cfc3b8fa.

PR Close #51358
2023-08-14 13:48:47 -07:00
Payam Valadkhan
f7cfc3b8fa refactor(core): implement runtime logic to compute component dependencies in local compilation mode (#51309)
The runtime `ɵɵsetNgModuleScope` is modified to accept raw scope info as passed to it in local compilation mode. The runtime further registers the ng-module in the deps tracker. Then the runtime `ɵɵgetComponentDepsFactory` is implemented to use the deps tracker to get the component dependencies which leads to a valid and working Angular code.

PR Close #51309
2023-08-14 08:58:47 -07:00