Commit graph

1262 commits

Author SHA1 Message Date
Kristiyan Kostadinov
5212b47bbf refactor(compiler): introduce defer trigger instructions (#51315)
Adds the logic for generating the instructions for the various deferred triggers.

PR Close #51315
2023-08-11 06:55:13 -07:00
Kristiyan Kostadinov
79f9d49fad refactor(compiler): introduce defer block instructions (#51315)
Adds the logic for generating `{#defer}`, `{:placeholder}`, `{:loading}` and `{:error}` block instructions in the compiler.

PR Close #51315
2023-08-11 06:55:13 -07:00
Kristiyan Kostadinov
151b04f683 refactor(compiler): add method for generating template instructions (#51315)
Moves the logic for creating a `ɵɵtemplate` instruction into a separate method so that it can be reused for `defer` blocks.

PR Close #51315
2023-08-11 06:55:13 -07:00
Kristiyan Kostadinov
36b180ade4 refactor(compiler): implement conditional block AST (#51299)
Adds the AST for `if`, `else if` and `else` blocks.

PR Close #51299
2023-08-10 13:48:55 -07:00
Kristiyan Kostadinov
4424920f0b refactor(compiler): implement for block AST (#51299)
Adds the AST for `for` and `empty` blocks.

PR Close #51299
2023-08-10 13:48:55 -07:00
Kristiyan Kostadinov
31c6c5e944 refactor(compiler): implement switch block AST (#51299)
Adds the AST for `switch`, `case` and `default` blocks.

PR Close #51299
2023-08-10 13:48:55 -07:00
Payam Valadkhan
827e10ae0e refactor(compiler): add a factory for component dependencies in local compilation mode (#51089)
A factory generator function called "i0.ɵɵgetComponentDepsFactory" is added to generate a factory function for component dependencies. This function will use the deps tracker to calculate the component's dependencies.

For standalone components the component imports (if exists) will be passed to this function. Alternatively this function can grab the imports directly from the decorate, but such extraaction needs some runtime logic which overlapps with what the trait compiler is doing. So better to pass the imports directly to this function at compile time.

PR Close #51089
2023-08-08 13:58:48 -07:00
Kristiyan Kostadinov
b1f96096d3 refactor(compiler): correctly identify lazy directives and pipes used after a nested defer block (#51262)
Fixes that if a directive/pipe is used after a nested `defer` block, we weren't tracking it as lazy anymore. This was due to the fact that we were resetting the `isInDeferBlock` to false every time instead of the previous value.

PR Close #51262
2023-08-04 11:27:39 -04:00
Kristiyan Kostadinov
1045abd3c8 refactor(compiler): add more deferred validations (#51262)
Adds validations for the following invalid deferred block structures:
* Duplicated triggers.
* Multiple `minimum` parameters on `placeholder` and `loading` blocks.
* Multiple `after` parameters on `loading` blocks.

PR Close #51262
2023-08-04 11:27:39 -04:00
Kristiyan Kostadinov
d11548f2ef refactor(compiler): store deferred triggers as a map (#51262)
Stores the `deferred` block triggers as a map instead of an array, because triggers can't be duplicated and because having to search through an array will be inconvenient later on.

I've also added a `DeferredBlock.visitAll` method to deduplicate the logic from the various visitor implementations.

PR Close #51262
2023-08-04 11:27:39 -04:00
Miles Malerba
74974f80e0 refactor(compiler): Parse extracted class attributes (#51258)
Adds logic to parse extracted class attributes into separate
ExtractedAttributeOps per class in the attribute.

PR Close #51258
2023-08-03 14:34:53 -04:00
Miles Malerba
d792db8652 refactor(compiler): Adds a new phase for parsing extracted styles (#51258)
Adds a new phase that converts previously extracted
ExtractedAttributeOps representing a style attribute into individual
ExtractedAttributeOps representing each of the style properties set in
the style attribute.

PR Close #51258
2023-08-03 14:34:53 -04:00
Miles Malerba
82009a529a refactor(compiler): Make ElementAttributes an implementation detail (#51258)
Refactors ElementAttributes to be an implementation detail of the const
collection phase, rather than an object that is added to all ElementOps.

PR Close #51258
2023-08-03 14:34:53 -04:00
Miles Malerba
aa9223e067 refactor(compiler): Use ExtractedAttributeOp for const collection (#51258)
Refactors the const collection phase to populate ElementAttributes from
the newly added ExtractedAttributeOp.

PR Close #51258
2023-08-03 14:34:53 -04:00
Miles Malerba
8b646f57d0 refactor(compiler): Create temporary ops during attribute extraction (#51258)
Refactors the attribute extraction phase to create a new temporary op
called `ExtractedAttributeOp` rather than directly populating
`ElementAttributes`.

PR Close #51258
2023-08-03 14:34:52 -04:00
Miles Malerba
2d52d5e62c refactor(compiler): support safe function calls (#51100)
Adds support for safe function calls in template pipeline compiler

PR Close #51100
2023-08-01 13:45:34 -07:00
Miles Malerba
42caeeef21 refactor(compiler): reuse temp vars when possible (#51100)
Updates the template pipeline's temporary variables phase to reuse
temporary variables within an expression. The algorithm implemented here
reuses variables more aggressively than TemplateDefinitionBuilder. This
change in behavior is acceptable, as it is unlikely to cause any
failures, and implementing the exact behavior observed in
TemplateDefinitionBuilder would be difficult.

PR Close #51100
2023-08-01 13:45:34 -07:00
Andrew Kushnir
efb486e8bc refactor(compiler): handle defer blocks in TemplateDefinitionBuilder (#51162)
Updates the TemplateDefinitionBuilder class to generate the `defer` instruction for `{#defer}` blocks. Also generates dependency function that would be invoked at runtime (with dynamic imports inside).

PR Close #51162
2023-08-01 11:50:05 -07:00
Andrew Kushnir
08992a5f2f refactor(compiler): compute the list of dependencies for defer blocks (#51162)
This commit brings the logic to calculate teh set of dependencies for each defer block. For each dependency we also identify whether it can be defer-loaded or not.

PR Close #51162
2023-08-01 11:50:05 -07:00
Andrew Kushnir
553cbaed84 refactor(compiler): update TemplateBinder and DirectiveBinder to work with defer blocks (#51162)
This commit updates the logic of the TemplateBinder and DirectiveBinder classes to recognize defer blocks. The logic is updated to prevent Directive and Pipe matching inside the defer block. Instead, the scope for those blocks would be calculated separately.

PR Close #51162
2023-08-01 11:50:04 -07:00
Miles Malerba
c1052cf7a7 refactor(compiler): add support for sanitizing properties and attributes (#51156)
Sets sanitizer functions when attempting to set sensitive properties and attributes

PR Close #51156
2023-07-28 15:11:51 -07:00
Kristiyan Kostadinov
72255288bf refactor(compiler): add utility to enable deferred blocks for testing (#51183)
Adds the `ɵsetEnabledBlockTypes` utility that can be used when writing JIT tests using `defer` blocks. Intended usage:

```ts
import {ɵsetEnabledBlockTypes as setEnabledBlockTypes} from '@angular/compiler/src/jit_compiler_facade';

describe('deferred tests', () => {
  beforeEach(() => setEnabledBlockTypes(['defer']));
  afterEach(() => setEnabledBlockTypes([]));

  it('should work', () => {
    // test goes here
  });
});
```

PR Close #51183
2023-07-28 14:42:04 -07:00
Miles Malerba
09bf32724f refactor(compiler): add support for animation listeners (#50975)
Adds support for binding animation listeners, e.g.

PR Close #50975
2023-07-28 14:40:13 -07:00
Miles Malerba
570bd67eae refactor(compiler): make listener instruction chainable (#50975)
Makes the `ɵɵlistener` instruction chainable in the template pipeline

PR Close #50975
2023-07-28 14:40:13 -07:00
Miles Malerba
7dd99cd843 refactor(compiler): add support for animation properties (#50975)
Adds support for binding animation properties, e.g.

PR Close #50975
2023-07-28 14:40:13 -07:00
Miles Malerba
88a5711b1f refactor(compiler): make element instruction chainable (#50975)
Makes the `ɵɵelement` instruction chainable in the template pipeline

PR Close #50975
2023-07-28 14:40:13 -07:00
P4
6755f5354c fix(compiler): return full spans for Comment nodes (#50855)
Change sourceSpan for Comment nodes to cover the whole comment
instead of just the opening token.

The primary motivation for this is the interaction between ESLint and
`@angular-eslint`. ESLint can detect unused `eslint-disable` directives
in comments and automatically remove them when running with `--fix`.
This is based on ranges computed from AST spans, and as a result
does not work inside Angular templates - right now all comments
claim to be 4 characters long so only the opening `<!--` is removed.

PR Close #50855
2023-07-28 14:39:18 -07:00
Dylan Hunn
50613117bd refactor(compiler): Ingest host attribute bindings in template pipeline (#51188)
Host property bindings beginning with `attr.` should have `Attribute` binding kind, and result in an `attribute` instruction.

This should really be handled in the parser in the future.

PR Close #51188
2023-07-28 11:47:57 -07:00
Dylan Hunn
a42c91e78b refactor(compiler): Generate temporaries in host bindings for template pipeline (#51188)
Add the ability to name and resolve generated temporary variables in host bindings, using the existing phase.

PR Close #51188
2023-07-28 11:47:57 -07:00
Dylan Hunn
72a59bdc4d refactor(compiler): Support svg and math namespace instructions in template pipeline (#51188)
Templates may contain special `svg` and `math` elements, as well as logical descendants of those elements (e.g. `svg` may contain `g`). These will be parsed with a special colon-prefixed *namespace identifier*, such as `:svg:svg`, or `:svg:g`, or `:math:infinity`.

The template pipeline now considers these namespace prefixes, and stores them specially on the Element and Template data structures, ultimately generating the appropriate runtime instructions to change namespaces when needed.

PR Close #51188
2023-07-28 11:47:57 -07:00
Dylan Hunn
c4b289ab8f refactor(compiler): Allow chaining of listeners in template pipeline (#51188)
Calls to the listener instruction can be chained.

PR Close #51188
2023-07-28 11:47:57 -07:00
Dylan Hunn
8f50385041 refactor(compiler): support ngNonBindable in the template pipeline (#51188)
When a container-like element has the `ngNonBindable` special attribute, bindings are disabled for it and its descendants. This requires emitting the `disableBindings` and `enableBindings` instructions when nested content exists.

PR Close #51188
2023-07-28 11:47:57 -07:00
Dylan Hunn
1c553ee915 refactor(compiler): Delete some redundant types in template pipeline. (#50899)
Previously we refactored the compilation to use the concepts of "jobs" and "units." However, old type aliases were provided to avoid changing all call-sites in bulk. Here, those aliases are deleted, and call sited updated:

1. `ComponentCompilation` becomes `ComponentCompilationJob`.
2. `ViewCompilation` becomes `ViewCompilationUnit`.

PR Close #50899
2023-07-27 15:08:05 -07:00
Dylan Hunn
5a0ecdb58b refactor(compiler): Allow host binding functions to specialize bindings (#50899)
Interestingly, host bindings are parsed quite differently from template functions. For example, bindings such as `[style.foo]: 3px` would be parsed into a value, unit, and type when bound to a template, but will not be parsed as such when used in a host binding.

In this commit, we remedy this shortcoming by adding support for bindings in host binding functions to the template pipeline. In particular, we create a phase to process these bindings, and transform them into the correct output binding kind.

Additionally, we fix some other minor bugs and omissions.

Finally, we enable compilation of host bindings with the template pipeline, which requires us to turn off a number of failing tests.

PR Close #50899
2023-07-27 15:08:05 -07:00
Dylan Hunn
7652ec7b67 refactor(compiler): Allow host bindings to be ingested into the template pipeline. (#50899)
Alter the compiler code to ingest and process host bindings, using the newly updated compilation passes.

This is currently switched off in the outer compiler layer, but lays the foundation for actually generating the host binding functions using template pipeline.

PR Close #50899
2023-07-27 15:08:05 -07:00
Dylan Hunn
5ed8db2287 refactor(compiler): Refactor processing of bindings and interpolations. (#50899)
Today, bindings on templates are ingested in highly distinct ways, depending on the parsed binding kind, as well as special cases for `style` and `class`. This makes it very difficult to also ingest them for host bindings without duplicating all this subtle logic.

To solve this, we introduce two major related refactors:

1. Move all processing of attributes into phases. This dramatically reduces the amount of code in `ingest.ts`, which is now only responsible for ingesting an abstract `BindingOp`. The later phases replace each `BindingOp` with more specific ops for each binding kind. For example, `binding_specialization.ts` transforms each abstract `BindingOp` into a concrete `PropertyOp`, `AttributeOp`, etc. Likewise, `style_binding_specialization.ts` performs special-case transformations for style and class bindings. This approach has the additional advantage of separating the creation of attribute and property bindings from other special cases.

2. Eliminate all interpolation ops. Instead, allow the expression inside of an op to be of a new `Interpolation` type. The reify code will then emit the appropriate instruction variant (interpolated or unary).

3. Separate some concerns that were previously mixed in, such as empty bindings and listeners on templates.

These refactors cause major downstream code changes across the system, especially to attribute extraction and variable counting.

PR Close #50899
2023-07-27 15:08:05 -07:00
Dylan Hunn
30237d1751 refactor(compiler): Template pipeline: accept host bindings in additional phases (#50899)
Modify most of the remaining necessary phases to accept generic `CompilationJobs`. This includes `phasePureLiteralStructures`, `phaseNullishCoalescing`, `phaseExpandSafeReads`, `phaseVariableOptimization`, `phaseNaming`, and `phasePureFunctionExtraction`.

PR Close #50899
2023-07-27 15:08:05 -07:00
Dylan Hunn
8f67c0751d refactor(compiler): Prepare the template pipeline to support host bindings. (#50899)
Refactor `compilation.ts` by introducing two new concepts:
1. A compilation unit, which has create and update ops. Compilations of individual views are compilation units, as are individual host bindings.
2. Aa compilation job, which has several compilation units. For example, a whole component is a compilation job, because it can have many view compilation units. A host binding compilation is a job in addition to a unit, because each host binding unit is always a singleton.

Then, we begin modifying phases to accept general compilation jobs instead of component compilations specifically, which will allow us to run them on host bindings. In particular, we update the following phases: `phaseReify`, and `phaseChaining`.

PR Close #50899
2023-07-27 15:08:04 -07:00
Dylan Hunn
fe7de0dcea refactor(compiler): Compatibility mode for the template pipeline. (#50899)
Add a compatibility setting to the component compilation. Accordingly, remove all the custom compatibility flags passed to each phase, and use the main setting instead.

PR Close #50899
2023-07-27 15:08:04 -07:00
Dylan Hunn
31ff476060 refactor(compiler): Introduce source maps in the template pipeline. (#50899)
Begin producing source maps for the template pipeline, for a couple fundamental kinds of instructions, including elements, templates, properties, text, and interpolations.

PR Close #50899
2023-07-27 15:08:04 -07:00
Dylan Hunn
8a6a72e7cb refactor(compiler): Fix $event in listeners for template pipeline (#50899)
Previously, `$event` was interpreted as a lexical read on the enclosing context. Now, a new pass converts such reads into simple output AST reads of `$event`, so they are not processed by the context resolution or naming phases. Additionally, the same pass sets a field on the enclosing listener op, so that the reify phase does not have to search for reads of `$event`.

PR Close #50899
2023-07-27 15:08:04 -07:00
Dylan Hunn
c6010f0610 refactor(compiler): Support $any in template pipeline (#50899)
`$any(...)` casts should be dropped, except when they are an explicit call on `this.$any(...)`. Fix a bug in which we were transforming `ThisReceiver` into an implicit receiver.

PR Close #50899
2023-07-27 15:08:04 -07:00
Kristiyan Kostadinov
92ebfd1ca7 refactor(compiler): handle braces in block parameters (#51143)
Fixes that using braces in the block parameters would result in incorrect tokens being produced. Currently we don't have any blocks that allow object literal parameters, but it may come up in the future.

PR Close #51143
2023-07-24 08:13:51 -07:00
Andrew Kushnir
24bf133eb6 refactor(compiler): add support for dynamic imports in the output AST (#51087)
This commit updates the output AST (and related visitors) to support dynamic imports. This functionality will be used later to generate the output for defer blocks.

PR Close #51087
2023-07-19 16:54:42 +00:00
Kristiyan Kostadinov
7410d6847b refactor(compiler): add compiler flag to enable deferred blocks for testing (#51079)
Adds a new compiler option that will allow `defer` (and other) blocks to be enabled when writing unit tests.

PR Close #51079
2023-07-18 17:05:29 +00:00
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