Skip to content
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

Support import/export aka modules #348

Open
mstoykov opened this issue Dec 6, 2021 · 3 comments
Open

Support import/export aka modules #348

mstoykov opened this issue Dec 6, 2021 · 3 comments

Comments

@mstoykov
Copy link
Contributor

mstoykov commented Dec 6, 2021

I am adding this issue mostly to say that I and @oleiade will be working on it this week and hopefully will have at least a WIP/PoC PR by the end of it, in case somebody else decides to work on it in the meantime.

After we have made some progress and have nailed down some things I will update this issue with more info

@mstoykov mstoykov changed the title Support import/export Support import/export aka moduesl Dec 6, 2021
@mstoykov mstoykov changed the title Support import/export aka moduesl Support import/export aka modules Dec 6, 2021
@faisalraja
Copy link

What does the code look like for selecting the actual file/module?

Something like this in my head if my question isn't clear.

vm.SetModuleLoader(func(module string) (string, error) {
    // do something to load module code
    moduleCode := getModuleCodeById(module)
    return moduleCode, nil
})

@mstoykov
Copy link
Contributor Author

mstoykov commented Jan 5, 2022

Sorry for the slow reply @faisalraja , there has been some holidays ;).

The API is far from complete (everything really is) - but no. In order for the possibility of having not JS modules, but for example having some made by the host environment (the program inside which the JS is running), the specification specifies (:wink:) HostResolveImportedModule which returns an instance of a Module(Record).

So that means that you will need, if the Module that is being imported is a text module(js code basically), to parse it and then return it as shown in the tc39_test.go changes we have done:
https://github.com/MStoykov/goja/blob/96d718b7c25a57a2c028dd87484f244c46324e21/tc39_test.go#L686-L716
Instead of just returning the code. I am not dismissing the idea of having a helper for this, but there are more pressing matters ;)

I would like to also note that all of this code is a PoC/WIP, and it still doesn't work, which hopefully will take me a day or two to fix. And after it actually works it's likely all of the API will be redone to be again, close to the specification, but not as verbatim as currently.

@mstoykov
Copy link
Contributor Author

mstoykov commented Sep 8, 2022

A draft PR has been opened 🎉

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