Skip to content

fix: multiple minor issues#221

Merged
timfish merged 6 commits intonodejs:mainfrom
BridgeAR:BridgeAR/2026-01-12-fix-memory-leak
Jan 13, 2026
Merged

fix: multiple minor issues#221
timfish merged 6 commits intonodejs:mainfrom
BridgeAR:BridgeAR/2026-01-12-fix-memory-leak

Conversation

@BridgeAR
Copy link
Member

@BridgeAR BridgeAR commented Jan 12, 2026

Please see individual commits for the changes. I am happy to separate these into different commits, if requested.

One of the fixes is a small memory leak in case of dynamic import failing.

Refs: DataDog/dd-trace-js#6567

@BridgeAR BridgeAR force-pushed the BridgeAR/2026-01-12-fix-memory-leak branch 3 times, most recently from 14ab548 to 1c9b79a Compare January 12, 2026 16:55
The dynamic import error case would gather up specifiers without
ever using them. In case an application has many such errors, it
could cause problems for users.
The return type of esmExports was wrong. To fix it, it not only
changes it to .size as it might still be wrong, it also checks for
ESM syntax such as import. That way it is safer to differentiate
between CJS and ESM in these cases.
@BridgeAR BridgeAR force-pushed the BridgeAR/2026-01-12-fix-memory-leak branch from 1c9b79a to 45c2742 Compare January 12, 2026 17:00
// - We treat `import.meta` and static `import ...` as ESM.
// - We do NOT treat `import(` (dynamic import) as ESM because it is allowed
// in CJS as an expression.
if (source.indexOf('import') === -1) return false
Copy link
Contributor

Choose a reason for hiding this comment

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

Won't this be a full scan of the text prior to doing a subsequent full in the rest of the function?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, while this should be a fast path in most circumstances, since indexOf is faster than the loop below and ideally, this case has no import statements anyway (it is only the fallback case)

Copy link
Contributor

Choose a reason for hiding this comment

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

Won't this trigger a false positive?

// some 1,000+ lines
logger.info('import successful')

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that would be a false positive, while it would just be additional work for that case. I am fine to remove it, while I am relatively confident that the average case will profit from the indexOf check.

Copy link
Contributor

@timfish timfish left a comment

Choose a reason for hiding this comment

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

Happy to merge all these fixes as one PR but we need to ensure that all the individual changes are picked up by release-please so they all end up in the changelog.

I'll have a look. Maybe it'll work if we include them all in the merge commit?

@timfish timfish merged commit 40c1009 into nodejs:main Jan 13, 2026
51 checks passed
@timfish
Copy link
Contributor

timfish commented Jan 13, 2026

Yes, that worked!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants