Commit graph

34 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
Kristiyan Kostadinov
9eef041211 refactor(compiler): implement let declarations in render3 ast (#55848)
Introduces a new `LetDeclaration` into the Render3 AST, simiarly to the HTML AST, and adds an initial integration into the various visitors.

PR Close #55848
2024-05-30 14:55:36 +00: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
c7348084f0 refactor(compiler-cli): capture ng-content children in AST (#54854)
Updates the template AST to capture the content of `ng-content` elements instead of throwing an error.

PR Close #54854
2024-03-26 09:17:58 -07:00
Kristiyan Kostadinov
eb625d3783 fix(compiler): declare for loop aliases in addition to new name (#54942)
Currently when aliasing a `for` loop variable with `let`, we replace the variable's old name with the new one. Since users have found this to be confusing, these changes switch to a model where the variable is available both under the original name and the new one.

Fixes #52528.

PR Close #54942
2024-03-21 22:13:14 -07:00
Kristiyan Kostadinov
40c53577b8 refactor(compiler): introduce unknown block node (#52047)
Adds an `UnknownBlock` node to the Ivy AST to represent blocks that haven't been recognized by the compiler. This will make it easier to integrate blocks into the language service.

PR Close #52047
2023-10-05 13:10:05 -07:00
Kristiyan Kostadinov
aaa597393d refactor(compiler): implement template type checking for loop blocks (#51690)
Adds support for template type checking inside `for` blocks. It is implemented by generating a JS `for...of` statement inside the TCB. The various loop variables (e.g. `$index`) are implemented by declaring a local number variable.

PR Close #51690
2023-09-20 11:26:05 +02:00
Kristiyan Kostadinov
d42e02333a refactor(compiler): implement template type checking for if blocks (#51690)
Adds support for template type checking inside `if` blocks. It is implemented by generating a JS `if` statement inside the TCB which allows us to do type narrowing of the expression. The `as` parameter is implemented by declaring a variable inside the `if` statement.

PR Close #51690
2023-09-20 11:26:05 +02:00
Kristiyan Kostadinov
36b180ade4 refactor(compiler): implement conditional block AST (#51299)
Adds the AST for `if`, `else if` and `else` blocks.

PR Close #51299
2023-08-10 13:48:55 -07:00
Kristiyan Kostadinov
4424920f0b refactor(compiler): implement for block AST (#51299)
Adds the AST for `for` and `empty` blocks.

PR Close #51299
2023-08-10 13:48:55 -07:00
Kristiyan Kostadinov
31c6c5e944 refactor(compiler): implement switch block AST (#51299)
Adds the AST for `switch`, `case` and `default` blocks.

PR Close #51299
2023-08-10 13:48:55 -07:00
Kristiyan Kostadinov
d11548f2ef refactor(compiler): store deferred triggers as a map (#51262)
Stores the `deferred` block triggers as a map instead of an array, because triggers can't be duplicated and because having to search through an array will be inconvenient later on.

I've also added a `DeferredBlock.visitAll` method to deduplicate the logic from the various visitor implementations.

PR Close #51262
2023-08-04 11:27:39 -04:00
Kristiyan Kostadinov
9e61616ffe refactor(compiler): introduce deferred block AST (#51050)
Adds the logic to create `defer`-specific AST nodes from the generic HTML `BlockGroup` and `Block`. The logic for parsing the triggers will be in the next commit.

PR Close #51050
2023-07-17 21:05:47 +00:00
JoostK
db05ae13a6 refactor(compiler): remove parsing support for quote expressions (#44915)
So-called "Quote expressions" were added in b6ec2387b3
to support foreign syntax to be used in Angular templates, requiring a custom
template transform to convert them somehow during compilation. Support for template
transforms was originally implemented in a43ed79ee7 but
has since been dropped. Since the compiler is not public API the quote expressions
should not have any usages anymore. Removing support for them can improve error
reporting for expressions that contain a `:`, e.g. binding to a URL without quotes:

```html
<a [href]="http://google.com">Click me</a>
```

Here, `http` would be parsed as foreign "http" quote expression with `//google.com` as
value, later reporting the error "Quotes are not supported for evaluation!" because
there was no template transform to convert that code.

Closes #40398

PR Close #44915
2022-01-31 23:31:11 +00:00
Kristiyan Kostadinov
a4ab6d6b72 feat(compiler): add support for safe calls in templates (#44580)
Adds support for safely calling functions that may be undefined inside template expressions. E.g. `maybeUndefined?.()`

Fixes #42298.

PR Close #44580
2022-01-11 17:32:47 +00:00
Kristiyan Kostadinov
2028c3933f refactor(compiler): combine call ASTs (#42882)
Currently the compiler has three different classes to represent a "call to something":
1. `MethodCall` - `foo.bar()`
2. `SafeMethodCall` - `foo?.bar()`.
3. `FunctionCall` - Any calls that don't fit into the first two classes. E.g. `foo.bar()()`.

There are a few problems with this approach:
1. It is inconistent with the TypeScript AST which only has one node: `CallExpression`.
2. It means that we have to maintain more code, because the various parts of the compiler need to know about three node types.
3. It doesn't allow us to easily implement some new JS features like safe calls (e.g. `foo.bar?.())`).

These changes rework the compiler so that it produces only one node: `Call`. The new node behaves  similarly to the TypeScript `CallExpression` whose `receiver` can be any expression.

There was a similar situation in the output AST where we had an `InvokeMethodExpression` and `InvokeFunctionExpression`. I've combined both of them into `InvokeFunctionExpression`.

PR Close #42882
2021-09-21 20:55:29 +00:00
Paul Gschwendtner
96c93260a2 refactor(compiler): ensure compatibility with noImplicitOverride (#42512)
Adds the `override` keyword to the `compiler` sources to ensure
compatibility with `noImplicitOverride`.

PR Close #42512
2021-07-12 13:11:14 -07:00
Kristiyan Kostadinov
ba084857ea feat(compiler): support safe keyed read expressions (#41911)
Currently we support safe property (`a?.b`) and method (`a?.b()`) accesses, but we don't handle safe keyed reads (`a?.[0]`) which is inconsistent. These changes expand the compiler in order to support safe key read expressions as well.

PR Close #41911
2021-06-03 13:22:41 -07:00
JoostK
4b06ef75aa refactor(compiler): associate accurate source spans with ICU expressions (#39072)
Prior to this change, expressions within ICUs would have a source span
corresponding with the whole ICU. This commit narrows down the source
spans of these expressions to the exact location in the source file, as
a prerequisite for reporting type check errors within these expressions.

PR Close #39072
2020-10-08 11:55:27 -07:00
Joey Perrott
d1ea1f4c7f build: update license headers to reference Google LLC (#37205)
Update the license headers throughout the repository to reference Google LLC
rather than Google Inc, for the required license headers.

PR Close #37205
2020-05-26 14:26:58 -04:00
Alex Rickabaugh
83a9159063 style(compiler): reformat of codebase with new clang-format version (#36520)
This commit reformats the packages/compiler tree using the new version of
clang-format.

PR Close #36520
2020-04-08 14:51:08 -07:00
Keen Yee Liau
208ef7bd62 refactor(compiler): Remove NullAstVisitor and visitAstChildren (#35619)
This commit removes the `NullAstVisitor` and `visitAstChildren` exported
from `packages/compiler/src/expression_parser/ast.ts` because they
contain duplicate and buggy implementation, and their use cases could be
sufficiently covered by `RecursiveAstVisitor` if the latter implements the
`visit` method. This use case is only needed in the language service.

With this change, any visitor that extends `RecursiveAstVisitor` could
just define their own `visit` function and the parent class will behave
correctly.

A bit of historical context:
In language service, we need a way to tranverse the expression AST in a
selective manner based on where the user's cursor is. This means we need a
"filtering" function to decide which node to visit and which node to not
visit. Instead of refactoring `RecursiveAstVisitor` to support this,
`visitAstChildren` was created. `visitAstChildren` duplicates the
implementation of `RecursiveAstVisitor`, but introduced some bugs along
the way. For example, in `visitKeyedWrite`, it visits
```
obj -> key -> obj
```
instead of
```
obj -> key -> value
```

Moreover, because of the following line
```
visitor.visit && visitor.visit(ast, context) || ast.visit(visitor, context);
```
`visitAstChildren` visits every node *twice*.

PR Close #35619
2020-02-28 07:13:17 -08:00
ayazhafiz
fd4fed14d8 fix(compiler): absolute source span for template attribute expressions (#33189)
Prior to this commit, the absolute spans (relative to template source
file rather than the start of an expression) of expressions in a
template attribute like `*ngIf` were generated incorrectly, equating to
the relative spans.
This fixes the bug by passing an `absoluteOffset` parameter when parsing
template bindings.

Through some levels of indirection, this is required for the Language
Service to support text replacement in
https://github.com/angular/angular/pull/33091.

PR Close #33189
2019-10-17 18:48:59 -04:00
Ayaz Hafiz
b04488d692 feat(compiler): record absolute span of template expressions in parser (#31897)
Currently, the spans of expressions are recorded only relative to the
template node that they reside in, not their source file.

Introduce a `sourceSpan` property on expression ASTs that records the
location of an expression relative to the entire source code file that
it is in. This may allow for reducing duplication of effort in
ngtsc/typecheck/src/diagnostics later on as well.

Child of #31898

PR Close #31897
2019-10-14 20:14:16 +00:00