esmangle icon indicating copy to clipboard operation
esmangle copied to clipboard

Mangle object properties

Open hummeleBop opened this issue 11 years ago • 6 comments

Hi there, Thanks for your AMAZING work ;) In future, do you plan to mangle object properties ? I use the application from the git repository.

With the following code:

let u = (function(){
let my_huge_function = function() { return 'test'; };

Object.defineProperties(my_huge_function, {
   very_long_name: { value: "hello", writable: false } } );

my_huge_function.other_very_long_name = "hello 2?";
return my_huge_function.other_very_long_name;
})();

alert(u); // print "hello 2?";

I get:

let u=function(){let a=function(){return'test'};return Object.defineProperties(a,{very_long_name:{value:'hello',writable:!1}}),a.other_very_long_name='hello 2?',a.other_very_long_name}();alert(u)

hummeleBop avatar May 07 '13 00:05 hummeleBop

How would that work? (wrt [] etc).

vendethiel avatar May 07 '13 01:05 vendethiel

@Nami-Doc: The Google Closure Compiler guys don't allow dynamic member access and actually believe that's an acceptable restriction. Hey, to each his own.

michaelficarra avatar May 07 '13 02:05 michaelficarra

Yes, and the compiler totally fails at it, giving everybody strange issues.

vendethiel avatar May 07 '13 09:05 vendethiel

There is an error in my exemple sorry :'( And I use 'let' keyword

There real code is following

let u = (function(){
let my_huge_function = function() { return 'test'; };

Object.defineProperties(my_huge_function, {
   very_long_name: { value: "hello", writable: false } } );

my_huge_function.other_very_long_name = "hello 2?";
return my_huge_function.other_very_long_name;
})();

alert(u); // print "hello 2?";

and the mangler result :



let u=function(){let a=function(){return'test'};return Object.defineProperties(a,{very_long_name:{value:'hello',writable:!1}}),a.other_very_long_name='hello 2?',a.other_very_long_name}();alert(u)


esmangle is a really nice soft for javascript 1.7.

hummeleBop avatar May 07 '13 10:05 hummeleBop

How would that work? (wrt [] etc).

Do you think disallowing dynamic member access is an acceptable restriction?

vendethiel avatar May 07 '13 10:05 vendethiel

In some cases.. Example of use Object.defineProperties I create application in xulrunner environment

hummeleBop avatar May 07 '13 11:05 hummeleBop