fix(compiler): validate @HostBinding name (#12139)

relates to #7500
This commit is contained in:
Victor Berchet
2016-10-07 13:53:53 -07:00
committed by Tobias Bosch
parent 709a6dea06
commit 13ecc140e8
2 changed files with 30 additions and 0 deletions

View File

@ -71,6 +71,13 @@ export class DirectiveResolver {
} else if (a instanceof HostBinding) {
const hostBinding: HostBinding = a;
if (hostBinding.hostPropertyName) {
const startWith = hostBinding.hostPropertyName[0];
if (startWith === '(') {
throw new Error(`@HostBinding can not bind to events. Use @HostListener instead.`);
} else if (startWith === '[') {
throw new Error(
`@HostBinding parameter should be a property name, 'class.<name>', or 'attr.<name>'.`);
}
host[`[${hostBinding.hostPropertyName}]`] = propName;
} else {
host[`[${propName}]`] = propName;