Commit Graph

2692 Commits

Author SHA1 Message Date
Paul Gschwendtner 8ef145fa1b feat(compiler): support public aliases for signal output API 2023-07-14 13:12:41 +00:00
Paul Gschwendtner 94f2daaa1c feat(compiler): support signal-based output API
* Detect and recognize outputs for type-checking and definition
  generation
* Add compliance tests & fake core infrastructure
* Add playground example
2023-07-14 13:12:41 +00:00
Paul Gschwendtner dc7882cf97 test: update partial output golden for content queries 2023-07-14 13:12:41 +00:00
Paul Gschwendtner 5f9bd59b14 feat(compiler): support signal based content queries
Compiler portion for supporting content queries in signal components.
This is based on the preparation work, for detecting such queries. See
previous commits.
2023-07-14 13:12:40 +00:00
Paul Gschwendtner e71e900708 feat(compiler): support generating queries for signal components 2023-07-14 13:12:40 +00:00
Paul Gschwendtner 0bf724f4d4 feat: support property interpolation in signal components 2023-07-14 13:12:40 +00:00
Paul Gschwendtner 5fa6ce3e61 WIP: Implement type-checking for signal inputs
New implementation of type-checking for signal inputs. Much simpler, and
without causing signficant type check block changes that would require
more changes to the language service completion logic / or rewrites of
more than 50+ handwritten code output tests for type check blocks.

See previous commits for other explored solutions.
2023-07-14 13:12:40 +00:00
Paul Gschwendtner d88ac6db12 WIP: Revert initial type-checking approach and completion adjustments
We will attempt a new solution that is not as invasive- and integrates
better with the constraints of the language service.
2023-07-14 13:12:40 +00:00
Paul Gschwendtner 46efe02e48 WIP: fixing tests and completion with signal based type checking
NOTE: This is very experimental and manual type check block code is not
updated. All of this complexity arises from the fact of attempting to
support bindings where they go to the same directive with multiple
inputs of the same name.

Potentially we can deprecate this behavior for input signal based
components and avoid this complexity. Alternative solution is to simply
repeat expression diagnostics if a binding goes to two same fields.
2023-07-14 13:12:39 +00:00
Paul Gschwendtner cd76360ea8 fixup! refactor(compiler): support o.BinaryExpression for assignments
Fix babel factory for linker
2023-07-14 13:12:39 +00:00
Alex Rickabaugh c402bb81f5 refactor(compiler): support o.BinaryExpression for assignments
Previously the compiler output AST did not support using
`o.BinaryExpression` for assignments (as TypeScript does). Instead
`o.WriteVarExpr` is defined, which only allows writing to string named
variables.
2023-07-14 13:12:39 +00:00
Paul Gschwendtner 193a32e5c1 WIP: fix regressions in type checking after signal changes
There was an interesting issue that surfaced in the type checking
tests. Previously an input was type-checked using an expression like:

```ts
myDir.input = myrDir.input2 = userExpr
```

Note how the user expression was only specified once. With signals for
type-checking we cannot do this because both inputs cannot use the same
expression unless we extract it into a separate variable. This is what
this commit implemements.

```ts
const x1 = userExpr;
toWriteableSignal(myDir.input).set(x1);
toWriteableSignal(myDir.input2).set(x2);
```

Note: Even if no input is bound, due to e.g. the `inputs` decorator
field being used and no statically analyzable class member being
discoverable- the user expression should be *evaluated*. This was
something we broke with the initial signal input prototyping.
2023-07-14 13:12:39 +00:00
Pawel Kozlowski 0e96528a70 refactor: fix lint issue
Minor refactor to fix the linting job.
2023-07-14 13:12:39 +00:00
Paul Gschwendtner 71e8bd8791 test: support signal library in compliance test fake_core package
Compliance tests do not depend on the real typings for
`@angular/core`, but rather a fake core package is used.

We want to be able to write compliance tests using signals, so we should
add some rough types to the fake core package. This will also be useful
in `fake_core` for type checking tests.
2023-07-14 13:12:39 +00:00
Paul Gschwendtner fcf9edbc78 test: generate partial golden for signal compliance test 2023-07-14 13:12:38 +00:00
Paul Gschwendtner 626d3ab586 test: ensure signal compliance test only runs with template pipeline 2023-07-14 13:12:38 +00:00
Paul Gschwendtner 3a607f51d6 refactor: remove debug print for type check block 2023-07-14 13:12:38 +00:00
Paul Gschwendtner ebf646a9c9 fixup! WIP: generate propertyCreate instructions in template pipeline
Fix expression lexical read transforms
2023-07-14 13:12:38 +00:00
Paul Gschwendtner 59d278c07c WIP: setup template pipeline acceptance tests on CI and base setup 2023-07-14 13:12:38 +00:00
Pawel Kozlowski 7e1de8cb6a refactor: making CI green-ish
Would be great to keep CI green, making changes in this direction.
2023-07-14 13:12:37 +00:00
Paul Gschwendtner c7bede629b WIP: type checking for signal inputs 2023-07-14 13:11:53 +00:00
Paul Gschwendtner 992f51bc6d WIP: Discover input class members in directive shared code. No type-chechking yet. 2023-07-14 13:11:53 +00:00
Payam Valadkhan 3b78d068ea refactor(compiler-cli): basic local compilation for components (#50545)
A minimal change to full compilation mode to work in local mode. Now compiler can compile components without ctor injections, though the compiled code missing the following items which will be added in subsequent commits:
* it does not produce `dependencies` for component definition.
* it fails if component has ctor injection

PR Close #50545
2023-07-13 09:34:53 -07:00
Payam Valadkhan 68fd99fad3 refactor(compiler-cli): Trait compiler workflow for local compilation mode (#50545)
The compiler will only include analysis and compile phases in local mode. Also a new `compileLocal` method is added to the annotation handler for local compilation.

This commit makes no change to the full/partial compilation code paths.

PR Close #50545
2023-07-13 09:34:53 -07:00
Charles Lyding 5bd530ab32 refactor(compiler-cli): add internal compiler option to control NgModule selector scope emit (#51007)
An internal compiler option named `supportJitMode` is now available for use by the Angular CLI.
This option currently controls the emit of NgModule selector scope information. This emitted
information is only needed in AOT mode when an application also uses JIT. However, AOT mode
combined with JIT mode is not currently supported nor will work in the Angular CLI. With
the Angular CLI, JIT mode is only supported if the entire application is built in JIT mode.
Without this option, the CLI needs to manually perform a code transform to remove the information
and also replicate TypeScript's import eliding. This is can be a complicated operation and must
be continually kept up to date with any changes to both the Angular compiler and TypeScript.
The introduction of this new option alleviates these concerns while also removing several build
time actions that would otherwise need to be performed on every application build.

PR Close #51007
2023-07-13 09:32:11 -07:00
Dylan Hunn 875851776c refactor(compiler): Generate attribute and attributeInterpolate instructions in template pipeline (#50818)
This commit adds the ability to generate attribute instructions as a result of property bindings such as `[attr.foo]='bar'` or `attr.foo='{{bar}}'`. "Singleton" interpolations, such as the previous example, will also be transformed into a simple `attribute` instruction.

PR Close #50818
2023-07-10 07:17:18 -07:00
Paul Gschwendtner 8a0c5c710a refactor: improve type safety of interpolation AST (#50903)
Instead of using `any`, we should use the actual types that
are available from the parser.

PR Close #50903
2023-07-10 07:08:28 -07:00
Payam Valadkhan 5724dbc82d test(compiler-cli): add compliance tests for NgModule only scenarios in local mode (#50577)
Reused the existing compliance tests for full compilation.

PR Close #50577
2023-06-30 11:38:36 -07:00
Payam Valadkhan c1d46b8c08 refactor(compiler-cli): add local option to compliance test infra (#50577)
The option 'local compile' is added for the test cases, and the locally compiled file for an input `abc.ts` is compared by default with the file `abc.local.js`. This allows to use the same input `abc.ts` for both full compilation (compared with `abc.js`) and local compilation (compared with `abc.local.js`). An example is provided in the next commit when compliance tests are added for the NgModule local compilation.

PR Close #50577
2023-06-30 11:38:35 -07:00
Payam Valadkhan a15a56cb5d refactor(compiler): add a new interface for NgModule metadata to t rebase be used in local compilation mode (#50577)
The new interface is discrete-unioned with the existing interface to cover the cases for local and global (i.e., full and partial) compilation modes.

This change of interface required some adjustmeents cross repo which explains the changes made to other files.

PR Close #50577
2023-06-30 11:38:35 -07:00
Payam Valadkhan 2034d8db27 refactor(compiler-cli): circuit out reference resolving in NgModule annotation handler in local compilation mode (#50577)
All attempts related to obtaining R3Reference for bootstrap, imports, exports and declarations are cut in local compilation mode.

This will allow the analysis to pass without any error diagnostics, but the result is a quite empty meta info. Next commits will add data to the meta so that the NgModule can be compiled more accurately.

PR Close #50577
2023-06-30 11:38:35 -07:00
Dylan Hunn 29bf476bfe refactor(compiler): Generate temporary variable assignments when function calls appear in a safe-access expression. (#50688)
The expression `a()?.b` should expand into `(tmp = a()) === null ? null : tmp.b`, in order to avoid calling the function `a()` twice.

This commit modifies the null-safe-expansion algorithm to emit temporary assignments, and provides the reification code to actually generate the declarations, assignments, and reads.

Note also that, with our bottom-up algorithm, there are some tricky cases when a function call exists inside an indexed access, such as `f1()?.[f2()?.a]?.b`. We add some special logic to avoid generating a double-assignment to the temporary storing the result of `f2()`.

Finally, there are opportunities to reuse the same temporary in expressions like `a?.[f()]?.[f()]`. We save this for the next commit.

PR Close #50688
2023-06-29 12:54:23 -07:00
Paul Gschwendtner e699f1a75d build: allow for compliance specs only using template pipeline (#50835)
When writing signal compliance tests, we need to limit these to only the
template pipeline.

PR Close #50835
2023-06-26 13:36:06 -07:00
Miles Malerba 060830e936 refactor(compiler): add support for interpolation in style mappings (#50489)
Add support for interpolation in style map bindings in the template
pipeline

PR Close #50489
2023-06-26 13:09:25 -07:00
Miles Malerba 3c1feedff8 refactor(compiler): add support for interpolation in style properties (#50489)
Add support for interpolation in style property bindings in the template
pipeline

PR Close #50489
2023-06-26 13:09:24 -07:00
Miles Malerba 3627e4c4e7 refactor(compiler): add support for empty bindings (#50489)
Add support for empty bindings in the template pipeline

PR Close #50489
2023-06-26 13:09:24 -07:00
Miles Malerba ebe10dd68f refactor(compiler): add support style property units (#50489)
Add support for specifying units in style property bindings in the
template pipeline

PR Close #50489
2023-06-26 13:09:24 -07:00
Miles Malerba b289332f2c refactor(compiler): add support for style map bindings (#50489)
Add support for style map bindings in the template pipeline

PR Close #50489
2023-06-26 13:09:24 -07:00
Miles Malerba 1b038945ee refactor(compiler): add support for style property bindings (#50489)
Add support for style property bindings in the template pipeline

PR Close #50489
2023-06-26 13:09:24 -07:00
Angular Robot bb617f580c build: update babel dependencies (#50509)
See associated pull request for more information.

PR Close #50509
2023-06-21 11:44:59 -07:00
Charles Lyding 64745a89b2 refactor(compiler-cli): remove unused HandlerFlags enum (#50604)
The `HandlerFlags` enum is a leftover remnant of ngcc and is no longer used.

PR Close #50604
2023-06-20 13:01:48 -07:00
Charles Lyding 47cc56858f refactor(compiler-cli): add internal compiler option to control class metadata emit (#50604)
An internal compiler option named `supportTestBed` is now available for use by the
Angular CLI. This option currently controls the extraction and emit of Angular class
metadata. This emitted information is only needed in AOT mode when using certain
TestBed APIs. However, AOT mode is currently not available for unit testing within
the Angular CLI. As a result, the metadata is not used within CLI generation applications
and in particular production applications. Without this option, the CLI needs to
manually perform a code transform to remove the metadata and also replicate TypeScript's
import eliding. This is can be a complicated operation and must be continually kept
up to date with any changes to both the Angular compiler and TypeScript. The introduction
of this new option alleviates these concerns.

PR Close #50604
2023-06-20 13:01:48 -07:00
Paul Gschwendtner cec5cd6eb5 test: mark ngtsc test target as flaky (#50718)
A larger investigation on why this is flaky is needed. Currently the
test is flaky with around 77% sucess rate and negatively impacts team
productivity. Subjectively, as reported by team members this it's much
more flaky than a success rate of 77%.

PR Close #50718
2023-06-15 15:34:43 +02:00
Paul Gschwendtner 12bad6576d fix(compiler-cli): libraries compiled with v16.1+ breaking with Angular framework v16.0.x (#50714)
If a library is compiling with Angular v16.1.0, the library will break
for users that are still on Angular v16.0.x. This happens because the
`DirectiveDeclaration` or `ComponentDeclaration` types are not expecting
an extra field for `signals` metadata. This field was only added to the
generic types in `16.1.0`- so compilations fail with errors like this:

```
Error: node_modules/@angular/material/icon/index.d.ts:204:18 -
  error TS2707: Generic type 'ɵɵComponentDeclaration' requires between 7 and 9 type arguments.
```

To fix this, we quickly roll back the code for inserting this metadata
field. That way, libraries remain compatible with all v16.x framework
versions.

We continue to include the `signals` metadata if `signals: true` is set.
This is not public API anyway right now- so cannot happen- but imagine
we expose some signal APIs in e.g. 16.2.x, then we'd need this metadata
and can reasonably expect signal-component library users to use a more
recent framework core version.

PR Close #50714
2023-06-14 16:27:59 +02:00
Matthieu Riegler 8468df19c9 fix(migrations): Prevent a component from importing itself. (#50554)
This commit fixes the migrations for recursive components.

fixes #50525

PR Close #50554
2023-06-14 15:44:35 +02:00
Paul Gschwendtner 82adc86353 refactor(compiler-cli): fix incremental compilation breaking when running compiler through closure (#50673)
If the compiler CLI is running through closure compiler, the trait
decorator handlers are converted from classes to functions as ES5
is picked as default output target for the bundled version.

The problem is that currently all trait handlers end up having the
same `name`. i.e. an empty string, and therefore adopting previous
traits from a previous build iteration result in the incorrect handler
being used for e.g. registrering, compiling etc- causing
ambiguous/confusing errors down the line in other parts.

We can look into changing the output target in the future, but even
then we are safer using an actual literal due to property renaming.

```$$closure$$NgModuleDecoratorHandler = function() {}`.

It is is questionable if we should just simply NOT run the compiler
through JSCompiler.

PR Close #50673
2023-06-14 15:26:00 +02:00
Matthieu Riegler 595d8b54c0 refactor(compiler-cli): deprecate allowEmptyCodegenFiles (#50379)
The `allowEmptyCodegenFiles` is not used anymore.

PR Close #50379
2023-06-14 11:19:46 +02:00
Dylan Hunn 88962b72a9 refactor(compiler): Support safe property reads and keyed reads. (#50594)
Angular's null-safe access operators differ from Javascript's built-in semantics, in that they short-circuit to `null` instead of `undefined`. This necessitates providing a custom transformation, instead of relying on Typescript or Javascript itseld.

The old TemplateDefinitionBuilder uses a top-down approach based on the Visitor pattern, in which it recursively extracts the left-most safe access, and hoists it to a null check at the top. See `expression_converter.ts` for details.

In this commit, we replace that approach with a new bottom-up algorithm, as part of the template pipeline. This requires an intermediate expression type to represent the not-yet-expanded ternary operators, and is split into its own pass.

Null-safe function calls are not yet implemented, since they will rely on a future temporary variable allocation pass.

Co-authored-by: Alex Rickabaugh <alxhub@users.noreply.github.com>

PR Close #50594
2023-06-13 18:59:43 +02:00
Miles Malerba 15ab146e6c refactor(compiler): improve handling of bindings and attributes (#50664)
Refactor attribute and property binding ingestion and add an attribute extraction phase

Co-authored-by: Alex Rickabaugh <alxhub@users.noreply.github.com>
Co-authored-by: Dylan Hunn <dylhunn@users.noreply.github.com>

Only add the value to the ElementAttributes map for style and attribute kinds

Other kinds should not have their value represented in the consts array

Add missing attribute ingesiton for templates

Unify how template and element bindings are ingested

This resolves the issue of missing listener attributes on templates. In
order to avoid emitting extraneous instructions, listener ops on
templates are stripped in the attribute extraction phase instead.

Handle different binding types separately in ingest

Cleanup code and comments

Disable test that fails on new explicit error.

Previously the test was passing because ingestPropertyBinding treated
attribute bindings as normal bindings which happened to be ok for the
particular test. Now there's an explicit error that attrbiute bindings
aren't yet handled which causes the test to fail

Address feeback

PR Close #50664
2023-06-13 18:34:58 +02:00
Miles Malerba 9429f96f62 test(compiler): Prevent back-sliding on already passing template pipeline tests (#50582)
Add a flag to disable specific tests when testing the template pipeline

Mark the currently failing tests

Add the template pipeline tests to CI

Update package.json

Co-authored-by: Paul Gschwendtner <paulgschwendtner@gmail.com>

PR Close #50582
2023-06-12 18:25:41 +02:00