From 59f3ebdd3c7354468a8224b74cc27b1de7536aba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Bou=C3=A7as?= Date: Tue, 8 Feb 2022 12:33:16 +0000 Subject: [PATCH] fix: guard against self-referencing element in `shouldTranspile` (#1007) * fix: guard against self-referencing parent in `shouldTranspile` * refactor: move self-reference check up * refactor: use `parentPaths` variable Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- src/runtimes/node/bundlers/nft/es_modules.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/runtimes/node/bundlers/nft/es_modules.ts b/src/runtimes/node/bundlers/nft/es_modules.ts index 461fdd243..fed639a4f 100644 --- a/src/runtimes/node/bundlers/nft/es_modules.ts +++ b/src/runtimes/node/bundlers/nft/es_modules.ts @@ -114,9 +114,10 @@ const shouldTranspile = ( } const { parents } = reason + const parentPaths = [...parents].filter((parentPath) => parentPath !== path) // If the path is an entrypoint, we transpile it only if it's an ESM file. - if (parents.size === 0) { + if (parentPaths.length === 0) { const isESM = esmPaths.has(path) cache.set(path, isESM) @@ -126,7 +127,7 @@ const shouldTranspile = ( // The path should be transpiled if every parent will also be transpiled, or // if there is no parent. - const shouldTranspilePath = [...parents].every((parentPath) => shouldTranspile(parentPath, cache, esmPaths, reasons)) + const shouldTranspilePath = parentPaths.every((parentPath) => shouldTranspile(parentPath, cache, esmPaths, reasons)) cache.set(path, shouldTranspilePath)