Merge branch 'master' into code-generator
Conflicts: lib/6to5/transformers/classes.js test/fixtures/transformation/source-maps/class/expected.js test/fixtures/transformation/source-maps/class/source-mappings.json
This commit is contained in:
4
lib/6to5/templates/class-props.js
Normal file
4
lib/6to5/templates/class-props.js
Normal file
@@ -0,0 +1,4 @@
|
||||
(function (child, staticProps, instanceProps) {
|
||||
if (staticProps) Object.defineProperties(child, staticProps);
|
||||
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
|
||||
})
|
||||
@@ -107,16 +107,28 @@ var buildClassBody = function (file, construct, body, className, superName, node
|
||||
}, true));
|
||||
}
|
||||
|
||||
var instanceProps;
|
||||
var staticProps;
|
||||
|
||||
if (!_.isEmpty(instanceMutatorMap)) {
|
||||
var protoId = util.template("prototype-identifier", {
|
||||
CLASS_NAME: className
|
||||
});
|
||||
|
||||
body.push(util.buildDefineProperties(instanceMutatorMap, protoId));
|
||||
instanceProps = util.buildDefineProperties(instanceMutatorMap, protoId);
|
||||
}
|
||||
|
||||
if (!_.isEmpty(staticMutatorMap)) {
|
||||
body.push(util.buildDefineProperties(staticMutatorMap, className));
|
||||
staticProps = util.buildDefineProperties(staticMutatorMap, className);
|
||||
}
|
||||
|
||||
if (instanceProps || staticProps) {
|
||||
instanceProps = instanceProps || b.literal(null);
|
||||
staticProps = staticProps || b.literal(null);
|
||||
|
||||
body.push(b.expressionStatement(
|
||||
b.callExpression(file.addDeclaration("class-props"), [className, staticProps, instanceProps])
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -24,6 +24,9 @@ exports.ObjectExpression = function (node, parent, file) {
|
||||
return util.template("object-define-properties-closure", {
|
||||
KEY: objId,
|
||||
OBJECT: node,
|
||||
CONTENT: util.buildDefineProperties(mutatorMap, objId).expression
|
||||
CONTENT: util.template("object-define-properties", {
|
||||
OBJECT: objId,
|
||||
PROPS: util.buildDefineProperties(mutatorMap)
|
||||
})
|
||||
});
|
||||
};
|
||||
|
||||
@@ -100,7 +100,7 @@ exports.pushMutatorMap = function (mutatorMap, key, kind, method) {
|
||||
}
|
||||
};
|
||||
|
||||
exports.buildDefineProperties = function (mutatorMap, keyNode) {
|
||||
exports.buildDefineProperties = function (mutatorMap) {
|
||||
var objExpr = b.objectExpression([]);
|
||||
|
||||
_.each(mutatorMap, function (map, key) {
|
||||
@@ -117,10 +117,7 @@ exports.buildDefineProperties = function (mutatorMap, keyNode) {
|
||||
objExpr.properties.push(propNode);
|
||||
});
|
||||
|
||||
return exports.template("object-define-properties", {
|
||||
OBJECT: keyNode,
|
||||
PROPS: objExpr
|
||||
}, true);
|
||||
return objExpr;
|
||||
};
|
||||
|
||||
exports.template = function (name, nodes, keepExpression) {
|
||||
|
||||
Reference in New Issue
Block a user