fix(ivy): jit compilation should support content queries with type predicates (#27068)

PR Close #27068
This commit is contained in:
Kara Erickson 2018-11-12 18:02:47 -08:00 committed by Andrew Kushnir
parent e6e590479e
commit bc652a2943
3 changed files with 29 additions and 4 deletions

View File

@ -185,6 +185,7 @@ function convertDirectiveFacadeToMetadata(facade: R3DirectiveMetadataFacade): R3
host: extractHostBindings(facade.host, facade.propMetadata), host: extractHostBindings(facade.host, facade.propMetadata),
inputs: {...inputsFromMetadata, ...inputsFromType}, inputs: {...inputsFromMetadata, ...inputsFromType},
outputs: {...outputsFromMetadata, ...outputsFromType}, outputs: {...outputsFromMetadata, ...outputsFromType},
queries: facade.queries.map(convertToR3QueryMetadata),
providers: facade.providers != null ? new WrappedNodeExpr(facade.providers) : null, providers: facade.providers != null ? new WrappedNodeExpr(facade.providers) : null,
}; };
} }

View File

@ -442,7 +442,7 @@ function createQueryDefinition(
query: R3QueryMetadata, constantPool: ConstantPool, idx: number | null): o.Expression { query: R3QueryMetadata, constantPool: ConstantPool, idx: number | null): o.Expression {
const predicate = getQueryPredicate(query, constantPool); const predicate = getQueryPredicate(query, constantPool);
// e.g. r3.Q(null, somePredicate, false) or r3.Q(0, ['div'], false) // e.g. r3.query(null, somePredicate, false) or r3.query(0, ['div'], false)
const parameters = [ const parameters = [
o.literal(idx, o.INFERRED_TYPE), o.literal(idx, o.INFERRED_TYPE),
predicate, predicate,

View File

@ -306,7 +306,7 @@ ivyEnabled && describe('render3 jit', () => {
expect((C as any).ngBaseDef.outputs).toEqual({prop1: 'alias1', prop2: 'alias2'}); expect((C as any).ngBaseDef.outputs).toEqual({prop1: 'alias1', prop2: 'alias2'});
}); });
it('should compile ContentChildren query on a directive', () => { it('should compile ContentChildren query with string predicate on a directive', () => {
@Directive({selector: '[test]'}) @Directive({selector: '[test]'})
class TestDirective { class TestDirective {
@ContentChildren('foo') foos: QueryList<ElementRef>|undefined; @ContentChildren('foo') foos: QueryList<ElementRef>|undefined;
@ -316,7 +316,7 @@ ivyEnabled && describe('render3 jit', () => {
expect((TestDirective as any).ngDirectiveDef.contentQueriesRefresh).not.toBeNull(); expect((TestDirective as any).ngDirectiveDef.contentQueriesRefresh).not.toBeNull();
}); });
it('should compile ContentChild query on a directive', () => { it('should compile ContentChild query with string predicate on a directive', () => {
@Directive({selector: '[test]'}) @Directive({selector: '[test]'})
class TestDirective { class TestDirective {
@ContentChild('foo') foo: ElementRef|undefined; @ContentChild('foo') foo: ElementRef|undefined;
@ -326,6 +326,30 @@ ivyEnabled && describe('render3 jit', () => {
expect((TestDirective as any).ngDirectiveDef.contentQueriesRefresh).not.toBeNull(); expect((TestDirective as any).ngDirectiveDef.contentQueriesRefresh).not.toBeNull();
}); });
it('should compile ContentChildren query with type predicate on a directive', () => {
class SomeDir {}
@Directive({selector: '[test]'})
class TestDirective {
@ContentChildren(SomeDir) dirs: QueryList<SomeDir>|undefined;
}
expect((TestDirective as any).ngDirectiveDef.contentQueries).not.toBeNull();
expect((TestDirective as any).ngDirectiveDef.contentQueriesRefresh).not.toBeNull();
});
it('should compile ContentChild query with type predicate on a directive', () => {
class SomeDir {}
@Directive({selector: '[test]'})
class TestDirective {
@ContentChild(SomeDir) dir: SomeDir|undefined;
}
expect((TestDirective as any).ngDirectiveDef.contentQueries).not.toBeNull();
expect((TestDirective as any).ngDirectiveDef.contentQueriesRefresh).not.toBeNull();
});
it('should not pick up view queries from directives', () => { it('should not pick up view queries from directives', () => {
@Directive({selector: '[test]'}) @Directive({selector: '[test]'})
class TestDirective { class TestDirective {