Commit graph

720 commits

Author SHA1 Message Date
Joey Perrott
cbc258eec8 build: remove ts_project_interop infrastructure (#62908)
Remove the interop macros and final usages

PR Close #62908
2025-07-31 09:12:58 +00:00
Matthieu Riegler
5b25d93f27 fix(compiler): exclude more safe reads expression from 2way-binding (#62852)
Priori to this fix the parser would allow safereads in accestor receievers (but the direct one).

fixes #62837

PR Close #62852
2025-07-29 17:28:08 +00:00
Matthieu Riegler
7aacd569f5 refactor(compiler): Error on comment only interpolations (#62590)
This commit introduces a ParserError to prevent an error later in the pipepine

fixes #34084

PR Close #62590
2025-07-24 09:19:46 +00:00
Kristiyan Kostadinov
7767aa640c fix(compiler): allow more characters in square-bracketed attribute names (#62742)
Currently the HTML parser will stop parsing as soon as it hits an end character in the name of an attribute (e.g. `/` or `>`). This ends up being problematic with some third-party packages like Tailwind which uses a wider range of characters for its class names. While the characters are fine when inside the `class` attribute, our current parser behavior prevents users from setting those classes conditionally through `[class.]` bindings.

These changes adjust the parser to handle such cases.

Fixes #61671.

PR Close #62742
2025-07-23 11:06:47 -04:00
Joey Perrott
8bf97d1370 build: remove all usages of the interop_deps attr for ts_project and ng_project (#62732)
Remove all of the usages of interop_deps as attributes in the repo

PR Close #62732
2025-07-21 13:03:09 -04:00
Jessica Janiuk
fc8247de95 refactor(core): add compiler support for animation instructions (#62528)
this adds the compiler code to support the animate instructions.

PR Close #62528
2025-07-16 16:44:16 -04:00
Kristiyan Kostadinov
acdb8d673d refactor(compiler): indicate whether element is void at AST level (#62648)
Updates the HTML AST to indicate whether a specific element is a void element.

PR Close #62648
2025-07-16 12:40:25 +02:00
Kristiyan Kostadinov
18a675081f fix(compiler): more permissive parsing of @ characters (#62644)
When we introduced blocks, we made a deliberate decision to treat the `@` character as a reserved character in case we need to use it for other syntax in the future. This meant that some common cases, like writing out an email address in the template, can be broken.

After some recent discussions we decided to relax the requirement and only treat `@` as a reserve character if it's followed by a character sequence that matches a known block.

PR Close #62644
2025-07-15 13:24:47 -07:00
Kristiyan Kostadinov
56fbb3299a test(compiler): remove duplicated lexer tests (#62644)
There were 26 duplicated block tests in `lexer_spec.ts`, likely due to merge conflicts. These changes remove the duplicates while keeping the 6 tests that were different.

PR Close #62644
2025-07-15 13:24:47 -07:00
Kristiyan Kostadinov
a1e3f2bcd1 fix(compiler): incorrect spans for left side of binary operation (#62641)
Fixes that the span for the `left` side of a `Binary` AST included the range up to and including the operator.

Fixes #62617.

PR Close #62641
2025-07-15 07:57:32 -07:00
Jessica Janiuk
d7b94e0072 refactor(core): rename all animations package symbols (#62399)
Renames all animations package references with a "legacy" prefix for later easy cleanup.

PR Close #62399
2025-07-01 13:45:45 +00:00
Joey Perrott
b84859073b build: migrate to use web test runner rules (#62292)
Migrate karma tests throughout the repo to use the new web test runner based rule instead

PR Close #62292
2025-06-26 17:19:10 +00:00
Kristiyan Kostadinov
089ad0ee15 fix(compiler): produce more accurate errors for interpolations (#62258)
Currently when there's a parser error in interpolated text, the compiler reports an error on the entire text node. This can be really noisy in long strings.

These changes switch to reporting the errors on the specific expressions that caused them.

PR Close #62258
2025-06-25 16:58:56 +00:00
Kristiyan Kostadinov
982f90ff35 refactor(compiler): remove TokenError (#62160)
Replaces the `TokenError` class with `ParseError` to reduce the number of error classes we need to maintain.

PR Close #62160
2025-06-23 14:25:28 +02:00
Kristiyan Kostadinov
5e9707dc84 refactor(compiler): consolidate error classes (#62160)
Currently we have a `ParserError` that is used for the expression parser and a `ParseError` that is used everywhere else. These changes consolidate them into the `ParseError` to avoid confusion and make it easier to add more context in the future.

PR Close #62160
2025-06-23 14:25:28 +02:00
Kristiyan Kostadinov
0213cd23ff refactor(compiler): support new assignment operators in expression parser (#62064)
Updates the expression parser to account for the new assignment operators that were added to the lexer.

PR Close #62064
2025-06-23 14:23:29 +02:00
Kristiyan Kostadinov
cf3b583b43 refactor(compiler): support more assignment operators in lexer (#62064)
Adds support for the `+=`, `-=`, `*=`, `/=`, `%=`, `**=`, `&&=`, `||=` and `??=` assignment operators to the lexer.

PR Close #62064
2025-06-23 14:23:28 +02:00
Joey Perrott
3a0cfd544d build: migrate to using new jasmine_test (#62086)
Use the new jasmine_test based on rules_js instead of jasmine_node_test from rules_nodejs

PR Close #62086
2025-06-18 08:27:26 +02:00
Kristiyan Kostadinov
eb43e9242d refactor(compiler): account for new assignment AST (#61682)
Reworks the places that were depending on `PropertyWrite` and `KeyedWrite` to account for the new AST structure.

PR Close #61682
2025-06-03 11:08:50 -04:00
Kristiyan Kostadinov
08ee693995 refactor(compiler): produce binary expressions instead of dedicated write ones (#61682)
Currently our expression parser produces two different expressions for writes: `PropertyWrite` (e.g. `foo.bar = 123`) or `KeyedWrite` (e.g. `foo[0] = 123`). This is inconsistent with other ASTs, like TypeScript's, where writes are represented as binary expressions with a `=` operator and it makes it difficult to implement more write operators like `??=`, because we'd essentially have to duplicate them.

These changes switch the expression parser over to produce binary expressions instead.

PR Close #61682
2025-06-03 11:08:50 -04:00
Kristiyan Kostadinov
fd5a04927e fix(compiler): recover invalid parenthesized expressions (#61815)
When the expression parser consumes tokens inside a parenthesized expression, it looks for valid tokens until it hits and invalid one or a closing paren. If it finds an invalid token, it reports and error and tries to recover until it finds a closing paren. The problem is that in such cases, it would produce the `ParenthesizedExpression` and continue parsing **from** from the closing paren which would then produce more errors that add noise to the output and result in an incorrect representation of the user's code. E.g. `foo((event.target as HTMLElement).value)` would be recovered to `foo((event.target)).value` instead of `foo((event.target).value)`.

These changes resolve the issue by skipping over the closing paren at the recovery point.

Fixes #61792.

PR Close #61815
2025-06-02 15:50:46 -04:00
Kristiyan Kostadinov
5a76826d26 fix(compiler): only report parser errors on invalid expression (#61793)
Currently we reuse the same binding parser for all expressions in the template. Under the hood, the parser has a single `errors` array that it passes into all ASTs which means that if there's one binding with an error, those errors will be propagated to all other ASTs in the template.

These changes switch to having a unique `errors` array for each AST so we only report errors once.

Relates to #61792.

PR Close #61793
2025-06-02 09:56:00 -04:00
Kristiyan Kostadinov
a70f03a9b4 fix(compiler): move defer trigger assertions out of parser (#61747)
When defer blocks have a reference-based trigger without a parameter, we infer it from the placeholder block. This requires some validations like ensuring that there's only one element in the placeholder. The validations are currently implemented at the parser level which can affect tools like linters that need to pass `preserveWhitespaces: true` in order to get accurate source mappings.

These changes move the validations into the template type checker so that they still get flagged, but much later in the process. Moving them over involves a bit more work, because the template type checker also sets `preserveWhitespaces: true`.

Fixes #61725.

PR Close #61747
2025-05-30 13:44:58 -04:00
Paul Gschwendtner
ef44f671f4 build: migrate packages/compiler to ts_project (#61566)
Migrates `packages/compiler` to `ts_project`.

PR Close #61566
2025-05-29 14:39:10 -04:00
Kristiyan Kostadinov
c11527fc68 refactor(compiler): remove unused code (#61668)
Removes the following unused code from the compiler:
* The ICU expander appears to be some really old code converting ICUs into legacy-style control flow directives. It's annoying to keep this one since we need to update it any time the AST changes.
* The `PipeCollector` class wasn't used anywhere.
* The `partitionArray` function wasn't used anywhere.
* The `newArray` function was used only in one test and it can be easily replaced with `new Array().fill`.

PR Close #61668
2025-05-26 12:21:09 +00:00
Matthieu Riegler
3e102f0b84 fix(compiler): lexer support for template literals in object literals (#61601)
This commit fixes a shortcoming of the lexer with template literals

fixes #61572

PR Close #61601
2025-05-26 10:24:16 +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
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
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
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
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
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
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
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
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
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
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
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
ef1fd137a9 fix(compiler): incorrect spans for template literals (#60323)
Fixes that we were producing zero-length spans for template literals and template literal elements.

Fixes #60320.
Fixes #60319.

PR Close #60323
2025-03-11 12:59:00 -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