_specialChars error
tamaranga opened this issue · 2 comments
input:
var formManager=(function(){
var $progress, $block, $blockCaption;
}());
output:
var formManager=(function(){var p,b,b;}());
variables $block
and $blockCaption
should not have the same name b.
php code to reproduce:
$script = 'var formManager=(function(){
var $progress, $block, $blockCaption;
}());';
$packer = new Tholu\Packer\Packer($script, 'None', false, true, false);
echo $packer->pack();
This is expected behaviour. Relevant part of the documentation:
Special Characters
To aid compression you may flag your private and local variables. The packer will then encode your variables as shown below. Because there is no real concept of "private" and "local" variables in JavaScript I’ll define the terms as follows:
Local ($)
Variables used only in the current scope. Typically, arguments and variables in functions. Flag local variables with a dollar sign ($) prefix and they will be truncated to the first character. Additional dollar signs will lengthen the result. Numeric suffixes are preserved.
Example:
// unpacked:
function test($left, $top1, $top2, $$length) {
// do something
};
// packed:
function test(l,t1,t2,le){};
Take care not to create naming conflicts in your functions. Restrict the dollar sign truncation to local variables only.
Private (_)
Variables used throughout your script but not outside of it. Flag private variables with a single underscore (_) prefix and they will be encoded to an underscore followed by a number.
An example:
// unpacked:
var _CONSTANT = 42;
function _test($left, $top1, $top2, $$length) {
return ($top1 / $top2) + _CONSTANT;
};
// packed:
var _0=42;function _1(l,t1,t2,le){return(t1/t2)+_0};
Debug Code (;;;)
Three semi-colons (;;;) are treated like single-line comments.
For example, this code:
;;; alert("TEST!");
Would be removed by the packing program.
Thank you