Commit graph

2753 commits

Author SHA1 Message Date
Kristiyan Kostadinov
59387ee476 feat(core): support styles and styleUrl as strings (#51715)
Adds support for passing in `@Component.styles` as a string. Also introduces a new `styleUrl` property on `@Component` for providing a single stylesheet. This is more convenient for the most common case where a component only has one stylesheet associated with it.

PR Close #51715
2023-09-12 13:57:07 -07:00
Kristiyan Kostadinov
f9939757d3 build: skip simulated file system tests on Windows (#51738)
The code for detecting a Windows CI run from #51701 didn't work, because Bazel isolates the environment variables. These changes work around the issue by passing in a custom variable with the `--test_env` flag.

PR Close #51738
2023-09-12 12:56:27 -07:00
Kristiyan Kostadinov
52cc7f839b build: align with internal tsconfig options (#51728)
Currently internally Angular has some customized tsconfig files, because we don't align with the tsconfig of the rest of g3. These changes enable `noImplicitReturns` and `noPropertyAccessFromIndexSignature` to align better with the internal config.

PR Close #51728
2023-09-12 11:39:42 -07:00
Kristiyan Kostadinov
b3edcda9e6 build: attempt to deflake windows tests (#51701)
Adds some logic to try and deflake the tests on Windows.

PR Close #51701
2023-09-08 09:28:02 -07:00
Kristiyan Kostadinov
88a0af64fd perf(core): generate arrow functions for pure function calls (#51668)
Reworks the pure functions to use arrow functions with an implicit return instead of function expressions. This allows us to shave off some bytes for each pure function, because we can avoid some of the syntax.

PR Close #51668
2023-09-06 15:32:02 +00:00
Kristiyan Kostadinov
7c068861b7 refactor(compiler): output arrow functions for deferred dependencies functions (#51650)
Reworks the compiler to generate arrow functions for the deferred dependencies which reduces the number of bytes we generate.

PR Close #51650
2023-09-05 18:16:59 +00:00
Kristiyan Kostadinov
7fa17d00f6 test(compiler): fix failing tests (#51656)
Fixes some tests that started failing, because a couple of connected PRs landed at the same time.

PR Close #51656
2023-09-05 15:02:52 +00:00
Kristiyan Kostadinov
05a16b973d refactor(compiler): add support for advanced tracking expressions (#51618)
These changes build on top of #51514 to add support for advanced expressions inside the `track` parameter of `for` loop blocks. There are two different outputs that the compiler can generate:

1. If the tracking function only references the item or `$index`, the compiler generates a pure arrow function as a constant references in the `repeaterCreate` instruction.
2. If the tracking function has references to properties outside of the `for` loop block, the compiler will rewrite those references to go through `this` and generate a function declaration. The runtime will `bind` the declaration to the current component instance so that the rewritten `this` references are resolved correctly.

Advanced tracking expression come with the following limitations to ensure the best possible performance:
1. They can only reference the item, `$index` and properties directly on the component instance. This means that there'll be an error when accessing this like local template variables and references. While we could get this to work, we would have to traverse the context tree at runtime which will degrade the performance of the loop, because it's a linear time operation that is performed on each comparison. Furthermore, allowing local references would require us re-evaluate the list when any one of them has changed.
2. Pipes aren't allowed inside the tracking function.
3. Object literals and pipes used inside the tracking expression will be recreated on each invocation.

PR Close #51618
2023-09-05 14:19:18 +00:00
Kristiyan Kostadinov
6ecafa3305 refactor(compiler): computed for loop variables exposed on the wrong scope (#51618)
Fixes that the computed for loop variables (e.g. $first and $last) were exposed on the parent scope instead of the for loop scope.

PR Close #51618
2023-09-05 14:19:18 +00:00
Kristiyan Kostadinov
75ab0bdf45 refactor(compiler): type check deferred when and prefetch when triggers (#51570)
Adds type checking support to the deferred `when` and `prefetch when` triggers.

PR Close #51570
2023-09-05 14:18:44 +00:00
Kristiyan Kostadinov
0c8917b348 refactor(compiler): type check contents of control flow blocks (#51570)
Adds type checking for the contents of `if`, `switch` and `for` blocks.

**Note:** this is just an initial implementation to get some basic type checking working and to figure out the testing setup. We'll need special TCB structures for this syntax so that we can support type narrowing.

PR Close #51570
2023-09-05 14:18:44 +00:00
Kristiyan Kostadinov
1ce9f0aff3 refactor(compiler): type check the contents of defer blocks (#51570)
Fixes that the contents of `defer` blocks weren't being type checked.

PR Close #51570
2023-09-05 14:18:44 +00:00
Matthieu Riegler
525acbb165 docs: remove NG6999 error page. (#51588)
`NGMODULE_VE_DEPENDENCY_ON_IVY_LIB` was a ViewEngine related error. This commit removes the doc page but keeps a redirection for older versions still throwing this error.

PR Close #51588
2023-08-31 17:30:57 +00:00
Joey Perrott
3bca9db4a5 fix(compiler-cli): remove unnecessary escaping in regex expressions (#51554)
Correct various Useless regular-expression character escape issues.

PR Close #51554
2023-08-29 21:52:33 +00:00
Joey Perrott
de2550d988 fix(compiler-cli): correct incomplete escaping (#51557)
Correct incomplete escaping and replace all instances of `

PR Close #51557
2023-08-29 19:48:25 +00:00
Kristiyan Kostadinov
685d01e106 perf(core): chain template instructions (#51546)
With the new control flow and defer blocks it'll be common for several template instructions to be declare one after another. These changes add support for chaining to the `template` instruction which will allow us to save some bytes.

PR Close #51546
2023-08-29 16:38:52 +00:00
Kristiyan Kostadinov
d83dfaa8ea refactor(compiler): generate for loop block instructions (#51514)
Adds the initial implementation to generate the instructions for the `for` loop block.

**Note:** the expressions we support in the `track` paramateter are currently limited to tracking by identity or index, or a specific property of the item. Supporting more advanced expression will require additional work that I'll do in a follow-up PR.

PR Close #51514
2023-08-29 16:38:22 +00:00
Dylan Hunn
ab0f9eeba5 refactor(compiler): Implement switch blocks in template pipeline (#51518)
`switch` blocks are part of the new control flow syntax. This commit adds support for processing them, and emitting the appropriate templates and conditional instructions.

PR Close #51518
2023-08-29 00:16:00 +00:00
Dylan Hunn
c2d859241b refactor(compiler): Enable additional passing tests (#51498)
Some additional tests were already passing.

PR Close #51498
2023-08-28 21:51:04 +00:00
Dylan Hunn
c013bff48a refactor(compiler): Support $event in host bindings (#51498)
Run the existing phase that deals with `$event` during host binding compilation.

PR Close #51498
2023-08-28 21:51:04 +00:00
Dylan Hunn
bca26b88b1 refactor(compiler): Generalize the ordering phase to also order create mode (#51498)
`syntheticHostListener` and `listener` have ordering dependencies. We reuse the existing ordering phase, and generalize it to also order create mode instructions.

PR Close #51498
2023-08-28 21:51:04 +00:00
Dylan Hunn
f13223b140 refactor(compiler): Support host animation events. (#51498)
Animation listeners on host bindings result in a special `syntheticHostListener` instruction. We can now emit this instruction.

Additionally, the naming phase for events has been slightly refactored to smoothly incorporate whether the event is from a host listener, as well as whether it is an animation listener.

PR Close #51498
2023-08-28 21:51:04 +00:00
Dylan Hunn
1ea8617cd2 refactor(compiler): Support host binding listeners (#51498)
We can now ingest host bindings listeners into the template pipeline, and process them using the pre-existing phases.

PR Close #51498
2023-08-28 21:51:04 +00:00
Dylan Hunn
5546cb3197 refactor(compiler): More closely match TDB binding ordering (#51498)
For host bindings, `TemplateDefinitionBuilder` seems to use a different binding ordering, in which style bindings come after all the property bindings. We approximate that by treating `hostProperty` differently from `property` in the ordering phase.

PR Close #51498
2023-08-28 21:51:04 +00:00
Dylan Hunn
cae01dae1b refactor(compiler): Support class and style attrs in host bindings (#51498)
The template pipeline is already capable of parsing and processing class and style attributes on templates. We now extend that functionality to host bindings.

The parser, for some reason, splits out class and style attributes into a `specialAttributes` field. We merge them back into the main attributes map, and allow the template pipeline to process them normally.

PR Close #51498
2023-08-28 21:51:04 +00:00
Dylan Hunn
d0b83b14be refactor(compiler): Backwards compatibility with TDB for host attributes (#51498)
TemplateDefinitionBuilder only extracts host attributes if they are text attributes. For example, `[attr.foo]="'my-value'"` is not extracted despite being a string literal, because it is not a text attribute.

PR Close #51498
2023-08-28 21:51:04 +00:00
Dylan Hunn
8f90630dc8 refactor(compiler): Support synthetic host property bindings. (#51498)
Host property bindings can be animation bindings, and should be ingested and emitted as such, as well as being processed by the renaming phase.

PR Close #51498
2023-08-28 21:51:04 +00:00
Dylan Hunn
0df7828637 refactor(compiler): Extract host binding static attributes to hostAttrs (#51498)
Host bindings can apply static attributes. These will be extracted to a `hostAttrs` field on the host binding function's metadata.

In order to achieve this, we add an `attributes` field to the host binding job. Then, we peform attribute exraction on host bindings. We finally populate the `attributes` field directly, instead of relying on a `consts` array.

PR Close #51498
2023-08-28 21:51:04 +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
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
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
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
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
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
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
Kristiyan Kostadinov
5212b47bbf refactor(compiler): introduce defer trigger instructions (#51315)
Adds the logic for generating the instructions for the various deferred triggers.

PR Close #51315
2023-08-11 06:55:13 -07:00
Kristiyan Kostadinov
79f9d49fad refactor(compiler): introduce defer block instructions (#51315)
Adds the logic for generating `{#defer}`, `{:placeholder}`, `{:loading}` and `{:error}` block instructions in the compiler.

PR Close #51315
2023-08-11 06:55:13 -07:00
Kristiyan Kostadinov
36b180ade4 refactor(compiler): implement conditional block AST (#51299)
Adds the AST for `if`, `else if` and `else` blocks.

PR Close #51299
2023-08-10 13:48:55 -07:00
Kristiyan Kostadinov
4424920f0b refactor(compiler): implement for block AST (#51299)
Adds the AST for `for` and `empty` blocks.

PR Close #51299
2023-08-10 13:48:55 -07:00
Kristiyan Kostadinov
31c6c5e944 refactor(compiler): implement switch block AST (#51299)
Adds the AST for `switch`, `case` and `default` blocks.

PR Close #51299
2023-08-10 13:48:55 -07:00
Payam Valadkhan
1eda1bdfcc refactor(compiler-cli): ctor dependencies in local compilation mode (#51089)
Ctor deps are added to the fctory function for all the angular classes: NgModule, Component, Pipe, Directive and Injectable

PR Close #51089
2023-08-08 13:58:48 -07:00
Payam Valadkhan
827e10ae0e refactor(compiler): add a factory for component dependencies in local compilation mode (#51089)
A factory generator function called "i0.ɵɵgetComponentDepsFactory" is added to generate a factory function for component dependencies. This function will use the deps tracker to calculate the component's dependencies.

For standalone components the component imports (if exists) will be passed to this function. Alternatively this function can grab the imports directly from the decorate, but such extraaction needs some runtime logic which overlapps with what the trait compiler is doing. So better to pass the imports directly to this function at compile time.

PR Close #51089
2023-08-08 13:58:48 -07:00
Payam Valadkhan
e26080be0b refactor(compiler-cli): ng module injector compilation in local mode (#51089)
In local mode the compiler combines the raw imports and exports and pass them to the injector definition as the imports field. It is not possible to filter out ng modules at compile time though, and it will be done in runtime.

Unit tests also added, and since that was the first time adding tests for local compilation some tweaks had to be made in order to disable diagnostics in local compilation mode in order for tests to run (such situation is also the case in real compilation where we ignore all teh diagnostics basically)

PR Close #51089
2023-08-08 13:58:48 -07:00
Andrew Kushnir
6f506cdff0 refactor(compiler): drop regular imports when symbols can be defer-loaded (#51171)
This commit updates the logic to drop regular imports when all symbols that it brings can be defer-loaded.
The change ensures that there is no mix of regular and dynamic imports present in a source file.

PR Close #51171
2023-08-04 11:28:07 -04:00
Kristiyan Kostadinov
d11548f2ef refactor(compiler): store deferred triggers as a map (#51262)
Stores the `deferred` block triggers as a map instead of an array, because triggers can't be duplicated and because having to search through an array will be inconvenient later on.

I've also added a `DeferredBlock.visitAll` method to deduplicate the logic from the various visitor implementations.

PR Close #51262
2023-08-04 11:27:39 -04:00