babel / minify

:scissors: An ES6+ aware minifier based on the Babel toolchain (beta)
https://babeljs.io/repl
MIT License
4.39k stars 225 forks source link

Why Is Transform-Member-Expression-Literals Added? #640

Closed trisys3 closed 7 years ago

trisys3 commented 7 years ago

Input Code

Actual Output

Expected Output

Details

This is more a question about process than about code generation. I was wondering why babili includes the transform-member-expression-literals plugin. It is not needed unless your environment is pre-ES3, which means only really early versions of Internet Explorer. According to this kangax table, which I got from the StackOverflow question about support for reserved words as property names, only IE8 and below do not support this. That means this plugin is not needed for any IE version supported by Microsoft. If that is OK with you, fine. I know there are a lot of businesses still on XP, and some on Vista who are still on IE8, which is also not supported by Microsoft.

My bigger problem is that this actually increases the code length, meaning not only are you putting in more work than you need to for no benefit, you are essentially hurting yourself for no reason. I do not mean to be so harsh, but I am seriously wondering why.

One last thing is that this is done outside of babili, as well. I am not sure how many people just include babili without including that plugin, even when they need to, but I assume that is why the plugin is included? If so, is that necessary to do anymore? Are there any stats on how many businesses actually need IE8 and how many developers catering to those businesses who use babel end up including babili without realizing they need that other plugin?

On the constructive side, could we have an option to ignore this plugin? It could be something like "ES5: true" or "ES3: false".

Why does babili include transform-member-expression-literals by default? Could we get an option to ignore it?

boopathi commented 7 years ago

That plugin converts property access foo["bar"] to foo.bar if bar is a valid identifier that can be used as a property name and is always equal to/shorter than the original version.

If you don't want to use this plugin, there is an option to NOT run this transform - https://github.com/babel/minify/tree/master/packages/babel-preset-minify#1-1-mapping-with-plugin

{
  memberExpressionLiterals: false
}
trisys3 commented 7 years ago

Thanks. I removed babel-minify as it was slow due to using babel's minified option, which is really slow, but if I ever use it again, I will be sure to add that option.