Opened 10 years ago

Closed 8 years ago

#3241 closed defect (fixed)

[patch][ccla]Shrinksafe forward reference problem

Reported by: guest Owned by: alex
Priority: high Milestone: 1.4
Component: ShrinkSafe Version: 0.9
Keywords: Cc: lu758p1w5882xyk@…
Blocked by: Blocking:

Description (last modified by dylan)

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.

Attachments (1)

3241.patch (31.4 KB) - added by peller 8 years ago.
Patch from Richard Backhouse (IBM) including a test. Produces debug info using JSON

Download all attachments as: .zip

Change History (13)

comment:1 in reply to: ↑ description Changed 10 years ago by guest

I already mentionned and dicussed this problem here :

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

comment:2 Changed 10 years 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.

comment:3 Changed 10 years ago by peller

  • Component changed from General to BuildTools
  • Owner changed from anonymous to alex

comment:4 Changed 10 years ago by bill

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

comment:5 Changed 10 years ago by bill

  • Milestone changed from 0.9 to 1.1

comment:6 Changed 10 years ago by peller

  • Component changed from BuildTools to ShrinkSafe
  • Keywords shrinksafe removed

comment:7 Changed 10 years ago by dylan

  • Milestone changed from 1.1 to 1.2

moving shrinksafe bugs to 1.2

comment:8 Changed 9 years 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...

comment:9 Changed 9 years ago by dylan

  • Description modified (diff)
  • Milestone changed from 1.2 to future

moving shrinksafe bugs to future... help wanted.

comment:10 Changed 9 years 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.

comment:11 Changed 8 years ago by peller

  • Milestone changed from future to 1.4
  • Summary changed from Shrinksafe forward reference problem to [patch][ccla]Shrinksafe forward reference problem

Changed 8 years ago by peller

Patch from Richard Backhouse (IBM) including a test. Produces debug info using JSON

comment:12 Changed 8 years ago by peller

  • Resolution set to fixed
  • Status changed from new to closed

Fixed in [17254]

Note: See TracTickets for help on using tickets.