@@ -570,17 +570,17 @@ namespace ts {
570
570
// ---------------------------------------------------------------------
571
571
// TypeScript | Javascript
572
572
// ---------------------------------------------------------------------
573
- // @dec | let C_1;
574
- // class C { | let C = C_1 = class C {
575
- // static x() { return C.y; } | static x() { return C_1.y; }
576
- // static y = 1; | }
573
+ // @dec | let C_1 = class C {
574
+ // class C { | static x() { return C_1.y; }
575
+ // static x() { return C.y; } | }
576
+ // static y = 1; | let C = C_1;
577
577
// } | C.y = 1;
578
578
// | C = C_1 = __decorate([dec], C);
579
579
// ---------------------------------------------------------------------
580
- // @dec | let C_1;
581
- // export class C { | let C = C_1 = class C {
582
- // static x() { return C.y; } | static x() { return C_1.y; }
583
- // static y = 1; | }
580
+ // @dec | let C_1 = class C {
581
+ // export class C { | static x() { return C_1.y; }
582
+ // static x() { return C.y; } | }
583
+ // static y = 1; | let C = C_1;
584
584
// } | C.y = 1;
585
585
// | C = C_1 = __decorate([dec], C);
586
586
// | export { C };
@@ -612,10 +612,10 @@ namespace ts {
612
612
// ---------------------------------------------------------------------
613
613
// TypeScript | Javascript
614
614
// ---------------------------------------------------------------------
615
- // @dec | let C_1;
616
- // export default class C { | let C = C_1 = class C {
617
- // static x() { return C.y; } | static x() { return C_1.y; }
618
- // static y = 1; | }
615
+ // @dec | let C_1 = class C {
616
+ // export default class C { | static x() { return C_1.y; }
617
+ // static x() { return C.y; } | }
618
+ // static y = 1; | let C = C_1;
619
619
// } | C.y = 1;
620
620
// | C = C_1 = __decorate([dec], C);
621
621
// | export default C;
@@ -627,7 +627,7 @@ namespace ts {
627
627
// ... = class ${name} ${heritageClauses} {
628
628
// ${members}
629
629
// }
630
- let classExpression : Expression = setOriginalNode (
630
+ const classExpression : Expression = setOriginalNode (
631
631
createClassExpression (
632
632
name ,
633
633
visitNodes ( node . heritageClauses , visitor , isHeritageClause ) ,
@@ -647,35 +647,19 @@ namespace ts {
647
647
enableSubstitutionForDecoratedClasses ( ) ;
648
648
decoratedClassAlias = createUniqueName ( node . name && ! isGeneratedIdentifier ( node . name ) ? node . name . text : "default" ) ;
649
649
decoratedClassAliases [ getOriginalNodeId ( node ) ] = decoratedClassAlias ;
650
-
651
- // We emit the class alias as a `let` declaration here so that it has the same
652
- // TDZ as the class.
653
-
654
- // let ${decoratedClassAlias};
655
- addNode ( statements ,
656
- createVariableStatement (
657
- /*modifiers*/ undefined ,
658
- createLetDeclarationList ( [
659
- createVariableDeclaration ( decoratedClassAlias )
660
- ] )
661
- )
662
- ) ;
663
-
664
- // ${decoratedClassAlias} = ${classExpression}
665
- classExpression = createAssignment (
666
- decoratedClassAlias ,
667
- classExpression ,
668
- /*location*/ location ) ;
669
650
}
670
651
671
- // let ${name} = ${classExpression};
652
+ const declaredName = getDeclarationName ( node , /*allowComments*/ true ) ;
653
+
654
+ // let ${name} = ${classExpression} where name is either declaredName if the class doesn't contain self-reference
655
+ // or decoratedClassAlias if the class contain self-reference.
672
656
addNode ( statements ,
673
657
setOriginalNode (
674
658
createVariableStatement (
675
659
/*modifiers*/ undefined ,
676
660
createLetDeclarationList ( [
677
661
createVariableDeclaration (
678
- getDeclarationName ( node , /*allowComments*/ true ) ,
662
+ decoratedClassAlias || declaredName ,
679
663
/*type*/ undefined ,
680
664
classExpression
681
665
)
@@ -686,6 +670,29 @@ namespace ts {
686
670
)
687
671
) ;
688
672
673
+ if ( decoratedClassAlias ) {
674
+ // We emit the class alias as a `let` declaration here so that it has the same
675
+ // TDZ as the class.
676
+
677
+ // let ${declaredName} = ${decoratedClassAlias}
678
+ addNode ( statements ,
679
+ setOriginalNode (
680
+ createVariableStatement (
681
+ /*modifiers*/ undefined ,
682
+ createLetDeclarationList ( [
683
+ createVariableDeclaration (
684
+ declaredName ,
685
+ /*type*/ undefined ,
686
+ decoratedClassAlias
687
+ )
688
+ ] ) ,
689
+ /*location*/ location
690
+ ) ,
691
+ /*original*/ node
692
+ )
693
+ ) ;
694
+ }
695
+
689
696
return decoratedClassAlias ;
690
697
}
691
698
0 commit comments