Minify: babel-plugin-minify-dead-code-elimination should remove unused arguments

Created on 19 Sep 2016  路  8Comments  路  Source: babel/minify

Original issue: https://github.com/babel/babel/issues/4531

Input Code

Here's a reproduction repo

const foo = (arg1, arg2) => arg1

.babelrc (or what it might look like)

{
  "plugins": ["minify-dead-code-elimination"]
}

Expected Behavior

I would expect the output to be:

const foo = (arg1) => arg1

Current Behavior

Instead, the plugin doesn't do anything with unused arguments

const foo = (arg1, arg2) => arg1

Possible Solution

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.

Context

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.

Your Environment

| software | version |
| --- | --- |
| Babel | 6.14.0 |
| node | 6.5.0 |
| npm | 3.10.7 |
| Operating System | Mac OSX |

help wanted

All 8 comments

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

I just figured this one out and did that as we speak. That was a very quick response. Thank you

Was this page helpful?
0 / 5 - 0 ratings

Related issues

boopathi picture boopathi  路  3Comments

kangax picture kangax  路  4Comments

developit picture developit  路  5Comments

Reinmar picture Reinmar  路  4Comments

curiousdannii picture curiousdannii  路  3Comments