Fix emit trailing comma for array binding pattern for varaible declaration
This commit is contained in:
parent
1f055b95aa
commit
8320bca4d0
1 changed files with 12 additions and 1 deletions
|
@ -993,7 +993,18 @@ module ts {
|
|||
}
|
||||
|
||||
function emitBindingPattern(bindingPattern: BindingPattern) {
|
||||
emitCommaList(bindingPattern.elements, emitBindingElement);
|
||||
// Only select non-omitted expression from the bindingPattern's elements.
|
||||
// We have to do this to avoid emitting trailing commas.
|
||||
// For example:
|
||||
// original: var [, c,,] = [ 2,3,4]
|
||||
// emitted: declare var c: number; // instead of declare var c:number, ;
|
||||
let elements: Node[] = [];
|
||||
for (let element of bindingPattern.elements) {
|
||||
if (element.kind !== SyntaxKind.OmittedExpression){
|
||||
elements.push(element);
|
||||
}
|
||||
}
|
||||
emitCommaList(elements, emitBindingElement);
|
||||
}
|
||||
|
||||
function emitBindingElement(bindingElement: BindingElement) {
|
||||
|
|
Loading…
Reference in a new issue