Commit graph

1900 commits

Author SHA1 Message Date
Kristiyan Kostadinov
21b993c8df refactor(compiler): remove allowInvalidAssignmentEvents flag (#58988)
Deletes the `allowInvalidAssignmentEvents` which was added to facilitate a migration away from invalid two-way bindings. Since the migration doesn't exist anymore, we don't need the flag either.

PR Close #58988
2024-12-02 08:55:42 +01:00
Kristiyan Kostadinov
f280467398 fix(compiler-cli): account for multiple generated namespace imports in HMR (#58924)
The current HMR compiler assumes that there will only be one namespace import in the generated code (`@angular/core`). This is incorrect, because the compiler may need to generate additional imports in some cases (e.g. importing directives through a module). These changes adjust the compiler to capture all the namespaces in an array and pass them along.

Fixes #58915.

PR Close #58924
2024-11-28 10:00:56 +01:00
Jessica Janiuk
30891d8dec refactor(core): Consolidates shouldTrigger* methods down to one (#58833)
This cleans up the triggering code base and consolidates it down to one
function that outlines the logic. This also resolves the `hydrate when`
behavior issue.

fixes: #58709

PR Close #58833
2024-11-27 17:00:06 +01:00
Jessica Janiuk
38fe180d34 refactor(compiler): Adds ingest and flags for defer details (#58833)
This adds TDeferDetailsFlags to indicate the presence of hydration triggers, and any future flags we add to defer.

PR Close #58833
2024-11-27 17:00:05 +01:00
Utku Gultopu
0f1c71869e docs: capitalize webpack with a lowercase W (#56812)
PR Close #56812
2024-11-26 22:24:11 +00:00
Kristiyan Kostadinov
4e9244990a fix(compiler-cli): more accurate diagnostics for host binding parser errors (#58870)
Currently host bindings are in a bit of a weird state, because their source spans all point to the root object literal, rather than the individual expression. This is tricky to handle at the moment, because the object is being passed around as a `Record<string, string>` since the compiler needs to support both JIT and non-JIT environments, and because the AOT compiler evaluates the entire literal rather than doing it expression-by-expression. As a result, when we report errors in one of the host bindings, we end up highlighting the entire expression which can be very noisy in an IDE.

These changes aim to report a more accurate error for the most common case where the `host` object is initialized to a `string -> string` object literal by matching the failing expression to one of the property initializers. Note that this isn't 100% reliable, because we can't map cases like `host: SOME_CONST`, but it's still better than the current setup.

PR Close #58870
2024-11-25 15:25:48 +00:00
Georgy Serga
549a00d18b fix(compiler): fix multiline selectors (#58681)
multiline selectors where not correctly recognized by the regexp, fix it to fetch newlines as well

Fixes #58399

PR Close #58681
2024-11-15 11:30:27 +01:00
Georgy Serga
58a84b2f79 fix(compiler): resolve :host:host-context(.foo) (#58681)
fix results which had to parse several `-shadowcsshost-no-combinator` occurrences in a single selector

PR Close #58681
2024-11-15 11:30:27 +01:00
Georgy Serga
9587437e60 fix(compiler): transform chained pseudo-selectors (#58681)
fix transformation logic for `:where` and `:is` pseudo-selectors
when these selectors were used in a chain. results were often broken,
the last letter of the selector was incorrectly trimmed.
see tests for examples

Fixes #58226

PR Close #58681
2024-11-15 11:30:27 +01:00
Georgy Serga
70e800ecec fix(compiler): fix :host parsing in pseudo-selectors (#58681)
fix several use-cases where `:host` was used in or around pseudo-selectors
- `:host` followed by a comma inside pseudo-selectors
- `:host` outside of pseudo-selectors when another `:host` is present within
see tests for examples

PR Close #58681
2024-11-15 11:30:27 +01:00
Kristiyan Kostadinov
c421ffdbfb fix(compiler): control flow nodes with root at the end projected incorrectly (#58607)
Fixes an edge case where a control flow node that has non-projectable nodes followed by an element node at the end would cause the entire control flow node to be project. For example if we have a projection target of `Main: <ng-content/> Slot: <ng-content select="[foo]"/>`, inserting a node of `@if (true) {Hello <span foo>world</span>}` would project the entire `Hello world` into the `[foo]` slot.

In the process of working on the issue, I also found that `@let` declarations at the root of the control flow node would prevent content projection as well.

PR Close #58607
2024-11-12 18:05:00 +00:00
Kristiyan Kostadinov
7d0ba0cac8 refactor(compiler): trigger hmr load on initialization (#58465)
Adjusts the HMR initialization to avoid the edge case where a developer makes change to a non-rendered component that exists in a lazy loaded chunk that has not been loaded yet. The changes include:
* Moving the `import` statement out into a separate function.
* Adding a null check for `d.default` before calling `replaceMEtadata`.
* Triggering the `import` callback eagerly on initialization.

Example of the new generated code:

```js
(() => {
  function Cmp_HmrLoad(t) {
    import(
      /* @vite-ignore */ "/@ng/component?c=test.ts%40Cmp&t=" + encodeURIComponent(t)
    ).then((m) => m.default && i0.ɵɵreplaceMetadata(Cmp, m.default, [/* Dependencies go here */]));
  }
  (typeof ngDevMode === "undefined" || ngDevMode) && Cmp_HmrLoad(Date.now());
  (typeof ngDevMode === "undefined" || ngDevMode) &&
    import.meta.hot &&
    import.meta.hot.on("angular:component-update", (d) => {
      if (d.id === "test.ts%40Cmp") {
        Cmp_HmrLoad(d.timestamp);
      }
    });
})();
```

PR Close #58465
2024-11-01 19:14:16 +00:00
Kristiyan Kostadinov
5ca48e802b refactor(compiler): remove unused field from output AST (#58444)
The `ExternalReference.runtime` field wasn't being used anywhere.

PR Close #58444
2024-11-01 14:32:57 +00:00
Kristiyan Kostadinov
21adbba784 fix(compiler): avoid having to duplicate core environment (#58444)
Switches to referencing the core environment directly in the generated code, instead of having to duplicate it.

PR Close #58444
2024-11-01 14:32:57 +00:00
Brandon Roberts
992410e928 fix(compiler): add more specific matcher for hydrate never block (#58360)
Fixes an issue where additional characters were allowed afte the "hydrate never" block.

Closes #58358

PR Close #58360
2024-10-28 12:35:11 -07:00
Matthieu Riegler
5d9cc8f408 refactor(core): remove the standalone feature (#58288)
By removing the standalone feature, we reduce the amount of code generated for components but at the cost of including the `StandaloneService` in the main bundle even if no standalone components are included in it.

PR Close #58288
2024-10-24 16:19:02 -07:00
Matthieu Riegler
a10f7cfbc2 refactor(core): Don't generate standalone: true for definitions (#58238)
The runtime default is now `standalone: true`.
`ɵɵdefineComponent`, `ɵɵdefineDirective` and `ɵɵdefinePipe` now set `standalone` as `true` by default in the definitions.

PR Close #58238
2024-10-24 12:44:12 -07:00
Kristiyan Kostadinov
5971037613 test(compiler): update failing tests (#58217)
Fixes some tests that started failing, because #58154 made it so placeholder-only messages are extracted while #58176 added some tests that only contain placeholders.

PR Close #58217
2024-10-16 09:47:10 +00:00
Kristiyan Kostadinov
a3cb530d84 fix(compiler): handle typeof expressions in serializer (#58217)
Fixes that some changes which landed at the same time caused a compilation error in the serialized.

PR Close #58217
2024-10-16 09:47:10 +00:00
Matthieu Riegler
0c9d721ac1 feat(compiler): add support for the typeof keyword in template expressions. (#58183)
This commit adds the support for `typeof` in template expressions like interpolation, bindings, control flow blocks etc.

PR Close #58183
2024-10-16 07:31:00 +00:00
Kristiyan Kostadinov
ca651d18d6 refactor(compiler): generate HMR update function (#58205)
Adds some code to the compiler that will generate the HMR update callback function definition.

PR Close #58205
2024-10-16 07:22:45 +00:00
Kristiyan Kostadinov
1524069b36 refactor(compiler): output AST visitor not visiting implicit arrow function returns (#58205)
Fixes that the output AST's `RecursiveVisitor` wasn't visiting all the nodes when an arrow function has an implicit return. The problem was that we were calling the `visitExpression` method directly, instead of `.visitExpression`. This doesn't affect existing code since the `RecursiveVisitor` isn't used anywhere, but it will affect future HMR code.

PR Close #58205
2024-10-16 07:22:45 +00:00
Doug Parker
6d33ab5afe refactor(compiler): remove preservePlaceholders (#58176)
While effective, `preservePlaceholders` unfortunately is not viable in google3 at the moment due to some complexities with how TC extracts messages. Therefore this feature is being removed in favor of whitespace trimming of expressions, which is viable for TC and provides most of the same benefit.

This is a partial revert of dab722f9c8.

PR Close #58176
2024-10-16 06:42:37 +00:00
Doug Parker
6c126d5c5d refactor(compiler): trim insignificant whitespace in expressions when preserveSignificantWhitespace === false. (#58176)
This parses and reserializes expressions to normalize their whitespace formatting and make them more durable to insignificant changes in whitespace which might otherwise alter message IDs despite no translator-meaningful change being made.

PR Close #58176
2024-10-16 06:42:37 +00:00
Doug Parker
474163cd1d refactor(compiler): add expression serializer (#58176)
This serializes the expression AST back into a string. This is useful to normalize whitespace in expressions so i18n messages are not affected by insignificant changes (such as going from `{{ foo }}` to `{{\n  foo\n}}`).

PR Close #58176
2024-10-16 06:42:37 +00:00
Matthieu Riegler
a34090bc71 refactor(compiler): dynamic default for the partial compiler. (#58169)
Use `semver` in the partial compiler to decide on a default value

Co-authored-by: Alex Rickabaugh <alxhub@users.noreply.github.com>

PR Close #58169
2024-10-15 16:05:14 +00:00
Matthieu Riegler
6b8c494d05 feat(core): flipping the default value for standalone to true (#58169)
With this commit directives, components & pipes are standalone by default.

To be declared in an `NgModule`, those require now `standalone: false`.

PR Close #58169
2024-10-15 16:05:14 +00:00
Charles Lyding
bbca205d5e refactor(compiler): adjust HMR initializer block for improved Vite support (#58173)
For the HMR initializer block to support being used in a Vite setup with
import analysis, the import call expression needs to be a runtime generated
value and include the `@vite-ignore` special comment. Without the first,
Vite will error prior to loading the application. Without the second, a
warning will be shown for each import which is effectively each component
within the application when HMR is enabled.

PR Close #58173
2024-10-14 15:21:40 +00:00
Charles Lyding
4a6c6505d9 refactor(compiler): support generating URL expressions with dynamic imports (#58173)
The compiler's AST factories now support generating a dynamic import call
expression with either a string literal or an expression. The later is useful
for cases where the URL is dynamically created at runtime. Also, a leading
comment can now be added to the URL for cases where bundler behavior
needs to be included via special comments.

PR Close #58173
2024-10-14 15:21:40 +00:00
Matthieu Riegler
09df589e31 refactor(core): Migrate all packages with the explicit-standalone-flag schematic. (#58160)
All components, directives and pipes will now use standalone as default.
Non-standalone decorators have now `standalone: false`.

PR Close #58160
2024-10-14 14:58:57 +00:00
Doug Parker
ba4340875a fix(compiler): ignore placeholder-only i18n messages (#58154)
Message which only contain a single placeholder cannot be translated, there is no static text to be translated. Therefore these messages can be skipped and shouldn't be extracted at all.

Ideally, Angular would throw an error if a message is only a placeholder, since it should not contain an `i18n` attribute at all. However this would be a breaking change and require a migration which isn't in scope right now. We can explore converting this to a hard error sometime in the future.

PR Close #58154
2024-10-13 16:48:34 +00:00
Kristiyan Kostadinov
6f7803a3ff refactor(compiler): add logic to generate the HMR initializer (#58150)
Adds the logic that will generate the `import` expression that will initializer HMR for a specific component.

PR Close #58150
2024-10-11 07:03:15 +00:00
Georgy Serga
46a6324c82 fix(compiler): scope :host-context inside pseudo selectors, do not decrease specificity (#57796)
parse constructions like `:where(:host-context(.foo))` correctly
revert logic which lead to decreased specificity if `:where` was applied
to another selector, for example `div` is transformed to `div[contenta]`
with specificity of (0,1,1) so `div:where(.foo)` should not decrease it
leading to `div[contenta]:where(.foo)` with the same specificity (0,1,1)
instead of `div:where(.foo[contenta])` with specificity equal to (0,0,1)

PR Close #57796
2024-10-10 08:13:22 +00:00
Georgy Serga
69529d8873 fix(compiler): fix parsing of the :host-context with pseudo selectors (#57796)
fix regexp which is used to test for host inside pseudo selectors

PR Close #57796
2024-10-10 08:13:22 +00:00
Georgy Serga
2374b87b64 fix(compiler): preserve attributes attached to :host selector (#57796)
keep attributes used to scope :host selectors

PR Close #57796
2024-10-10 08:13:22 +00:00
Georgy Serga
e8d1944999 fix(compiler): add multiple :host and nested selectors support (#57796)
add support for nested and deeply nested (up to three levels) selectors,
parse multiple :host selectors, scope selectors within pseudo functions

PR Close #57796
2024-10-10 08:13:22 +00:00
Georgy Serga
292ea4714f fix(compiler): fix comment typo (#57796)
fix spelling in the comment

PR Close #57796
2024-10-10 08:13:22 +00:00
Georgy Serga
82144b6d63 fix(compiler): allow combinators inside pseudo selectors (#57796)
allow css combinators within pseudo selector functions, parsing those
correctly. Similarly to previous version, don't break selectors
into part if combinators are within parenthesis, for example
`:where(.one > .two)`

PR Close #57796
2024-10-10 08:13:22 +00:00
Georgy Serga
bc5f1175e9 fix(compiler): transform pseudo selectors correctly for the encapsulated view (#57796)
fix scoping and transforming logic of the `shimCssText` for the
components with encapsulated view:
- add support for pseudo selector functions
- apply content scoping for inner selectors of `:is()` and `:where()`
- allow multiple comma separated selectors inside pseudo selectors

Fixes #45686

PR Close #57796
2024-10-10 08:13:21 +00:00
P4
97fb86d331 perf(core): set encapsulation to None for empty component styles (#57130)
Make it so that encapsulation for empty styles, styles containing only whitespace and comments, etc.
is handled the same way as with no styles at all.

Components without styles already have view encapsulation set to `None`
to avoid generating unnecessary attributes for style scoping, like `_ngcontent-ng-c1` (#27175)

If the component has an empty external styles file instead, the compiler would generate
a component definition without the `styles` field, but still using the default encapsulation.
This can result in runtime overhead if the developer forgets to delete the empty styles file
generated automatically for new components by Angular CLI.

Closes #16602

PR Close #57130
2024-10-08 09:30:01 -07:00
Dylan Hunn
09f589f000 fix(compiler): this.a should always refer to class property a (#55183)
Consider a template with a context variable `a`:
```
<ng-template let-a>{{this.a}}</ng-template>
```

t push -fAn interpolation inside that template to `this.a` should intuitively read the class variable `a`. However, today, it refers to the context variable `a`, both in the TCB and the generated code.

In this commit, the above interpolation now refers to the class field `a`.

BREAKING CHANGE: `this.foo` property reads no longer refer to template context variables. If you intended to read the template variable, do not use `this.`.
Fixes #55115

PR Close #55183
2024-10-08 16:02:18 +00:00
Charles Lyding
c69371151a refactor(compiler): support external runtime component styles for file-based stylesheets (#57613)
The AOT compiler now has the capability to handle component stylesheet files as
external runtime files. External runtime files are stylesheets that are not embedded
within the component code at build time. Instead a URL path is emitted within a component's
metadata. When combined with separate updates to the shared style host and DOM renderer,
this will allow these stylesheet files to be fetched and processed by a development
server on-demand. This behavior is controlled by an internal compiler option `externalRuntimeStyles`.
The Angular CLI development server will also be updated to provide the serving functionality
once this capability is enabled. This capability enables upcoming features such as automatic
component style hot module replacement (HMR) and development server deferred stylesheet processing.
The current implementation does not affect the behavior of inline styles. Only the
behavior of stylesheet files referenced via component properties `styleUrl`/`styleUrls`
and relative template `link` elements are changed by enabling the internal option.

PR Close #57613
2024-10-07 08:20:22 -07:00
Matthieu Riegler
84b6896956 refactor(platform-server): Add an ssr benchmark setup. (#57647)
In order to investigate the performances of SSR, this commit introduces a benchmark suite which will measure several step of the rendering.

PR Close #57647
2024-10-04 10:45:22 -07:00
Kristiyan Kostadinov
682da6f59f refactor(core): fix typo in function name (#57988)
Fixes a typo in the `replaceMetadata` function name.

PR Close #57988
2024-09-30 13:31:24 -07:00
Kristiyan Kostadinov
c44f087482 refactor(core): add initial implementation of function to replace metadata at runtime (#57953)
Adds the new `ɵɵreplaceMedata` function that can be used to replace the metadata of a component class and re-render all instances in place without refreshing the page. The function isn't used anywhere at the moment, but it will be necessary for future functionality.

PR Close #57953
2024-09-26 14:28:35 -07:00
Joey Perrott
9dbe6fc18b refactor: update license text to point to angular.dev (#57901)
Update license text to point to angular.dev instead of angular.io

PR Close #57901
2024-09-24 15:33:00 +02:00
Kristiyan Kostadinov
39098f3a9b refactor(compiler): finalize hydrate syntax (#57831)
Finalizes compiler implementation of the new `hydrate` triggers by:
* Reworking the logic that was depending on the `hydrateSpan` to distinguish hydrate triggers from non-hydrate triggers.
* Fixing that the `hydrate when` trigger didn't have a `hydrateSpan`.
* Adding an error if a parameter is passed into a `hydrate` trigger.
* Add an error if other `hydrate` triggers are used with `hydrate never`.
* Replacing the `prefetch` and `hydrate` flags in the template pipeline with a `modifiers` field.
* Fixing an error that was being thrown when reifying `hydrate` triggers in the pipeline.
* Adding quick info support for the `hydrate` keyword in the language service.
* Adding some tests for the new logic.

PR Close #57831
2024-09-17 11:05:17 +02:00
Jessica Janiuk
79b54bba9c refactor(compiler): initial integration of hydrate triggers into the compiler (#57831)
Sets up the AST for hydrate triggers.

PR Close #57831
2024-09-17 11:05:17 +02:00
Charles Lyding
149d69e47c refactor(compiler): allow internal style encapsulation helper to directly encapsulate for a component (#57809)
For component stylesheet hot module replacement scenarios, it will be necessarily to directly
encapsulate a component's stylesheet in a single operation. This currently requires the
consumer of the `encapsulateStyle` helper to use the internal Angular attribute values combined
with a find/replace over the entire stylesheet. To avoid both of these, the helper function now
has an optional second parameter which allows direct and full encapsulation of a style for a given
component when the component identifier is known.

PR Close #57809
2024-09-16 12:14:57 +02:00
Kristiyan Kostadinov
40ff18f87a fix(compiler): produce less noisy errors when parsing control flow (#57711)
Currently several parsing errors in the new control flow (e.g. missing `track` expression) produce errors whose span targets the entire block. This can be really noisy in the IDE where the error can span many lines in the template.

These changes switch to highlighting just the start of the block.

PR Close #57711
2024-09-09 14:10:01 +00:00