add assignment pattern shorthand support to explode transformer - fixes #1566

This commit is contained in:
Sebastian McKenzie
2015-05-18 22:44:40 +01:00
parent b4cd2df745
commit 12104f822f
3 changed files with 28 additions and 3 deletions

View File

@@ -5,9 +5,9 @@ export var metadata = {
group: "builtin-setup"
};
function buildClone(bindingKey, refKey) {
function buildClone(bindingKey, refKey, check?) {
return function (node) {
if (node[bindingKey] === node[refKey]) {
if (node[bindingKey] === node[refKey] || (check && check(node))) {
node[refKey] = t.removeComments(clone(node[refKey]));
}
};
@@ -25,6 +25,9 @@ function buildListClone(listKey, bindingKey, refKey) {
};
}
export var Property = buildClone("value", "key");
export var Property = buildClone("value", "key", function (node) {
return t.isAssignmentPattern(node.value) && node.value.left === node.key;
});
export var ExportDeclaration = buildListClone("specifiers", "local", "exported");
export var ImportDeclaration = buildListClone("specifiers", "local", "imported");