@@ -2374,7 +2374,7 @@ module ts {
23742374 i ++ ;
23752375 }
23762376 write ( "[" ) ;
2377- emitList ( elements , pos , i - pos , multiLine , trailingComma ) ;
2377+ emitList ( elements , pos , i - pos , multiLine , trailingComma && i === length ) ;
23782378 write ( "]" ) ;
23792379 pos = i ;
23802380 }
@@ -2389,17 +2389,17 @@ module ts {
23892389 var elements = node . elements ;
23902390 if ( elements . length === 0 ) {
23912391 write ( "[]" ) ;
2392- return ;
23932392 }
2394- if ( languageVersion >= ScriptTarget . ES6 ) {
2393+ else if ( languageVersion >= ScriptTarget . ES6 ) {
23952394 write ( "[" ) ;
2396- emitList ( elements , 0 , elements . length , /*multiLine*/ ( node . flags & NodeFlags . MultiLine ) !== 0 ,
2395+ emitList ( elements , 0 , elements . length , /*multiLine*/ ( node . flags & NodeFlags . MultiLine ) !== 0 ,
23972396 /*trailingComma*/ elements . hasTrailingComma ) ;
23982397 write ( "]" ) ;
2399- return ;
24002398 }
2401- emitListWithSpread ( elements , /*multiLine*/ ( node . flags & NodeFlags . MultiLine ) !== 0 ,
2402- /*trailingComma*/ elements . hasTrailingComma ) ;
2399+ else {
2400+ emitListWithSpread ( elements , /*multiLine*/ ( node . flags & NodeFlags . MultiLine ) !== 0 ,
2401+ /*trailingComma*/ elements . hasTrailingComma ) ;
2402+ }
24032403 }
24042404
24052405 function emitObjectLiteral ( node : ObjectLiteralExpression ) {
@@ -2502,12 +2502,12 @@ module ts {
25022502
25032503 function skipParentheses ( node : Expression ) : Expression {
25042504 while ( node . kind === SyntaxKind . ParenthesizedExpression || node . kind === SyntaxKind . TypeAssertionExpression ) {
2505- node = ( < ParenthesizedExpression > node ) . expression ;
2505+ node = ( < ParenthesizedExpression | TypeAssertion > node ) . expression ;
25062506 }
25072507 return node ;
25082508 }
25092509
2510- function emitTarget ( node : Expression ) : Expression {
2510+ function emitCallTarget ( node : Expression ) : Expression {
25112511 if ( node . kind === SyntaxKind . Identifier || node . kind === SyntaxKind . ThisKeyword || node . kind === SyntaxKind . SuperKeyword ) {
25122512 emit ( node ) ;
25132513 return node ;
@@ -2526,12 +2526,14 @@ module ts {
25262526 var target : Expression ;
25272527 var expr = skipParentheses ( node . expression ) ;
25282528 if ( expr . kind === SyntaxKind . PropertyAccessExpression ) {
2529- target = emitTarget ( ( < PropertyAccessExpression > expr ) . expression ) ;
2529+ // Target will be emitted as "this" argument
2530+ target = emitCallTarget ( ( < PropertyAccessExpression > expr ) . expression ) ;
25302531 write ( "." ) ;
25312532 emit ( ( < PropertyAccessExpression > expr ) . name ) ;
25322533 }
25332534 else if ( expr . kind === SyntaxKind . ElementAccessExpression ) {
2534- target = emitTarget ( ( < PropertyAccessExpression > expr ) . expression ) ;
2535+ // Target will be emitted as "this" argument
2536+ target = emitCallTarget ( ( < PropertyAccessExpression > expr ) . expression ) ;
25352537 write ( "[" ) ;
25362538 emit ( ( < ElementAccessExpression > expr ) . argumentExpression ) ;
25372539 write ( "]" ) ;
@@ -2546,13 +2548,16 @@ module ts {
25462548 write ( ".apply(" ) ;
25472549 if ( target ) {
25482550 if ( target . kind === SyntaxKind . SuperKeyword ) {
2551+ // Calls of form super(...) and super.foo(...)
25492552 emitThis ( target ) ;
25502553 }
25512554 else {
2555+ // Calls of form obj.foo(...)
25522556 emit ( target ) ;
25532557 }
25542558 }
25552559 else {
2560+ // Calls of form foo(...)
25562561 write ( "void 0" ) ;
25572562 }
25582563 write ( ", " ) ;
0 commit comments