Skip to content

Commit 85e1962

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. (cherry picked from commit 5cd01d6)
1 parent e7e03b7 commit 85e1962

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
@@ -3094,12 +3094,36 @@ describe('R3 template transform', () => {
30943094
);
30953095
});
30963096

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

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

0 commit comments

Comments
 (0)