Skip to content

Commit 5cd01d6

Browse files
JeanMechethePunderWoman
authored andcommitted
refactor(compiler): check that ng-container don't have class bindings
This is the same change as #70808 but for g3 only due to its breaking nature.
1 parent b178c11 commit 5cd01d6

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

‎packages/compiler/src/render3/r3_template_transform.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,14 @@ class HtmlAstToIvyAst implements html.Visitor {
242242
`Attribute bindings are not supported on ng-container. Use property bindings instead.`,
243243
bound.sourceSpan,
244244
);
245+
// TODO(v23): Enable this breaking change
246+
// g3-only-start
247+
// } else if (
248+
// bound.type === BindingType.Class ||
249+
// (bound.type === BindingType.Property && bound.name === 'class')
250+
// ) {
251+
// this.reportError(`Class bindings are not supported on ng-container.`, bound.sourceSpan);
252+
// g3-only-end
245253
}
246254
}
247255
}

‎packages/compiler/test/render3/r3_template_transform_spec.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3098,12 +3098,36 @@ describe('R3 template transform', () => {
30983098
);
30993099
});
31003100

3101+
// TODO(v23): Enable this breaking change
3102+
xit('should report an error for class bindings on ng-container', () => {
3103+
const template = `<ng-container [class.foo]="true"></ng-container>`;
3104+
const errors = parse(template, {ignoreError: true}).errors;
3105+
expect(errors.length).toBe(1);
3106+
expect(errors[0].msg).toBe('Class bindings are not supported on ng-container.');
3107+
});
3108+
3109+
// TODO(v23): Enable this breaking change
3110+
xit('should report an error for [class] property bindings on ng-container', () => {
3111+
const template = `<ng-container [class]="'my-class'"></ng-container>`;
3112+
const errors = parse(template, {ignoreError: true}).errors;
3113+
expect(errors.length).toBe(1);
3114+
expect(errors[0].msg).toBe('Class bindings are not supported on ng-container.');
3115+
});
3116+
31013117
it('should not report an error on non-attr bindings on ng-container', () => {
31023118
const template = `<ng-container *ngIf"test" [ngTemplateOutlet]="foo"></ng-container>`;
31033119
const errors = parse(template, {ignoreError: true}).errors;
31043120
expect(errors.length).toBe(0);
31053121
});
31063122

3123+
// TODO(v23): Enable this breaking change
3124+
xit('should report an error for class interpolation on ng-container', () => {
3125+
const template = `<ng-container class="{{foo}}"></ng-container>`;
3126+
const errors = parse(template, {ignoreError: true}).errors;
3127+
expect(errors.length).toBe(1);
3128+
expect(errors[0].msg).toBe('Class bindings are not supported on ng-container.');
3129+
});
3130+
31073131
describe('@content blocks', () => {
31083132
it('should parse a valid @content block', () => {
31093133
expectFromHtml(`

0 commit comments

Comments
 (0)