support static property on ClassMethods - fixes #28
This commit is contained in:
1
lib/6to5/templates/class-static-method.js
Normal file
1
lib/6to5/templates/class-static-method.js
Normal file
@@ -0,0 +1 @@
|
||||
CLASS_NAME.METHOD_NAME = FUNCTION;
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user