better t.toIdentifier behaviour that doesn't camelcase on underscores - fixes #610

This commit is contained in:
Sebastian McKenzie
2015-01-28 20:01:55 +11:00
parent 4b66dcb738
commit 69f2a0d3f1

View File

@@ -226,7 +226,7 @@ t.prependToMemberExpression = function (member, append) {
};
/**
* Description
* Check if the input `node` is going to be evaluated, ie. is a refernece.
*
* @param {Object} node
* @param {Object} parent
@@ -331,13 +331,10 @@ t.toIdentifier = function (name) {
name = name.replace(/^[-0-9]+/, "");
// camel case
name = name.replace(/[-_\s]+(.)?/g, function (match, c) {
name = name.replace(/[-\s]+(.)?/g, function (match, c) {
return c ? c.toUpperCase() : "";
});
// remove underscores from start of name
name = name.replace(/^\_/, "");
if (!t.isValidIdentifier(name)) {
name = "_" + name;
}