support static property on ClassMethods - fixes #28

This commit is contained in:
Sebastian McKenzie
2014-10-10 13:57:08 +11:00
parent 3cb8866fcc
commit 3e34bbe722
5 changed files with 54 additions and 5 deletions

View File

@@ -0,0 +1 @@
CLASS_NAME.METHOD_NAME = FUNCTION;

View File

@@ -63,7 +63,8 @@ var buildClass = function (node, generateUid) {
};
var buildClassBody = function (body, className, superName, node) {
var mutatorMap = {};
var instanceMutatorMap = {};
var staticMutatorMap = {};
var classBody = node.body.body;
_.each(classBody, function (node) {
@@ -79,20 +80,32 @@ var buildClassBody = function (body, className, superName, node) {
throw util.errorWithNode(node, "unknown kind for constructor method");
}
} else {
var add = addInstanceMethod;
var mutatorMap = instanceMutatorMap;
if (node.static) {
add = addStaticMethod;
mutatorMap = staticMutatorMap
}
if (node.kind === "") {
addInstanceMethod(body, className, methodName, method);
add(body, className, methodName, method);
} else {
util.pushMutatorMap(mutatorMap, methodName, node.kind, node);
}
}
});
if (!_.isEmpty(mutatorMap)) {
if (!_.isEmpty(instanceMutatorMap)) {
var protoId = util.template("prototype-identifier", {
CLASS_NAME: className
});
body.push(util.buildDefineProperties(mutatorMap, protoId));
body.push(util.buildDefineProperties(instanceMutatorMap, protoId));
}
if (!_.isEmpty(staticMutatorMap)) {
body.push(util.buildDefineProperties(staticMutatorMap, className));
}
};
@@ -148,6 +161,14 @@ var addConstructor = function (construct, method) {
construct.rest = method.rest;
};
var addStaticMethod = function (body, className, methodName, method) {
body.push(util.template("class-static-method", {
METHOD_NAME: methodName,
CLASS_NAME: className,
FUNCTION: method
}, true));
};
var addInstanceMethod = function (body, className, methodName, method) {
body.push(util.template("class-method", {
METHOD_NAME: methodName,