From 331f8314be040f177cddbd95f07e5f9ed9ba5d50 Mon Sep 17 00:00:00 2001 From: Alexey Date: Sun, 1 Aug 2021 12:25:02 +0300 Subject: [PATCH] Change unique templates filtration --- src/lib/ast/get-templates-imports.js | 11 +++-------- src/lib/utils/is-unique-template.js | 14 -------------- 2 files changed, 3 insertions(+), 22 deletions(-) delete mode 100644 src/lib/utils/is-unique-template.js diff --git a/src/lib/ast/get-templates-imports.js b/src/lib/ast/get-templates-imports.js index 3892b91..1b3150a 100644 --- a/src/lib/ast/get-templates-imports.js +++ b/src/lib/ast/get-templates-imports.js @@ -1,6 +1,6 @@ import {getFirstExistedPath} from '../utils/get-first-existed-path'; import {getPossiblePaths} from '../utils/get-possible-paths'; -import {isUniqueTemplate} from '../utils/is-unique-template'; +import {isUniqueAsset} from '../utils/is-unique-asset'; import {getDependenciesTemplates} from './get-dependencies-templates'; @@ -21,11 +21,6 @@ async function filterPaths([path, paths]) { } } - -function filterUniqueTemplates(templates) { - return templates.filter(isUniqueTemplate); -} - /** * @param {Object} loaderContext * @param {nunjucks.nodes.Root} nodes @@ -41,9 +36,9 @@ export function getTemplatesImports(loaderContext, nodes, searchPaths) { } return true; - }); + }).filter(isUniqueAsset); const possiblePaths = getPossiblePaths(templateDeps, searchPaths); const resolvedTemplates = possiblePaths.map(filterPaths); - return Promise.all(resolvedTemplates).then(filterUniqueTemplates); + return Promise.all(resolvedTemplates); } diff --git a/src/lib/utils/is-unique-template.js b/src/lib/utils/is-unique-template.js deleted file mode 100644 index cce794b..0000000 --- a/src/lib/utils/is-unique-template.js +++ /dev/null @@ -1,14 +0,0 @@ -import {isUniqueObject} from './is-unique-object'; - - -export const isUniqueTemplate = isUniqueObject(getTemplateIndex); - -function getTemplateIndex(list, templateDescriptor) { - const [templateImport, templatePath] = templateDescriptor; - return list.findIndex(function compareImports([itemImport, itemPath]) { - return ( - itemImport.toString() === templateImport.toString() && - itemPath.toString() === templatePath.toString() - ); - }); -}