Commit graph

3415 commits

Author SHA1 Message Date
Kristiyan Kostadinov
9e847fc60d fix(compiler): handle tracking expressions requiring temporary variables (#58520)
Currently when we generate the tracking expression for a `@for` block, we process its expression in the context of the creation block. This is incorrect, because the expression may require ops of its own for cases like nullish coalescing or safe reads. The result is that while we do generate the correct variable, they're added to the creation block rather than the tracking function which causes an error at runtime.

These changes address the issue by keeping track of a separate set of ops for the `track` expression that are prepended to the generated function, similarly to how we handle event listeners.

Fixes #56256.

PR Close #58520
2025-02-12 09:56:08 -08:00
Kristiyan Kostadinov
5cd26a9420 fix(compiler-cli): handle deferred blocks with shared dependencies correctly (#59926)
When the compiler analyzes the defer blocks in a component, it generates two sets of dependencies: ones specific for each block and others from all the deferred blocks within the component. The logic that combines all the defer block dependencies wasn't de-duplicating them which resulted in us producing `setClassMetadataAsync` calls where the callback can have multiple parameters with the same name. This was a problem both in full and partial compilation, but the latter was more visible, because Babel throws an error in such cases.

These changes add some logic to de-duplicate the dependencies so that we produce valid code.

Fixes #59922.

PR Close #59926
2025-02-12 09:15:53 -08:00
Kristiyan Kostadinov
e47c1e5abe refactor(compiler): pass more information to HMR replacement function (#59854)
Adjusts the code we generate for HMR so that it passes in the HMR ID and `import.meta` to the `replaceMetadata` call. This is necessary so we can do better logging of errors.

PR Close #59854
2025-02-12 09:05:30 -08:00
Kristiyan Kostadinov
146ab9a76e feat(core): support TypeScript 5.8 (#59830)
Updates the repo to support TypeScript 5.8 which is currently in beta.

PR Close #59830
2025-02-03 14:00:41 -08:00
Kristiyan Kostadinov
a97136052f fix(compiler-cli): gracefully fall back if const enum cannot be passed through (#59815)
Adds some logic so that if we can't produce a runtime representation of an enum, the dev server can fall back to refreshing the page.

PR Close #59815
2025-02-03 13:58:31 -08:00
Kristiyan Kostadinov
bae94b82fd fix(compiler-cli): handle const enums used inside HMR data (#59815)
When we generate an HMR replacement function, we determine which locals from the file are used and we pass them by reference. This works fine in most cases, but breaks down for const enums which don't have a runtime representation.

These changes work around the issue by passing in all the values as an object literal.

Fixes #59800.

PR Close #59815
2025-02-03 13:58:31 -08:00
Kristiyan Kostadinov
03bcd30e34 fix(compiler-cli): handle enum members without initializers in partial evaluator (#59815)
Fixes that the partial evaluator was interpreting initializer-less enum members as undefined. In this case the value is the same as the index.

PR Close #59815
2025-02-03 13:58:31 -08:00
Kristiyan Kostadinov
fe8a68329b feat(compiler): support untagged template literals in expressions (#59230)
Updates the compiler to support untagged template literals inside of the expression syntax (e.g. ``hello ${world}``).

PR Close #59230
2025-01-21 12:04:53 -08:00
Kristiyan Kostadinov
6960ec0c03 refactor(compiler-cli): handle template literals in ngtsc (#59230)
Updates the translators that convert expression ASTs to account for template literals.

PR Close #59230
2025-01-21 12:04:53 -08:00
Kristiyan Kostadinov
4016aa3229 refactor(compiler): clean up tagged templates in output AST (#59230)
Makes the following cleanups in the output AST:
* The `TemplateLiteral` and `TemplateLiteralElement` nodes have been renamed to `TemplateLiteralExpr` and `TemplateLiteralElementExpr` respectively for consistency and to avoid overlaps with the expression AST nodes.
* The `TemplateLiteralExpr` and `TemplateLiteralElementExpr` have been refactored to be `Expression`s for correctness. This involves updating some existing code.
* The `TaggedTemplateExpr` has been renamed to `TaggedTemplateLiteralExpr` for consistency.

PR Close #59230
2025-01-21 12:04:52 -08:00
Kristiyan Kostadinov
eb7e765e2f refactor(compiler): produce AST for template literals (#59230)
Updates the compiler to parse the template literal tokens into the new `TemplateLiteral` and `TemplateLiteralElement` AST nodes.

PR Close #59230
2025-01-21 12:04:52 -08:00
Charles Lyding
5a13dff22c fix(compiler-cli): handle new expressions when extracting dependencies (#59637)
Updates the HMR dependencies extraction logic to handle new expressions.
For example, `deps: [[new Optional(), dep]]`.

PR Close #59637
2025-01-21 10:47:43 -08:00
Charles Lyding
8de0f3f79b fix(compiler-cli): handle conditional expressions when extracting dependencies (#59637)
Updates the HMR dependencies extraction logic to handle conditional expressions.
For example, `providers: [condition ? providersA : providersB]`.

PR Close #59637
2025-01-21 10:47:43 -08:00
Kristiyan Kostadinov
67be7d2e06 fix(compiler-cli): extract parenthesized dependencies during HMR (#59644)
Fixes that the HMR dependency extraction logic wasn't accounting for parenthesized identifiers correctly.

PR Close #59644
2025-01-21 09:50:27 -08:00
Kristiyan Kostadinov
ea2346955c fix(core): capture self-referencing component during HMR (#59644)
Fixes that we were filtering out the component itself from the set of dependencies when HMR is enabled, breaking self-referencing components.

Fixes #59632.

PR Close #59644
2025-01-21 09:50:27 -08:00
Alan Agius
30c4404752 fix(compiler): update @ng/component URL to be relative (#59620)
This change is required to resolve https://github.com/angular/angular-cli/pull/29248 and works in conjunction with https://github.com/angular/angular-cli/pull/29386. It ensures that HMR (Hot Module Replacement) functions correctly with `base href`, proxies, and other advanced development setups.

PR Close #59620
2025-01-20 09:10:13 +01:00
Kristiyan Kostadinov
f9b13e4e58 fix(compiler-cli): disable tree shaking during HMR (#59595)
When HMR is enabled, we need to capture the dependencies used in a template and forward them to the HMR replacement function. One half of this process is static, meaning that we can't change it after the initial compilation. Tree shaking becomes a problem in such a case, because the user can change the template in a way that changes the set of dependencies which will start matching with the static part of the HMR code.

These changes disable the tree shaking when HMR is enabled to ensure that the dependencies stay stable.

Fixes #59581.

PR Close #59595
2025-01-20 08:59:30 +01:00
Andrew Kushnir
d0ad030ec7 Revert "feat(compiler-cli): detect missing structural directive imports (#59443)" (#59544)
This reverts commit ed705a856a.

PR Close #59544
2025-01-15 13:38:37 -08:00
Kevin Brey
ed705a856a feat(compiler-cli): detect missing structural directive imports (#59443)
Adds a new diagnostic that ensures that a standalone component using custom structural directives in a template has the necessary imports for those directives.

Fixes #37322

PR Close #59443
2025-01-15 13:59:37 -05:00
hawkgs
b9155b5121 docs: set syntax highlighting to the remaining Markdown code examples blocks (#59088)
There are some code blocks that slipped through the initial Regex-es.

Related to #59026

PR Close #59088
2025-01-14 15:14:02 -05:00
Kristiyan Kostadinov
915593ad25 refactor(compiler): fix typo in method name (#59479)
Fixes a typo in the `AstVisitor.visitTypeofExpresion` method's name.

PR Close #59479
2025-01-13 10:57:51 -05:00
Charles Lyding
a4164141a3 fix(compiler): use chunk origin in template HMR request URL (#59459)
The URL that is dynamically imported to fetch a potential component update
for HMR is now based on the value of `import.meta.url`. This ensures that
the request is sent to the same location that was used to retrieve the
application code. For some development server setups the HTML base HREF
may not be the location of the Angular development server. By using the
application code location which was generated by the development server,
HMR requests can continue to work as expected in these scenarios. In
most common cases, this change will not have any effect as the HTML base
HREF aligns with the location of the application code files.

PR Close #59459
2025-01-09 18:21:48 -05:00
Kristiyan Kostadinov
3638f93acc fix(compiler-cli): handle more node types when extracting dependencies (#59445)
Fixes that the HMR dependency extraction logic wasn't handling some node types. Most of these are a bit edge-case-ey in component definitions, but variable initializers and arrow functions can realistically happen in factories.

PR Close #59445
2025-01-09 12:22:46 -05:00
Kristiyan Kostadinov
adc6c094f4 build: clean up pipeline-specific tests (#59450)
Now that we only have the template pipeline, we can remove the `.pipeline` extension from the files.

PR Close #59450
2025-01-09 09:56:06 -05:00
Jessica Janiuk
2563f39f29 Revert "refactor(core): remove unused injection props (#59209)" (#59386)
This reverts commit 91b53881d1.

PR Close #59386
2025-01-06 21:35:58 +00:00
Matthieu Riegler
e0401ec1f0 refactor(compiler-cli): extract function overload separatly (#56489)
in order for the docs to process function entry, this commit refactor function extraction by keeping the implementation as a the default entry and adds all the overloads into a separate array of entries.

fixes #56144

PR Close #56489
2025-01-06 20:50:59 +00:00
Matthieu Riegler
91b53881d1 refactor(core): remove unused injection props (#59209)
Those were also properties that were kept to also support of old compiled targets.

PR Close #59209
2025-01-06 17:28:41 +00:00
Kristiyan Kostadinov
ee99879fdc fix(compiler-cli): preserve defer block dependencies during HMR when class metadata is disabled (#59313)
Fixes that the compiler wasn't capturing defer block dependencies correctly when `supportTestBed` is disabled. We had tests for this, but we didn't notice the issue because the dependencies ended up being captured because of the `setClassMetadata` calls. Once they're disabled, the dependencies stopped being recorded.

Fixes #59310.

PR Close #59313
2025-01-06 17:26:30 +00:00
Kristiyan Kostadinov
ce3b6641fb fix(compiler-cli): account for more expression types when determining HMR dependencies (#59323)
During the HMR dependency analysis we need to check if an identifier is top-level or not. We do this by looking at each identifier and its parent, however we didn't account for some cases. These changes expand our logic to cover more of the common node types.

Related to https://github.com/angular/angular/issues/59310#issuecomment-2563963501.

PR Close #59323
2025-01-06 17:25:57 +00:00
Kristiyan Kostadinov
ceadd28ea1 fix(compiler): allow $any in two-way bindings (#59362)
Some time ago we narrowed down the expressions we support in two-way bindings, because in most cases any apart from property reads doesn't make sense. This ended up preventing users from using `$any` in the binding since it's considered a function call.

These changes update the validation logic to allow `$any`.

Fixes #51165.

PR Close #59362
2025-01-06 17:25:25 +00:00
Kristiyan Kostadinov
b2fcad8c1d refactor(compiler-cli): expose diagnostic error code (#59353)
Exports the error codes so that they can be reused.

PR Close #59353
2025-01-06 16:21:26 +00:00
Paul Gschwendtner
47212e0a45 refactor(compiler-cli): fix instanceof for error not working (#59219)
We recently introduced a custom error to allow us to catch certain types
of errors. Unfortunately it doesn't work as expected in G3 because the
Node execution seems to run with ES5.

PR Close #59219
2024-12-17 09:36:52 -08:00
Kristiyan Kostadinov
0dee2681f7 fix(compiler-cli): consider pre-release versions when detecting feature support (#59061)
Fixes that the logic which checks whether a feature is supported didn't account for pre-releases.

Fixes https://github.com/angular/vscode-ng-language-service/issues/2123.

PR Close #59061
2024-12-05 16:15:12 -08:00
Kristiyan Kostadinov
1b9492edf8 fix(compiler-cli): error in unused standalone imports diagnostic (#59064)
Fixes a null pointer error in the unused standalone imports diagnostic. It was caused by an inconsistency in TypeScript's built-in types.

Fixes #58872.

PR Close #59064
2024-12-05 16:14:02 -08:00
Kristiyan Kostadinov
6fd8a20978 refactor(compiler-cli): move two-way binding fix behind flag (#59002)
Moves the fix for type checking the event side of two-way bindings behind a compiler flag so that we can roll it out in v20.

PR Close #59002
2024-12-05 16:11:02 -08:00
Kristiyan Kostadinov
c5c20e9d86 fix(compiler-cli): check event side of two-way bindings (#59002)
In the past two-way bindings used to be interpreted as `foo = $event` at the parser level. In #54065 it was changed to preserve the actual expression, because it was problematic for supporting two-way binding to signals. This unintentionally ended up causing the TCB to two-way bindings to look something like `someOutput.subscribe($event => expr);` which does nothing. It largely hasn't been a problem, because the input side of two-way bindings was still being checked, except for the case where the input side of the two-way binding has a wider type than the output side.

These changes re-add type checking for the output side by generating the following TCB instead:

```
someOutput.subscribe($event => {
  var _t1 = unwrapSignalValue(this.someField);
  _t1 = $event;
});
```

PR Close #59002
2024-12-05 16:11:02 -08:00
Kristiyan Kostadinov
68c5e02548 refactor(compiler-cli): rename misleading function (#59002)
The `isSplitTwoWayBinding` function was a bit misleading, because it has side effects. Renames the function make it a bit more explicit.

PR Close #59002
2024-12-05 16:11:02 -08:00
Kristiyan Kostadinov
4559e125f0 refactor(compiler): generate debug location instruction (#58982)
Adds the logic that will generate the `ɵɵattachSourceLocations` instruction.

Fixes #42530.

PR Close #58982
2024-12-05 16:09:55 -08:00
Kristiyan Kostadinov
c9b3bd8409 refactor(compiler): capture template path (#58982)
Captures the template path in the component's metadata so it can be used later on.

PR Close #58982
2024-12-05 16:09:55 -08:00
Kristiyan Kostadinov
00d5b0dfd3 refactor(compiler-cli): rework path normalization function (#58982)
Tweaks the `getProjectRelativePath` function so it's not as dependent on the TypeScript AST.

PR Close #58982
2024-12-05 16:09:55 -08:00
Alex Rickabaugh
2e907eaa98 refactor(compiler-cli): remove circular dep in the partial evaluator (#59083)
Use `import type` to break a phantom import cycle.

PR Close #59083
2024-12-05 16:01:14 -08:00
hawkgs
0513fbc9fc docs: set syntax highlighting of code examples MD code blocks (#59026)
Set the syntax highlighting based on the code examples' language.

PR Close #59026
2024-12-04 17:30:28 +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
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
bd1f1294ae feat(core): support TypeScript 5.7 (#58609)
Updates the repo to allow for TypeScript 5.7 to be used.

PR Close #58609
2024-11-25 17:12:10 +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
JoostK
21f757c1c4 fix(core): correctly perform lazy routes migration for components with additional decorators (#58796)
This fixes an issue where the lazy-routes migration would crash for component classes a
decorator without arguments in front of the `@Component` decorator (in particular, it needed
to be the first decorator).

Fixes #58793

PR Close #58796
2024-11-21 16:43:30 +00:00
Paul Gschwendtner
0675a243f4 refactor(compiler-cli): parse angularCompilerOptions from bazel options as a fallback (#58637)
This commit is only useful to Google. It fixes that some code relies on
`readConfiguration`, but doesn't properly parse Angular compiler options
as those are part of `bazelOptions.angularCompilerOptions` if the
1P-generated tsconfig's are used.

PR Close #58637
2024-11-14 14:55:54 +00:00
Kristiyan Kostadinov
731e3ea883 refactor(compiler-cli): broaden type of getPotentialImportsFor (#58627)
Currently the `getPotentialImportsFor` only accepts a `ClassDeclaration` as the context for generating an import, but that's not necessary because it doesn't require any class-specific information. These changes expand it to any `Node` so that it can be used when generating imports in testing declarations.

PR Close #58627
2024-11-13 18:04:31 +00:00