@@ -837,7 +837,7 @@ namespace ts {
837
837
startLexicalEnvironment ( ) ;
838
838
839
839
let statementOffset = - 1 ;
840
- let thisCaptureStatus = SuperCaptureResult . NoReplacement ;
840
+ let superCaptureStatus = SuperCaptureResult . NoReplacement ;
841
841
if ( hasSynthesizedSuper ) {
842
842
// If a super call has already been synthesized,
843
843
// we're going to assume that we should just transform everything after that.
@@ -854,13 +854,17 @@ namespace ts {
854
854
addRestParameterIfNeeded ( statements , constructor , hasSynthesizedSuper ) ;
855
855
Debug . assert ( statementOffset >= 0 , "statementOffset not initialized correctly!" ) ;
856
856
857
- thisCaptureStatus = declareOrCaptureOrReturnThisForConstructorIfNeeded ( statements , constructor , ! ! extendsClauseElement , statementOffset ) ;
858
- if ( thisCaptureStatus === SuperCaptureResult . ReplaceSuperCapture || thisCaptureStatus === SuperCaptureResult . ReplaceWithReturn ) {
859
- statementOffset ++ ;
860
- }
857
+ superCaptureStatus = declareOrCaptureOrReturnThisForConstructorIfNeeded ( statements , constructor , ! ! extendsClauseElement , statementOffset ) ;
861
858
}
862
859
863
- addDefaultSuperCallIfNeeded ( statements , constructor , extendsClauseElement , hasSynthesizedSuper ) ;
860
+ if ( superCaptureStatus === SuperCaptureResult . NoReplacement ) {
861
+ superCaptureStatus = addDefaultSuperCallIfNeeded ( statements , constructor , extendsClauseElement , hasSynthesizedSuper ) ;
862
+ }
863
+
864
+ // The last statement expression was replaced. Skip it.
865
+ if ( superCaptureStatus === SuperCaptureResult . ReplaceSuperCapture || superCaptureStatus === SuperCaptureResult . ReplaceWithReturn ) {
866
+ statementOffset ++ ;
867
+ }
864
868
865
869
if ( constructor ) {
866
870
const body = saveStateAndInvoke ( constructor , makeTransformerForConstructorBodyAtOffset ( statementOffset ) ) ;
@@ -870,7 +874,7 @@ namespace ts {
870
874
// Return `_this` unless we're sure enough that it would be pointless to add a return statement.
871
875
// If there's a constructor that we can tell returns in enough places, then we *do not* want to add a return.
872
876
if ( extendsClauseElement
873
- && thisCaptureStatus !== SuperCaptureResult . ReplaceWithReturn
877
+ && superCaptureStatus !== SuperCaptureResult . ReplaceWithReturn
874
878
&& ! ( constructor && isSufficientlyCoveredByReturnStatements ( constructor . body ) ) ) {
875
879
statements . push (
876
880
createReturn (
@@ -955,6 +959,16 @@ namespace ts {
955
959
) ;
956
960
const superReturnValueOrThis = createLogicalOr ( superCall , actualThis ) ;
957
961
962
+ if ( ! constructor ) {
963
+ // We must be here because the user didn't write a constructor
964
+ // but we needed to call 'super()' anyway - but if that's the case,
965
+ // we can just immediately return the result of a 'super()' call.
966
+ statements . push ( createReturn ( superReturnValueOrThis ) ) ;
967
+ return SuperCaptureResult . ReplaceWithReturn ;
968
+ }
969
+
970
+ // The constructor was generated for some reason.
971
+ // Create a captured '_this' variable.
958
972
statements . push (
959
973
createVariableStatement (
960
974
/*modifiers*/ undefined ,
@@ -969,7 +983,11 @@ namespace ts {
969
983
) ;
970
984
971
985
enableSubstitutionsForCapturedThis ( ) ;
986
+
987
+ return SuperCaptureResult . ReplaceSuperCapture ;
972
988
}
989
+
990
+ return SuperCaptureResult . NoReplacement ;
973
991
}
974
992
975
993
/**
0 commit comments