Skip to content

Fix import { types } from "@babel/core" with native ESM#14663

Merged
nicolo-ribaudo merged 2 commits intobabel:mainfrom
nicolo-ribaudo:import-types-from-core
Jun 18, 2022
Merged

Fix import { types } from "@babel/core" with native ESM#14663
nicolo-ribaudo merged 2 commits intobabel:mainfrom
nicolo-ribaudo:import-types-from-core

Conversation

@nicolo-ribaudo
Copy link
Copy Markdown
Member

@nicolo-ribaudo nicolo-ribaudo commented Jun 12, 2022

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

This is another step in the direction of #13414. It makes it possible to use named imports for types, tokTypes, traverse and template from @babel/core, which were not available because the Node.js CJS-ESM interop doesn't recognize our lazy reexports.

Basically this code:

Object.defineProperty(exports, "types", {
  enumerable: true,
  get: function () {
    return _types();
  }
});

Is replaced by this (which is detected by the Node.js interpo) by a custom plugin:

Object.defineProperty((0, exports), "types", {
  enumerable: true,
  get: function () {
    return _types();
  }
});
0 && (exports.types = 0);

The second commit removes the usage of @babel/core's default export in our tests, which in theory shouldn't exist.

@nicolo-ribaudo nicolo-ribaudo added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label Jun 12, 2022
@babel-bot
Copy link
Copy Markdown
Collaborator

babel-bot commented Jun 12, 2022

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

@nicolo-ribaudo nicolo-ribaudo requested a review from JLHwung June 18, 2022 11:22
@nicolo-ribaudo nicolo-ribaudo force-pushed the import-types-from-core branch from dcaff9b to 73ced7a Compare June 18, 2022 11:34
@nicolo-ribaudo nicolo-ribaudo merged commit a32306d into babel:main Jun 18, 2022
@nicolo-ribaudo nicolo-ribaudo deleted the import-types-from-core branch June 18, 2022 22:39
@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 Sep 18, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 18, 2022
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 PR: Bug Fix 🐛 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants