add util.isReferenced to check if a node is directly referenced
This commit is contained in:
@@ -150,6 +150,24 @@ exports.template = function (name, nodes, keepExpression) {
|
||||
}
|
||||
};
|
||||
|
||||
exports.isReferenced = function (node, parent) {
|
||||
// we're a property key
|
||||
if (parent.type === "Property" && parent.key === node) return false;
|
||||
|
||||
var isMemberExpression = parent.type === "MemberExpression";
|
||||
|
||||
// we're in a member expression and we're the computed property so we're referenced
|
||||
var isComputedProperty = isMemberExpression && parent.property === node && parent.computed;
|
||||
|
||||
// we're in a member expression and we're the object so we're referenced
|
||||
var isObject = isMemberExpression && parent.object === node;
|
||||
|
||||
// we are referenced
|
||||
if (!isMemberExpression || isComputedProperty || isObject) return true;
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
exports.codeFrame = function (lines, lineNumber, colNumber) {
|
||||
colNumber = Math.max(colNumber, 0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user