starlight icon indicating copy to clipboard operation
starlight copied to clipboard

Support dynamic imports

Open andrieshiemstra opened this issue 3 years ago • 3 comments

When trying to use a dynamic import

    let module_var_promise = import("my_module.mjs").then((my_module) => {
        return my_module.someVar;
    });

I get an error SyntaxError: 'import', and 'export' cannot be used outside of module code

Is there a technical reason for not supporting dynamic imports outside module code or is it just an oversimplification of the error checking code?

andrieshiemstra avatar May 23 '21 15:05 andrieshiemstra

never mind, it's simply that there is no dynamic module import method yet and starlight thinks i'm trying to do a static import..

andrieshiemstra avatar May 23 '21 15:05 andrieshiemstra

I think it is worth to keep this issue open. To get dynamic import first I have to implement async functions (there's already some of functionality for async fns internally and generators are working now).

playXE avatar May 24 '21 06:05 playXE

figured that out thanks to https://github.com/swc-project/swc/issues/140

i'm going to try to impl a Promise class so i can transpile async functions / await statements (and impl a import function)

andrieshiemstra avatar May 25 '21 08:05 andrieshiemstra