Commit graph

1988 commits

Author SHA1 Message Date
Kristiyan Kostadinov
46af02395f fix(compiler): avoid conflicts between HMR code and local symbols (#61550)
Currently we construct the HMR replacement URL inline by calling into the native `URL` constructor. This can cause conflicts with user code that defines a symbol called `URL`.

These changes resolve the issue by moving the URL construction into a separate function. This has a secondary benefit of making the generated code easier to follow and allowing us to update the URL without changing the compiled code.

Fixes #61517.

PR Close #61550
2025-05-21 12:25:25 +00:00
Joey Perrott
7f6bb91c5d build: update compiler-cli to not be stamped when used for the compiler in ng_project (#61535)
The compiler-cli package needs to be unstamped and will the resulting generated code will be stamped as expected.

PR Close #61535
2025-05-21 09:16:06 +00:00
Alan Agius
8f65223bd8 fix(core): update min Node.js support to 20.19, 22.12, and 24.0 (#61499)
This is to match the versions of the Angular CLI.

See: https://github.com/angular/angular-cli/pull/30349

PR Close #61499
2025-05-20 14:15:13 +00:00
Paul Gschwendtner
7e571069bc refactor(compiler): avoid duplication between FactoryTarget type (#61472)
Avoids duplication of the `FactoryTarget` enums. This is necessary
now because we are exposing the previously deeply-imported JIT facade
now via the exports; and the typing integration tests surface a type
conflict due to the different duplicated enums.

PR Close #61472
2025-05-20 10:00:43 +00:00
Paul Gschwendtner
3a106a35bc build: move private testing helpers outside platform-browser/testing (#61472)
These helpers are often imported by various tests throughout the
repository, but the helpers aren't exported/exposed from the public
entry-point; even though they confusingly reside in there.

This commit fixes this, and moves the helpers into
`packages/private/testing`. This is a preparation for the `ts_project`
migration where we don't want to leverage deep imports between packages.

PR Close #61472
2025-05-20 10:00:43 +00:00
Kristiyan Kostadinov
7fa3203ee7 refactor(compiler): account for pipes without names (#61328)
Updates the compiler logic to account for pipe definitions that may not have names.

PR Close #61328
2025-05-19 08:24:06 +00:00
Paul Gschwendtner
397f9987ef build: support new ng_project rule (#61275)
Supports the `ng_project` rule with the local compiler-cli version
from HEAD.

PR Close #61275
2025-05-14 12:01:51 +00:00
Kristiyan Kostadinov
eae1083a54 refactor(compiler): indicate in AST if node is self-closing (#61307)
Follow-up from https://github.com/angular/angular/pull/61240#discussion_r2084445328. Adds a `isSelfClosing` property on element-like AST nodes so consumers can easily determine if it's self-closing, rather than having to look at the spans. This is useful for migrations and in the language service.

PR Close #61307
2025-05-14 11:06:22 +02:00
Kristiyan Kostadinov
8f2874e86d fix(compiler): incorrectly handling let declarations inside i18n (#60512)
The compiler wasn't handling `@let` declarations placed inside i18n blocks. The problem is that `assignI18nSlotDependencies` phase assigns the `target` of i18n ops much earlier than the `@let` optimization. If the `@let` ends up getting optimized because it isn't used in any child views, the pointer in the i18n instruction becomes invalid. This hadn't surfaced so far, because we didn't optimize `declareLet` ops, however once we do, we start hitting assertions that the optimized `declareLet` isn't used anywhere.

These changes resolve the issue by moving the i18n phases after the `@let` optimization.

PR Close #60512
2025-05-13 16:31:38 -07:00
Kristiyan Kostadinov
a6b7b9b8c5 perf(compiler): reduce allocations for let declarations only used in the same view (#60512)
We have some code that avoids `storeLet` calls for declarations only used in the same view, however we didn't previously remove the corresponding `declareLet` calls, because of the following case:

```
@let foo = something$ | async; <!-- First in the template -->
{{foo}}
```

Here we need a `TNode` (created by `declareLet`) in order for DI to work correctly. Since this is only required when using pipes, we can optimize away expressions that do not have pipes.

PR Close #60512
2025-05-13 16:31:38 -07:00
Paul Gschwendtner
810b0a7e5c refactor: add explicit types for exports relying on inferred call return type (#61312)
As part of the Bazel toolchain migration we noticed that implicit types
generated by the TypeScript compiler sometimes end up referencing types
from other packages (i.e. cross-package imports).

These imports currently work just because the Bazel `ts_library` and
`ng_module` rules automatically inserted a `<amd-module
name="@angular/x" />` into `.d.ts` of packages. This helped TS figure
out how to import a given file. Notably this is custom logic that is not
occuring in vanilla TS or Angular compilations—so we will drop this
magic as part of the toolchain cleanup!

To improve code quality and keep the existing behavior working, we are
doing the following:

- adding a lint rule that reduces the risk of such imports breaking. The
  failure scenario without the rule is that API goldens show unexpected
  diffs, and types might be duplicated in a different package!

- keeping the `<amd-module` headers, but we manually insert them into
  the package entry-points. This should ensure we don't regress
  anywhere; while we also improved general safety around this above.

Long-term, isolated declarations or a lint rule from eslint-typescript
can make this even more robust.

PR Close #61312
2025-05-13 22:45:18 +00:00
Kristiyan Kostadinov
814e6b07ac refactor(compiler): detect directly referenced pipes during parsing (#61158)
Moves the logic to detect directly referenced pipes into the compiler so that we don't have to do it ad-hoc.

PR Close #61158
2025-05-08 07:11:37 +02:00
Kristiyan Kostadinov
bb863ee0db refactor(compiler): consolidate combined recursive visitors (#61158)
We have several cases where we need a visitor that traverses both the template and expression ASTs fully. Currently we're re-implementing the visitor each time which means that we need to update multiple visitors every time something changes.

These changes add a single base class that we can reuse to simplify such cases in the future.

PR Close #61158
2025-05-08 07:11:36 +02:00
Paul Gschwendtner
032b802f54 build: remove irrelevant madge circular deps tests (#61156)
We don't need this tooling anymore because we are already validating
that there are no circular dependencies via the `ng-dev` tooling that
checks `.ts` files directly.

Also these tests never actually failed to my knowledge.

PR Close #61156
2025-05-07 11:28:59 -07:00
Alan Agius
d5c6f2c4de refactor: add Node.js 24 as supported version (#61142)
Node.js 24 has been released https://nodejs.org/en/about/previous-releases

Closes: #61140

PR Close #61142
2025-05-06 13:38:25 -07:00
Kristiyan Kostadinov
2c17145520 refactor(compiler): element references not resolved when selectorless matcher is passed in (#61100)
Fixes that the template binder didn't resolve references to DOM nodes (e.g. `<div #ref></div>` if the matcher being passed in isn't a `SelectorMatcher`.

PR Close #61100
2025-05-05 14:38:13 -07:00
arturovt
4184e0b9c2 refactor(compiler): improve stringify (#60013)
This is the same change that was made in this commit (cf3a5073ec). See its description for clarification.

PR Close #60013
2025-04-30 12:40:02 -07:00
Kristiyan Kostadinov
abdb6e2945 refactor(compiler): allow binder to be created without matcher (#61018)
Currently to create an `R3TargetBinder`, we have to pass some sort of directive matcher, however we also have a couple of use cases where we use the binder to do analysis that's unrelated to directives (e.g. resolving the `@defer` blocks). In these cases having to create a dummy matcher adds some slight overhead and makes the code harder to reason about since it looks like directive matching may be happening.

These changes update the `R3TargetBinder` to allow for `null` to be passed as the directive matcher.

PR Close #61018
2025-04-29 21:06:10 +00:00
Kristiyan Kostadinov
8488279659 refactor(compiler): simplify tracking of directives (#61018)
An earlier commit that introduced tracking of selectorless directives to the template binder made it so `getDirectivesOfNode` returns _all_ of the matched directives while a new method called `getOwnedDirectives` would return only the ones brought in by the specific node.

In hindsight, this is likely to cause bugs in the future, because it's unclear whether to reach for `getDirectivesOfNode` or `getOwnedDirectives`. These changes remove `getOwnedDirectives` and make it so in selectorless `getDirectivesOfNode` accepts the directive AST node itself.

Another goal of this refactor is that the TCB shouldn't have to check the `selectorlessEnabled` config option.

PR Close #61018
2025-04-29 21:06:10 +00:00
Kristiyan Kostadinov
4b0f733cb4 refactor(compiler): add more information to template binder (#60977)
Updates the template binder to include information about directives owned by a specific component/directive node and the names of template symbols that don't exist. These will be used when generating the type check block.

PR Close #60977
2025-04-24 13:02:39 -07:00
Kristiyan Kostadinov
bc9a067ef4 refactor(compiler-cli): add flag to enable selectorless (#60977)
Adds a private flag that we can use to enable selectorless as it's being developed.

PR Close #60977
2025-04-24 13:02:39 -07:00
Kristiyan Kostadinov
3d86b3ade7 refactor(compiler): account for selectorless in template binder (#60952)
Updates the template binder to account for the new selectorless AST nodes. This is a prerequisite to supporting template type checking of the new syntax.

PR Close #60952
2025-04-23 09:55:54 +02:00
Kristiyan Kostadinov
3719752cef refactor(compiler): validate references in selectorless (#60952)
Adds the follow validations to the selectorless template parsing:
* Local references with values are not allowed (e.g. `#foo="bar"`).
* Multiple local references with the same on a component or directive are not allowed.

PR Close #60952
2025-04-23 09:55:54 +02:00
Kristiyan Kostadinov
08512ee285 refactor(compiler): add flag to enable selectorless parsing (#60952)
Adds a flag to `parseTemplate` to enable selectorless.

PR Close #60952
2025-04-23 09:55:54 +02:00
Kristiyan Kostadinov
6cce056d41 refactor(compiler): allow different kinds of directive matchers to be passed to binder (#60952)
Updates the target binder to allow either a selector-based or selectorless matcher to be passed in. This will allow us to skip some of the overhead when matching directives to nodes.

PR Close #60952
2025-04-23 09:55:54 +02:00
Matthieu Riegler
1b8e7ab9fe feat(compiler): support the in keyword in Binary expression (#58432)
This commit adds the support for the `in` keyword as a relational operator, with the same precedence as the other relational operators (<,>, <=, >=)

BREAKING CHANGE: 'in' in an expression now refers to the operator

PR Close #58432
2025-04-22 21:44:12 +02:00
Matthieu Riegler
84d359c173 refactor(compiler): add support for the new search element (#54945)
See #whatwg/html#5811
Spec: https://html.spec.whatwg.org/multipage/grouping-content.html#the-search-element

breaking change: You cannot have self-closing `search` component anymore as they are recognized as a native non-void element.

fixes #54944

PR Close #54945
2025-04-14 09:34:35 -04: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
Kristiyan Kostadinov
42039b7253 refactor(compiler): produce selectorless ASTs (#60724)
Adds the initial logic to produce the `Component` and `Directive` AST nodes from their equivalents in the HTML AST.

PR Close #60724
2025-04-04 11:28:47 -07:00
Kristiyan Kostadinov
334d0fa585 refactor(compiler): allow for security context to be inferred without tag name (#60724)
Currently it's required to pass in the tag name when determining the security context, however with selectorless we might not have a tag name. These changes update the logic to account for it.

PR Close #60724
2025-04-04 11:28:47 -07:00
Kristiyan Kostadinov
10b5beab3d refactor(compiler): add start/end spans to ng-content element (#60724)
Adds `startSourceSpan` and `endSourceSpan` to the `Content` AST node so it's consistent with the rest of the element-like nodes.

PR Close #60724
2025-04-04 11:28:47 -07:00
Kristiyan Kostadinov
bf9dd185b0 refactor(compiler): introduce R3 AST nodes for components and directives (#60724)
Sets up the AST nodes for components and directives in the R3 AST.

PR Close #60724
2025-04-04 11:28:47 -07:00
Kristiyan Kostadinov
3a6e45f965 refactor(compiler): integrate new nodes into visitors (#60724)
Integrates the `Component` and `Directive` nodes into the various visitors.

PR Close #60724
2025-04-04 11:28:47 -07:00
Kristiyan Kostadinov
c74b168382 refactor(compiler): produce AST from selectorless tokens (#60724)
Updates the HTML parser to produce AST nodes from the tokens produced that were added to the lexer in the previous commit.

PR Close #60724
2025-04-04 11:28:47 -07:00
Kristiyan Kostadinov
dc1c0a0e44 refactor(compiler): add component and directives nodes to HTML AST (#60724)
Updates the HTML AST to add nodes for components and directives. Also adds a `directives` field to `Element`.

PR Close #60724
2025-04-04 11:28:47 -07:00
Kristiyan Kostadinov
03944ccf52 refactor(compiler): add experimental tokenization of directives (#60724)
Sets up tokenization for the new experimental directive syntax.

PR Close #60724
2025-04-04 11:28:46 -07:00
Kristiyan Kostadinov
e8dbc363b1 refactor(compiler): add experimental tokenization of components (#60724)
Sets up the tokenization for the new experimental selectorless components as a first step towards producing an AST.

PR Close #60724
2025-04-04 11:28:46 -07:00
Matthieu Riegler
7da56e23d0 refactor(compiler): add selectedcontent to the DOM element schema registry (#60683)
This is only adding support for `selectedcontent` at the compiler level. At runtime it doesn't behave as expected see #60636

fixes #60679

PR Close #60683
2025-04-02 16:27:01 +00:00
Matthieu Riegler
e4be32d8f0 refactor(compiler): prevent object methods being recognised as entities (#58100)
With this commit object methods (like `valueOf`, `toString` are not considered as valid entities anymore.

PR Close #58100
2025-04-02 11:35:53 +00:00
Andrew Kushnir
c702e8af0b refactor(compiler): convert scripts within packages/compiler to relative imports (#60625)
This commit updates scripts within `packages/compiler` 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
Kristiyan Kostadinov
e6d2afbfb9 fix(compiler): throw for invalid "as" expression in if block (#60580)
Adds some validation that the "as" expression in an `@if` block is valid.

Fixes #59939.

PR Close #60580
2025-03-27 20:24:58 +00:00
Kristiyan Kostadinov
ec8c8f827e refactor(compiler): allow name parsing logic to be reused (#60561)
Moves the logic for parsing event names out into methods on the `BindingParser` so we don't have to duplicate it. Also updates the types to more accurately represent the runtime value.

PR Close #60561
2025-03-26 20:46:45 -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
d2a8639b25 refactor: remove peer dependency on core from compiler (#60437)
Note that this is not a public-facing change because the compiler is not
supposed to be used directly. See `public-api-surface.md`

We are changing this because in the current state, for advanced setups
like our Bazel infrastructure in Material, this peer dependency can
result in a cycle. That is because we may decide to link the
`@angular/core` package using the compiler-cli/compiler; while
transitively the compiler has a dependency on core. That's a cycle
(surfacing in Bazel w/ `rules_js`).

Dropping this optional peer dependency is acceptable because `core`,
since recently, also has an optional peer dependency on the compiler.
This one makes more sense and is also more user-facing (people generally
never install the compiler directly).

Notably the compiler does not have any runtime dependency on `core` and
this was purely added for some safety checking. See:
8c171da29f

PR Close #60437
2025-03-18 18:15:07 +01:00
Kristiyan Kostadinov
7ffcb504df refactor(compiler): account for host element in binder (#60267)
Updates the `R3TargetBinder` to ingest host element nodes.

PR Close #60267
2025-03-17 14:28:40 +01:00
Kristiyan Kostadinov
a34353c736 refactor(compiler): add AST node for host element (#60267)
Adds the `HostElement` AST node that can be used to represent the host of a directive. Also exposes the `BindingParser` type so it's easier to pass around the return value of `makeBindingParser`.

PR Close #60267
2025-03-17 14:28:40 +01:00