On Fri, Nov 2, 2018 at 10:27 PM YJ <yang.ji...@celigo.com> wrote:
> Hi all,
>
> A shot in the dark but is there any way right now to disallow the use of 
> dynamic es module import?
>
> In this snippet:
>
> let ns = await import("some-module");
>
> Instead of let ns become a rejected promise during run time, can I somehow 
> make the usage of dynamic import a compile time error(or run time error, but 
> throw an exception right away instead of returning a promise) ?
>
> Thanks

Short answer: you can't.

Longer answer: starting V8 with --noharmony_dynamic_import will
disable dynamic imports (at least, for as long as that flag stays
around) but won't turn import statements into compile-time errors,
they'll just be parsed as regular function call statements.

Throwing an exception from your HostImportModuleDynamicallyCallback
won't work either. V8 turns those into rejected promises.

Possible solution: pre-parse the source file with something like
Esprima and check for dynamic import statements by walking the AST?
You probably need to patch Esprima first because I don't think it
knows about dynamic imports right now.

I'm curious why you want to make it a hard error.

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to