Commit Graph

27506 Commits

Author SHA1 Message Date
Paul Gschwendtner c4b6d474f8 WIP STYLING: temp change to fix styling template pipeline emit 2023-07-14 15:52:38 +00:00
Paul Gschwendtner 78efc406ba WIP STYLING: improve comment correctness styling 2023-07-14 15:30:48 +00:00
Paul Gschwendtner c277e88b22 WIP STYLING: styling findings/reversing 2023-07-14 15:30:45 +00:00
Paul Gschwendtner 574b1c276d 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-07-14 13:12:41 +00:00
Paul Gschwendtner 40eb5e3207 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-07-14 13:12:41 +00:00
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 ffc61749ff test: rework and enable outputs test to verify functionality 2023-07-14 13:12:41 +00:00
Paul Gschwendtner f70d80c8c7 refactor(compiler): properly sanitize identifier names in template pipeline
Currently, a listener on an element containing a dash, will result in
runtime errors because the function name will be generated using a dash.

e.g.

```
function MyApp_Template_some-comp_bla_0() {}
```

throwing with a syntax error due to the dash. We fix this by re-using
the sanitize identifier function from the current template definition
builder.
2023-07-14 13:12:41 +00:00
Pawel Kozlowski a4cb2e671c 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-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
Pawel Kozlowski cfd466dfbb feat(core): reactive content queries
Runtime part of the reactive content queries.
2023-07-14 13:12:40 +00:00
Pawel Kozlowski 61ce057a09 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-07-14 13:12:40 +00:00
Pawel Kozlowski 8dc6c9fe22 fix(core): adjust reactive query types
Improvements to the types signature in viewChild / viewChildren.
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
Pawel Kozlowski 1168fd585f fixup! refactor(core): rename queryCreate to viewQueryCreate 2023-07-14 13:12:40 +00:00
Pawel Kozlowski 18ea007390 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-07-14 13:12:40 +00:00
Paul Gschwendtner bd23af0639 test: update api golden for core for new query APIs 2023-07-14 13:12:40 +00:00
Pawel Kozlowski 6b0e1c7703 feat(core): reactive queries
Initial runtime implementation of the reactive view queries
(in preparation for the compiler work).
2023-07-14 13:12:40 +00:00
Pawel Kozlowski 6b89ce9e27 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-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
Pawel Kozlowski 7acf163f51 test: fix signal tests after property binding changes
Property bindings are wrapped into computed now.
2023-07-14 13:12:40 +00:00
Paul Gschwendtner 6808375e50 ci: send test job failures to reactivity channel 2023-07-14 13:12:40 +00:00
Pawel Kozlowski 97d6781be7 refactor(core): fix lint issues
Fixing lint issues that I've just introduced...
2023-07-14 13:12:40 +00:00
Pawel Kozlowski f12e8e3ea2 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-07-14 13:12:40 +00:00
Paul Gschwendtner f5638c25e6 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-07-14 13:12:40 +00:00
Paul Gschwendtner d82eb27f69 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-07-14 13:12:40 +00:00
Paul Gschwendtner 3b5218b768 ci: setup initial slack notifications for test failures in signal branch
Note: only going into the dev-infra channel for now until we get
everything green to avoid spam.
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
Pawel Kozlowski 09ad1ef5a2 refactor(compiler): add required file header
Add required file header.
2023-07-14 13:12:39 +00:00
Pawel Kozlowski 48f4f86835 test: add basic test for event listeners
Adding a passing test for a listener invocation
that changes signal value.
2023-07-14 13:12:39 +00:00
Pawel Kozlowski 183c92baed 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-07-14 13:12:39 +00:00
Alex Rickabaugh e03ccb60ed 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-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 0a7a8e496e test: disable input signal initialization test
Still needs to be implemented and discussed.
2023-07-14 13:12:39 +00:00
Paul Gschwendtner 779e1d872f test: update core API golden to add input API 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 41f8584aad feat(core): propertyInterpolationCreate
Skeleton of the propertyInterpolationCreate instruction.
2023-07-14 13:12:39 +00:00
Paul Gschwendtner 4b8e6b36ab build: fix lint errors 2023-07-14 13:12:39 +00:00
Pawel Kozlowski 4c58b2f8cf test: add failing tests for property interpolation
Adding failing tests for the property interpolation so we
keep those instructions on our radar.
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
Pawel Kozlowski 1d1338fced 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-07-14 13:12:39 +00:00
Pawel Kozlowski 1344da62ad test: enable passing tests after recent code changes
Enabling newly passing tests.
2023-07-14 13:12:39 +00:00
Alex Rickabaugh 0c821b28f3 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-07-14 13:12:39 +00:00
Alex Rickabaugh ebef1a592a wip: ignore dep polling when input signals change their backing
Previously, input signals had a bug where when their backing computation or
value would change, it would notify consumers, but consumers would poll the
input signal to check if its value really changed. This polling operation
would transitively poll the input signal's previous dependencies, which of
course would report that they hadn't changed.

This commit adds logic in the `InputSignalImpl` to skip dependency polling
whenever the signal's backing computation or value changes, until that value
is read for the first time.
2023-07-14 13:12:39 +00:00
Paul Gschwendtner 4c97f56223 fixup! wip: specialize virtual instructions
Fix bundle size tests after core changes for virtual update
2023-07-14 13:12:39 +00:00