Skip to content

Commit

Permalink
remove custom coffeescript, add coffee-inheritance hacks from custom …
Browse files Browse the repository at this point in the history
…coffee repo directly
  • Loading branch information
lancejpollard committed Sep 13, 2012
1 parent eef4677 commit 5bc58cf
Show file tree
Hide file tree
Showing 12 changed files with 725 additions and 588 deletions.
129 changes: 128 additions & 1 deletion coffee.js → coffee-inheritance.js
Expand Up @@ -8,12 +8,14 @@ var helpers = require('coffee-script/lib/coffee-script/helpers');
var Literal = nodes.Literal; var Literal = nodes.Literal;
var Extends = nodes.Extends; var Extends = nodes.Extends;
var Code = nodes.Code; var Code = nodes.Code;
var Class = nodes.Class;
var Param = nodes.Param; var Param = nodes.Param;
var Block = nodes.Block; var Block = nodes.Block;
var Call = nodes.Call; var Call = nodes.Call;
var Assign = nodes.Assign; var Assign = nodes.Assign;
var Value = nodes.Value; var Value = nodes.Value;
var Parens = nodes.Parens; var Parens = nodes.Parens;
var Access = nodes.Access;
var If = nodes.If; var If = nodes.If;
var Arr = nodes.Arr; var Arr = nodes.Arr;
var compact = helpers.compact; var compact = helpers.compact;
Expand All @@ -39,6 +41,103 @@ var METHOD_DEF = RegExp("^(?:(" + IDENTIFIER_STR + ")\\.prototype(?:\\.(" + IDEN
var IS_STRING = /^['"]/; var IS_STRING = /^['"]/;
var __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; var __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };


Class.prototype.addProperties = function(node, name, o) {
var assign, base, exprs, func, props;
props = node.base.properties.slice(0);
exprs = (function() {
var _results;
_results = [];
while (assign = props.shift()) {
if (assign instanceof Assign) {
base = assign.variable.base;
delete assign.context;
func = assign.value;
if (base.value === 'constructor') {
if (this.ctor) {
throw new Error('cannot define more than one constructor in a class');
}
if (func.bound) {
throw new Error('cannot define a constructor as a bound function');
}
if (func instanceof Code) {
assign = this.ctor = func;
} else {
this.externalCtor = o.scope.freeVariable('class');
assign = new Assign(new Literal(this.externalCtor), func);
}
} else {
if (assign.variable["this"]) {
assign._isClassProp = true;
func["static"] = true;
if (func.bound) {
func.context = name;
}
} else {
assign._isInstanceProp = true;
assign.variable = new Value(new Literal(name), [new Access(new Literal('prototype')), new Access(base)]);
if (func instanceof Code && func.bound) {
this.boundFuncs.push(base);
func.bound = false;
}
}
}
}
_results.push(assign);
}
return _results;
}).call(this);
return compact(exprs);
};

Class.prototype.compileNode = function(o) {
var call, decl, e, i, key, klass, lname, name, params, value, _i, _len, _ref2, _ref3;
decl = this.determineName();
name = decl || '_Class';
if (name.reserved) {
name = "_" + name;
}
lname = new Literal(name);
this.hoistDirectivePrologue();
this.setContext(name);
this.walkBody(name, o);
if (this.parent) {
this.superClass = new Literal(o.scope.freeVariable('super', false));
this.body.expressions.unshift(new Extends(lname, this.superClass));
}
this.ensureConstructor(name);
this.body.spaced = true;
if (!(this.ctor instanceof Code)) {
this.body.expressions.unshift(this.ctor);
}
this.body.expressions.push(lname);
(_ref2 = this.body.expressions).unshift.apply(_ref2, this.directives);
_ref3 = this.body.expressions;
for (i = _i = 0, _len = _ref3.length; _i < _len; i = ++_i) {
e = _ref3[i];
if (e._isInstanceProp) {
key = e.variable.properties[e.variable.properties.length - 1].name.toString();
value = e.value;
this.body.expressions[i] = this.hookBodyExpression('instance', name, key, value);
} else if (e._isClassProp) {
key = e.variable.properties[e.variable.properties.length - 1].name.toString();
value = e.value;
this.body.expressions[i] = this.hookBodyExpression('class', name, key, value);
}
}
this.addBoundFunctions(o);
call = Closure.wrap(this.body);
if (this.parent) {
call.args.push(this.parent);
params = call.variable.params || call.variable.base.params;
params.push(new Param(this.superClass));
}
klass = new Parens(call, true);
if (this.variable) {
klass = new Assign(this.variable, klass);
}
return klass.compile(o);
}

Code.prototype.compileNode = function(o) { Code.prototype.compileNode = function(o) {
var code, exprs, i, idt, lit, name, p, param, params, ref, splats, uniqs, val, wasEmpty, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _len5, _m, _n, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8; var code, exprs, i, idt, lit, name, p, param, params, ref, splats, uniqs, val, wasEmpty, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _len5, _m, _n, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8;
o.scope = new Scope(o.scope, this.body, this); o.scope = new Scope(o.scope, this.body, this);
Expand Down Expand Up @@ -189,7 +288,7 @@ Extends.prototype.compile = function(o) {
return new nodes.Assign(this.child, new nodes.Call(new nodes.Value(new nodes.Literal(utility('extends'))), [this.child, this.parent])).compile(o); return new nodes.Assign(this.child, new nodes.Call(new nodes.Value(new nodes.Literal(utility('extends'))), [this.child, this.parent])).compile(o);
}; };


nodes.Class.prototype.compileNode = function(o) { Class.prototype.compileNode = function(o) {
var call, decl, e, i, key, klass, lname, name, params, value, _i, _len, _ref2, _ref3; var call, decl, e, i, key, klass, lname, name, params, value, _i, _len, _ref2, _ref3;
decl = this.determineName(); decl = this.determineName();
name = decl || '_Class'; name = decl || '_Class';
Expand Down Expand Up @@ -238,6 +337,34 @@ nodes.Class.prototype.compileNode = function(o) {
return klass.compile(o); return klass.compile(o);
}; };


Class.prototype.hookBodyExpression = function(type, name, key, value) {
var clazz, keyL, newExpression, util;
if (type === 'instance') {
util = new Literal(utility('defineProperty'));
} else if (type === 'class') {
util = new Literal(utility('defineStaticProperty'));
} else {
throw new Error('hookBodyExpression() requires type of class or instance');
}
clazz = new Literal(name);
keyL = new Literal(key);
if (value instanceof Code) {
value.klass = name;
if (!(value.name != null)) {
value.name = key;
}
if (value.bound) {
value.context = name;
}
}
newExpression = new Call(new Value(util), [clazz, keyL, value]);
newExpression.klass = name;
if (newExpression.bound) {
newExpression.context = name;
}
return newExpression;
};

utility = function(name) { utility = function(name) {
var ref; var ref;
ref = "__" + name; ref = "__" + name;
Expand Down
2 changes: 1 addition & 1 deletion grunt.coffee
Expand Up @@ -4,7 +4,7 @@
module.exports = (grunt) -> module.exports = (grunt) ->
require('./packages/tower-tasks/tasks')(grunt) require('./packages/tower-tasks/tasks')(grunt)


require('./coffee') require('./coffee-inheritance')


_ = grunt.utils._ _ = grunt.utils._
file = grunt.file file = grunt.file
Expand Down
3 changes: 1 addition & 2 deletions index.js
@@ -1,7 +1,6 @@
var path = require('path'); var path = require('path');


console.log('here') require('./coffee-inheritance');
require('./coffee');


// require tower // require tower
var root = path.join(__dirname, 'lib/tower.js'); var root = path.join(__dirname, 'lib/tower.js');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -81,7 +81,7 @@
"knox": "0.0.11", "knox": "0.0.11",
"gm": "~1.4.1", "gm": "~1.4.1",
"nodemailer": "~0.3.21", "nodemailer": "~0.3.21",
"coffee-script": ">= 1.3.2" "coffee-script": ">= 1.3.3"
}, },
"devDependencies": { "devDependencies": {
"cli-table": ">= 0.0.1", "cli-table": ">= 0.0.1",
Expand Down
Expand Up @@ -40,7 +40,9 @@
"mongodb": ">= 0.9.9-7", "mongodb": ">= 0.9.9-7",
"mint": ">= 0.3.0", "mint": ">= 0.3.0",
"npm": ">= 1.1.32", "npm": ">= 1.1.32",
"tower": ">= 0.4.1" "tower": ">= 0.4.1",
"coffee-script": ">= 1.3.3",
"coffeecup": ">= 0.3.0"
}, },
"devDependencies": { "devDependencies": {
"stylus": ">= 0.17.0", "stylus": ">= 0.17.0",
Expand All @@ -63,8 +65,7 @@
"scripts": { "scripts": {
"test": "./node_modules/mocha/bin/mocha $(find test -name \"*Test.coffee\")", "test": "./node_modules/mocha/bin/mocha $(find test -name \"*Test.coffee\")",
"prepublish": "npm prune; rm -rf node_modules/*/{test,example,bench}*", "prepublish": "npm prune; rm -rf node_modules/*/{test,example,bench}*",
"start": "node server.js -e production", "start": "node server.js -e production"
"postinstall": "npm install git://github.com/viatropos/coffeecup.git --force && npm install git://github.com/viatropos/coffee-script.git --force"
}, },
"tower": { "tower": {
"stylesheets": "<%= app.stylesheetEngine %>", "stylesheets": "<%= app.stylesheetEngine %>",
Expand Down

0 comments on commit 5bc58cf

Please sign in to comment.