From 1c2cb23417f60602b49df3fa53400ed498b0d11d Mon Sep 17 00:00:00 2001 From: Nolan Lawson <nlawson@salesforce.com> Date: Thu, 3 Mar 2022 11:08:51 -0800 Subject: [PATCH] fix: use flatMap/map --- .../@lwc/babel-plugin-component/src/utils.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/@lwc/babel-plugin-component/src/utils.js b/packages/@lwc/babel-plugin-component/src/utils.js index c07aef5407..a209f2ea47 100644 --- a/packages/@lwc/babel-plugin-component/src/utils.js +++ b/packages/@lwc/babel-plugin-component/src/utils.js @@ -51,17 +51,16 @@ function getEngineImportsStatements(path) { function getEngineImportSpecifiers(path) { const imports = getEngineImportsStatements(path); - - return imports - .reduce((acc, importStatement) => { + return ( + imports // Flat-map the specifier list for each import statement - return [...acc, ...importStatement.get('specifiers')]; - }, []) - .reduce((acc, specifier) => { + .flatMap((importStatement) => importStatement.get('specifiers')) // Get the list of specifiers with their name - const imported = specifier.get('imported').node.name; - return [...acc, { name: imported, path: specifier }]; - }, []); + .map((specifier) => { + const imported = specifier.get('imported').node.name; + return { name: imported, path: specifier }; + }) + ); } function normalizeFilename(source) {