PSMinifier icon indicating copy to clipboard operation
PSMinifier copied to clipboard

Feature: Variable Rename and Command Aliasing

Open dkattan opened this issue 3 years ago • 3 comments

In this PR I have implemented variable renaming and command shortening via aliases.

dkattan avatar Apr 04 '22 04:04 dkattan

@dkattan This looks interesting. There are a few issues I have with the current implementation:

  1. Renaming variables should not be the default.

For one, several variables are well-known or important, and thus changing the variable names may change functionality in a breaking way. For another, changing variables as a default becomes significantly more obfuscating that this project is intended to do. I don't mind the theoretical functionality being there (as long as it's optional).

  1. Renaming aliases should not be the default, either

Scripts can make use of "Smart Aliasing", where the name of the alias helps define the way the script is called (see modules like Irregular. Like with variable rename, this could be useful, but only if it doesn't surprise / break functionality.

  1. Both renaming variables and renaming aliasing should support a lookup table of renames.

  2. Stylistic changes to indentation are unwanted/ unneeded (and make the change harder to review).

  3. There's no tracking issue(s) here. Could you open a few issues:

  • [ ] An enhancement tracking the rename of variables
  • [ ] An enhancement tracking the renaming of aliases
  • [ ] An enhancement tracking the choice of -StatementSeparator (I like this, btw)
  • [ ] An enhancement tracking the refactoring of Compress-ScriptBlock to using inner functions

Thanks!

StartAutomating avatar May 03 '22 21:05 StartAutomating

@dkattan Thanks for the recent follow (it reminded me of this PR).

Please let me know if you want to me to make some time to run thru this with you and discuss how to make it fit. I'm hoping to make some updates to PSMinifier to make it more flexible and would love to figure out a way for this to fit.

Hope this helps

StartAutomating avatar Mar 10 '23 20:03 StartAutomating

@dkattan Thanks for the recent follow (it reminded me of this PR).

Please let me know if you want to me to make some time to run thru this with you and discuss how to make it fit. I'm hoping to make some updates to PSMinifier to make it more flexible and would love to figure out a way for this to fit.

Hope this helps

Hey I meant to reply earlier. Everything you brought up I think is valid. Personally I think renaming the variables should be renamed by default as I think that introduces a tremendous amount of compression and I believe is the default for other minifiers, but I am aware of the need to exclude special variables. I agree it blurs the line between minification and obfuscation but I just think to every minified javascript file I see and typically functions and variables are 1 letter. Anyway, default behavior is not truly important in the grand scheme of things.

My wife was on a bachelorette party the weekend I was working on this which is what afforded me the time to go down the rabbit hole as deep as I did. I don't think I'll have the bandwidth to finish it out properly but I'm happy to run through the changes and my thought process. I'll see if I can find your email and we can connect.

dkattan avatar Mar 10 '23 21:03 dkattan