tc39/proposal-asset-references

Module assets should be preloaded with deps

Opened this issue · 1 comments

Asset references to be used for dynamic imports can have a syntax label which roughly equates to "modulepreload" (the loader is told that the asset is a module which should be resolved and fetched with all of its dependencies), whereas generic assets are fetched with "preload". It would be a massive shortcoming and missed opportunity for many host usages if the proposal didn't capture this.

asset Foo from "foo";

await import(Foo); // TypeError? Or just resolve deps now as per regular dynamic imports?
asset Foo from "foo" as module;
// or
asset module Foo from "foo";
// etc.

await import(Foo); // All static dependencies of "foo" have been statically fetched.

The addition of such an "attribute" is further incentive to unify with Import Assertions or its follow-ups, ref #16.

This is captured by https://github.com/tc39/proposal-import-reflection, where:

import module x from "<specifier>";
await import(x);

is proposed as the syntax for module references, and:

import asset x from "<specifier>";
hostReadFile(x);

is suggested as the future of this proposal for host-managed asset references.