Commit graph

3473 commits

Author SHA1 Message Date
Paul Gschwendtner
abe96914f5 build: remove unnecessary feature detection that breaks with shared chunks (#60825)
Since APF can contain shared chunks, where e.g. `eetemplate` lives, the
`coreHasSymbol` check is no longer reliable. Right now it even prevents
the version range check (that is reliably working) from running because
we detect a `index.d.ts` file but simply don't find the requested
symbol in there (we don't expand exports via type checker).

PR Close #60825
2025-04-10 14:19:52 +00:00
Kristiyan Kostadinov
8744c9a165 fix(compiler-cli): ensure HMR works with different output module type (#60797)
Currently when we transpile the HMR update module, we use the project's compiler options verbatim. This appears to break down with some module types, whereas we have to use a native export.

These changes override the compiler options to ensure that the user's options don't end up breaking HMR.

Fixes #60795.

PR Close #60797
2025-04-09 11:42:55 -07:00
Enea Jahollari
7a971766dc feat(compiler): add extended diagnostic for uninvoked track function on @for blocks (#60495)
The compiler will warn devs when they haven't invoked the track function passed to track in @for blocks

PR Close #60495
2025-04-08 10:10:33 -07:00
Kristiyan Kostadinov
92c4123a74 refactor(compiler): integrate new AST nodes into visitors (#60724)
Updates the various visitors to add placeholders for the new AST nodes.

PR Close #60724
2025-04-04 11:28:47 -07:00
Andrew Kushnir
4f458a825d refactor(compiler-cli): convert scripts within packages/compiler-cli to relative imports (#60625)
This commit updates scripts within `packages/compiler-cli` to relative imports as a prep work to the upcoming infra updates.

PR Close #60625
2025-04-01 11:57:53 +00:00
Kristiyan Kostadinov
9c106f4401 refactor(core): introduce domProperty instruction (#60608)
Renames the `hostProperty` instruction to `domProperty` since it's not really host-specific and we can use it for other DOM-specific operations in the future.

PR Close #60608
2025-03-31 13:15:19 +00:00
Jessica Janiuk
005ad65b1f fix(core): prevent omission of deferred pipes in full compilation (#60571)
This prevents a bug where pipes would be excluded from defer dependency generation.

PR Close #60571
2025-03-31 13:11:12 +00:00
Andrew Scott
5948cd03c5 fix(compiler-cli): Produce fatal diagnostic on duplicate decorated properties (#60376)
This prevents the compilation and language service from crashing.

fixes https://github.com/angular/vscode-ng-language-service/issues/2091

PR Close #60376
2025-03-27 20:26:42 +00:00
Kristiyan Kostadinov
1e6faad479 fix(compiler-cli): correctly parse event name in HostListener (#60561)
Fixes that we weren't accounting for targeted events when creating the AST for `@HostListener`-decorated members.

PR Close #60561
2025-03-26 20:46:45 -07:00
Kristiyan Kostadinov
7e03af898e fix(compiler-cli): set correct target when type checking events (#60561)
Currently the TCB generation code doesn't handle targeted events (e.g. `(document:click)`) which ends up binding to the current element and can have type inference implications. These changes take the event's `target` into account.

PR Close #60561
2025-03-26 20:46:45 -07:00
Paul Gschwendtner
9f18c7cc74 fix(compiler-cli): support relative imports to symbols outside rootDir (#60555)
By default, the compiler-cli uses the relative import strategy when
there is no `rootDir` or `rootDirs`. This is expected as everything is
assumed to be somehow reachable through relative imports.

With `rootDirs` that allow for a "virtual file system"-like environment,
the compiler is not necessarily able to always construct proper relative
imports. The compiler includes the `LogicalProjectStrategy` for this
reason. This strategy is able to respect `rootDirs` to construct
relative paths when possible.

This logic currently accidentally triggers when there is a `rootDir`
set. This option is not to be confused with the virtual directory
option called `rootDirs`. The compiler currently confuses this and
accidentally enters this mode when there is just a `rootDir`— breaking
in monorepos that imports can point outside the `rootDir` to e.g. other
compilation unit's `.d.ts` (which is valid; just not `.ts` sources can
live outside the root dir).

This is necessary for our Bazel toolchain migration.

PR Close #60555
2025-03-26 20:45:55 -07:00
Alan Agius
fe9b79b615 feat(core): update Node.js version support (#60545)
Node.js v18 will reach End-of-Life on April 30, 2025, and will no longer be supported in Angular v20.
Node.js Release Schedule: https://github.com/nodejs/release#release-schedule

BREAKING CHANGE:
- Angular no longer supports Node.js v18.
- Node.js versions 22.0 to 22.10 are also no longer supported.

Before upgrading to Angular v20, ensure the Node.js version is at least 20.11.1.
For the full list of supported versions, visit: https://angular.dev/reference/versions

PR Close #60545
2025-03-26 20:42:16 -07:00
Kristiyan Kostadinov
8b990a31c3 fix(compiler): error if rawText isn't estimated correctly (#60529)
The `TemplateLiteralElementExpr` has some logic where it tries to estimate the `rawText` if one isn't provided by looking at the node's source span. The problem with this approach is that we have some long-standing issues with our expression AST parser (see https://github.com/angular/angular/pull/60267#discussion_r1986402524) where it might not produce accurate spans if escape sequences are involved. This in turn can lead to unrecoverable errors, because TypeScript will throw an error if the raw string doesn't match the cooked one when constructing a TypeScript AST node.

These changes remove the logic that depends on the source span and relies purely on the secondary fallback that inserts escaped characters manually.

It's also worth noting that the `rawText` doesn't seem to matter much at this point, because the main usage of it is when downlevelling template literals to ES5 which we no longer support.

Fixes #60528.

PR Close #60529
2025-03-26 20:37:31 -07:00
Jessica Janiuk
58e1d9e39a refactor(compiler): Add conditionalCreate instruction (#60425)
This adds a new instruction for dealing with creating conditionals. It ensures flags are set on the TNode for later identification during hydration.

PR Close #60425
2025-03-21 14:45:23 -07:00
Miles Malerba
55e9f1ffa2 refactor(compiler-cli): remove unnecessary paren logic for ternaries (#60263)
Removes logic that was explicitly adding parentheses around ternaries
used as the condition of another ternary. Instead we can just rely on
Typescript to add the parentheses if they are needed to make the code
match the structure of the AST.

Also added a note pointing to the issue that currently prevents us from
removing similar logic pertaining to nullish coalescing

PR Close #60263
2025-03-21 14:34:35 -07:00
Paul Gschwendtner
e0ff321433 build: prepare testing infrastructure for code splitting of core package (#60487)
When we switch to relative imports, shared `.d.ts` chunks can be
generated.

We need to also pull these into our mock virtual FS testing
environments. Notably this does not cause a test slow-down because we
are talking about very few extra `.d.ts` chunk files. In our experiments
before, with no dts bundling, we saw test time increase from e.g.
20seconds to 100seconds. The 20s are still the same locally!

In addition, since code for definitions can now reside in shared `.d.ts`
chunks, the language service tests need to be adjusted in cases where
they assert for code definition locations in `@angular/core`. A new
helper prepares for more code to be moved into arbitrary `.d.ts` files;
we should simply assert the definition comes out of
`node_modules/@angular/core`.

PR Close #60487
2025-03-20 12:30:57 -07:00
Paul Gschwendtner
164bb3f4a3 build: disable RBE for compliance partial goldens (#60473)
We've seen these tests regularly, but somewhat rarely to be
stuck/hanging in the remote execution workers. Since the issue was
reproducable locally (via local RBE environment), we can improve
stability for the team until we resolve this with the RBE team.

PR Close #60473
2025-03-20 07:40:22 +00:00
Kristiyan Kostadinov
29eded6457 fix(compiler-cli): report more accurate diagnostic for invalid import (#60455)
Currently when an incorrect value is in the `imports` array, we highlight the entire array which can be very noisy for large arrays. This comes up semi-regularly (at least for me) when an import is missing.

These changes add some logic that reports a more accurate diagnostic location for the most common case where the `imports` array is static. Non-static arrays will fall back to the current behavior.

PR Close #60455
2025-03-19 19:06:38 +01:00
Kristiyan Kostadinov
2d51a203dc fix(compiler-cli): wrong event name for host listener decorators (#60460)
Fixes that when generating the type checking code `@HostListener`, we were using the method name instead of the event name.

PR Close #60460
2025-03-19 19:05:44 +01:00
Miles Malerba
bec1610da2 feat(compiler-cli): add extended diagnostic for invalid nullish coalescing (#60279)
The semantics for nullish coalescing (`??`) in Javascript/Typescript
differ slightly from the semantics in Angular templates. Mixing nullish
coalescing with logical and/or without parentheses is an error in
Javascript. This PR adds an extended diagnostic that can be enabled to
treat it as an error in Angular templates as well.

PR Close #60279
2025-03-19 10:21:48 +01:00
Paul Gschwendtner
2ca72faab1 build: improve partial compliance golden generation and add debug logging (#60427)
Improves the partial compliance golden generation to not rely on large
files being transmitted via `stdout`. Instead the files are written
directly as it's done in idiomatic Bazel generation actions.

In addition, we add extra stdout logging for the Bazel action, to see if
the process is actually invoked in RBE workers. Right now those are
occassionally stuck, but neither us, nor the RBE team can see anything
running, and they're occasionally stuck for 1hr.

PR Close #60427
2025-03-18 07:10:43 +00:00
Kristiyan Kostadinov
bf2b0253bc refactor(compiler-cli): move typeCheckHostBindings option (#60267)
Moves the `typeCheckHostBindings` option into `StrictTemplateOptions` and renames the latter.

PR Close #60267
2025-03-17 14:28:41 +01:00
Kristiyan Kostadinov
1971e57a45 feat(compiler-cli): support type checking of host bindings (#60267)
Historically Angular's type checking only extended to templates, however host bindings can contain expressions as well which can have type checking issues of their own. These changes expand the type checking infrastructure to cover the `host` object literal, `@HostBinding` decorators and `@HostListener` with full language service support coming in future commits.

Note that initially the new functionality is disabled by default and has to be enabled using the `typeCheckHostBindings` compiler flag.

PR Close #60267
2025-03-17 14:28:41 +01:00
Kristiyan Kostadinov
eb4c22e6d9 refactor(compiler-cli): enable type checking of directive classes (#60267)
Updates the directive handler to enable type checking of directives. Currently this only applies to checking of host bindings.

PR Close #60267
2025-03-17 14:28:40 +01:00
Kristiyan Kostadinov
84b3721351 refactor(compiler-cli): produce host binding type checking information for components (#60267)
Sets up the logic that produces the information necessary to type check host bindings of a component. Also introduces a compiler flag for toggling checking of host bindings.

PR Close #60267
2025-03-17 14:28:40 +01:00
Kristiyan Kostadinov
0669709120 refactor(compiler-cli): add logic for synthesizing host element (#60267)
Adds the logic that creates a `HostElement` AST node based on the host bindings of a directive.

PR Close #60267
2025-03-17 14:28:40 +01:00
Kristiyan Kostadinov
b8f2a50c68 refactor(compiler-cli): track host binding information (#60267)
Sets up the infrastructure to track the host bindings of directives for type checking purposes.

PR Close #60267
2025-03-17 14:28:40 +01:00
Kristiyan Kostadinov
04d963c0a5 fix(core): remove unused parameter from listener instruction (#60406)
Removes the `useCapture` parameter from the `listener` instruction, because it's not used.

PR Close #60406
2025-03-17 12:16:03 +01:00
Angular Robot
1668b9fbb0 build: update babel dependencies to v7.26.10 (#60398)
See associated pull request for more information.

PR Close #60398
2025-03-17 10:29:43 +01:00
Paul Gschwendtner
4fa5d18e5a feat(bazel): support bundling .d.ts with code splitting (#60321)
Instead of relying on Microsoft's API extractor for `d.ts` bundling,
we are switching to Rollup-based `.d.ts` bundling.

This allows us to support code spliting, even for `.d.ts` files,
allowing for relative imports to be used between entry-points, without
ending up duplicating `.d.ts` definitions in two files. This would otherwise cause
problems with assignability of types.

It also nicely integrates into our existing rollup configuration, and
overall simplifies the `ng_package` rule even further!

Notably `tsup` also uses this rollup plugin, and it seems to work well.
Keep in mind that Microsoft's API extractor is pretty hard to integrate,
caused many problems in the past, and isn't capable of code splitting.
This aligns our d.ts bundling with the .mjs bundling (great alignment).

PR Close #60321
2025-03-11 13:03:08 -07:00
Matthieu Riegler
c73520bb74 refactor(compiler): remove empty empty string suffix from interpolation instructions (#60066)
With this change, interpolations that don't have a suffix will miss the last argument which was previously an empty string.

PR Close #60066
2025-03-10 16:31:34 -07:00
Matthieu Riegler
db5963797d docs(docs-infra): Extract class constructors (#60302)
fixes #59180

PR Close #60302
2025-03-10 16:05:02 -07:00
Kristiyan Kostadinov
9be2b334ed fix(compiler-cli): handle transformed classes when generating HMR code (#60298)
We had several places where we were trying to get the source file of a class for which we're generating HMR-related code. These calls will fail if the class was transformed so we have to get its source file through the original node.

Fixes #60287.

PR Close #60298
2025-03-10 09:58:52 -07:00
Charles Lyding
a1cacc5b17 fix(compiler-cli): avoid fatal diagnostics for missing template files (#58673)
A build will still fail in this case. However, for the language service,
this allows the component to exist in the compiler registry and prevents
cascading diagnostics within an IDE due to "missing" components. The
originating template related errors will still be reported in the IDE.
This case is particularly important when a template file either does
not exist or is inaccessible to the language service.

PR Close #58673
2025-03-10 09:54:16 -07:00
Miles Malerba
00938699b8 refactor(compiler-cli): handle parentheses in the template pipeline (#60169)
Now that the expression AST contains parenthesized expressions, this
refactors the template pipeline to strip out the ones we don't need.

PR Close #60169
2025-03-10 09:53:10 -07:00
Miles Malerba
d4cfeb0a86 refactor(compiler): add parenthesized expressions to experssion ast (#60169)
Following up on #60127 which added the concept of a parenthesized
expression to the output AST, this does the same for the expression AST.

PR Close #60169
2025-03-10 09:53:10 -07:00
Paul Gschwendtner
a02e270fcb build: properly compile tests in core with Angular compiler (#60268)
Previously we never could use relative imports to import e.g. `Component`
in e.g. the `core/tests/bundling` folder. This was necessary because otherwise the
Angular compiler wouldn't process those files as it wouldn't recognize
the Angular decorator as the one from `@angular/core`.

Notably this still isn't a large issue because relative imports still
work for most core tests, that are JIT compiled!

For bundling tests though, or some smaller targets, our new upcoming
guidelines for using relative imports inside the full package; fall
apart. This commit unblocks this effort and allows us to use relative
imports in all tests of `packages/core`. This is achieved by leveraging
the existing `isCore` functionality of the compiler, and fixing a few
instances that were missing before.

PR Close #60268
2025-03-07 11:00:47 -08:00
Kristiyan Kostadinov
afea8a9d0c refactor(compiler-cli): rework resource handling to allow directives (#60191)
Currently only components can have resources, because they're the only symbol kinds being type checked. Since we want to add directives to it, these changes rework the resource handling to accommodate them.

PR Close #60191
2025-03-06 10:39:31 -08:00
Kristiyan Kostadinov
44a8de20d5 refactor(compiler-cli): rework source manager to accommodate directives (#60191)
Currently the `TemplateSourceManager` is set up to specifically cater to component templates. These changes make it more generic so we can reuse it for directives.

PR Close #60191
2025-03-06 10:39:31 -08:00
Kristiyan Kostadinov
5af15a6d50 refactor(compiler-cli): rework type checking internals to accommodate more than components (#60191)
Currently a lot of the internal type checking data structures are set up specifically for components, because we only support type checking of templates. Since this will change in future commits, these changes prepare for it by renaming various methods and separating out component-specific data.

PR Close #60191
2025-03-06 10:39:31 -08:00
Kristiyan Kostadinov
c14386900f refactor(compiler-cli): change TemplateId terminology (#60191)
Renames the `TemplateId` and terminology related to it, because we'll be using it for more than just templates.

PR Close #60191
2025-03-06 10:39:31 -08:00
Matthieu Riegler
8b8e3fdca4 docs(docs-infra): Don't truncate types in symbol extraction (#59909)
PR Close #59909
2025-03-04 19:54:57 +00:00
Miles Malerba
ffb19e64f1 fix(compiler-cli): preserve required parens for nullish coalescing (#60060)
Fixes outputted nullish coalescing expressions to not drop parentheses
when it would change the meaning of the expression.

PR Close #60060
2025-03-04 17:44:54 +00:00
Miles Malerba
7e2d5c2203 test(compiler-cli): Update tests for nullish coalescing (#60060)
Updates tests to reflect the fact that we no loger down-level nullish
coalescing.

PR Close #60060
2025-03-04 17:44:53 +00:00
Miles Malerba
2a23209b08 refactor(compiler): stop down-leveling nullish coalescing (#60060)
Stop down-leveling the nullish coalescing (`??`) operator in templates.
Depending on the ES version typescript may still down-level it.

PR Close #60060
2025-03-04 17:44:53 +00:00
Kristiyan Kostadinov
326d48afb4 feat(core): drop support for TypeScript older than 5.8 (#60197)
Narrows down the versions of TypeScript we need to support.

BREAKING CHANGE:
* TypeScript versions less than 5.8 are no longer supported.

PR Close #60197
2025-03-04 17:39:06 +00:00
Alan Agius
d92fba084b refactor(compiler): remove ngcc binary (#60185)
Remove ngcc deprecation binary

PR Close #60185
2025-03-03 22:05:22 +00:00
Miles Malerba
51b8ff23ce feat(compiler): support tagged template literals in expressions (#59947)
Adds support for using tagged template literals in Angular templates.

Ex:
```
@Component({
  template: '{{ greet`Hello, ${name()}` }}'
})
export class MyComp {
  name = input();

  greet(strings: TemplateStringsArray, name: string) {
    return strings[0] + name + strings[1] + '!';
  }
}
```

PR Close #59947
2025-02-28 19:53:33 +00:00
Andrew Scott
f9043e24ac fix(compiler-cli): ensure template IDs are not reused if a source file changes (#60152)
This commit fixes a bug where nodes are reused across incremental
compilations. The source file's next template ID is lost because a new
source file is created but nodes may still be retained.

PR Close #60152
2025-02-28 19:53:05 +00:00
Miles Malerba
7c9b4892e9 fix(compiler-cli): preserve required parens in exponentiation expressions (#60101)
Parentheses are required around a unary operator used in the base of an
exponentiation expression. For example: `(-1) ** 3`

PR Close #60101
2025-02-28 16:28:10 +00:00