-
Notifications
You must be signed in to change notification settings - Fork 495
Make import_from_js modules serializable
#5710
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
base: main
Are you sure you want to change the base?
Conversation
|
The generated output of |
a8d22fc to
7f5fc0a
Compare
7f5fc0a to
30efd8e
Compare
| const obj = obj_ as | ||
| | { [importName]: string; [getAccessorList]: string[] } | ||
| | undefined; | ||
| const moduleName = obj?.[importName]; |
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.
When obj is undefined, how about early return?
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.
Well we return on the next line if obj is undefined or obj[importName] is undefined.
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, but if we add
if(obj === undefined) {
return
}then I guess we can make TypeScript happy and remove obj? from the rest of the function.
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 can just get rid of the ?. below since typescript knows that moduleName would be undefined if obj were nullish and so we take the early return path.
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.
Sounds good.
| if (!moduleName) { | ||
| return undefined; | ||
| } | ||
| modules.add(moduleName); |
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.
It is slightly uncomfortable to me that this function has a side effect of updating the modules set, which needs to be drilled down to this function from a very top-level makeLinearMemorySnapshot. But I guess it is trivial thing.
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.
Yeah it's unfortunate but the dynamic import is async and deserialization has to be async. Perhaps we should change it upstream so the deserialization can be async, that would make use cases like this simpler.
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.
Yeah it's unfortunate but the dynamic import is async and deserialization has to be async. Perhaps we should change it upstream so the deserialization can be async, that would make use cases like this simpler.
| if (!mod || typeof mod !== 'object') { | ||
| return mod; | ||
| } | ||
| return new Proxy(mod, { |
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.
This proxy if not easy to understand. Could you add some high level explanation?
No description provided.