Skip to content

Conversation

@hoodmane
Copy link
Contributor

No description provided.

@github-actions
Copy link

github-actions bot commented Dec 16, 2025

The generated output of @cloudflare/workers-types matches the snapshot in types/generated-snapshot 🎉

@hoodmane hoodmane force-pushed the hoodmane/snapshot-import-from-js branch from a8d22fc to 7f5fc0a Compare December 16, 2025 23:08
@hoodmane hoodmane force-pushed the hoodmane/snapshot-import-from-js branch from 7f5fc0a to 30efd8e Compare December 17, 2025 16:15
@hoodmane hoodmane marked this pull request as ready for review December 17, 2025 21:45
@hoodmane hoodmane requested review from a team as code owners December 17, 2025 21:45
@jasnell jasnell added the python Issues/PRs relating to Python Workers label Dec 17, 2025
const obj = obj_ as
| { [importName]: string; [getAccessorList]: string[] }
| undefined;
const moduleName = obj?.[importName];
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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, {
Copy link
Contributor

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?

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

Labels

python Issues/PRs relating to Python Workers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants