fix comments not being retained from MethodDefinition in classes
This commit is contained in:
parent
d09bafaf8c
commit
00483917f0
@ -1,3 +1,7 @@
|
|||||||
|
# 1.12.16
|
||||||
|
|
||||||
|
* Fix missing comments not being retained from `MethodDefinition` in classes.
|
||||||
|
|
||||||
# 1.12.15
|
# 1.12.15
|
||||||
|
|
||||||
* Update `acorn-6to5`.
|
* Update `acorn-6to5`.
|
||||||
|
|||||||
@ -254,6 +254,7 @@ Class.prototype.pushConstructor = function (method) {
|
|||||||
|
|
||||||
this.hasConstructor = true;
|
this.hasConstructor = true;
|
||||||
t.inherits(construct, fn);
|
t.inherits(construct, fn);
|
||||||
|
t.inheritsComments(construct, method);
|
||||||
|
|
||||||
construct.defaults = fn.defaults;
|
construct.defaults = fn.defaults;
|
||||||
construct.params = fn.params;
|
construct.params = fn.params;
|
||||||
|
|||||||
@ -70,6 +70,9 @@ t.isReferenced = function (node, parent) {
|
|||||||
// we're a property key so we aren't referenced
|
// we're a property key so we aren't referenced
|
||||||
if (t.isProperty(parent) && parent.key === node) return false;
|
if (t.isProperty(parent) && parent.key === node) return false;
|
||||||
|
|
||||||
|
// we're a variable declarator id so we aren't referenced
|
||||||
|
if (t.isVariableDeclarator(parent) && parent.id === node) return false;
|
||||||
|
|
||||||
var isMemberExpression = t.isMemberExpression(parent);
|
var isMemberExpression = t.isMemberExpression(parent);
|
||||||
|
|
||||||
// we're in a member expression and we're the computed property so we're referenced
|
// we're in a member expression and we're the computed property so we're referenced
|
||||||
@ -161,7 +164,7 @@ t.toBlock = function (node, parent) {
|
|||||||
t.getIds = function (node, map, ignoreTypes) {
|
t.getIds = function (node, map, ignoreTypes) {
|
||||||
ignoreTypes = ignoreTypes || [];
|
ignoreTypes = ignoreTypes || [];
|
||||||
|
|
||||||
var search = [node];
|
var search = [].concat(node);
|
||||||
var ids = {};
|
var ids = {};
|
||||||
|
|
||||||
while (search.length) {
|
while (search.length) {
|
||||||
@ -185,14 +188,6 @@ t.getIds = function (node, map, ignoreTypes) {
|
|||||||
return ids;
|
return ids;
|
||||||
};
|
};
|
||||||
|
|
||||||
t.isLet = function (node) {
|
|
||||||
return t.isVariableDeclaration(node) && (node.kind !== "var" || node._let);
|
|
||||||
};
|
|
||||||
|
|
||||||
t.isVar = function (node) {
|
|
||||||
return t.isVariableDeclaration(node, { kind: "var" }) && !node._let;
|
|
||||||
};
|
|
||||||
|
|
||||||
t.getIds.nodes = {
|
t.getIds.nodes = {
|
||||||
AssignmentExpression: "left",
|
AssignmentExpression: "left",
|
||||||
ImportSpecifier: "id",
|
ImportSpecifier: "id",
|
||||||
@ -214,13 +209,32 @@ t.getIds.arrays = {
|
|||||||
ObjectPattern: "properties"
|
ObjectPattern: "properties"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
t.isLet = function (node) {
|
||||||
|
return t.isVariableDeclaration(node) && (node.kind !== "var" || node._let);
|
||||||
|
};
|
||||||
|
|
||||||
|
t.isVar = function (node) {
|
||||||
|
return t.isVariableDeclaration(node, { kind: "var" }) && !node._let;
|
||||||
|
};
|
||||||
|
|
||||||
|
t.removeComments = function (child) {
|
||||||
|
delete child.leadingComments;
|
||||||
|
delete child.trailingComments;
|
||||||
|
return child;
|
||||||
|
};
|
||||||
|
|
||||||
|
t.inheritsComments = function (child, parent) {
|
||||||
|
child.leadingComments = _.compact([].concat(child.leadingComments, parent.leadingComments));
|
||||||
|
child.trailingComments = _.compact([].concat(child.trailingComments, parent.trailingComments));
|
||||||
|
return child;
|
||||||
|
};
|
||||||
|
|
||||||
t.inherits = function (child, parent) {
|
t.inherits = function (child, parent) {
|
||||||
child.loc = parent.loc;
|
child.loc = parent.loc;
|
||||||
child.end = parent.end;
|
child.end = parent.end;
|
||||||
child.range = parent.range;
|
child.range = parent.range;
|
||||||
child.start = parent.start;
|
child.start = parent.start;
|
||||||
child.leadingComments = parent.leadingComments;
|
t.inheritsComments(child, parent);
|
||||||
child.trailingComments = parent.trailingComments;
|
|
||||||
return child;
|
return child;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -106,8 +106,13 @@ exports.buildDefineProperties = function (mutatorMap) {
|
|||||||
if (key[0] === "_") return;
|
if (key[0] === "_") return;
|
||||||
|
|
||||||
node = _.clone(node);
|
node = _.clone(node);
|
||||||
|
var inheritNode = node;
|
||||||
if (t.isMethodDefinition(node)) node = node.value;
|
if (t.isMethodDefinition(node)) node = node.value;
|
||||||
mapNode.properties.push(t.property("init", t.identifier(key), node));
|
|
||||||
|
var prop = t.property("init", t.identifier(key), node);
|
||||||
|
t.inheritsComments(prop, inheritNode);
|
||||||
|
t.removeComments(inheritNode);
|
||||||
|
mapNode.properties.push(prop);
|
||||||
});
|
});
|
||||||
|
|
||||||
objExpr.properties.push(propNode);
|
objExpr.properties.push(propNode);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user