fix export of parameters when renaming the binding of exported functions - fixes #2753

This commit is contained in:
Sebastian McKenzie 2015-11-02 19:24:23 +00:00
parent 2bdc222c0b
commit d1d0ed901e
5 changed files with 41 additions and 2 deletions

View File

@ -0,0 +1,9 @@
export function foo(bar) {
}
var bar = {
foo: function () {
foo;
}
};

View File

@ -0,0 +1,8 @@
export { _foo as foo };
function _foo(bar) {}
var bar = {
foo: function foo() {
_foo;
}
};

View File

@ -123,3 +123,7 @@ export function _getPattern(parts, context) {
export function getBindingIdentifiers(duplicates?) {
return t.getBindingIdentifiers(this.node, duplicates);
}
export function getOuterBindingIdentifiers(duplicates?) {
return t.getOuterBindingIdentifiers(this.node, duplicates);
}

View File

@ -42,7 +42,7 @@ export default class Renamer {
// build specifiers that point back to this export declaration
let isDefault = exportDeclar.isExportDefaultDeclaration();
let bindingIdentifiers = parentDeclar.getBindingIdentifiers();
let bindingIdentifiers = parentDeclar.getOuterBindingIdentifiers();
let specifiers = [];
for (let name in bindingIdentifiers) {
@ -80,7 +80,7 @@ export default class Renamer {
maybeConvertFromClassFunctionExpression(path) {
return; // TODO
// retain the `name` of a class/function expression
if (!path.isFunctionExpression() && !path.isClassExpression()) return;

View File

@ -91,3 +91,21 @@ getBindingIdentifiers.keys = {
VariableDeclaration: ["declarations"],
VariableDeclarator: ["id"]
};
export function getOuterBindingIdentifiers(
node: Object,
duplicates?: boolean,
): Object {
if (t.isFunction(node)) {
let id = node.id;
if (id) {
return {
[id.name]: duplicates ? [id] : id
};
} else {
return {};
}
} else {
return getBindingIdentifiers(node, duplicates);
}
}