Skip to content

Commit 8320bca

Browse files
author
Yui T
committed
Fix emit trailing comma for array binding pattern for varaible declaration
1 parent 1f055b9 commit 8320bca

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/compiler/declarationEmitter.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,18 @@ module ts {
993993
}
994994

995995
function emitBindingPattern(bindingPattern: BindingPattern) {
996-
emitCommaList(bindingPattern.elements, emitBindingElement);
996+
// Only select non-omitted expression from the bindingPattern's elements.
997+
// We have to do this to avoid emitting trailing commas.
998+
// For example:
999+
// original: var [, c,,] = [ 2,3,4]
1000+
// emitted: declare var c: number; // instead of declare var c:number, ;
1001+
let elements: Node[] = [];
1002+
for (let element of bindingPattern.elements) {
1003+
if (element.kind !== SyntaxKind.OmittedExpression){
1004+
elements.push(element);
1005+
}
1006+
}
1007+
emitCommaList(elements, emitBindingElement);
9971008
}
9981009

9991010
function emitBindingElement(bindingElement: BindingElement) {

0 commit comments

Comments
 (0)