Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic import declarations and expressions #1130

Merged
merged 6 commits into from
Apr 1, 2024
Merged

Conversation

edemaine
Copy link
Collaborator

@edemaine edemaine commented Mar 31, 2024

Fixes #727:

  • import { getX } from libraryconst { getX } = await import('library') if not at the top level
  • import lib, {getX} from libraryconst lib = await import('library'), {getX} = lib if not at the top level
  • stuff := import { getX, getY } from libraryconst stuff = (await import('library')).{getX, getY}

This complements existing functionality of stuff := import 'library'stuff := import('library'). Note that stuff := import library has a different meaning than above (use the variable library instead of the string).

I haven't implemented assert/with yet. I probably should... Import assertions via assert/with should work now.

Also fixes a bug where {x: y} := obj got implicitly returned as {x}, but it should be {y} (!).

@bbrk24
Copy link
Contributor

bbrk24 commented Mar 31, 2024

import lib, {getX} from libraryconst lib = await import('library'), {getX} = lib if not at the top level

Shouldn't this be

const ref = await import('library'),
  { getX, default: lib } = ref;

?

Copy link
Contributor

@STRd6 STRd6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks like a very useful feature that makes dynamic imports much easier to use.

@edemaine edemaine merged commit 33d1066 into main Apr 1, 2024
2 checks passed
@edemaine edemaine deleted the dynamic-import-decl branch April 1, 2024 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

non-toplevel importing
3 participants