arboleya / coffee-toaster

Minimalist build system for CoffeeScript.
114 stars 23 forks source link

Files not picked up in namespace when they are subclasses #38

Closed friendofasquid closed 12 years ago

friendofasquid commented 12 years ago

Seems like if I have a file in a folder dist/foo

class Foo

and then , in the same folder

class Bar extends Foo

then Bar isn't available in the foo namespace (e.g. foo.Bar) but Foo is (foo.Foo). If I remove the extends from Bar, it is available.

arboleya commented 12 years ago

Hi,

Everything worked as expected, there must be something wrong with your code.

Take a look at this example, maybe it can help you.

Folder's structure

friendofasquid
|-- app.js
|-- src
|   `-- foo
|       |-- bar.coffee
|       `-- foo.coffee
`-- toaster.coffee

File contents

src/foo/bar.coffee

#<< foo/foo

class Bar extends foo.Foo
    constructor:->
        console.log "NEW BAR!"
        new foo.Foo()

new foo.Bar()

src/foo/foo.coffee

class Foo
    constructor:->
        console.log "NEW FOO!"

app.js

var __t;

__t = function(ns) {
  var curr, index, part, parts, _i, _len;
  curr = null;
  parts = [].concat = ns.split(".");
  for (index = _i = 0, _len = parts.length; _i < _len; index = ++_i) {
    part = parts[index];
    if (curr === null) {
      curr = eval(part);
      continue;
    } else {
      if (curr[part] == null) {
        curr = curr[part] = {};
      } else {
        curr = curr[part];
      }
    }
  }
  return curr;
};

var foo = {};

(function() {
  var __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

  __t('foo').Foo = (function() {

    function Foo() {
      console.log("NEW FOO!");
    }

    return Foo;

  })();

  __t('foo').Bar = (function(_super) {

    __extends(Bar, _super);

    function Bar() {
      console.log("NEW BAR!");
      new foo.Foo();
    }

    return Bar;

  })(foo.Foo);

  new foo.Bar();

}).call(this);

Running

$ node app.js 
NEW BAR!
NEW FOO!