support for CallExpression in Scope.prototype.generateUidBasedOnNode

This commit is contained in:
Sebastian McKenzie
2015-01-04 07:59:43 +11:00
parent 0c0f40d14a
commit 7f4efecb7d
5 changed files with 31 additions and 44 deletions

View File

@@ -63,38 +63,29 @@ Scope.prototype.generateUidBasedOnNode = function (parent, file) {
node = parent.left;
} else if (t.isVariableDeclarator(parent)) {
node = parent.id;
}
var id = "ref";
if (t.isProperty(node)) {
} else if (t.isProperty(node)) {
node = node.key;
}
if (t.isIdentifier(node)) {
id = node.name;
} else if (t.isLiteral(node)) {
id = node.value;
} else if (t.isMemberExpression(node)) {
var parts = [];
var parts = [];
var add = function (node) {
if (t.isMemberExpression(node)) {
add(node.object);
add(node.property);
} else if (t.isIdentifier(node)) {
parts.push(node.name);
} else if (t.isLiteral(node)) {
parts.push(node.value);
}
};
var add = function (node) {
if (t.isMemberExpression(node)) {
add(node.object);
add(node.property);
} else if (t.isIdentifier(node)) {
parts.push(node.name);
} else if (t.isLiteral(node)) {
parts.push(node.value);
} else if (t.isCallExpression(node)) {
add(node.callee);
}
};
add(node);
add(node);
id = parts.join("$");
}
id = id.replace(/^_/, "");
var id = parts.join("$");
id = id.replace(/^_/, "") || "ref";
return file.generateUidIdentifier(id, this);
};
@@ -108,10 +99,6 @@ Scope.prototype.generateUidBasedOnNode = function (parent, file) {
*/
Scope.prototype.generateTempBasedOnNode = function (node, file) {
if (!t.isIdentifier(node) && !t.isMemberExpression(node)) {
throw new TypeError("Invalid node type " + JSON.stringify(node.type) + " passed to Scope.prototype.generateTempBasedOnNode");
}
if (t.isIdentifier(node) && this.has(node.name, true)) {
return null;
}