maxtaco / coffee-script

IcedCoffeeScript
http://maxtaco.github.com/coffee-script
MIT License
726 stars 58 forks source link

Destructuring doesn't work in defer statements #78

Closed boris-petrov closed 11 years ago

boris-petrov commented 11 years ago

When destructuring into instance vars. Check this example:

class A
  foo: (callback) ->
    callback bar: 2

  a: ->
    await @foo defer({ @bar })
    console.log @bar

new A().a()

Prints undefined. Funny thing is that the destructuring works if it's not into an instance var (i.e. without the @).

maxtaco commented 11 years ago

This is definitely a bug, on input this:

class Foo
  joe : () ->
    await foo defer { @yo, hi }

I'm seeing this output:

Foo = (function() {
    function Foo() {}

    Foo.prototype.joe = function() {
      var hi, ___iced_passed_deferral, __iced_deferrals, __iced_k,
        _this = this;
      __iced_k = __iced_k_noop;
      ___iced_passed_deferral = iced.findDeferral(arguments);
      __iced_deferrals = new iced.Deferrals(__iced_k, {
        parent: ___iced_passed_deferral,
        filename: "x.iced",
        funcname: "Foo.joe"
      });
      foo(__iced_deferrals.defer({
        assign_fn: (function(__slot_1) {
          return function() {
            __slot_1.yo = arguments[0]._this;
            return hi = arguments[0].hi;
          };
        })(this),
        lineno: 2
      }));
      __iced_deferrals._fulfill();
    };
    return Foo;
  })();

There's one problem at least, which is arguments[0]._this should be arguments[0].yo. Also, I wonder if I should be passing _this as opposed to this to assign_fn. I'll look into it. Thanks for the bug report.

maxtaco commented 11 years ago

Live in version 1.6.3-e. Thanks for this bug report.