rollup / plugins

🍣 The one-stop shop for official Rollup plugins
MIT License
3.57k stars 568 forks source link

constructor var name or function parameters are ending up with the same name as the class #1645

Open saadshams opened 7 months ago

saadshams commented 7 months ago

Problem:

Screen Shot 2023-12-06 at 8 16 30 PM

t in the constructor parameter is the same name as the class name. this._notifyMethodis getting assigned to the class. One would suspect that the variable name should shadow the class ref name but that's not the case.

There's no problem if tested with Mocha standalone in the Node.js environment.

The failure is for end-to-end testing using nightwatch when browsers are involved. I have all nightwatch tests pass with the non-minifed version, but they fail with the minified version for all (safari, chrome, firefox).

Upon closer inspection, I found that one of the constructor parameters was using the same name as the class name, and hence, during assignment, the property got assigned to the class type.

I was passing a function reference and when I attempted to call, the error is thrown: "TypeError: Cannot call a class as a function."

Manual Fix: renamed constructor parameter to t1 to differentiate. Screen Shot 2023-12-06 at 8 12 52 PM

Expected Behavior

Class names should differ from parameter names

Actual Behavior

Class names and variable names share the same character set.

Additional Information

the error will occur as soon as instantiate the class object. new Foo

saadshams commented 5 months ago

A quick solution could be to use capital letters for the class names and small-case for the functions and variables.