fix(ivy): support inputs/outputs in decorator metadata in JIT (#24565)
PR Close #24565
This commit is contained in:
parent
7d3fd4d655
commit
7b2b1afe71
|
@ -144,17 +144,20 @@ export function awaitCurrentlyCompilingComponents(): Promise<void> {
|
||||||
function directiveMetadata(type: Type<any>, metadata: Directive): R3DirectiveMetadata {
|
function directiveMetadata(type: Type<any>, metadata: Directive): R3DirectiveMetadata {
|
||||||
// Reflect inputs and outputs.
|
// Reflect inputs and outputs.
|
||||||
const propMetadata = getReflect().propMetadata(type);
|
const propMetadata = getReflect().propMetadata(type);
|
||||||
const inputs: StringMap = {};
|
|
||||||
const outputs: StringMap = {};
|
|
||||||
|
|
||||||
const host = extractHostBindings(metadata, propMetadata);
|
const host = extractHostBindings(metadata, propMetadata);
|
||||||
|
|
||||||
|
const inputsFromMetadata = parseInputOutputs(metadata.inputs || []);
|
||||||
|
const outputsFromMetadata = parseInputOutputs(metadata.outputs || []);
|
||||||
|
|
||||||
|
const inputsFromType: StringMap = {};
|
||||||
|
const outputsFromType: StringMap = {};
|
||||||
for (let field in propMetadata) {
|
for (let field in propMetadata) {
|
||||||
propMetadata[field].forEach(ann => {
|
propMetadata[field].forEach(ann => {
|
||||||
if (isInput(ann)) {
|
if (isInput(ann)) {
|
||||||
inputs[field] = ann.bindingPropertyName || field;
|
inputsFromType[field] = ann.bindingPropertyName || field;
|
||||||
} else if (isOutput(ann)) {
|
} else if (isOutput(ann)) {
|
||||||
outputs[field] = ann.bindingPropertyName || field;
|
outputsFromType[field] = ann.bindingPropertyName || field;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -163,7 +166,9 @@ function directiveMetadata(type: Type<any>, metadata: Directive): R3DirectiveMet
|
||||||
name: type.name,
|
name: type.name,
|
||||||
type: new WrappedNodeExpr(type),
|
type: new WrappedNodeExpr(type),
|
||||||
selector: metadata.selector !,
|
selector: metadata.selector !,
|
||||||
deps: reflectDependencies(type), host, inputs, outputs,
|
deps: reflectDependencies(type), host,
|
||||||
|
inputs: {...inputsFromMetadata, ...inputsFromType},
|
||||||
|
outputs: {...outputsFromMetadata, ...outputsFromType},
|
||||||
queries: [],
|
queries: [],
|
||||||
lifecycle: {
|
lifecycle: {
|
||||||
usesOnChanges: type.prototype.ngOnChanges !== undefined,
|
usesOnChanges: type.prototype.ngOnChanges !== undefined,
|
||||||
|
@ -213,3 +218,13 @@ function isHostBinding(value: any): value is HostBinding {
|
||||||
function isHostListener(value: any): value is HostListener {
|
function isHostListener(value: any): value is HostListener {
|
||||||
return value.ngMetadataName === 'HostListener';
|
return value.ngMetadataName === 'HostListener';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseInputOutputs(values: string[]): StringMap {
|
||||||
|
return values.reduce(
|
||||||
|
(map, value) => {
|
||||||
|
const [field, property] = value.split(',').map(piece => piece.trim());
|
||||||
|
map[field] = property || field;
|
||||||
|
return map;
|
||||||
|
},
|
||||||
|
{} as StringMap);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue