Commit graph

122 commits

Author SHA1 Message Date
Kristiyan Kostadinov
159be56709 fix(compiler): recover template literals with broken expressions (#64150)
Fixes two issues that were preventing template literals from being recovered properly if one of the interpolated expressions is broken:
1. We weren't updating the expected brace counter when an interpolation starts which in turn was throwing off the recovery logic in `skip`.
2. When producing tokens for template literals, we were treating the closing brace as an operator whereas other places treat it as a character. Even after fixing the first issue, this was preventing the recovery logic from working correctly.

Fixes #63940.

PR Close #64150
2025-09-30 16:01:50 -04:00
Matthieu Riegler
04462ed67f refactor(compiler): Remove the interpolation config (#64071)
After #63474, we don't need that anymore.

PR Close #64071
2025-09-29 15:29:46 -04:00
Jessica Janiuk
221d5687ae Revert "refactor(compiler): Remove the interpolation config (#64071)" (#64110)
This reverts commit 768a09d3c3.

PR Close #64110
2025-09-26 15:16:53 -04:00
Matthieu Riegler
768a09d3c3 refactor(compiler): Remove the interpolation config (#64071)
After #63474, we don't need that anymore.

PR Close #64071
2025-09-26 12:36:50 -04:00
Kristiyan Kostadinov
539717f58a feat(core): support regular expressions in templates (#63887)
Updates the template syntax to support inline regular expressions.

PR Close #63887
2025-09-18 15:08:56 +00:00
Kristiyan Kostadinov
c1559ece52 refactor(compiler): tokenize regular expression literals (#63887)
Updates the expression lexer to produce tokens for regular expression literals.

PR Close #63887
2025-09-18 15:08:56 +00:00
Andrew Kushnir
a53ef1d69a Revert "refactor(compiler): tokenize regular expression literals (#63857)" (#63883)
This reverts commit 8a69c0629b.

PR Close #63883
2025-09-17 19:36:17 +00:00
Andrew Kushnir
ae55578b92 Revert "feat(core): support regular expressions in templates (#63857)" (#63883)
This reverts commit 328a2bf719.

PR Close #63883
2025-09-17 19:36:17 +00:00
Kristiyan Kostadinov
328a2bf719 feat(core): support regular expressions in templates (#63857)
Updates the template syntax to support inline regular expressions.

PR Close #63857
2025-09-17 16:06:51 +00:00
Kristiyan Kostadinov
8a69c0629b refactor(compiler): tokenize regular expression literals (#63857)
Updates the expression lexer to produce tokens for regular expression literals.

PR Close #63857
2025-09-17 16:06:50 +00:00
Joey Perrott
2fcafb65c5 build: rename defaults2.bzl to defaults.bzl (#63383)
Use defaults.bzl for the common macros

PR Close #63383
2025-08-25 15:45:01 -07:00
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
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
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
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
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
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
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
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
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
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
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
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
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
Miles Malerba
f2d5cf7edd feat(compiler): support exponentiation operator in templates (#59894)
Adds support for the exponentiation (`**`) operator in templates

Ex:
```
@Component {
  template: '{{2 ** 3}}'
}
```

PR Close #59894
2025-02-25 11:03:37 -05:00
Miles Malerba
0361c2d81f feat(compiler): support void operator in templates (#59894)
Add support for the `void` operator in templates and host bindings.

This is useful when binding a listener that may return `false` and
unintentionally prevent the default event behavior.

Ex:
```
@Directive({
  host: { '(mousedown)': 'void handleMousedown()' }
})
```

BREAKING CHANGE: `void` in an expression now refers to the operator

Previously an expression in the template like `{{void}}` referred to a
property on the component class. After this change it now refers to the
`void` operator, which would make the above example invalid. If you have
existing expressions that need to refer to a property named `void`,
change the expression to use `this.void` instead: `{{this.void}}`.

PR Close #59894
2025-02-25 11:03:37 -05: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
Kristiyan Kostadinov
353005b97f refactor(compiler): tokenize template literals (#59230)
Reworks the lexer to produce tokens for template literal expressions.

PR Close #59230
2025-01-21 12:04:52 -08: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
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
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
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
Paul Gschwendtner
5162a32de8 refactor(compiler): expose shorthand object metadata in expression AST (#56405)
Whenever we parse object property assignment shorthands in expression
ASTs, the AST will have no information about whether the property read
for the `LiteralMap` is built based on the shorthand or not.

Exposing this information in the AST is useful for migrations as those
might need to decompose the shorthand into its longer form to e.g.
invoke a signal read.

PR Close #56405
2024-06-13 10:12:52 -07:00
Joey Perrott
8f69c83b84 refactor: migrate compiler to prettier formatting (#55398)
Migrate formatting to prettier for compiler from clang-format

PR Close #55398
2024-04-18 14:18:08 -07:00
Kristiyan Kostadinov
a436e2d5ea refactor(compiler): preserve expression in two-way listeners (#54154)
Currently the listener side two-way listeners are parsed by appending `=$event` to the raw expression. This is problematic, because:
1. It can interfere with other expressions (see #37809).
2. It can lead to confusing error messages because users will see code that they didn't write.
3. It doesn't allow us to further manipulate the expression.

These changes remove the logic that appends `=$event` to resolve the issue. There's also some new logic that checks the expression after it has been parsed to ensure that the result is an assignable expression.

Subsequent commits will update the code that emits the expression to add back the `$event` assignment where it's needed.

PR Close #54154
2024-02-01 14:39:32 +00:00
Kristiyan Kostadinov
5fb707f81a fix(compiler): produce placeholder for blocks in i18n bundles (#52958)
When blocks were initially implemented, they were represented as containers in the i18n AST. This is problematic, because block affect the structure of the message.

These changes introduce a new `BlockPlaceholder` AST node and integrate it into the i18n pipeline. With the new node blocks are represented with the `START_BLOCK_<name>` and `CLOSE_BLOCK_<name>` placeholders.

PR Close #52958
2023-11-20 08:59:24 -08:00
Kristiyan Kostadinov
c07805612f test(core): clean up unnecessary nesting in old tests (#52239)
A lot of our tests are wrapped in `{}` which serves no purpose, aside from increasing the nesting level and, in some cases, causing confusion. The braces appear to be a leftover from a time when all tests were wrapped in a `function main() {}`. The function declaration was removed in #21053, but the braces remained, presumably because it was easier to search&replace for `function main()`, but not to remove the braces at the same time.

PR Close #52239
2023-10-19 09:26:15 -07:00
Paul Gschwendtner
8a0c5c710a refactor: improve type safety of interpolation AST (#50903)
Instead of using `any`, we should use the actual types that
are available from the parser.

PR Close #50903
2023-07-10 07:08:28 -07:00
Matthieu Riegler
ad28cddd41 refactor(platform-browser): replace our own toBeAnInstanceOf with toBeInstanceOf (#50661)
There is no need to maintain that matcher since jasmine provides its own !

PR Close #50661
2023-06-14 10:58:04 +02:00
Matthieu Riegler
d4ef20736f refactor(compiler): handle #24571 todos. (#49220)
This commit removes the remaining TODO(issue/24571) in compiler code base.

PR Close #49220
2023-04-18 16:30:44 +00:00