@@ -2374,7 +2374,7 @@ module ts {
2374
2374
i ++ ;
2375
2375
}
2376
2376
write ( "[" ) ;
2377
- emitList ( elements , pos , i - pos , multiLine , trailingComma ) ;
2377
+ emitList ( elements , pos , i - pos , multiLine , trailingComma && i === length ) ;
2378
2378
write ( "]" ) ;
2379
2379
pos = i ;
2380
2380
}
@@ -2389,17 +2389,17 @@ module ts {
2389
2389
var elements = node . elements ;
2390
2390
if ( elements . length === 0 ) {
2391
2391
write ( "[]" ) ;
2392
- return ;
2393
2392
}
2394
- if ( languageVersion >= ScriptTarget . ES6 ) {
2393
+ else if ( languageVersion >= ScriptTarget . ES6 ) {
2395
2394
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 ,
2397
2396
/*trailingComma*/ elements . hasTrailingComma ) ;
2398
2397
write ( "]" ) ;
2399
- return ;
2400
2398
}
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
+ }
2403
2403
}
2404
2404
2405
2405
function emitObjectLiteral ( node : ObjectLiteralExpression ) {
@@ -2502,12 +2502,12 @@ module ts {
2502
2502
2503
2503
function skipParentheses ( node : Expression ) : Expression {
2504
2504
while ( node . kind === SyntaxKind . ParenthesizedExpression || node . kind === SyntaxKind . TypeAssertionExpression ) {
2505
- node = ( < ParenthesizedExpression > node ) . expression ;
2505
+ node = ( < ParenthesizedExpression | TypeAssertion > node ) . expression ;
2506
2506
}
2507
2507
return node ;
2508
2508
}
2509
2509
2510
- function emitTarget ( node : Expression ) : Expression {
2510
+ function emitCallTarget ( node : Expression ) : Expression {
2511
2511
if ( node . kind === SyntaxKind . Identifier || node . kind === SyntaxKind . ThisKeyword || node . kind === SyntaxKind . SuperKeyword ) {
2512
2512
emit ( node ) ;
2513
2513
return node ;
@@ -2526,12 +2526,14 @@ module ts {
2526
2526
var target : Expression ;
2527
2527
var expr = skipParentheses ( node . expression ) ;
2528
2528
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 ) ;
2530
2531
write ( "." ) ;
2531
2532
emit ( ( < PropertyAccessExpression > expr ) . name ) ;
2532
2533
}
2533
2534
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 ) ;
2535
2537
write ( "[" ) ;
2536
2538
emit ( ( < ElementAccessExpression > expr ) . argumentExpression ) ;
2537
2539
write ( "]" ) ;
@@ -2546,13 +2548,16 @@ module ts {
2546
2548
write ( ".apply(" ) ;
2547
2549
if ( target ) {
2548
2550
if ( target . kind === SyntaxKind . SuperKeyword ) {
2551
+ // Calls of form super(...) and super.foo(...)
2549
2552
emitThis ( target ) ;
2550
2553
}
2551
2554
else {
2555
+ // Calls of form obj.foo(...)
2552
2556
emit ( target ) ;
2553
2557
}
2554
2558
}
2555
2559
else {
2560
+ // Calls of form foo(...)
2556
2561
write ( "void 0" ) ;
2557
2562
}
2558
2563
write ( ", " ) ;
0 commit comments