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

rest spread ignores default values #10735

Open
eps1lon opened this issue Nov 19, 2019 · 1 comment · May be fixed by #10738
Open

rest spread ignores default values #10735

eps1lon opened this issue Nov 19, 2019 · 1 comment · May be fixed by #10738

Comments

@eps1lon
Copy link
Contributor

@eps1lon eps1lon commented Nov 19, 2019

Bug Report

Current Behavior
Default values are ignored for rest variables.

Input Code

const props = {};
const {
  InputProps: {
    classes,
    ...InputPropsOther
  } = { foo: 1 },
  ...other
} = props;

console.log(InputPropsOther);

Output Code
See #10736

Expected behavior/code

logs { foo: 1 }

Can't provide a runkit since no node version supports that syntax but Chrome 78 does and it matches the expected behavior.

Babel Configuration (.babelrc, package.json, cli command, .eslintrc)

preset-env with chrome 51 as the target

Environment

  • Babel version(s): 7.7.3
  • Node/npm version: repl
  • OS: [e.g. OSX 10.13.4, Windows 10]
  • Monorepo: no
  • How you are using Babel: repl

Possible Solution

Additional context/Screenshots
Causes crashes for nested {} default values because it transpiles to props.InputProps.classe where props.InputProps can be undefined but guarded against with a default {}. Omitting that default value results in "cannot read property classes of undefined"

@babel-bot

This comment has been minimized.

Copy link
Collaborator

@babel-bot babel-bot commented Nov 19, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.