Ticket #3241 (new defect)

Opened 18 months ago

Last modified 11 days ago

Shrinksafe forward reference problem

Reported by: guest Owned by: alex
Priority: normal Milestone: future
Component: ShrinkSafe Version: 0.9
Severity: major Keywords:
Cc: lu758p1w5882xyk@…

Description (last modified by dylan) (diff)

Shrinksafe breaks this code :

function my_object(){
        var a=''
        this.doIt = function(){
                doingIt()
        }
        this.getA = function(){
                return a
        }
        var doingIt=function(){
                a = 'done'
        }
}
var mm=new my_object()
mm.doIt()
alert( mm.getA() )

Here is the shrinked code :

function my_object(){
var a="";
this.doIt=function(){
doingIt();
};
this.getA=function(){
return a;
};
var _2=function(){
a="done";
};
}
var mm=new my_object();
mm.doIt();
alert(mm.getA());

The probleme is that the function "doingIt()" has been renamed "_2" but the call hasn't been renamed. If I reorder "doingIt()" and "doIt()" , the probleme is solved.

Change History

in reply to: ↑ description   Changed 18 months ago by guest

I already mentionned and dicussed this problem here :

http://dojotoolkit.org/docs/shrinksafe#comment-2544

  Changed 17 months ago by jburke

  • milestone set to 0.9

Ticket #3581 is a duplicate of this bug, providing another context in which variable order is important.

  Changed 17 months ago by peller

  • owner changed from anonymous to alex
  • component changed from General to BuildTools

  Changed 16 months ago by bill

  • summary changed from Shrinksafe breaks function inside objects in some cases to Shrinksafe forward reference problem

  Changed 16 months ago by bill

  • milestone changed from 0.9 to 1.1

  Changed 14 months ago by peller

  • keywords shrinksafe removed
  • component changed from BuildTools to ShrinkSafe

  Changed 9 months ago by dylan

  • milestone changed from 1.1 to 1.2

moving shrinksafe bugs to 1.2

  Changed 4 months ago by JasonBunting

I don't know if this helps or not, but found something interesting in my own 'discovery' of this bug.

This compresses just fine:

  SomeOtherFunction(function() {
    var calculateSomething = function(val) {
      doSomethingInteresting(1, 1, 1);
    };
    var calculateSomethingElse = function(val) {
      doSomethingInteresting(1, 1, null);
    };
    var doSomethingInteresting = function(foo, bar, baz) {
      // some code here...
    };	
  });

But this slightly different version doesn't:

  SomeOtherFunction(function() {
    var calculateSomething = function(val) {
      doSomethingInteresting(1, 1, function(array) { array.push(val); });
    };
    var calculateSomethingElse = function(val) {
      doSomethingInteresting(1, 1, null);
    };
    var doSomethingInteresting = function(foo, bar, baz) {
      // some code here...
    };	
  });

The only difference in this example is the anonymous function being passed in the first function's call of the doSomethingInteresting function.

Hope that helps...

  Changed 4 months ago by dylan

  • description modified (diff)
  • milestone changed from 1.2 to future

moving shrinksafe bugs to future... help wanted.

  Changed 11 days ago by peller

The example cited in the description works as of Dojo 1.2 (see #7127) However, Richard Backhouse has an example which still fails:

(function() {
function MyClass(){
    this.foo = function(argument1, argument2){
            var mytest = test;
    }
    this.bar = function(){}
}
var test = "test";
});

results in

(function(){
function _1(){
this.foo=function(_2,_3){
var _4=test;
};
this.bar=function(){
};
};
var _5="test";
});  

the var test is not converted in the inner function.

Note: See TracTickets for help on using tickets.