fix export of parameters when renaming the binding of exported functions - fixes #2753
This commit is contained in:
parent
2bdc222c0b
commit
d1d0ed901e
9
packages/babel-core/test/fixtures/transformation/spec.function-name/modules-4/actual.js
vendored
Normal file
9
packages/babel-core/test/fixtures/transformation/spec.function-name/modules-4/actual.js
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
export function foo(bar) {
|
||||
|
||||
}
|
||||
|
||||
var bar = {
|
||||
foo: function () {
|
||||
foo;
|
||||
}
|
||||
};
|
||||
8
packages/babel-core/test/fixtures/transformation/spec.function-name/modules-4/expected.js
vendored
Normal file
8
packages/babel-core/test/fixtures/transformation/spec.function-name/modules-4/expected.js
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
export { _foo as foo };
|
||||
function _foo(bar) {}
|
||||
|
||||
var bar = {
|
||||
foo: function foo() {
|
||||
_foo;
|
||||
}
|
||||
};
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user