Repository navigation
Conversation
b7a8b82 to
f3dfcfe
Compare
f3dfcfe to
e99d42b
Compare
fdcecd6 to
af14208
Compare
dbf45c7 to
363c2ef
Compare
JeanMeche
left a comment
There was a problem hiding this comment.
Nice improvement! Splitting the validation between r3_template_transform.ts (for syntactic errors that don't depend on component metadata: [attr.foo] on <ng-template>, property/event/reference bindings and selection/selector typos on <ng-content>) and the TCB (TcbContentAttributesOp for static attributes on <ng-content> that don't match a parent component's content projection slot) fits cleanly into the existing architecture and works across both ngtsc and ngp.
Extracting validateNgContentElement and validateNoAttributeBindings also keeps visitElement much easier to read.
I left a few comments on edge cases around multi-class attributes / comma-separated slot selectors, namespaced attributes, legacy .d.ts metadata, and reporting multiple invalid bindings.
f6014b5 to
41017f3
Compare
41017f3 to
e952401
Compare
e952401 to
c7d9237
Compare
… bindings Virtual elements such as `<ng-content>` and `<ng-template>` do not support certain bindings and attributes: - `<ng-template>` does not support attribute bindings (`[attr.foo]`). - `<ng-content>` does not support property bindings (`[id]`), event bindings (`(click)`), or template references (`#ref`). - `<ng-content>` only supports an allowlist of static attributes (`select`, `ngProjectAs`, `ngSkipHydration`, `ngPreserveWhitespaces`), as well as static attributes that select a content projection slot of a parent component when re-projecting `<ng-content>`. If `selection` or `selector` is encountered on `<ng-content>`, a helpful "Did you mean 'select'?" suggestion is provided. Enforcing these checks is a breaking change for existing templates. To roll this out safely in two steps, this change guards the new checks behind `g3-only` / `3p-only` markers so they take effect internally first, leaving external (3P) behavior unchanged until the v23 breaking-change window opens: - Template transformation (`r3_template_transform.ts`): guard `<ng-content>` binding/reference validation, passing parsed `attributes` to `t.Content`, and `<ng-template>` attribute binding validation with `g3-only`/`3p-only` markers and `TODO(v23)` comments. - Type Check Block (`scope.ts`, `content_projection.ts`, `oob.ts`): add `TcbContentAttributesOp` and `getContentAttributesInProjectionSlots` across both `ngtsc` and `ngp`, and guard queueing the op and recording parent projection slots in `Scope` behind `g3-only` markers with `TODO(v23)`. - Tests: add `TODO(v23)` skipped (`xit`) tests in `r3_template_transform_spec.ts` and `diagnostics_spec.ts` to re-enable when the breaking change lands in 3P, and fix invalid `<ng-content>` attributes in existing tests and examples.
c7d9237 to
5173d2e
Compare
This PR extends compiler and template type-checking validation for virtual elements to
<ng-content>and<ng-template>.Because disallowing unsupported bindings and attributes on
<ng-content>and<ng-template>is a breaking change for existing templates, this PR guards the new checks behindg3-only/3p-onlymarkers so they take effect internally first, leaving external (3P) behavior unchanged until the v23 breaking-change window opens (tracked in #72191):r3_template_transform.ts):g3-only/3p-onlymarkers andTODO(v23):<ng-template>does not support attribute bindings ([attr.foo]).<ng-content>does not support property bindings ([id]), event bindings ((click)), or template references (#ref), and uses parsedattributesrather than rawelement.attrsont.Content.TcbContentAttributesOpinngtscandngp):g3-onlymarkers andTODO(v23)inScope(recordContentNodesInProjectionSlotsand queueingTcbContentAttributesOp).<ng-content>enforces an allowlist for static attributes (selectcase-insensitive,ngProjectAs,ngSkipHydration,ngPreserveWhitespaces) and allows static attributes that select a specific content projection slot of a parent component when re-projecting.selectionorselectoris used on<ng-content>(and does not match a parent projection slot), a helpful suggestion is provided:'selection'/'selector' is not supported on ng-content. Did you mean 'select'?.TODO(v23)skipped (xit) tests inr3_template_transform_spec.tsanddiagnostics_spec.tsto be re-enabled when the breaking change lands in 3P.slot="foo",selector="...", orclass="..."were mistakenly used on<ng-content>.ng_template_bindingsandng-contentstructural directive goldens) unchanged until v23.