@@ -3199,28 +3199,41 @@ module ts {
31993199 }
32003200 }
32013201
3202- function emitMemberAssignments ( node : ClassLikeDeclaration , staticFlag : NodeFlags ) {
3203- forEach ( node . members , member => {
3204- if ( member . kind === SyntaxKind . PropertyDeclaration && ( member . flags & NodeFlags . Static ) === staticFlag && ( < PropertyDeclaration > member ) . initializer ) {
3205- writeLine ( ) ;
3206- emitLeadingComments ( member ) ;
3207- emitStart ( member ) ;
3208- emitStart ( ( < PropertyDeclaration > member ) . name ) ;
3209- if ( staticFlag ) {
3210- emitDeclarationName ( node ) ;
3211- }
3212- else {
3213- write ( "this" ) ;
3214- }
3215- emitMemberAccessForPropertyName ( ( < PropertyDeclaration > member ) . name ) ;
3216- emitEnd ( ( < PropertyDeclaration > member ) . name ) ;
3217- write ( " = " ) ;
3218- emit ( ( < PropertyDeclaration > member ) . initializer ) ;
3219- write ( ";" ) ;
3220- emitEnd ( member ) ;
3221- emitTrailingComments ( member ) ;
3202+ function getInitializedProperties ( node : ClassLikeDeclaration , static : boolean ) {
3203+ let properties : PropertyDeclaration [ ] = [ ] ;
3204+ for ( let member of node . members ) {
3205+ if ( member . kind === SyntaxKind . PropertyDeclaration && static === ( ( member . flags & NodeFlags . Static ) !== 0 ) && ( < PropertyDeclaration > member ) . initializer ) {
3206+ properties . push ( < PropertyDeclaration > member ) ;
32223207 }
3223- } ) ;
3208+ }
3209+
3210+ return properties ;
3211+ }
3212+
3213+ function emitPropertyDeclarations ( node : ClassLikeDeclaration , properties : PropertyDeclaration [ ] ) {
3214+ for ( let property of properties ) {
3215+ emitPropertyDeclaration ( node , property ) ;
3216+ }
3217+ }
3218+
3219+ function emitPropertyDeclaration ( node : ClassLikeDeclaration , property : PropertyDeclaration ) {
3220+ writeLine ( ) ;
3221+ emitLeadingComments ( property ) ;
3222+ emitStart ( property ) ;
3223+ emitStart ( property . name ) ;
3224+ if ( property . flags & NodeFlags . Static ) {
3225+ emitDeclarationName ( node ) ;
3226+ }
3227+ else {
3228+ write ( "this" ) ;
3229+ }
3230+ emitMemberAccessForPropertyName ( property . name ) ;
3231+ emitEnd ( property . name ) ;
3232+ write ( " = " ) ;
3233+ emit ( property . initializer ) ;
3234+ write ( ";" ) ;
3235+ emitEnd ( property ) ;
3236+ emitTrailingComments ( property ) ;
32243237 }
32253238
32263239 function emitMemberFunctionsForES5AndLower ( node : ClassLikeDeclaration ) {
@@ -3425,7 +3438,7 @@ module ts {
34253438 emitEnd ( baseTypeElement ) ;
34263439 }
34273440 }
3428- emitMemberAssignments ( node , /*staticFlag*/ 0 ) ;
3441+ emitPropertyDeclarations ( node , getInitializedProperties ( node , /*static:*/ false ) ) ;
34293442 if ( ctor ) {
34303443 var statements : Node [ ] = ( < Block > ctor . body ) . statements ;
34313444 if ( superCall ) {
@@ -3591,7 +3604,7 @@ module ts {
35913604 // HasLexicalDeclaration (N) : Determines if the argument identifier has a binding in this environment record that was created using
35923605 // a lexical declaration such as a LexicalDeclaration or a ClassDeclaration.
35933606 writeLine ( ) ;
3594- emitMemberAssignments ( node , NodeFlags . Static ) ;
3607+ emitPropertyDeclarations ( node , getInitializedProperties ( node , /*static:*/ true ) ) ;
35953608 emitDecoratorsOfClass ( node ) ;
35963609
35973610 // If this is an exported class, but not on the top level (i.e. on an internal
@@ -3648,7 +3661,7 @@ module ts {
36483661 writeLine ( ) ;
36493662 emitConstructor ( node , baseTypeNode ) ;
36503663 emitMemberFunctionsForES5AndLower ( node ) ;
3651- emitMemberAssignments ( node , NodeFlags . Static ) ;
3664+ emitPropertyDeclarations ( node , getInitializedProperties ( node , /*static:*/ true ) ) ;
36523665 writeLine ( ) ;
36533666 emitDecoratorsOfClass ( node ) ;
36543667 writeLine ( ) ;
0 commit comments