proposal-defer-import-eval icon indicating copy to clipboard operation
proposal-defer-import-eval copied to clipboard

Alternative import attribute name to express lack of guarantee

Open acutmore opened this issue 4 years ago • 9 comments

As there is no guarantee that the imported module is evaluated lazily, e.g. it has already been evaluated, or it contains top level await. Perhaps a name that more clearly expresses this is a hint rather than an assertion would work better?

Bikeshed:

import {x} from "y" with { preferLazy: true };
import {x} from "y" with { lazyHint: true };

acutmore avatar Jan 30 '21 18:01 acutmore

I like preferLazy! That communicates it pretty well. Feel free to add this (both really) to the bikeshedding doc (closer to the top, the bottoms ones are a bit more unsure...). I can also add it on monday.

codehag avatar Jan 30 '21 18:01 codehag

It should be less length in words for example just "lazy"

Jack-Works avatar Jan 31 '21 02:01 Jack-Works

It should be less length in words for example just "lazy"

We can also consider it, In fact, that would be ideal! I already ran into issues with people confusing this proposal with lazy loading -- a process which must be async. This is why the proposal name change from "lazy modules" to "defer module evaluation". I suspect that lazy on it's own will be too overloaded a term to be precise here.

codehag avatar Jan 31 '21 11:01 codehag

(also, the above applies to "preferLazy", but I think we should consider everything) -- feel free to make a pr with that one too.

codehag avatar Jan 31 '21 14:01 codehag

So what about defer import { } from 'str'?

Jack-Works avatar Jan 31 '21 15:01 Jack-Works

also a possibility! probably better than lazy import ...

codehag avatar Jan 31 '21 17:01 codehag

Reopening so we can keep bikeshedding. If you folks don't open prs then I will add them on monday.

codehag avatar Jan 31 '21 17:01 codehag

I'm a strong 👍 on some name that communicates that there's no guarantee here. As I mentioned in #27, I don't think it's surprising that a deferred import can't prevent the evaluation of a module if it needed to be evaluated non-lazily elsewhere in the module graph, but I do think handling of top-level await is potentially confusing.

In #27, I proposed partialDefer or deferSync

ethanresnick avatar Oct 10 '23 17:10 ethanresnick

I thought that import attributes would be a natural fit for this feature. I think it would be good to at least address in the proposal why there is new syntax instead of using import attributes.

justinfagnani avatar Jun 11 '24 19:06 justinfagnani