paiq/blackcoffee — pull request #6 by tgriesser (2013-12-05 23:00:03+00:00)
Title: Exposing utility and UTILITIES in nodes.coffee

First, just wanted to say really great work on this fork.

I've recently found myself in need of the old `extended` functionality which was removed awhile back (ticket https://github.com/jashkenas/coffee-script/pull/1960), and I figured that this fork might be a good way to add it back in there. I found that exposing `UTILITIES` and `utility` in `nodes.coffee` helps in this case, allowing you to do something like:

```coffee
macro ->

# Correctly set up a prototype chain for inheritance, including a reference
# to the superclass for `super()` calls, and copies of any static properties.
# and adding back the "extended" functionality
macro.UTILITIES.extends = -> """
function(child, parent) {
for (var key in parent) {
if (#{macro.utility 'hasProp'}.call(parent, key)) child[key] = parent[key];
}
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor();
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
return child;
}
"""

macro.Extends::compileToFragments = (o) ->
new macro.Call(new macro.Value(new macro.Literal macro.utility 'extends'), [@child, @parent]).compileToFragments o
```

Does this seem like a reasonable use case?