Merged
Conversation
14ab548 to
1c9b79a
Compare
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.
1c9b79a to
45c2742
Compare
bengl
approved these changes
Jan 12, 2026
jsumners-nr
reviewed
Jan 12, 2026
| // - 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 |
Contributor
There was a problem hiding this comment.
Won't this be a full scan of the text prior to doing a subsequent full in the rest of the function?
Member
Author
There was a problem hiding this comment.
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)
Contributor
There was a problem hiding this comment.
Won't this trigger a false positive?
// some 1,000+ lines
logger.info('import successful')
Member
Author
There was a problem hiding this comment.
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.
jsumners-nr
approved these changes
Jan 12, 2026
timfish
approved these changes
Jan 13, 2026
Merged
Contributor
|
Yes, that worked! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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