Parametert properties should be added after any prologue

This commit is contained in:
John Lusty
2022-04-20 08:31:00 +01:00
parent d45098e23b
commit 891cb6f317
+14 -9
View File
@@ -1359,16 +1359,21 @@ namespace ts {
if (parameterPropertyDeclarationCount > 0) {
const parameterProperties = visitNodes(constructor.body.statements, visitor, isStatement, indexOfFirstStatementAfterSuperAndPrologue, parameterPropertyDeclarationCount);
let superAndPrologueStatementCount = prologueStatementCount;
// If a synthetic super() call was added, add them just after it
if (needsSyntheticConstructor) {
superAndPrologueStatementCount += 1;
// If there was a super() call found, add parameter properties immediately after it
if (superStatementIndex >= 0) {
addRange(statements, parameterProperties);
}
else {
// Add add parameter properties to the top of the constructor after the prologue
let superAndPrologueStatementCount = prologueStatementCount;
// If a synthetic super() call was added, need to account for that
if (needsSyntheticConstructor) superAndPrologueStatementCount++;
statements = [
...statements.slice(0, superAndPrologueStatementCount),
...parameterProperties,
...statements.slice(superAndPrologueStatementCount),
];
}
statements = [
...statements.slice(0, superAndPrologueStatementCount),
...parameterProperties,
...statements.slice(superAndPrologueStatementCount),
];
indexOfFirstStatementAfterSuperAndPrologue += parameterPropertyDeclarationCount;
}