Skip to content

Make imports in .mjs files use node-like behavior where 'exports' is '.default' only. #7545

Merged
loganfsmyth merged 1 commit intobabel:masterfrom
loganfsmyth:commonjs-mjs-interop
Mar 15, 2018
Merged

Make imports in .mjs files use node-like behavior where 'exports' is '.default' only. #7545
loganfsmyth merged 1 commit intobabel:masterfrom
loganfsmyth:commonjs-mjs-interop

Conversation

@loganfsmyth
Copy link
Copy Markdown
Member

Q                       A
Fixed Issues? Fixes #7518
Patch: Bug Fix? N
Major: Breaking Change? Y, if people happen to already be using .mjs
Minor: New Feature? Y
Tests Added + Pass? Yes
Documentation PR
Any Dependency Changes?
License MIT

e.g.

// data.js - a standard CommonJS dfile
exports.named = "named";

then

import def, * as namespace from "./data";

console.log(def); // { named: "named" }
console.log(namespace); // { default: { named: "named" } }

whereas in .js files and in Babel 6, it was

import def, * as namespace from "./data";

console.log(def); // { named: "named" }
console.log(namespace); // { default: { named: "named" }, named: "named" }

so that

import { named } from "./data";

will work in Babel 6, but will not work in .mjs files in Babel 7.

@loganfsmyth loganfsmyth added PR: Breaking Change 💥 A type of pull request used for our changelog categories for next major release PR: New Feature 🚀 A type of pull request used for our changelog categories area: modules i: enhancement labels Mar 10, 2018
@loganfsmyth loganfsmyth requested a review from Jessidhia March 10, 2018 22:02
@babel-bot
Copy link
Copy Markdown
Collaborator

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

1 similar comment
@babel-bot
Copy link
Copy Markdown
Collaborator

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

// Both the default and namespace interops pass through __esModule
// objects, but the namespace interop is used to enable Babel's
// destructuring-like interop behavior for normal CommonJS.
// Since some tooling has started to remove that behavior, we expose
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🎉

Some people have actually published .mjs with this behavior too.

@jaydenseric
Copy link
Copy Markdown

Does this relate to, or fix #7294?

@loganfsmyth
Copy link
Copy Markdown
Member Author

@jaydenseric Tangentially in that it related to node ESM stuff, but I don't think this would fix that specifically.

@loganfsmyth loganfsmyth merged commit c662c2a into babel:master Mar 15, 2018
@loganfsmyth loganfsmyth deleted the commonjs-mjs-interop branch March 15, 2018 20:27
aminmarashi pushed a commit to aminmarashi/babel that referenced this pull request Mar 17, 2018
mAAdhaTTah added a commit to valtech-nyc/babel that referenced this pull request Mar 18, 2018
* master: (131 commits)
  v7.0.0-beta.42
  Use strict namespace behavior for mjs files. (babel#7545)
  Remove outdated spec deviation note [skip ci] (babel#7571)
  Ensure that the backward-compat logic for plugin-utils copies over the version API properly. (babel#7580)
  Rename actual/expected test files to input/output (babel#7578)
  Use helper-module-import inside entry plugin too
  Use helper-module-imports instead of custom import (babel#7457)
  Fix "Module build failed: Error: Cannot find module '@babel/types'" (babel#7575)
  Wrap wrapNativeSuper helpers in redefining functions for better tree-shakeability (babel#7188)
  Favour extends helper over objectWithoutProperties when whole object gets copied anyway (babel#7390)
  Fix incorrect value of _cache in _wrapNativeSuper (babel#7570)
  [transform-classes] Fix typo in _wrapNativeSuper helper
  [typeof-symbol] Guard against undefined built-in globals
  update to beta.41 (babel#7568)
  v7.0.0-beta.41
  Fix import of type ConfigItem (babel#7561)
  Run node 9 on circleci and remove from travis (babel#7560)
  docs: [skip ci] fix proposal link text
  update preset-env after build-data (babel#7543)
  Re-add TEST_ONLY and use Jest's -t for TEST_GREP. (babel#7556)
  ...
mAAdhaTTah added a commit to valtech-nyc/babel that referenced this pull request Mar 18, 2018
…ature/pipe-await

* 'master' of https://github.com/valtech-nyc/babel: (131 commits)
  v7.0.0-beta.42
  Use strict namespace behavior for mjs files. (babel#7545)
  Remove outdated spec deviation note [skip ci] (babel#7571)
  Ensure that the backward-compat logic for plugin-utils copies over the version API properly. (babel#7580)
  Rename actual/expected test files to input/output (babel#7578)
  Use helper-module-import inside entry plugin too
  Use helper-module-imports instead of custom import (babel#7457)
  Fix "Module build failed: Error: Cannot find module '@babel/types'" (babel#7575)
  Wrap wrapNativeSuper helpers in redefining functions for better tree-shakeability (babel#7188)
  Favour extends helper over objectWithoutProperties when whole object gets copied anyway (babel#7390)
  Fix incorrect value of _cache in _wrapNativeSuper (babel#7570)
  [transform-classes] Fix typo in _wrapNativeSuper helper
  [typeof-symbol] Guard against undefined built-in globals
  update to beta.41 (babel#7568)
  v7.0.0-beta.41
  Fix import of type ConfigItem (babel#7561)
  Run node 9 on circleci and remove from travis (babel#7560)
  docs: [skip ci] fix proposal link text
  update preset-env after build-data (babel#7543)
  Re-add TEST_ONLY and use Jest's -t for TEST_GREP. (babel#7556)
  ...
mAAdhaTTah added a commit to valtech-nyc/babel that referenced this pull request Mar 21, 2018
* master: (140 commits)
  Update to beta.42 (babel#7609)
  Disable flow on transformClass, fix preset-env errors (babel#7605)
  Logical Assignment: ensure computed key isn't recomputed (babel#7604)
  Remove obsolete max-len eslint rule and reformat some stuff to fit (babel#7602)
  Centralize Babel's own compilation config to make it easier to follow. (babel#7599)
  Run prettier to format all JSON.
  Tweak es2015-related plugin order in preset-env (babel#7586)
  Refactored quirky inheritance in babel-plugin-transform-classes (babel#7444)
  Add RegExp support to include/exclude preset-env options (babel#7242)
  v7.0.0-beta.42
  Use strict namespace behavior for mjs files. (babel#7545)
  Remove outdated spec deviation note [skip ci] (babel#7571)
  Ensure that the backward-compat logic for plugin-utils copies over the version API properly. (babel#7580)
  Rename actual/expected test files to input/output (babel#7578)
  Use helper-module-import inside entry plugin too
  Use helper-module-imports instead of custom import (babel#7457)
  Fix "Module build failed: Error: Cannot find module '@babel/types'" (babel#7575)
  Wrap wrapNativeSuper helpers in redefining functions for better tree-shakeability (babel#7188)
  Favour extends helper over objectWithoutProperties when whole object gets copied anyway (babel#7390)
  Fix incorrect value of _cache in _wrapNativeSuper (babel#7570)
  ...
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 5, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area: modules outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Breaking Change 💥 A type of pull request used for our changelog categories for next major release PR: New Feature 🚀 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an option for strict CJS interop (no destructuring-like behavior, just .default)

4 participants