fix(ivy): unable to inherit view queries into component from directive (#29203)
Fixes components not being able to inherit their view queries from a directive. This PR resolves FW-1146. PR Close #29203
This commit is contained in:

committed by
Matias Niemelä

parent
a5a35ff54a
commit
0ffa2f2e73
@ -129,13 +129,13 @@ export interface R3DirectiveMetadataFacade {
|
||||
usesInheritance: boolean;
|
||||
exportAs: string[]|null;
|
||||
providers: Provider[]|null;
|
||||
viewQueries: R3QueryMetadataFacade[];
|
||||
}
|
||||
|
||||
export interface R3ComponentMetadataFacade extends R3DirectiveMetadataFacade {
|
||||
template: string;
|
||||
preserveWhitespaces: boolean;
|
||||
animations: any[]|undefined;
|
||||
viewQueries: R3QueryMetadataFacade[];
|
||||
pipes: Map<string, any>;
|
||||
directives: {selector: string, expression: any}[];
|
||||
styles: string[];
|
||||
|
@ -133,7 +133,6 @@ export class CompilerFacadeImpl implements CompilerFacade {
|
||||
...convertDirectiveFacadeToMetadata(facade),
|
||||
selector: facade.selector || this.elementSchemaRegistry.getDefaultComponentElementName(),
|
||||
template,
|
||||
viewQueries: facade.viewQueries.map(convertToR3QueryMetadata),
|
||||
wrapDirectivesAndPipesInClosure: false,
|
||||
styles: facade.styles || [],
|
||||
encapsulation: facade.encapsulation as any,
|
||||
@ -235,6 +234,7 @@ function convertDirectiveFacadeToMetadata(facade: R3DirectiveMetadataFacade): R3
|
||||
outputs: {...outputsFromMetadata, ...outputsFromType},
|
||||
queries: facade.queries.map(convertToR3QueryMetadata),
|
||||
providers: facade.providers != null ? new WrappedNodeExpr(facade.providers) : null,
|
||||
viewQueries: facade.viewQueries.map(convertToR3QueryMetadata),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -53,6 +53,11 @@ export interface R3DirectiveMetadata {
|
||||
*/
|
||||
queries: R3QueryMetadata[];
|
||||
|
||||
/**
|
||||
* Information about the view queries made by the directive.
|
||||
*/
|
||||
viewQueries: R3QueryMetadata[];
|
||||
|
||||
/**
|
||||
* Mappings indicating how the directive interacts with its host element (host bindings,
|
||||
* listeners, etc).
|
||||
@ -128,11 +133,6 @@ export interface R3ComponentMetadata extends R3DirectiveMetadata {
|
||||
nodes: t.Node[];
|
||||
};
|
||||
|
||||
/**
|
||||
* Information about the view queries made by the component.
|
||||
*/
|
||||
viewQueries: R3QueryMetadata[];
|
||||
|
||||
/**
|
||||
* A map of pipe names to an expression referencing the pipe type which are in the scope of the
|
||||
* compilation.
|
||||
|
@ -69,6 +69,10 @@ function baseDirectiveFields(
|
||||
definitionMap.set('contentQueries', createContentQueriesFunction(meta, constantPool));
|
||||
}
|
||||
|
||||
if (meta.viewQueries.length) {
|
||||
definitionMap.set('viewQuery', createViewQueriesFunction(meta, constantPool));
|
||||
}
|
||||
|
||||
// Initialize hostVarsCount to number of bound host properties (interpolations illegal),
|
||||
// except 'style' and 'class' properties, since they should *not* allocate host var slots
|
||||
const hostVarsCount = Object.keys(meta.host.properties)
|
||||
@ -228,10 +232,6 @@ export function compileComponentFromMetadata(
|
||||
directiveMatcher = matcher;
|
||||
}
|
||||
|
||||
if (meta.viewQueries.length) {
|
||||
definitionMap.set('viewQuery', createViewQueriesFunction(meta, constantPool));
|
||||
}
|
||||
|
||||
// e.g. `template: function MyComponent_Template(_ctx, _cm) {...}`
|
||||
const templateTypeName = meta.name;
|
||||
const templateName = templateTypeName ? `${templateTypeName}_Template` : null;
|
||||
@ -549,7 +549,7 @@ function createTypeForDef(meta: R3DirectiveMetadata, typeBase: o.ExternalReferen
|
||||
|
||||
// Define and update any view queries
|
||||
function createViewQueriesFunction(
|
||||
meta: R3ComponentMetadata, constantPool: ConstantPool): o.Expression {
|
||||
meta: R3DirectiveMetadata, constantPool: ConstantPool): o.Expression {
|
||||
const createStatements: o.Statement[] = [];
|
||||
const updateStatements: o.Statement[] = [];
|
||||
const tempAllocator = temporaryAllocator(updateStatements, TEMPORARY_NAME);
|
||||
|
Reference in New Issue
Block a user