Commit graph

789 commits

Author SHA1 Message Date
Kristiyan Kostadinov
a4f312060c refactor(compiler): require a reference in DirectiveMeta
Requires the `DirectiveMeta` to have a `ref` so that we can find duplicates easily.
2026-04-07 14:51:37 -07:00
Kristiyan Kostadinov
de533fe491 refactor(compiler-cli): move ClassPropertyMapping into compiler
Moves the `ClassPropertyMapping` into the compiler, rather than having to pass around the limited `InputOutputPropertySet` interface that is only implemented by `ClassPropertyMapping`.
2026-04-07 14:51:37 -07:00
Kristiyan Kostadinov
ea1e34c4dd refactor(compiler): move matchSource into base metadata
Moves the `matchSource` into the base metadata so the binder can use it.
2026-04-07 14:51:37 -07:00
Alan Agius
d04ddd73df fix(core): prevent binding unsafe attributes on SVG animation elements (#67797)
SVG animation elements (`animate` and `set`) can be used to animate sensitive attributes like `href` or `xlink:href`. Binding to these animation attributes (like `to`, `from`, or `values`) with a sensitive target creates an XSS vector.

This change mitigates this risk by:
1. Classifying `to`, `from`, and `values` on `<animate>` and `<set>` elements as `ATTRIBUTE_NO_BINDING` in the DOM security schema to prevent standard dynamic bindings.
2. Adding runtime validations in `ɵɵvalidateAttribute` to verify that `attributeName` is not a sensitive attribute (such as `href` or `xlink:href`) when processed by a set of `SECURITY_SENSITIVE_ATTRIBUTE_NAMES`. If it is, a runtime error `UNSAFE_ATTRIBUTE_BINDING` is thrown.
3. Adding regression tests in `integration_spec.ts` to ensure unsafe bindings throw an error while safe ones pass correctly.

PR Close #67797
2026-04-01 11:43:59 +02:00
Alan Agius
fea25d1a60 fix(compiler): register SVG animation attributes in URL security context (#67797)
This change is a security hardening measure to prevent potentially unsafe attribute value manipulation through SVG animations. By mapping `animate|to`, `animate|from`, `animate|values`, and `set|to` to the `SecurityContext.URL`,  Angular will now automatically sanitize these attributes.

PR Close #67797
2026-04-01 11:43:59 +02:00
Matt Lewis
880a57d4b3 fix(compiler): prevent shimCssText from adding extra blank lines per CSS comment
The comment placeholder restoration in `shimCssText` appended an unconditional
`+ '\n'` to each non-hash comment replacement. Because `_commentRe` does not
consume the newline that follows a comment in the source, that newline already
remains in `cssText`. The extra `'\n'` was therefore inserted on top of the
existing one, shifting every line after each comment down by one. In files with
many comments (e.g. large SCSS preambles) this shifts all subsequent CSS rules
far enough that the CSS sourcemap — generated before `shimCssText` runs —
points to completely wrong source locations in browser DevTools.

The fix is to drop the `+ '\n'`; internal newlines within a multi-line comment
are still preserved via `_newLinesRe`, and the trailing newline that follows the
comment in `cssText` is already present without any extra injection.

(cherry picked from commit 5a712d42d1)
2026-03-20 15:17:35 -07:00
yogeshwaran-c
23ea431c4e fix(compiler): parse named HTML entities containing digits
The lexer's isNamedEntityEnd function stopped scanning entity names
when encountering a digit character, causing 24 valid HTML named
entities with digits in their names (e.g. &sup1;, &frac12;, &blk34;)
to be treated as plain text instead of decoded to their corresponding
Unicode characters.

Fixes #51323

(cherry picked from commit 75560ce43d)
2026-03-17 12:54:45 -07:00
Kristiyan Kostadinov
ed2d324f9c fix(compiler): disallow translations of iframe src
Fixes that the compiler was allowing translations of `src` attributes in iframes which can be a security issue.

(cherry picked from commit 78dea55351)
2026-03-12 10:01:31 -07:00
Andrew Scott
1df1697c6e fix(compiler): prevent mutation of children array in RecursiveVisitor
RecursiveVisitor.visitIfBlockBranch was permanently mutating the children array by pushing the expressionAlias into it. This change clones the array before pushing to avoid this side effect.

(cherry picked from commit 72a17afaf3)
2026-03-04 22:41:36 +00:00
Matthieu Riegler
95b3f37d4a feat(compiler): Exhaustive checks for switch blocks
`@switch` blocks can now enable exhaustive typechecking by adding `@default(never);` at the end of a `@switch` block.
2026-02-17 10:25:31 -08:00
Matthieu Riegler
6e0d783e5b refactor(compiler): Add info about unclosed element.
We chose to throw 2 errors here because we can't assume the intention of the developer and the span we target are different.

fixes #57032
2026-02-13 09:41:37 -08:00
Matthew Beck
06d94ac0ca Revert "refactor(compiler): Add info about unclosed element."
This reverts commit 097208454b.
2026-02-12 09:30:57 -08:00
Matthieu Riegler
097208454b refactor(compiler): Add info about unclosed element.
We chose to throw 2 errors here because we can't assume the intention of the developer and the span we target are different.

fixes #57032
2026-02-12 08:55:20 -08:00
Matthew Beck
b386f95bd0 Revert "refactor(compiler): Add info about unclosed element."
This reverts commit 9b69e29603.
2026-02-12 08:54:40 -08:00
Matthieu Riegler
9b69e29603 refactor(compiler): Add info about unclosed element.
We chose to throw 2 errors here because we can't assume the intention of the developer and the span we target are different.

fixes #57032
2026-02-12 07:58:06 -08:00
Kristiyan Kostadinov
11834a4274 fix(compiler): add geolocation element to schema
A new `geolocation` tag was recently added to Chrome. These changes update the schema to account for it.

See https://developer.chrome.com/blog/geolocation-html-element
2026-02-09 12:25:37 -08:00
Angular Robot
11767cabe4 build: update Jasmine to 6.0.0
Jasmine enables `forbidDuplicateNames: true` by default. So we also need to desambiguate duplicate spec names.
2026-02-09 12:15:57 -08:00
Matthieu Riegler
a1441a432d refactor(compiler): remove zone-based testing utilities
Having zone.js here already wasn't necessary.
2026-02-09 07:55:12 -08:00
SkyZeroZx
2a0241a665 test(compiler): remove zone-based testing utilities
Removes usages of zone-based helpers such as
`waitForAsync` as part of the migration to zoneless tests.

Completes the transition to zoneless.
2026-02-05 16:56:55 -08:00
Kristiyan Kostadinov
d9c980a958 build: initial test of TypeScript 6
Resolves some initial test failures after updating to TypeScript 6.
2026-01-15 13:41:01 -08:00
Matthieu Riegler
72534e2a34 feat(compiler): Add support for the instanceof binary operator
Because why not ?

fixes #59975
2026-01-13 08:33:12 -08:00
Kristiyan Kostadinov
f05d08f432 refactor(compiler): add arrow function parsing
Updates the expression parser to handle arrow functions. Since arrow functions share syntax with other AST nodes, we have to detect them by looking ahead and then potentially jumping backwards depending on what we see.
2026-01-09 10:35:37 -08:00
Kristiyan Kostadinov
ab536f8f32 refactor(compiler): add AST nodes for arrow functions
Expands the expression AST to include arrow functions.
2026-01-09 10:35:37 -08:00
Kristiyan Kostadinov
d01e54dea4 refactor(compiler): tokenize =>
Adds some logic to tokenize the `=>` character combination in the lexer.
2026-01-09 10:35:37 -08:00
Matthieu Riegler
0ad3adc7c6 fix(compiler): Support empty cases
Before this commit empty @cases ended up being interpreted as consecutive cases.
2026-01-07 15:47:59 -08:00
Kristiyan Kostadinov
3a56c1367f fix(compiler): produce accurate span for typeof and void expressions
Fixes that the `typeof` and `void` expressions were starting their spans from the expression start, rather than the keyword.

Fixes #66174.
2026-01-07 14:04:05 -05:00
Kristiyan Kostadinov
a0dfa5fa86 feat(core): support rest arguments in function calls
Updates the template syntax to support rest arguments in function calls. This can be handy for functions with a variable number of arguments.
2026-01-07 12:37:52 -05:00
Kristiyan Kostadinov
6e18fa8bc9 feat(core): support spread elements in array literals
Expands the template syntax to support spread elements inside arrays. This can be handy for some bindings.
2026-01-07 12:37:52 -05:00
Kristiyan Kostadinov
19ca3b66a3 refactor(compiler): add spread elements to expression AST
Updates the expression AST to support spread elements that will be used for arrays and function calls.
2026-01-07 12:37:52 -05:00
Kristiyan Kostadinov
e407280ab5 feat(core): support spread expressions in object literals
Adds support for spread expressions inside of object literals. This can be handy when constructing maps for `class` bindings.
2026-01-07 12:37:52 -05:00
Kristiyan Kostadinov
81549248b7 refactor(compiler): add spread elements to expression AST
Updates the expression AST to have support for spread elements inside object literals.
2026-01-07 12:37:52 -05:00
Kristiyan Kostadinov
35830079bd refactor(compiler): handle spread operators in the lexer
Updates the expression lexer to handle spread operators.
2026-01-07 12:37:52 -05:00
Matthieu Riegler
640693da8e feat(compiler): Add support for multiple swich cases matching
consecutive `@case` blocks are now supported:

```ts
@switch (case) {
  @case (0)
  @case (1) {
    case 0 or 1
  }
  @case (2) {
    case 2
  }
  @default {
    default
  }
}
```

fixes #14659
2026-01-07 09:23:50 -05:00
Kristiyan Kostadinov
fa7cb4b87a fix(compiler): stop ThisReceiver inheritance from ImplicitReceiver
Back in #39323, I added a new `ThisReceiver` node to represent accesses done through `this` and I ended up making it inherit from `ImplicitReceiver`. The logic was that in most cases accessing through `this` was the same as the implicit access.

Over the years this has proven to not be a great idea, because no other AST nodes do this and one has to keep it in mind whenever dealing with `ImplicitReceiver`.

These changes remove the inheritance and update all of the usage sites accordingly.
2026-01-02 08:21:49 +01:00
Kristiyan Kostadinov
76fa180005 fix(compiler): provide location information for literal map keys
Adds spans for the keys of a `LiteralMap`.

Fixes #66175.
2026-01-02 08:18:02 +01:00
Alan Agius
d4111eebc6
refactor(compiler): remove unnecessary sanitization for safe attributes
Remove sanitization for attributes that cannot execute code (e.g. `javascript: URIs`).
2025-12-15 14:13:38 -08:00
Andrew Kushnir
8243bb3064 Revert "refactor(compiler): remove unnecessary sanitization for safe attributes"
This reverts commit 128aef0ede.
2025-12-12 12:59:47 -08:00
Alan Agius
128aef0ede
refactor(compiler): remove unnecessary sanitization for safe attributes
Remove sanitization for attributes that cannot execute code (e.g. `javascript: URIs`).
2025-12-12 08:05:58 -08:00
Alan Agius
1c6b0704fb
fix(compiler): prevent XSS via SVG animation attributeName and MathML/SVG URLs
This commit implements a security fix to prevent XSS vulnerabilities where SVG animation elements (`<animate>`, `<set>`, etc.) could be used to modify the `href` or `xlink:href` attributes of other elements to `javascript:` URLs.
2025-12-01 10:26:56 +01:00
Kristiyan Kostadinov
b6c141bf8b refactor(compiler): remove container blocks config
Removes the ability to specify container blocks when creating an i18n parser. We were only passing in `switch` and it likely won't change.
2025-11-19 14:28:20 -08:00
Matthew Beck
9e7ddcaa10 fix(compiler): don't choke on unbalanced parens in declaration block
Following https://github.com/angular/angular/pull/64509 we started
choking on unbalanced closing parentheses in declaration blocks,
specifically in quoted background-image urls. This was reported in
https://github.com/angular/angular/issues/65137.

This occured because we previously (and now again) traverse the entire
declaration block when selecting for :host-context() selectors to shim.
This is an oddity of how we parse styles today, and is likely something
we'd want to remove if we parsed selectors properly.

This change adds a new flag to _splitOnTopLevelCommas which allows it to
continue past unbalanced closing parentheses in the declaration block,
returning _convertColonHostContext to its previous behavior while
keeping support for the extra nesting in :host-context().
2025-11-17 09:46:01 -08:00
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. &#x1F6C8;) 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