Skip to content

Dynamic import enhanced #6194

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

Closed
mununki opened this issue Apr 23, 2023 · 3 comments
Closed

Dynamic import enhanced #6194

mununki opened this issue Apr 23, 2023 · 3 comments
Assignees

Comments

@mununki
Copy link
Member

mununki commented Apr 23, 2023

A few more points to consider include:

  1. Destructuring assignment for dynamic import of value
    It is said that modern bundlers perform tree-shaking for expressions like let {forEach} = ... If possible, it might be worth generating JavaScript output like var {forEach} = ...

  2. The current implementation uses the module_system to find the path:string corresponding to the module_id, but it does not consider cases when there are multiple module_systems. Also, within the Js_name_of_module_id.string_of_module_id function, Js_packages_state.get_packages_info () is being used. The same function was used in the place where Pimport was compiled.

@cristianoc
Copy link
Collaborator

Not sure I understand the multiple module systems. I thought there's only one in bsconfig and that's propagated to all dependencies?

@mununki
Copy link
Member Author

mununki commented Apr 23, 2023

I see it's modeled as a module_system list here https://github.com/rescript-lang/rescript-compiler/blob/master/jscomp/core/js_packages_info.ml#L57-L67, which I'm not sure about because I'm not familiar with it, so I'll have to look into the compiler logic a bit more.

@mununki
Copy link
Member Author

mununki commented Apr 23, 2023

For 1, the compiler already does a great job of reduction, but I think it's worth comparing the bundling results of the following two pieces of code.

var forEach = await import("..").then(function (m) {return m.forEach;})

var {forEach} = await import("..")

@mununki mununki self-assigned this Apr 23, 2023
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

No branches or pull requests

2 participants