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

[preset-env] Add targets for dynamic import #10203

Closed
wants to merge 1 commit into from

Conversation

nicolo-ribaudo
Copy link
Member

Q                       A
Fixed Issues?
Patch: Bug Fix? Yes
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

In engines which support import() natively, it doesn't need to be transpiled. For example, someone might write this code:

import color from "./static-module";

main();
async function main() {
  if (!window.$) await import("jquery-cdn");

  $("body").css("background", color);
}

and it could safely become

define(["./static-module", function(foo) {
  main();
  async function main() {
    if (!window.$) await import("jquery-cdn");

    $("body").css("background", color);
  }
});

NOTE: I'm not 100% sure that this PR is correct. If someone doesn't want import() to be transpiled, you might argue that they shouldn't transpile static imports neither and thus use modules: false

@babel-bot
Copy link
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/11108/

@JLHwung
Copy link
Contributor

JLHwung commented Jul 30, 2020

Note that we have implemented similar checks for export-ns-from: #11849 I will see if I can revive this PR and targets for next minor release.

@JLHwung JLHwung added PR: New Feature 🚀 A type of pull request used for our changelog categories and removed i: discussion labels Jul 30, 2020
@JLHwung JLHwung changed the base branch from master to main July 30, 2020 14:33
@nicolo-ribaudo
Copy link
Member Author

I don't think anymore that this is something that we should do. We should not implicitly mix two module systems (esm and something else). It's usually a mistake, and if someone really wants to do it they can already explicitly disable proposal-dynamic-import.

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jan 14, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: preset-env PR: New Feature 🚀 A type of pull request used for our changelog categories Spec: Dynamic Import
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants