@@ -1387,7 +1387,11 @@ module ts {
13871387 }
13881388 else if ( bindingPattern . kind === SyntaxKind . ArrayBindingPattern ) {
13891389 write ( "[" ) ;
1390- emitCommaList ( bindingPattern . elements , emitBindingElement ) ;
1390+ let elements = bindingPattern . elements ;
1391+ emitCommaList ( elements , emitBindingElement ) ;
1392+ if ( elements && elements . hasTrailingComma ) {
1393+ write ( ", " ) ;
1394+ }
13911395 write ( "]" ) ;
13921396 }
13931397 }
@@ -1402,40 +1406,51 @@ module ts {
14021406 } : undefined ;
14031407 }
14041408
1405- if ( bindingElement . propertyName ) {
1406- // bindingElement has propertyName property in the following case:
1407- // { y: [a,b,c] ...} -> bindingPattern will have a property called propertyName for "y"
1408- // We have to explicitly emit the propertyName before descending into its binding elements.
1409+ if ( bindingElement . kind === SyntaxKind . OmittedExpression ) {
1410+ // If bindingElement is an omittedExpression (i.e. containing elision),
1411+ // we will emit blank space (although this may differ from users' original code,
1412+ // it allows emitSeparatedList to write separator appropriately)
14091413 // Example:
1410- // original: function foo({y: [a,b,c]}) {}
1411- // emit : declare function foo({y: [a, b, c]}: { y: [any, any, any] }) void;
1412- writeTextOfNode ( currentSourceFile , bindingElement . propertyName ) ;
1413- write ( ": " ) ;
1414-
1415- // If bindingElement has propertyName property, then its name must be another bindingPattern of SyntaxKind.ObjectBindingPattern
1416- emitBindingPattern ( < BindingPattern > bindingElement . name ) ;
1414+ // original: function foo([, x, ,]) {}
1415+ // emit : function foo([ , x, , ]) {}
1416+ write ( " " ) ;
14171417 }
1418- else if ( bindingElement . name ) {
1419- if ( isBindingPattern ( bindingElement . name ) ) {
1420- // If it is a nested binding pattern, we will recursively descend into each element and emit each one separately.
1421- // In the case of rest element, we will omit rest element.
1418+ else if ( bindingElement . kind === SyntaxKind . BindingElement ) {
1419+ if ( bindingElement . propertyName ) {
1420+ // bindingElement has propertyName property in the following case:
1421+ // { y: [a,b,c] ...} -> bindingPattern will have a property called propertyName for "y"
1422+ // We have to explicitly emit the propertyName before descending into its binding elements.
14221423 // Example:
1423- // original: function foo([a, [[b]], c] = [1,[["string"]], 3]) {}
1424- // emit : declare function foo([a, [[b]], c]: [number, [[string]], number]): void;
1425- // original with rest: function foo([a, ...c]) {}
1426- // emit : declare function foo([a, ...c]): void;
1424+ // original: function foo({y: [a,b,c]}) {}
1425+ // emit : declare function foo({y: [a, b, c]}: { y: [any, any, any] }) void;
1426+ writeTextOfNode ( currentSourceFile , bindingElement . propertyName ) ;
1427+ write ( ": " ) ;
1428+
1429+ // If bindingElement has propertyName property, then its name must be another bindingPattern of SyntaxKind.ObjectBindingPattern
14271430 emitBindingPattern ( < BindingPattern > bindingElement . name ) ;
14281431 }
1429- else {
1430- Debug . assert ( bindingElement . name . kind === SyntaxKind . Identifier ) ;
1431- // If the node is just an identifier, we will simply emit the text associated with the node's name
1432- // Example:
1433- // original: function foo({y = 10, x}) {}
1434- // emit : declare function foo({y, x}: {number, any}): void;
1435- if ( bindingElement . dotDotDotToken ) {
1436- write ( "..." ) ;
1432+ else if ( bindingElement . name ) {
1433+ if ( isBindingPattern ( bindingElement . name ) ) {
1434+ // If it is a nested binding pattern, we will recursively descend into each element and emit each one separately.
1435+ // In the case of rest element, we will omit rest element.
1436+ // Example:
1437+ // original: function foo([a, [[b]], c] = [1,[["string"]], 3]) {}
1438+ // emit : declare function foo([a, [[b]], c]: [number, [[string]], number]): void;
1439+ // original with rest: function foo([a, ...c]) {}
1440+ // emit : declare function foo([a, ...c]): void;
1441+ emitBindingPattern ( < BindingPattern > bindingElement . name ) ;
1442+ }
1443+ else {
1444+ Debug . assert ( bindingElement . name . kind === SyntaxKind . Identifier ) ;
1445+ // If the node is just an identifier, we will simply emit the text associated with the node's name
1446+ // Example:
1447+ // original: function foo({y = 10, x}) {}
1448+ // emit : declare function foo({y, x}: {number, any}): void;
1449+ if ( bindingElement . dotDotDotToken ) {
1450+ write ( "..." ) ;
1451+ }
1452+ writeTextOfNode ( currentSourceFile , bindingElement . name ) ;
14371453 }
1438- writeTextOfNode ( currentSourceFile , bindingElement . name ) ;
14391454 }
14401455 }
14411456 }
0 commit comments