fix(compiler): assume queries with no matches as static (#15429)
This has the side effect of allowing `@Input` and `@ContentChild` on the same property if the query is static (see the bug description for details). Fixes #15417
This commit is contained in:

committed by
Victor Berchet

parent
92084f2b6a
commit
c8ab5cb0c5
@ -147,12 +147,8 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver {
|
||||
// Note: queries start with id 1 so we can use the number in a Bloom filter!
|
||||
const queryId = queryIndex + 1;
|
||||
const bindingType = query.first ? QueryBindingType.First : QueryBindingType.All;
|
||||
let flags = NodeFlags.TypeViewQuery;
|
||||
if (queryIds.staticQueryIds.has(queryId)) {
|
||||
flags |= NodeFlags.StaticQuery;
|
||||
} else {
|
||||
flags |= NodeFlags.DynamicQuery;
|
||||
}
|
||||
const flags =
|
||||
NodeFlags.TypeViewQuery | calcStaticDynamicQueryFlags(queryIds, queryId, query.first);
|
||||
this.nodes.push(() => ({
|
||||
sourceSpan: null,
|
||||
nodeFlags: flags,
|
||||
@ -491,15 +487,9 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver {
|
||||
this.nodes.push(null);
|
||||
|
||||
dirAst.directive.queries.forEach((query, queryIndex) => {
|
||||
let flags = NodeFlags.TypeContentQuery;
|
||||
const queryId = dirAst.contentQueryStartId + queryIndex;
|
||||
// Note: We only make queries static that query for a single item.
|
||||
// This is because of backwards compatibility with the old view compiler...
|
||||
if (queryIds.staticQueryIds.has(queryId) && query.first) {
|
||||
flags |= NodeFlags.StaticQuery;
|
||||
} else {
|
||||
flags |= NodeFlags.DynamicQuery;
|
||||
}
|
||||
const flags =
|
||||
NodeFlags.TypeContentQuery | calcStaticDynamicQueryFlags(queryIds, queryId, query.first);
|
||||
const bindingType = query.first ? QueryBindingType.First : QueryBindingType.All;
|
||||
this.nodes.push(() => ({
|
||||
sourceSpan: dirAst.sourceSpan,
|
||||
@ -1194,3 +1184,16 @@ function elementEventNameAndTarget(
|
||||
return eventAst;
|
||||
}
|
||||
}
|
||||
|
||||
function calcStaticDynamicQueryFlags(
|
||||
queryIds: StaticAndDynamicQueryIds, queryId: number, isFirst: boolean) {
|
||||
let flags = NodeFlags.None;
|
||||
// Note: We only make queries static that query for a single item.
|
||||
// This is because of backwards compatibility with the old view compiler...
|
||||
if (isFirst && (queryIds.staticQueryIds.has(queryId) || !queryIds.dynamicQueryIds.has(queryId))) {
|
||||
flags |= NodeFlags.StaticQuery;
|
||||
} else {
|
||||
flags |= NodeFlags.DynamicQuery;
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
Reference in New Issue
Block a user