Skip to content

Commit

Permalink
fix: guard against self-referencing element in shouldTranspile (#1007)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
eduardoboucas and kodiakhq[bot] committed Feb 8, 2022
1 parent c568511 commit 59f3ebd
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/runtimes/node/bundlers/nft/es_modules.ts
Expand Up @@ -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)
Expand All @@ -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)

Expand Down

1 comment on commit 59f3ebd

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱ Benchmark results

largeDepsEsbuild: 6.7s

largeDepsNft: 30.6s

largeDepsZisi: 52s

Please sign in to comment.