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

[plugin-proposal-optional-chaining] Loose mode produces unoptimized code for class methods #11084

Lodin opened this issue Feb 1, 2020 · 3 comments


Copy link

@Lodin Lodin commented Feb 1, 2020

Bug Report

  • I would like to work on a fix!

Current Behavior
The loose mode of optional-chaining plugin compiles class methods in non-optimized way repeating the call to the method instead of remembering its result.

It does not happen for function call though.

Input Code

  • REPL or Repo link if applicable: Runkit.

compiles to:

a.get(b) == null ? void 0 : a.get(b)();

Expected behavior/code
The result of method call should be memoized as it happens in the strict mode.

var a$get;

(a$get = a.get(b)) == null ? void 0 : a$get();

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)

  • Filename: babel.config.js
    plugins: [[require('@babel/plugin-proposal-optional-chaining'), {loose: true}]]


  • Babel version(s): 7.8.4
  • Node/npm version: v13.5.0/6.13.4
  • OS: Windows 10
  • Monorepo: Lerna
  • How you are using Babel: cli/programmatically

This comment has been minimized.

Copy link

@babel-bot babel-bot commented Feb 1, 2020

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


This comment has been minimized.

Copy link

@nicolo-ribaudo nicolo-ribaudo commented Feb 1, 2020

Note that this bug only affects optional calls. Optional member expressions are already memoized in loose mode.


This comment has been minimized.

Copy link

@oliverdunk oliverdunk commented Feb 1, 2020

I'd love to work on this one :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.