当模块被完全解析时,`import()` 会解析吗?

Does `import()` resolve when the module is fully parsed?

使用动态 import() 语法,我可以在运行时加载模块,例如

if (someCondition) await import('some-other-file');

是否可以安全地假设,一旦承诺解决,some-other-file 已被完全解析,并且它触发的任何同步副作用都已经发生?

是的,这是MDN Docs

中所写的实际行为

带有数据的演示 URL:

const code = "window.foo = 'bar';";
const importString = `data:application/javascript;charset=utf-8;base64,${btoa(code)}`;

import(importString).then(() => console.log(foo))