Move subclass inheritance to end (#7772)

We were using `Object.create` to setup the prototype chain at the start of the class definition, which lead to #7771.

I was a bit worried about a speed hit, but it seems everyone optimizes the two patterns the same way.
https://jsbench.github.io/#f9fca52407643d96458a35763b201215

Fixes #7771.
This commit is contained in:
Justin Ridgewell
2018-04-21 17:31:44 -04:00
committed by GitHub
parent 8f24f91166
commit f8ab9466d3
96 changed files with 331 additions and 284 deletions

View File

@@ -179,6 +179,7 @@ export default function transformClass(
}
pushDescriptors();
pushInheritsToBody();
}
function pushBody() {
@@ -236,8 +237,6 @@ export default function transformClass(
}
function pushDescriptors() {
pushInheritsToBody();
const { body } = classState;
let instanceProps;
@@ -538,8 +537,6 @@ export default function transformClass(
}
classState.body.push(classState.construct);
pushInheritsToBody();
}
/**
@@ -550,9 +547,9 @@ export default function transformClass(
setState({ pushedInherits: true });
// Unshift to ensure that the constructor inheritance is set up before
// Push to ensure that the constructor inheritance is set up after
// any properties can be assigned to the prototype.
classState.body.unshift(
classState.body.push(
t.expressionStatement(
t.callExpression(
classState.file.addHelper(