Skip to content

Commit 891cb6f

Browse files
committed
Parametert properties should be added after any prologue
1 parent d45098e commit 891cb6f

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/compiler/transformers/classFields.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,16 +1359,21 @@ namespace ts {
13591359
if (parameterPropertyDeclarationCount > 0) {
13601360
const parameterProperties = visitNodes(constructor.body.statements, visitor, isStatement, indexOfFirstStatementAfterSuperAndPrologue, parameterPropertyDeclarationCount);
13611361

1362-
let superAndPrologueStatementCount = prologueStatementCount;
1363-
// If a synthetic super() call was added, add them just after it
1364-
if (needsSyntheticConstructor) {
1365-
superAndPrologueStatementCount += 1;
1362+
// If there was a super() call found, add parameter properties immediately after it
1363+
if (superStatementIndex >= 0) {
1364+
addRange(statements, parameterProperties);
1365+
}
1366+
else {
1367+
// Add add parameter properties to the top of the constructor after the prologue
1368+
let superAndPrologueStatementCount = prologueStatementCount;
1369+
// If a synthetic super() call was added, need to account for that
1370+
if (needsSyntheticConstructor) superAndPrologueStatementCount++;
1371+
statements = [
1372+
...statements.slice(0, superAndPrologueStatementCount),
1373+
...parameterProperties,
1374+
...statements.slice(superAndPrologueStatementCount),
1375+
];
13661376
}
1367-
statements = [
1368-
...statements.slice(0, superAndPrologueStatementCount),
1369-
...parameterProperties,
1370-
...statements.slice(superAndPrologueStatementCount),
1371-
];
13721377

13731378
indexOfFirstStatementAfterSuperAndPrologue += parameterPropertyDeclarationCount;
13741379
}

0 commit comments

Comments
 (0)