Commit graph

748 commits

Author SHA1 Message Date
Matthew Beck
24cfd5a0ed fix(compiler): support complex selectors in :nth-child()
:nth-child() (and its siblings) support complex expressions, e.g.
`:nth-child(2n of :is(.foo, .bar))`. Previously we'd choke because of
the `:is()`. Now, we reuse the `_parenSuffix` subexpression to match
nested parentheses the same way we do for :host() and :host-context().
Note that we only support 3 levels of nesting, so a selector like
`:nth-child(n of :is(:has(:not(.foo))))` will still break.

I'll say yet again that we really should add a proper parser so we stop
getting bug reports like this :)

Fixes #64913
2025-11-11 14:03:32 -08:00
Matthew Beck
4b871b139b test(compiler): add test for :host:has(> .foo)
I took a quick look at my recent changes to see if I had inadvertently
fixed this bug, but I couldn't seem to reproduce it even before my
changes. Seems like it's working, though.

Closes #58436
2025-11-10 07:51:16 -08:00
Matthew Beck
680c3c7bff fix(compiler): support commas in :host() argument
This change adds support for commas in :host() arguments (e.g.
`:host(:not(.foo, .bar))` as well as in nested parens when the argument
is applied without parens (e.g. `:host:not(:has(.foo, .bar))`).
Previously these selectors would receive an extra `[nghost]` attr, e.g.
`[nghost]:not(.foo, [nghost].bar)`.

I didn't file a bug for this one, but it's also blocking on an internal
LSC. Like the other CSS changes, I'll run a TGP to confirm this isn't
breaking.
2025-11-07 10:43:32 -08:00
Matthew Berry
444143758e fix(compiler): support one additional level of nesting in :host()
Previously we supported one level of nested parentheses inside of a
`:host()` selector, e.g. `:host(:not(p))`. This caused a breakage in g3
when I migrated a selector from `:host:not(:has(p))` to
`:host(:not(:has(p)))`. This change adds support for just one more level
of nesting.

It'd be nice to move everything to a real CSS parser (or even update it
to count parentheses like I did with :host-context()), but I wasn't able
to get that to work in ~20 minutes and I'm focusing on other things at
the moment.

This change punts the problem until somebody tries to use just one more
level of nesting in a selector.

Fixes #64830
2025-11-06 10:53:42 -08:00
Alan Agius
26fed34e0e
build: format md files
This commit configures prettier to format markdown files.
2025-11-06 10:03:05 -08:00
Matthew Beck
b478e91068 fix(compiler): support arbitrary nesting in :host-context()
Previously we supported one level of nested pseudo-element selectors
inside :host-context(), e.g. :host-context(:is(.foo, .bar)). This was
based on a regex-based approach. We could support deeper levels of
nesting by updating the regex, but using a regex approach prohibits us
from supporting arbitrary nesting.

Rather than just adding one more level to the existing expression, I've
added a new generator function which splits selectors on commas in a
parenthesis-aware way. This allows us to support arbitrary nesting.

It's likely we'll want to reuse this in other places where we're not as
careful today. We'll probably do this on a request-based basis, though.

Fixes #59176
2025-10-27 13:40:47 +01:00
SkyZeroZx
9a7529dd66 fix(compiler): correctly compile long numeric HTML entities (#64297)
Fixes an issue where long numeric HTML entities (e.g. 🛈) were incorrectly compiled due to the use of 4-digit

PR Close #64297
2025-10-17 18:23:44 +00:00
Matthieu Riegler
62cda789a8 refactor(compiler): Improve pipe in track expression error (#64321)
Throw a parse error for a better context awareness.

fixes #64316

PR Close #64321
2025-10-13 08:59:56 -07:00
Kristiyan Kostadinov
f3207000fd refactor(compiler): parse options parameter on viewport triggers (#64130)
Updates the template parser and AST to capture a second object literal parameter on `viewport` triggers.

PR Close #64130
2025-10-09 05:32:20 -07:00
Matthew Berry
4fce3cad5e test(compiler): fix a @keyframes style encapsulation test (#64036)
I've updated the test to assert what I believe it was trying to assert
before. Without this change, the CSS is invalid so it's unclear what
behavior we're demonstrating.

PR Close #64036
2025-10-09 05:16:18 -07:00
Alan Agius
7eee93da1a build: remove empty globs (#64270)
Remove globs that do not match any files.

PR Close #64270
2025-10-07 20:28:11 -04:00
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
bd48349b76 refactor(compiler): throw on attribute bindings for ng-container (#64072)
They are never valid on ng-container.
fixes #53760

PR Close #64072
2025-09-26 13:53:00 -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
Matthieu Riegler
803dc8e44c fix(compiler): Add support for aria-invalid (#63748)
The `aria-invalid` attribute was supported but the `ariaInvalid` property was unknown by the schema.

fixes #63744

PR Close #63748
2025-09-15 18:41:16 +00:00
Jessica Janiuk
0a82138d4b fix(compiler): fixes regression with event parsing and animate prefix (#63470)
The new animations was not correctly looking for the `.` when parsing bindings. This resulted in arbitrary event bindings creating animate.leave instruction calls.

fixes: #63466

PR Close #63470
2025-08-29 11:53:30 +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
Kristiyan Kostadinov
9ac638548f fix(compiler): incorrect source span for expression AST inside template attribute (#63175)
Similar fix as #63082, but for template attributes. The root cause is the same where we should be using `fullStart` instead of `start` in order to account for whitespaces being skipped.

Fixes #63157.

PR Close #63175
2025-08-15 09:44:35 +02:00
Kristiyan Kostadinov
d17555a7c6 fix(compiler): incorrect spans for AST inside input value with leading space (#63082)
When parsing expressions inside a bound attribute, we offset all of its spans by an `absoluteOffset` in order to get the right spans in the source file. The offset was incorrect when parsing an attribute with leading spaces during the construction of the Ivy AST, because of the combination of:
1. We were setting the offset by looking at `valueSpan.start`.
2. The Ivy parser sets `leadingTriviaChars: [' ', '\n']` which means that spaces and new lines will be ignored in the `sourceSpan.start`.

These changes resolve the issue by using `valueSpan.fullStart` which includes the leading spaces.

Fixes #63069.

PR Close #63082
2025-08-11 11:57:05 -07:00
Kristiyan Kostadinov
a409534d6c feat(core): support as aliases on else if blocks (#63047)
Expands support for the `as` keyword to `@else if` blocks. Previously it was only allowed on `@if`.

PR Close #63047
2025-08-08 08:43:00 -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
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