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.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
module: support eval with ts syntax detection #56285
base: main
Are you sure you want to change the base?
module: support eval with ts syntax detection #56285
Changes from all commits
aeb77e9
f83b0d4
0c1d4d0
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably say something about syntax detection here, that first it attempts to run as CommonJS JavaScript, and depending on the parse error thrown, will retry as ESM JavaScript or CommonJS TypeScript; and then potentially a third time as ESM TypeScript? I’m not even sure what the flow would be, which probably means that we should spell it out 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not an expert on how the js syntax detection is implemented but the flow is:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The details of syntax detection are here: https://github.com/nodejs/node/blob/6012a4e9a2733b25a7023baa0a58bef85c9ebc5f/doc/api/esm.md#:~:text=at%20pjsonURL.-,DETECT_MODULE_SYNTAX,-(source)
The important part is to clarify which specific errors will trigger strip-types behavior. I assume there’s no overlap between the “retry as ESM” errors and the “retry with type stripping” errors, so the flow is no more expensive than the current detection flow: try first as CommonJS JavaScript, and retry as stripped types.
It gets even more complicated because doesn’t the strip-types flow itself use syntax detection? Like after it strips the types, then it initially tries to run as CommonJS, then retries as ESM?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it repeats the detection twice but its trasparent from my implementation. I'm not sure it can be skipped
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add the params to the JSDoc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add the params to the JSDoc?