Skip to content

Feature Request: import defer #4238

Description

@robpalme

Feature Request: TC39 Stage 3 import defer

Proposal repo: https://github.com/tc39/proposal-defer-import-eval

The new import defer syntax is at Stage 3 in the TC39 process and implementations are starting to move forward in browsers and tools.

This enables new optimizations in code splitting builds that avoid unnecessary code execution.

Example:

import defer * as mod from './mod.js';

export function lazyModUser () {
  mod.foo();
}

where mod is a "Deferred Module" flavor of Module Namespace, whose accessors (including e.g. reading keys) cause evaluation to run.

Desired support

At a minimum the syntax should be tolerated. Ideally this should be a fully compliant downlevel as that will benefit users the most. That requires function-wrapping the modules that will be lazily evaluated, i.e. they cannot be inlined (scope-hoisted).

References

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions