diff --git a/packages/compiler-cli/ngcc/src/host/esm2015_host.ts b/packages/compiler-cli/ngcc/src/host/esm2015_host.ts index 2893f98522aae7..7bab6d35c7f0b4 100644 --- a/packages/compiler-cli/ngcc/src/host/esm2015_host.ts +++ b/packages/compiler-cli/ngcc/src/host/esm2015_host.ts @@ -655,32 +655,16 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N return this.decoratorCache.get(decl) !; } - // First attempt extracting decorators from static properties. - let decoratorInfo = this.computeDecoratorInfoFromStaticProperties(classSymbol); - if (decoratorInfo === null) { - // If none were present, use the `__decorate` helper calls instead. - decoratorInfo = this.computeDecoratorInfoFromHelperCalls(classSymbol); - } else { - // If there was decorator information in static properties, it may be the case that only - // constructor parameters (`ctorParameters`) were present as static property and additional - // decorator info is represented using `__decorate` helper calls. Therefore, also inspect - // `__decorate` helpers and attach the class and member decorators it may contain to the - // computed decorator info. - // - // Note that the helper calls may also provide information about constructor parameters, if - // `emitDecoratorMetadata` was enabled for the published library. We can safely disregard this - // information from the helper calls, as the extracted information from the `ctorParameters` - // static property is fully complete by itself. - // - // Refer to https://github.com/ng-packagr/ng-packagr/pull/1401 where the static property - // transform of constructor parameters was ported from tsickle to ng-packagr. - if (decoratorInfo.classDecorators === null && decoratorInfo.memberDecorators.size === 0) { - const helperCallInfo = this.computeDecoratorInfoFromHelperCalls(classSymbol); - - decoratorInfo.classDecorators = helperCallInfo.classDecorators; - decoratorInfo.memberDecorators = helperCallInfo.memberDecorators; - } - } + // Extract decorators from static properties and `__decorate` helper calls, then merging them + // together where the information from the static properties is preferred. + const staticProps = this.computeDecoratorInfoFromStaticProperties(classSymbol); + const helperCalls = this.computeDecoratorInfoFromHelperCalls(classSymbol); + + const decoratorInfo: DecoratorInfo = { + classDecorators: staticProps.classDecorators || helperCalls.classDecorators, + memberDecorators: staticProps.memberDecorators || helperCalls.memberDecorators, + constructorParamInfo: staticProps.constructorParamInfo || helperCalls.constructorParamInfo, + }; this.decoratorCache.set(decl, decoratorInfo); return decoratorInfo; @@ -696,8 +680,10 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N * @returns All information on the decorators as extracted from static properties, or `null` if * none of the static properties exist. */ - protected computeDecoratorInfoFromStaticProperties(classSymbol: NgccClassSymbol): DecoratorInfo - |null { + protected computeDecoratorInfoFromStaticProperties(classSymbol: NgccClassSymbol): { + classDecorators: Decorator[] | null; memberDecorators: Map| null; + constructorParamInfo: ParamInfo[] | null; + } { let classDecorators: Decorator[]|null = null; let memberDecorators: Map|null = null; let constructorParamInfo: ParamInfo[]|null = null; @@ -717,16 +703,7 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N constructorParamInfo = this.getParamInfoFromStaticProperty(constructorParamsProperty); } - // If none of the static properties were present, no decorator info could be computed. - if (classDecorators === null && memberDecorators === null && constructorParamInfo === null) { - return null; - } - - return { - classDecorators, - memberDecorators: memberDecorators || new Map(), - constructorParamInfo: constructorParamInfo || [], - }; + return {classDecorators, memberDecorators, constructorParamInfo}; } /**