tc39 / proposal-source-phase-imports

Proposal to enable importing modules at the source phase

Home Page:https://tc39.es/proposal-source-phase-imports/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

trusted type representation superceding asset references

bmeck opened this issue · comments

It can be the case that this might supercede https://github.com/tc39/proposal-asset-references if we ensure that we can return a reference that is considered trusted but not evaluator nor fetched eagerly:

// a.mjs
import foo from 'foo' as 'trusted-reference';
import b from './b.mjs';
b(foo);

// b.mjs
export default function (foo) {
  import(foo);
}

Yes, this proposal could definitely capture asset reflection in that sense, where for that type of reflection non-eager loading could be defined within that if desired. I wasn't aware of the non-eager loading requirement there, can you detail more about this use case?

@guybedford the main usage is to be able to resolve a dependency, not to actually force that dependency to be loaded. Indeed the dependency may never be loaded depending on the evaluation of the module. For example CLI applications might have entire dead branches of features that are prohibitive to preload and just do lazy loading via "import" (I do this in some of my CLIs). Indeed even talking about resolving it can be done lazily / at idle time rather than load time while enforcing static analyzability.

@bmeck so it is not necessarily a security requirement but more about deferred loading as well as deferred execution in this case? So that you are effectively looking to provide more statically analyzable asset referencing than dynamic import or import.meta.url? Would preloaders ever be encouraged to load these things? Or is that left to modulepreload?

IDK about web spec nor do I really have much investment due to my social position regarding modulepreload; tooling, such as preloaders or bundlers, could use it without requiring partial evaluation though yes.

I'd be more in favor of this problem space of "reference but not load" being pushed onto asset references. I have elaborated my thoughts here.

Asset references is out of scope for the refocused scope of this proposal. Please direct concerns about asset references to the asset references proposal.