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-transform-react-jsx sets null on attributes parameter, but should be undefined. #9130

Open
jklarenbeek opened this Issue Dec 5, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@jklarenbeek

jklarenbeek commented Dec 5, 2018

Bug Report

Current Behavior
When JSX is transformed and encounters a element without attributes:

const jsx = (<h1>test</h1>);

the h (or React.createElement) function is called with an attributes parameter of null instead of undefined. Therefor the default value for a parameter does not kick in.

Input Code
https://codepen.io/bitSOCIAL/pen/xQowNa

Note the top function signature of h with a default value of an empty object literal for the attributes parameter.

function h(name, attributes = {}, ...rest) {
}

Expected behavior/code
I expect the attributes parameter to be undefined or defaulting to an empty object, if the default value for a parameter is set. Null in this case is not an option and only adds to the internal logic of the jsx render function.

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

  "babel": {
    "presets": [
      [
        "@babel/preset-env",
        {
          "modules": false,
          "useBuiltIns": false,
          "debug": true
        }
      ]
    ],
    "plugins": [
      [
        "@babel/plugin-transform-react-jsx",
        {
          "pragma": "h"
        }
      ]
    ]
  }

Environment

  • Babel version(s): ^7.1.5
  • Node/npm version: 10.12.0
  • OS: windows 10
  • plugin-transform-react-jsx version: ^7.0.0

Possible Solution
I can work around it ofcourse, but it doesn't use the buildin default value operator for parameters into account that was defined for javascript.

@babel-bot

This comment has been minimized.

Collaborator

babel-bot commented Dec 5, 2018

Hey @jklarenbeek! 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