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

Destructuring default function argument is instrumented incorrectly #263

Open
rabelloo opened this issue Jul 28, 2021 · 0 comments
Open

Comments

@rabelloo
Copy link

Given this example source code:

const fn = ({ prop } = {}) => prop;

Istanbul instruments the code in a way that executing the function always breaks with error TypeError: Cannot destructure 'undefined' as it is undefined., for example:

// format is as emitted by babel-plugin-istanbul
const fn = ({ prop  } = cov_3lpv0ilsj().b[0][0]++, {
})=>{
    cov_3lpv0ilsj().f[3]++;
    return prop;
};

The issue is clearly the default statement, which does not get properly wrapped in parens, for example this would work:

const fn = ({ prop } = (cov_3lpv0ilsj().b[0][0]++, {}))=> prop;

Also, if it helps, default values for properties in the destructure expression work just fine:

const fn = ({ prop = 'foo' }) => prop;

// becomes

const fn = ({ prop = (cov_3lpv0ilsj().b[0][0]++, 'foo') }) => prop;

Environment

@babel/core: 7.14.8
babel-plugin-istanbul: 6.0.0
node: v15.12.0

Config

.babelrc

{
  "plugins": ["istanbul"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant