From 7b2b1afe719a253e8765fece2239590c84adb8c9 Mon Sep 17 00:00:00 2001 From: Alex Rickabaugh Date: Fri, 15 Jun 2018 15:43:22 -0700 Subject: [PATCH] fix(ivy): support inputs/outputs in decorator metadata in JIT (#24565) PR Close #24565 --- packages/core/src/render3/jit/directive.ts | 25 +++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/packages/core/src/render3/jit/directive.ts b/packages/core/src/render3/jit/directive.ts index b05831dae3..b545f72306 100644 --- a/packages/core/src/render3/jit/directive.ts +++ b/packages/core/src/render3/jit/directive.ts @@ -144,17 +144,20 @@ export function awaitCurrentlyCompilingComponents(): Promise { function directiveMetadata(type: Type, metadata: Directive): R3DirectiveMetadata { // Reflect inputs and outputs. const propMetadata = getReflect().propMetadata(type); - const inputs: StringMap = {}; - const outputs: StringMap = {}; 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) { propMetadata[field].forEach(ann => { if (isInput(ann)) { - inputs[field] = ann.bindingPropertyName || field; + inputsFromType[field] = ann.bindingPropertyName || field; } else if (isOutput(ann)) { - outputs[field] = ann.bindingPropertyName || field; + outputsFromType[field] = ann.bindingPropertyName || field; } }); } @@ -163,7 +166,9 @@ function directiveMetadata(type: Type, metadata: Directive): R3DirectiveMet name: type.name, type: new WrappedNodeExpr(type), selector: metadata.selector !, - deps: reflectDependencies(type), host, inputs, outputs, + deps: reflectDependencies(type), host, + inputs: {...inputsFromMetadata, ...inputsFromType}, + outputs: {...outputsFromMetadata, ...outputsFromType}, queries: [], lifecycle: { usesOnChanges: type.prototype.ngOnChanges !== undefined, @@ -213,3 +218,13 @@ function isHostBinding(value: any): value is HostBinding { function isHostListener(value: any): value is 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); +}