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,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "6to5",
|
||||
"description": "Turn ES6 code into vanilla ES5 with source maps and no runtime",
|
||||
"version": "1.7.2",
|
||||
"version": "1.7.3",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://github.com/sebmck/6to5",
|
||||
"repository": {
|
||||
|
||||
13
test/fixtures/classes/static/actual.js
vendored
Normal file
13
test/fixtures/classes/static/actual.js
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
class A {
|
||||
static a() {
|
||||
|
||||
}
|
||||
|
||||
static get b(){
|
||||
|
||||
}
|
||||
|
||||
static set b(b){
|
||||
|
||||
}
|
||||
}
|
||||
14
test/fixtures/classes/static/expected.js
vendored
Normal file
14
test/fixtures/classes/static/expected.js
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
var A = function() {
|
||||
function A() {}
|
||||
|
||||
A.a = function() {};
|
||||
|
||||
Object.defineProperties(A, {
|
||||
b: {
|
||||
get: function() {},
|
||||
set: function(b) {}
|
||||
}
|
||||
});
|
||||
|
||||
return A;
|
||||
}();
|
||||
Reference in New Issue
Block a user