Don't split an exported class when renaming an inner binding (#8051)

This commit is contained in:
Nicolò Ribaudo 2018-06-12 19:45:21 +02:00 committed by Henry Zhu
parent 106907e605
commit 3c46e75b8f
4 changed files with 23 additions and 1 deletions

View File

@ -0,0 +1,5 @@
export class Foo extends Bar {
static foo = {};
test = args;
}

View File

@ -0,0 +1,3 @@
{
"plugins": ["external-helpers", "proposal-class-properties"]
}

View File

@ -0,0 +1,9 @@
export class Foo extends Bar {
constructor(..._args) {
var _temp;
return _temp = super(..._args), babelHelpers.defineProperty(this, "test", args), _temp;
}
}
babelHelpers.defineProperty(Foo, "foo", {});

View File

@ -108,7 +108,12 @@ export default class Renamer {
path.isClassExpression(),
);
if (parentDeclar) {
this.maybeConvertFromExportDeclaration(parentDeclar);
const bindingIds = parentDeclar.getBindingIdentifiers();
if (bindingIds[oldName] === binding.identifier) {
// When we are renaming an exported identifier, we need to ensure that
// the exported binding keeps the old name.
this.maybeConvertFromExportDeclaration(parentDeclar);
}
}
scope.traverse(block || scope.block, renameVisitor, this);