fix(ivy): more accurate detection of pipes in host bindings (#34655)

Pipes in host binding expressions are not supported in View Engine and Ivy, but in some more complex cases (like `(value | pipe) === true`) compiler was not reporting errors. This commit extends Ivy logic to detect pipes in host binding expressions and throw in cases bindings are present. View Engine behavior remains the same.

PR Close #34655
This commit is contained in:
Andrew Kushnir
2020-01-06 17:27:29 -08:00
committed by Matias Niemelä
parent def4127bf1
commit 39ec188003
3 changed files with 82 additions and 21 deletions

View File

@ -2250,30 +2250,68 @@ runInEachFileSystem(os => {
}
})
class FooCmp {}
`);
`);
const errors = env.driveDiagnostics();
expect(trim(errors[0].messageText as string))
.toContain('Cannot have a pipe in an action expression');
});
it('should throw in case pipes are used in host bindings', () => {
it('should throw in case pipes are used in host bindings (defined as `value | pipe`)', () => {
env.write(`test.ts`, `
import {Component} from '@angular/core';
import {Component} from '@angular/core';
@Component({
selector: 'test',
template: '...',
host: {
'[id]': 'id | myPipe'
}
})
class FooCmp {}
`);
@Component({
selector: 'test',
template: '...',
host: {
'[id]': 'id | myPipe'
}
})
class FooCmp {}
`);
const errors = env.driveDiagnostics();
expect(trim(errors[0].messageText as string))
.toContain('Host binding expression cannot contain pipes');
});
it('should throw in case pipes are used in host bindings (defined as `!(value | pipe)`)',
() => {
env.write(`test.ts`, `
import {Component} from '@angular/core';
@Component({
selector: 'test',
template: '...',
host: {
'[id]': '!(id | myPipe)'
}
})
class FooCmp {}
`);
const errors = env.driveDiagnostics();
expect(trim(errors[0].messageText as string))
.toContain('Host binding expression cannot contain pipes');
});
it('should throw in case pipes are used in host bindings (defined as `(value | pipe) === X`)',
() => {
env.write(`test.ts`, `
import {Component} from '@angular/core';
@Component({
selector: 'test',
template: '...',
host: {
'[id]': '(id | myPipe) === true'
}
})
class FooCmp {}
`);
const errors = env.driveDiagnostics();
expect(trim(errors[0].messageText as string))
.toContain('Host binding expression cannot contain pipes');
});
it('should generate host bindings for directives', () => {
env.write(`test.ts`, `
import {Component, HostBinding, HostListener, TemplateRef} from '@angular/core';