Original issue: https://github.com/babel/babel/issues/4531
Here's a reproduction repo
const foo = (arg1, arg2) => arg1
.babelrc (or what it might look like)
{
"plugins": ["minify-dead-code-elimination"]
}
I would expect the output to be:
const foo = (arg1) => arg1
Instead, the plugin doesn't do anything with unused arguments
const foo = (arg1, arg2) => arg1
I'm not certain whether this is totally the responsibility of babel-plugin-minify-dead-code-elimination, but I can't think of any other plugin that should do this.
I'm writing a program slicing tool that's using babel-plugin-minify-dead-code-elimination directly to remove dead code after I've manipulated the AST to remove sliced nodes.
| software | version |
| --- | --- |
| Babel | 6.14.0 |
| node | 6.5.0 |
| npm | 3.10.7 |
| Operating System | Mac OSX |
Sounds good but I think this would be better as an error (like in eslint) so that the source code has a removed argument instead.
I don't think we remove function args yet! But I'm sure it was on my to-do list to add to Babili.
Also note that this transformation will affect code depending on fn.length.
but I think this would be better as an error
I totally agree. But still, we should probably handle this case in this tool.
Also note that this transformation will affect code depending on
fn.length.
Definitely something to take into consideration with a test case I think :+1:
Hmm, pretty sure we had this implemented at some point.
Yeah I thought so to since it should be an easy win 馃槃
Guys this is not always a good idea. In fact, it has given me some pain recently. It eliminated the fourth argument from an express error middleware because the fourth argument next is not being used. The problem is that express as you might know looks for middlewares that accept four arguments explicitly so it can assign those as error handling middlewares
You can use the keepFnArgs option to disable this behavior: https://github.com/babel/minify/blob/8b7ed4adfc963f3c84d4a74c18e6a42aadb1396b/packages/babel-plugin-minify-dead-code-elimination/README.md#options
I just figured this one out and did that as we speak. That was a very quick response. Thank you