Commit Graph

1435 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 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 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
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 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 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
Pawel Kozlowski 09ad1ef5a2 refactor(compiler): add required file header
Add required file header.
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
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
Paul Gschwendtner ebf646a9c9 fixup! WIP: generate propertyCreate instructions in template pipeline
Fix expression lexical read transforms
2023-07-14 13:12:38 +00:00
Alex Rickabaugh 05ecc619fc wip: allocate vars for PropertyCreateOp
This commit adds the `ConsumesVarsTrait` to `PropertyCreateOp` which causes
vars to be counted for use in the virtual instructions it might add. This
allows the DOM test to pass.
2023-07-14 13:12:38 +00:00
JoostK 080bdfa77f test: allow signal component test to pass 2023-07-14 13:12:38 +00:00
Alex Rickabaugh 977bd97717 refactor(compiler): only reference a view via a variable if it's not ctx
Previously the template pipeline would prefer to use a local variable
definition in favor of ctx. This commit improves the logic to prefer `ctx`
for the root view even if a variable for the context is available.
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 f556b29d05 fixup! WIP: generate propertyCreate instructions in template pipeline
More work
2023-07-14 13:12:37 +00:00
Paul Gschwendtner a34a479ee5 WIP: generate propertyCreate instructions in template pipeline 2023-07-14 13:12:35 +00:00
Paul Gschwendtner f0c9eeceba WIP: create new instruction "propertyCreate" 2023-07-14 13:11:53 +00:00
Kristiyan Kostadinov b14a78ebb0 refactor(compiler): implement block syntax in html ast (#50953)
⚠️Disclaimer⚠️ this PR implements syntax that is still in an open RFC. It will be adjusted once the RFC is closed.

These changes implement the `BlockGroup` and `Block` AST nodes that will then be used to generate instructions based on the new syntax. A `BlockGroup` is a container for `Block` instances. The first block of a block is always implicit and required while any subsequent blocks are optional.

PR Close #50953
2023-07-13 09:32:53 -07:00
Daniel Puckowski c27a1e61d6 feat(compiler): scope selectors in @scope queries (#50747)
make sure selectors inside @scope queries are correctly scoped

PR Close #50747
2023-07-11 08:29:53 -07:00
Kristiyan Kostadinov 29aaded0c3 refactor(compiler): introduce block parsing in lexer (#50895)
⚠️Disclaimer⚠️ this PR implements syntax that is still in an open RFC. It will be adjusted once the RFC is closed.

These changes extend the lexer to recognize the concepts of a block group (`{#foo paramA; paramB}{/foo}`) and a block (`{:foo paramA; paramB;}`) which will be useful later on for the control flow and defer proposals. Block groups can be used anywhere and require a closing tag while block can only be used inside of a block.

The idea is that in the next PRs the markup AST will be expanded to have some more specialized node like `ConditionalBlock` or `DeferBlock` which will then be turned into instructions.

PR Close #50895
2023-07-11 08:21:48 -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 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
Alex Rickabaugh 57c9399ca6 refactor(compiler): save/restore view when listeners read references (#50834)
Previously, the template pipeline save/restore view logic only added the
save/restore operation in listeners inside embedded views. However, this
operation is also needed if local refs are accessed within a listener body.

This commit updates the logic to detect more accurately whether save/restore
is needed.

PR Close #50834
2023-06-30 11:33:27 -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
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
Paul Gschwendtner f77bd0a2bd refactor: fix lint warning in compiler code by adding explicit override (#50772)
We have a lint rule configured that enforces that any abstract member
implementation uses an explicit `override` identifier. This ensures that
downstream classes will have errors if the parent abstract class
suddenly removes the abstract member.

The lint rule, living in the dev-infra repository, occasionally does
miss some places due to a temporary TS version mismatch that causes
syntax kind indices to be different. Looks like we are now matching
again and there is a new lint failure that got introduced recently. This
commit fixes that error.

PR Close #50772
2023-06-20 17:20:50 +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 ad28cddd41 refactor(platform-browser): replace our own toBeAnInstanceOf with toBeInstanceOf (#50661)
There is no need to maintain that matcher since jasmine provides its own !

PR Close #50661
2023-06-14 10:58:04 +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
Dylan Hunn 1c635be80c refactor(compiler): Support non-null assertions. (#50594)
Because non-null assertions don't affect the generated code, we can just drop them.

PR Close #50594
2023-06-13 18:59:43 +02:00
Dylan Hunn 2c71920c2d refactor(compiler): Add initial support for nullish coalescing. (#50594)
Create a pass that expands nullish coalescing operators into null checks.

This is not yet finished because we need to emit temporary variable assignments, which we will do using a future temporary variable allocation pass. Also, TemplateDefinitionBuilder is a bit quirky, and we still need to exactly match its behavior.

Nevertheless, this is good enough to prevent the diffs from getting ruined as a result of nullish coalescing operations.

PR Close #50594
2023-06-13 18:59:43 +02:00
Dylan Hunn 70db25f206 refactor(compiler): Allow expressions to be deeply cloned. (#50594)
It is sometimes useful to clone an expression tree, in order to copy it and mutate it in a phase, without affecting other subtrees due to the copy-by-reference.

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
Kristiyan Kostadinov 4e663297c5 fix(compiler): error when reading compiled input transforms metadata in JIT mode (#50600)
Fixes an error that surfaced in #50580 where the compiler was throwing an error in JIT mode when reading the result of `compileDirectiveDeclaration`. It is caused by the fact that input transform functions were being passed around directly, instead of being wrapped in an AST node.

PR Close #50600
2023-06-07 12:47:16 -07:00
Alex Rickabaugh 9847085448 refactor(compiler): support property interpolation in the template pipeline (#50118)
This commit adds support for interpolated properties to the template
pipeline.

PR Close #50118
2023-06-01 08:46:08 -07:00
Alex Rickabaugh 6984431dde refactor(compiler): write expressions in the template pipeline (#50118)
This commit adds ingest and transformation support for property writes and
keyed writes to the template pipeline.

PR Close #50118
2023-06-01 08:46:08 -07:00
Alex Rickabaugh a48c5f72a6 refactor(compiler): support pipes in the template pipeline (#50118)
This commit adds end-to-end support for pipes in the template pipeline. This
support works across multiple steps:

1. Pipes are first ingested as `ir.PipeBindingExpr`s during the ingest step.

2. A "pipe creation" phase inserts operations to instantiate each required
pipe, based on the presence of those `ir.PipeBindingExpr`s.

3. A "variadic pipe" phase transforms pipes with more than 4 arguments into
variadic pipe bindings, which use a literal array argument. This literal
array will be later memoized into a pure function invocation.

4. A special phase (`phaseAlignPipeVariadicVarOffset`) reconciles a
difference in variable slot assignment logic between the template pipeline
and the `TemplateDefinitionBuilder`, to ensure that the pipeline output can
pass the existing tests. This phase should not affect runtime semantics and
can be dropped once matching output is no longer necessary.

5. Reification emits pipe instructions based on the argument count.

PR Close #50118
2023-06-01 08:46:07 -07:00
Alex Rickabaugh cc51122c52 refactor(compiler): fix insertBefore ownership logic (#50118)
The logic for `insertBefore` in template pipeline operation lists has a bug
when inserting at the end of a list. This commit fixes the safety assertions
to be more accurate.

PR Close #50118
2023-06-01 08:46:07 -07:00