fix(compiler): resolver should merge host bindings and listeners (#13474)
fixes #13327
This commit is contained in:
parent
d4ddb6004e
commit
aa3769ba69
|
@ -75,9 +75,8 @@ export class DirectiveResolver {
|
||||||
outputs.push(propName);
|
outputs.push(propName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const hostBinding =
|
const hostBindings = propertyMetadata[propName].filter(a => a && a instanceof HostBinding);
|
||||||
ListWrapper.findLast(propertyMetadata[propName], (a) => a instanceof HostBinding);
|
hostBindings.forEach(hostBinding => {
|
||||||
if (hostBinding) {
|
|
||||||
if (hostBinding.hostPropertyName) {
|
if (hostBinding.hostPropertyName) {
|
||||||
const startWith = hostBinding.hostPropertyName[0];
|
const startWith = hostBinding.hostPropertyName[0];
|
||||||
if (startWith === '(') {
|
if (startWith === '(') {
|
||||||
|
@ -90,13 +89,12 @@ export class DirectiveResolver {
|
||||||
} else {
|
} else {
|
||||||
host[`[${propName}]`] = propName;
|
host[`[${propName}]`] = propName;
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
const hostListener =
|
const hostListeners = propertyMetadata[propName].filter(a => a && a instanceof HostListener)
|
||||||
ListWrapper.findLast(propertyMetadata[propName], (a) => a instanceof HostListener);
|
hostListeners.forEach(hostListener => {
|
||||||
if (hostListener) {
|
|
||||||
const args = hostListener.args || [];
|
const args = hostListener.args || [];
|
||||||
host[`(${hostListener.eventName})`] = `${propName}(${args.join(',')})`;
|
host[`(${hostListener.eventName})`] = `${propName}(${args.join(',')})`;
|
||||||
}
|
});
|
||||||
const query = ListWrapper.findLast(propertyMetadata[propName], (a) => a instanceof Query);
|
const query = ListWrapper.findLast(propertyMetadata[propName], (a) => a instanceof Query);
|
||||||
if (query) {
|
if (query) {
|
||||||
queries[propName] = query;
|
queries[propName] = query;
|
||||||
|
|
|
@ -309,7 +309,8 @@ export function main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const directiveMetadata = resolver.resolve(Child);
|
const directiveMetadata = resolver.resolve(Child);
|
||||||
expect(directiveMetadata.host).toEqual({'[p1]': 'p1', '[p22]': 'p2', '[p3]': 'p3'});
|
expect(directiveMetadata.host)
|
||||||
|
.toEqual({'[p1]': 'p1', '[p21]': 'p2', '[p22]': 'p2', '[p3]': 'p3'});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support inheriting host listeners', () => {
|
it('should support inheriting host listeners', () => {
|
||||||
|
@ -329,8 +330,38 @@ export function main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const directiveMetadata = resolver.resolve(Child);
|
const directiveMetadata = resolver.resolve(Child);
|
||||||
expect(directiveMetadata.host).toEqual({'(p1)': 'p1()', '(p22)': 'p2()', '(p3)': 'p3()'});
|
expect(directiveMetadata.host)
|
||||||
|
.toEqual({'(p1)': 'p1()', '(p21)': 'p2()', '(p22)': 'p2()', '(p3)': 'p3()'});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should combine host bindings and listeners during inheritance', () => {
|
||||||
|
@Directive({selector: 'p'})
|
||||||
|
class Parent {
|
||||||
|
@HostListener('p11') @HostListener('p12')
|
||||||
|
p1() {}
|
||||||
|
|
||||||
|
@HostBinding('p21') @HostBinding('p22')
|
||||||
|
p2: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Child extends Parent {
|
||||||
|
@HostListener('c1')
|
||||||
|
p1() {}
|
||||||
|
|
||||||
|
@HostBinding('c2')
|
||||||
|
p2: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
const directiveMetadata = resolver.resolve(Child);
|
||||||
|
expect(directiveMetadata.host).toEqual({
|
||||||
|
'(p11)': 'p1()',
|
||||||
|
'(p12)': 'p1()',
|
||||||
|
'(c1)': 'p1()',
|
||||||
|
'[p21]': 'p2',
|
||||||
|
'[p22]': 'p2',
|
||||||
|
'[c2]': 'p2'
|
||||||
|
});
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('queries', () => {
|
describe('queries', () => {
|
||||||
|
|
Loading…
Reference in New Issue