From e69288418c35235b112067a4c1be235e1999ff86 Mon Sep 17 00:00:00 2001 From: JoostK Date: Sat, 5 Dec 2020 14:35:25 +0100 Subject: [PATCH] refactor(compiler-cli): reformat directive/pipe metadata extraction (#39961) The prior usage of a ternary expression caused the code to be formatted in a weird way, so this commit replaces the ternary with an `if` statement. PR Close #39961 --- .../partial_component_linker_1.ts | 71 ++++++++++--------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/packages/compiler-cli/linker/src/file_linker/partial_linkers/partial_component_linker_1.ts b/packages/compiler-cli/linker/src/file_linker/partial_linkers/partial_component_linker_1.ts index 6f5c9fa4b0..254107b7fa 100644 --- a/packages/compiler-cli/linker/src/file_linker/partial_linkers/partial_component_linker_1.ts +++ b/packages/compiler-cli/linker/src/file_linker/partial_linkers/partial_component_linker_1.ts @@ -65,42 +65,45 @@ export function toR3ComponentMeta( let wrapDirectivesAndPipesInClosure = false; - const directives: R3UsedDirectiveMetadata[] = metaObj.has('directives') ? - metaObj.getArray('directives').map(directive => { - const directiveExpr = directive.getObject(); - const type = directiveExpr.getValue('type'); - const selector = directiveExpr.getString('selector'); + let directives: R3UsedDirectiveMetadata[] = []; + if (metaObj.has('directives')) { + directives = metaObj.getArray('directives').map(directive => { + const directiveExpr = directive.getObject(); + const type = directiveExpr.getValue('type'); + const selector = directiveExpr.getString('selector'); - let typeExpr = type.getOpaque(); - if (type.isFunction()) { - typeExpr = type.getFunctionReturnValue().getOpaque(); - wrapDirectivesAndPipesInClosure = true; - } - return { - type: typeExpr, - selector: selector, - inputs: directiveExpr.has('inputs') ? - directiveExpr.getArray('inputs').map(input => input.getString()) : - [], - outputs: directiveExpr.has('outputs') ? - directiveExpr.getArray('outputs').map(input => input.getString()) : - [], - exportAs: directiveExpr.has('exportAs') ? - directiveExpr.getArray('exportAs').map(exportAs => exportAs.getString()) : - null, - }; - }) : - []; + let typeExpr = type.getOpaque(); + if (type.isFunction()) { + typeExpr = type.getFunctionReturnValue().getOpaque(); + wrapDirectivesAndPipesInClosure = true; + } + return { + type: typeExpr, + selector: selector, + inputs: directiveExpr.has('inputs') ? + directiveExpr.getArray('inputs').map(input => input.getString()) : + [], + outputs: directiveExpr.has('outputs') ? + directiveExpr.getArray('outputs').map(input => input.getString()) : + [], + exportAs: directiveExpr.has('exportAs') ? + directiveExpr.getArray('exportAs').map(exportAs => exportAs.getString()) : + null, + }; + }); + } - const pipes = metaObj.has('pipes') ? metaObj.getObject('pipes').toMap(value => { - if (value.isFunction()) { - wrapDirectivesAndPipesInClosure = true; - return value.getFunctionReturnValue().getOpaque(); - } else { - return value.getOpaque(); - } - }) : - new Map(); + let pipes = new Map(); + if (metaObj.has('pipes')) { + pipes = metaObj.getObject('pipes').toMap(value => { + if (value.isFunction()) { + wrapDirectivesAndPipesInClosure = true; + return value.getFunctionReturnValue().getOpaque(); + } else { + return value.getOpaque(); + } + }); + } return { ...toR3DirectiveMeta(metaObj, code, sourceUrl),