28282 Commits

Author SHA1 Message Date
Paul Gschwendtner 836530fdfd test: update symbol golden for defer
The golden JSON file is from  and doesn't support the virtual instruction
logic we've added in the signals branch. Surprisingly, this shows that something
is wrong with this test.
2023-10-13 10:37:48 +00:00
Paul Gschwendtner ca81661c95 fix(core): fix property_create instruction breaking binding to Zone targets
The property create instruction is currently failing to bind to Zone
targets if there is no advance call before the virtual instruction
that selects the intended element.
2023-10-12 17:29:21 +00:00
Paul Gschwendtner 5bf5cac714 refactor(core): rework queries to work with new signal graph API 2023-10-12 17:29:21 +00:00
Paul Gschwendtner 70861909a7 refactor(core): add more signal todos for input signal 2023-10-12 17:28:05 +00:00
Paul Gschwendtner f54cd057ad ci: enable github action tests for signals branch 2023-10-12 17:28:05 +00:00
Paul Gschwendtner 4ae88dc9be test: update compliance signal tests after template pipeline fixes/changes
The template pipeline now properly extracts the attribute constants,
so the older compliance tests from the signal branch need to be updated
to account for this new fix.
2023-10-12 17:28:05 +00:00
Paul Gschwendtner c8ac2b6d1e test: setup signal acceptance tests to also run with AOT compilation
This allows us to test the template pipeline TS emit (where we already
caught a bug using this), and also allows us to test the proper
recognition of e.g. `input`, `output`, `viewChild` etc- while also
testing type-checking.
2023-10-12 17:28:05 +00:00
Paul Gschwendtner 8151dd3cb6 fix(compiler): do not use constants for colocated shallow references
Currently the TS generated output (not JIT), breaks at runtime because
we emit all variables using the `Final` modifier. i.e. constants.

This breaks shallow references when we run our acceptance signal
tests using AOT.
2023-10-12 17:28:03 +00:00
Paul Gschwendtner 51ce1d6228 feat(compiler): support public aliases for signal output API 2023-10-12 17:27:39 +00:00
Paul Gschwendtner f79b106dfc 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-10-12 17:27:39 +00:00
Paul Gschwendtner 7504f24fe2 test: rework and enable outputs test to verify functionality 2023-10-12 17:27:39 +00:00
Pawel Kozlowski 63084b6502 feat(core): add runtime support for outputs in signal components
Runtime implementation is very simple - it adds the output function that
acts as an alias to the existing EventEmitter class constructor.
2023-10-12 17:27:39 +00:00
Paul Gschwendtner 1200ae9c6e test: update partial output golden for content queries 2023-10-12 17:27:39 +00:00
Paul Gschwendtner 0dbccabdf9 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-10-12 17:27:39 +00:00
Pawel Kozlowski 1d2f7545c5 feat(core): reactive content queries
Runtime part of the reactive content queries.
2023-10-12 17:27:39 +00:00
Pawel Kozlowski bf16d7e414 test(core): add test for QueryList.onDirty callback
Add a test verifying that the onDirty callback:
- does not fire initially;
- fires once when a query is marked dirty (even if there are
multiple setDirty notifications).
2023-10-12 17:27:39 +00:00
Pawel Kozlowski 6106fcf4c7 fix(core): adjust reactive query types
Improvements to the types signature in viewChild / viewChildren.
2023-10-12 17:27:39 +00:00
Paul Gschwendtner 3e01740e43 feat(compiler): support generating queries for signal components 2023-10-12 17:27:39 +00:00
Pawel Kozlowski 968700c5f9 refactor(core): rename queryCreate to viewQueryCreate
In the end we need to distinguish between view and content query
creation and need separate names for those instructions.
2023-10-12 17:27:39 +00:00
Paul Gschwendtner f108800804 test: update api golden for core for new query APIs 2023-10-12 17:27:39 +00:00
Pawel Kozlowski c77976d9aa feat(core): reactive queries
Initial runtime implementation of the reactive view queries
(in preparation for the compiler work).
2023-10-12 17:27:39 +00:00
Pawel Kozlowski 2c754081e1 fix(core): fix stringify logic for interpolated values
Make sure that null, undefined and NaN interpolated values
are rendered consistently with the current ivy approach:
- null and undefined are rendered as empty strings;
- NaN is rendered as-is.
2023-10-12 17:27:38 +00:00
Paul Gschwendtner 1a2a6659a0 feat: support property interpolation in signal components 2023-10-12 17:27:38 +00:00
Pawel Kozlowski 1067f8a439 test: fix signal tests after property binding changes
Property bindings are wrapped into computed now.
2023-10-12 17:27:38 +00:00
Pawel Kozlowski e94b474b96 refactor(core): fix lint issues
Fixing lint issues that I've just introduced...
2023-10-12 17:27:38 +00:00
Pawel Kozlowski 34f002db7e feat(core): introduce property interpolation and make DOM property bindings reactive
DOM bindings are wrapped into computed now so their values
are memoized. As the result expression in DOM bindings are
re-evaluated when a component is change-detected.
2023-10-12 17:27:38 +00:00
Paul Gschwendtner a0af416ca1 fix: variable optimization preserving unused nextContext calls due to listeners
With the recent changes for local refs, we now also generate all
variables in the create block.

This works overall, but we end up with incorrect variable optimization
because calls of `nextContext` in listener functions end up tricking
the optimization logic into thinking that the outer `nextContext` calls
in the create block are _relevant_ for the listener function body.

e.g.

```
if (create) {
  const _bla = nextContext();
  i0.listener(() => {
    restoreView();
    const _ctx1 = nextContext();
    /* do somth with _ctx1 */
  });
}
```

`_bla` can safely be removed here, even though a `ContextRead/Write` has
occurred inside the listener operation. We process listeners separately.
2023-10-12 17:27:38 +00:00
Paul Gschwendtner 6dc61179ca fix: do not generate pure functions for listeners
We recently changed the pure function code to look for
all operations in a view. This ended up causing pure functions
to be generated for expressions in listeners. This might be fine
but diverges from the existing TDB and breaks compliance tests.

Culprit commit: https://github.com/angular/angular/commit/a61e41c88049eb12a0b23b1e7fa49a16b0eb91d7
2023-10-12 17:27:38 +00:00
Paul Gschwendtner c09cace82b 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-10-12 17:27:38 +00:00
Paul Gschwendtner 6840f93f37 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-10-12 17:27:38 +00:00
Paul Gschwendtner 3f5e3001f4 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-10-12 17:27:38 +00:00
Pawel Kozlowski e5e405ee6e refactor(compiler): add required file header
Add required file header.
2023-10-12 17:27:37 +00:00
Pawel Kozlowski b263c00d36 test: add basic test for event listeners
Adding a passing test for a listener invocation
that changes signal value.
2023-10-12 17:27:20 +00:00
Pawel Kozlowski 3bd2fcd044 Revert "feat(core): propertyInterpolationCreate"
This reverts commit 2e3fe0747990647c5cfbba5429e90ed621b18e6e.

Based on the recent design discussion we are going to express property
interpolation as a computed function and reuse the propertyCreate
infrastructure.
2023-10-12 17:27:20 +00:00
Alex Rickabaugh 7feda88abb wip: support local references in signal property bindings
This commit adds support for local refs in signal property bindings, by
generating variables in the creation block. To implement this support:

* a new instruction shallowReference() is introduced, which is not tied to
  the current view context.
* variables are now generated for creation mode as well as update mode
* a new template pipeline pass (`phaseCreationVarColocation`) handles
  ordering of reference variable declaration and assignment in the creation
  block (guaranteeing references are only read after declarations).
2023-10-12 17:27:20 +00:00
Alex Rickabaugh f7265d34ac 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-10-12 17:26:52 +00:00
Paul Gschwendtner 5264c18b53 test: disable input signal initialization test
Still needs to be implemented and discussed.
2023-10-12 17:26:52 +00:00
Paul Gschwendtner 5ab3598746 test: update core API golden to add input API 2023-10-12 17:26:52 +00:00
Paul Gschwendtner f877b544a7 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-10-12 17:26:52 +00:00
Pawel Kozlowski f5edc3e9a8 feat(core): propertyInterpolationCreate
Skeleton of the propertyInterpolationCreate instruction.
2023-10-12 17:26:52 +00:00
Paul Gschwendtner 9bf377a424 build: fix lint errors 2023-10-12 17:26:52 +00:00
Pawel Kozlowski 0eced157a9 test: add failing tests for property interpolation
Adding failing tests for the property interpolation so we
keep those instructions on our radar.
2023-10-12 17:26:52 +00:00
Pawel Kozlowski df4196e63f refactor: fix lint issue
Minor refactor to fix the linting job.
2023-10-12 17:26:52 +00:00
Pawel Kozlowski 5dea0312d6 test: binding to a mix of zone and signal inputs
This commit adds a test for a case of a binding targetting
multiple inputs with the same name. Test passes for both
signal based components as well as a mix of zone and signal
based components.
2023-10-12 17:26:52 +00:00
Pawel Kozlowski 7b15e261ad test: enable passing tests after recent code changes
Enabling newly passing tests.
2023-10-12 17:26:51 +00:00
Alex Rickabaugh a59dcb52bd wip: one calculation for many input targets
Wrap bound expressions in `computed` where necessary to ensure all consumers
of a binding see the same value.
2023-10-12 17:26:51 +00:00
Paul Gschwendtner 6cd5dfa966 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-10-12 17:26:51 +00:00
Paul Gschwendtner 809a96e65d test: generate partial golden for signal compliance test 2023-10-12 17:26:51 +00:00
Paul Gschwendtner 2c6154fe14 test: ensure signal compliance test only runs with template pipeline 2023-10-12 17:26:51 +00:00
Paul Gschwendtner bdbb76f344 refactor: remove debug print for type check block 2023-10-12 17:26:51 +00:00