From 5b3a93db2fca4f8197dee1b979a3e22b282da697 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 19 Sep 2016 18:29:15 +0300 Subject: [PATCH] Always mark derived constructors as 'this'-capturing. --- src/compiler/checker.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 20fb56870da..29270628fb0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9322,11 +9322,6 @@ namespace ts { } } - // Even if 'super' isn't ever actually called, we may need to capture 'this' for a derived class. - if (languageVersion < ScriptTarget.ES6 && container && container.kind === SyntaxKind.Constructor) { - needToCaptureLexicalThis = needToCaptureLexicalThis || !!getClassExtendsHeritageClauseElement(getContainingClass(container)); - } - const canUseSuperExpression = isLegalUsageOfSuperExpression(container); let nodeCheckFlag: NodeCheckFlags = 0; @@ -14312,6 +14307,7 @@ namespace ts { // constructors of derived classes must contain at least one super call somewhere in their function body. const containingClassDecl = node.parent; if (getClassExtendsHeritageClauseElement(containingClassDecl)) { + captureLexicalThis(node.parent, containingClassDecl); const classExtendsNull = classDeclarationExtendsNull(containingClassDecl); const superCall = getSuperCallInConstructor(node); if (superCall) {