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

Babel is not able to output the optional chaining operator without transpiling it #12140

Closed
craig-jennings opened this issue Oct 5, 2020 · 3 comments
Labels
area: upstream i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@craig-jennings
Copy link

craig-jennings commented Oct 5, 2020

Bug Report

Current behavior
Babel is not able to output the optional chaining operator without first transpiling it.

With a browserslist of: last 2 Chrome versions

ERROR in ./index.js 3:14
Module parse failed: Unexpected token (3:14)
File was processed with these loaders:
 * ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| (() => {
|   const x = 'abc';
>   const y = x?.length;
| })();

With a browserslist of: last 2 Chrome versions, IE 11, it succeeds. However the output (as expected) has the optional chaining operator transpiled to

  var x = 'abc';
  var y = x === null || x === void 0 ? void 0 : x.length;

Input Code

const x = 'abc';
const y = x?.length;

Expected behavior
Babel would succeed even when the browserslist only lists browsers that currently support the optional chaining operator.

Babel Configuration

  • babel.config.js
module.exports = {
  presets: ['@babel/preset-env'],
};
  • .browserslistrc
last 2 Chrome versions
  • webpack.config.js
module.exports = {
  entry: './index.js',

  module: {
    rules: [
      {
        test: /\.js$/,
        use: 'babel-loader',
      },
    ],
  },
};
  • index.js
(() => {
  const x = 'abc';
  const y = x?.length;
})();

Environment

  • Babel version: v7.11.6
  • Node/Yarn version: Node 12.18.4/Yarn 1.22.4
  • OS: Windows 10
  • Monorepo: No
  • How you are using Babel: loader

Possible Solution

Additional context
Add any other context about the problem here. Or a screenshot if applicable

@babel-bot
Copy link
Collaborator

Hey @craigjennings11! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

@craig-jennings
Copy link
Author

I just made the connection that this is probably a webpack issue. Turns out that's the issue.

@JLHwung
Copy link
Contributor

JLHwung commented Oct 5, 2020

Duplicate of babel/babel-loader#871

@JLHwung JLHwung marked this as a duplicate of babel/babel-loader#871 Oct 5, 2020
@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 5, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: upstream i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

3 participants