rspivak / slimit

SlimIt - a JavaScript minifier/parser in Python
MIT License
550 stars 94 forks source link

Named closure function and its first argument are compiled to the same variable name. #75

Open spikesagal opened 9 years ago

spikesagal commented 9 years ago

For instance: foo(function bar(baz) {}); will compile to a(function b(b) {}); which is not valid JavaScript in strict mode:

[Error] SyntaxError: Cannot declare a parameter named 'b' as it shadows the name of a strict mode function. (anonymous function) (87608412746.js, line 1)

jabney commented 9 years ago

I'm also encountering the Cannot declare a parameter named 'b' as it shadows the name of a strict mode function issue in Safari.

I'm using slimit as part of a tool path that minimizes a set of JavaScript files as part of a python utility. I was able to work around the issue by removing all 'use strict' statements, but it's not ideal, and the code runs slower in the browser.

I also tried manually removing cases where the function parameter shadows the function name in my code, but the case function b(b) {...} still results after minification.

slimit works great otherwise. It won't minimize D3, but that's the only other problem I've ever found with this great utility. I'm hoping the strict mode issue can be resolved.