@@ -1718,6 +1718,9 @@ export function transformClassFields(context: TransformationContext): (x: Source
17181718 }
17191719 else if ( isPrivateIdentifierClassElementDeclaration ( member ) ) {
17201720 containsInstancePrivateElements = true ;
1721+ if ( resolver . getNodeCheckFlags ( member ) & NodeCheckFlags . ContainsConstructorReference ) {
1722+ facts |= ClassFacts . NeedsClassConstructorReference ;
1723+ }
17211724 }
17221725 else if ( isPropertyDeclaration ( member ) ) {
17231726 containsPublicInstanceFields = true ;
@@ -1849,6 +1852,7 @@ export function transformClassFields(context: TransformationContext): (x: Source
18491852 }
18501853 }
18511854
1855+ const isClassWithConstructorReference = resolver . getNodeCheckFlags ( node ) & NodeCheckFlags . ContainsConstructorReference ;
18521856 const isExport = hasSyntacticModifier ( node , ModifierFlags . Export ) ;
18531857 const isDefault = hasSyntacticModifier ( node , ModifierFlags . Default ) ;
18541858 let modifiers = visitNodes ( node . modifiers , modifierVisitor , isModifier ) ;
@@ -1887,6 +1891,12 @@ export function transformClassFields(context: TransformationContext): (x: Source
18871891 ) ) ;
18881892 }
18891893
1894+ const alias = getClassLexicalEnvironment ( ) . classConstructor ;
1895+ if ( isClassWithConstructorReference && alias ) {
1896+ enableSubstitutionForClassAliases ( ) ;
1897+ classAliases [ getOriginalNodeId ( node ) ] = alias ;
1898+ }
1899+
18901900 const classDecl = factory . updateClassDeclaration (
18911901 node ,
18921902 modifiers ,
@@ -1918,7 +1928,8 @@ export function transformClassFields(context: TransformationContext): (x: Source
19181928 // these statements after the class expression variable statement.
19191929 const isDecoratedClassDeclaration = ! ! ( facts & ClassFacts . ClassWasDecorated ) ;
19201930 const staticPropertiesOrClassStaticBlocks = getStaticPropertiesAndClassStaticBlock ( node ) ;
1921- const isClassWithConstructorReference = resolver . getNodeCheckFlags ( node ) & NodeCheckFlags . ClassWithConstructorReference ;
1931+ const classCheckFlags = resolver . getNodeCheckFlags ( node ) ;
1932+ const isClassWithConstructorReference = classCheckFlags & NodeCheckFlags . ContainsConstructorReference ;
19221933
19231934 let temp : Identifier | undefined ;
19241935 function createClassTempVar ( ) {
@@ -1935,7 +1946,6 @@ export function transformClassFields(context: TransformationContext): (x: Source
19351946 return getClassLexicalEnvironment ( ) . classConstructor = node . emitNode . classThis ;
19361947 }
19371948
1938- const classCheckFlags = resolver . getNodeCheckFlags ( node ) ;
19391949 const requiresBlockScopedVar = classCheckFlags & NodeCheckFlags . BlockScopedBindingInLoop ;
19401950 const temp = factory . createTempVariable ( requiresBlockScopedVar ? addBlockScopedVariable : hoistVariableDeclaration , /*reservedInNestedScopes*/ true ) ;
19411951 getClassLexicalEnvironment ( ) . classConstructor = factory . cloneNode ( temp ) ;
@@ -3236,7 +3246,7 @@ export function transformClassFields(context: TransformationContext): (x: Source
32363246
32373247 function trySubstituteClassAlias ( node : Identifier ) : Expression | undefined {
32383248 if ( enabledSubstitutions & ClassPropertySubstitutionFlags . ClassAliases ) {
3239- if ( resolver . getNodeCheckFlags ( node ) & NodeCheckFlags . ConstructorReferenceInClass ) {
3249+ if ( resolver . getNodeCheckFlags ( node ) & NodeCheckFlags . ConstructorReference ) {
32403250 // Due to the emit for class decorators, any reference to the class from inside of the class body
32413251 // must instead be rewritten to point to a temporary variable to avoid issues with the double-bind
32423252 // behavior of class names in ES6.
0 commit comments