From 891cb6f317a5e383baffc1fd7cd40b16d4e159e4 Mon Sep 17 00:00:00 2001 From: John Lusty <54030459+jlusty@users.noreply.github.com> Date: Wed, 20 Apr 2022 08:31:00 +0100 Subject: [PATCH] Parametert properties should be added after any prologue --- src/compiler/transformers/classFields.ts | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/compiler/transformers/classFields.ts b/src/compiler/transformers/classFields.ts index 77e2d76bfdb..cff2be7fb78 100644 --- a/src/compiler/transformers/classFields.ts +++ b/src/compiler/transformers/classFields.ts @@ -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; }