Commit graph

1426 commits

Author SHA1 Message Date
Kristiyan Kostadinov
76d22ae752 refactor(compiler): add defer trigger parsing (#51050)
Adds the logic to parse the `when` and `on` triggers in a deferred block.

PR Close #51050
2023-07-17 21:05:47 +00:00
Kristiyan Kostadinov
9e61616ffe refactor(compiler): introduce deferred block AST (#51050)
Adds the logic to create `defer`-specific AST nodes from the generic HTML `BlockGroup` and `Block`. The logic for parsing the triggers will be in the next commit.

PR Close #51050
2023-07-17 21:05:47 +00:00
Miles Malerba
f1cb971645 refactor(compiler): consolidate renaming logic (#50805)
Moves the property name normalization logic under the naming phase

PR Close #50805
2023-07-17 17:03:57 +00:00
Miles Malerba
154b695d6e refactor(compiler): add attribute bindings to ordering algorithm (#50805)
Adds attribute and attribute interpolation bindings to the ordering
algorithm that decides the order of various property, style, and
attribute ops.

PR Close #50805
2023-07-17 17:03:57 +00:00
Miles Malerba
3a0e091468 refactor(compiler): fix var counting for style bindings (#50805)
Use the correct number of var slots for style and class bindings.

PR Close #50805
2023-07-17 17:03:57 +00:00
Miles Malerba
afd2fd8681 refactor(compiler): ensure correct ordering of properties and attributes (#50805)
Ensures that all property and attribute ops are ordered consistently
regardless of the order they appear in the template. This ensures
correct precedence (e.g. `[style.color]="'#000'"` awlays wins out over
`[style]="{color: '#fff'}"`)

PR Close #50805
2023-07-17 17:03:57 +00:00
Miles Malerba
03e6dc3f28 refactor(compiler): normalize style prop binding names (#50805)
Normalizes style property names in bindings by converting them to
kebab-case and stripping off `!important`

PR Close #50805
2023-07-17 17:03:57 +00:00
Miles Malerba
a35e3799f3 refactor(compiler): make style and class properties chainable (#50805)
Makes the stylePropInterpolate and classProp functions chainable by the
compiler

PR Close #50805
2023-07-17 17:03:57 +00:00
Miles Malerba
2fb5a847ca refactor(compiler): fix single argument class and style interpolations (#50805)
Single argument class and style interpolations (e.g.
`style.color="{{color}"`) should be converted to standard class and
property operations with no interpolation (e.g. `[style.color]="color")

PR Close #50805
2023-07-17 17:03:57 +00:00
Miles Malerba
2f7072dc3f refactor(compiler): add support for class property bindings (#50805)
Adds support for bindings of the form `[class.some-class]="isActive"`

PR Close #50805
2023-07-17 17:03:57 +00:00
Miles Malerba
021025964a refactor(compiler): add support for class map interpolation bindings (#50805)
Adds support for bindings of the form `class="static {{dynamic}}"`

PR Close #50805
2023-07-17 17:03:57 +00:00
Miles Malerba
7e5e37af36 refactor(compiler): add support for class map bindings (#50805)
Adds support for bindings of the form `[class]="classActiveMap"`

PR Close #50805
2023-07-17 17:03:57 +00:00
Paul Gschwendtner
f15b24de04 refactor(compiler): properly sanitize identifier names in template pipeline (#50946)
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.

PR Close #50946
2023-07-14 19:48:49 +00:00
Matthieu Riegler
7b23d4de8c refactor(compiler): use globalThis for global (#50063)
`globalThis` is now available on every runtime supported by Angular

PR Close #50063
2023-07-14 18:32:01 +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
Alex Rickabaugh
803d7dc01d refactor(compiler): convert conditional ast in template pipeline (#50118)
This commit adds support for ternary expressions in the ingest operation of
the template pipeline.

PR Close #50118
2023-06-01 08:46:07 -07:00
Alex Rickabaugh
35227049a1 refactor(compiler): purify literal arrays and maps in template pipeline (#50118)
This commit transforms literal arrays and maps within expressions in the
template pipeline into `ir.PureFunctionExpr` expressions, in order to
memoize the allocation of objects and arrays inside the update pass of
change detection.

PR Close #50118
2023-06-01 08:46:07 -07:00
Alex Rickabaugh
a56726c069 refactor(compiler): transform all expressions in the template pipeline (#50118)
Previously the helper operations for transforming expressions in the
template pipeline would only operate against `ir.Expression`s. This commit
changes them to process `o.Expression`s instead, paving the way to use them
for transformations of native expressions in addition to IR expressions.

PR Close #50118
2023-06-01 08:46:07 -07:00
Alex Rickabaugh
1b37dcda61 refactor(compiler): add pure function support to the template pipeline (#50118)
This commit adds support for generating pure functions in the output
`ConstantPool` based on `ir.PureFunctionExpr`s. Note that nothing yet
generates these pure function forms - in the future they will be used both
in the implementation of the `pipeBindV` instruction as well as literal
arrays and maps in expressions.

PR Close #50118
2023-06-01 08:46:07 -07:00
Alex Rickabaugh
1928cd82d9 refactor(compiler): add ConstantPool to template pipeline compilations (#50118)
This commit adds the `ConstantPool` to `ComponentCompilation`, making it
available to all phases of the template pipeline. Constant extraction is a
common operation in pipeline phases.

PR Close #50118
2023-06-01 08:46:06 -07:00
Alex Rickabaugh
11469b58c3 refactor(compiler): add shared constant concept to ConstantPool (#50118)
This commit adds a "shared constant" concept to the `ConstantPool`. This
is a generalization of the `LiteralFactory` concept the pool previously
supported. For stability's sake, the existing concept isn't modified, but
could be unified in the future.

PR Close #50118
2023-06-01 08:46:06 -07:00
Alex Rickabaugh
93c9e9d456 refactor(compiler): add UsesVarOffset trait to template pipeline (#50118)
This commit introduces a new trait `UsesVarOffset` for expressions which
consume variable slots and thus need an offset into the variable slot space
to locate their slots.

PR Close #50118
2023-06-01 08:46:06 -07:00
Alex Rickabaugh
8dc2029012 refactor(compiler): generalize interpolation calling for v-arg functions (#50118)
The template pipeline implements variadic instruction generation for text
node interpolation using an `InterpolationConfig` concept. This commit
refactors that code to generalize it to work not just with interpolations,
but with all instruction generation for variadic instructions.

PR Close #50118
2023-06-01 08:46:06 -07:00
Alex Rickabaugh
05026a2a24 refactor(compiler): support literal array/maps in the template pipeline (#50118)
This commit adds support to the template pipeline to ingest and process
literal array and map expressions. A future phase may process these literal
expressions and memoize them into pure functions where required.

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