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/preset-env] Optional chaining operator not working in Chrome #13145

Closed
scinos opened this issue Apr 13, 2021 · 3 comments
Closed

[@babel/preset-env] Optional chaining operator not working in Chrome #13145

scinos opened this issue Apr 13, 2021 · 3 comments
Labels
i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@scinos
Copy link

scinos commented Apr 13, 2021

Bug Report

Repo with reproduction: https://github.com/scinos/test-babel-not-optional-chaining

Input Code

  • Filename .babelrc.js

    module.exports = {presets: ['@babel/preset-env']};
  • Filename .browserslistrc

    Chrome 88
    
  • Filename src/index.js

    console?.log("test")

Current behavior

When running babel src -d dist it generates a file with ?. transpiled down:

"use strict";

var _console;

(_console = console) === null || _console === void 0 ? void 0 : _console.log("test");

Expected behavior

It should generate a file with the optional chaining operator:

"use strict";

console?.log("test");

Environment

  System:
    OS: macOS 10.15.7
  Binaries:
    Node: 14.16.0 - ~/.nvm/versions/node/v14.16.0/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 6.14.11 - ~/.nvm/versions/node/v14.16.0/bin/npm
  npmPackages:
    @babel/cli: 7.13.14 => 7.13.14 
    @babel/compat-data: 7.13.15 => 7.13.15 
    @babel/core: 7.13.15 => 7.13.15 
    @babel/preset-env: 7.13.15 => 7.13.15 

Possible Solution

Looks like the error is related to Chrome (using Firefox 88 as the target works), and introduced since @babel/preset-env@7.13.10 and/or @babel/compat-data@7.13.11.

Potentially related to #13009 ?

@babel-bot
Copy link
Collaborator

Hey @scinos! 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."

@nicolo-ribaudo
Copy link
Member

Yes, Chrome doesn't fully support optional chaining.
If you want to compile only the unsupported bits of that feature, you can enable the bugfixes: true option of @babel/preset-env.

@JLHwung
Copy link
Contributor

JLHwung commented Apr 13, 2021

For more context, see #13001

Closing this issue as the behaviour is intended.

@JLHwung JLHwung closed this as completed Apr 13, 2021
@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 Jul 14, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug i: needs triage 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

4 participants