fixUnusedIdentifier: Delete trailing comma in array binding pattern (#24800)

This commit is contained in:
Andy 2018-06-08 10:39:01 -07:00 committed by GitHub
parent 7b2e09263c
commit 855c3a6d4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 11 deletions

View File

@ -228,15 +228,12 @@ namespace ts.codefix {
case SyntaxKind.BindingElement: {
const pattern = (parent as BindingElement).parent;
switch (pattern.kind) {
case SyntaxKind.ArrayBindingPattern:
changes.deleteNode(sourceFile, parent); // Don't delete ','
break;
case SyntaxKind.ObjectBindingPattern:
changes.deleteNodeInList(sourceFile, parent);
break;
default:
return Debug.assertNever(pattern);
const preserveComma = pattern.kind === SyntaxKind.ArrayBindingPattern && parent !== last(pattern.elements);
if (preserveComma) {
changes.deleteNode(sourceFile, parent);
}
else {
changes.deleteNodeInList(sourceFile, parent);
}
break;
}

View File

@ -57,7 +57,7 @@ verify.codeFixAll({
x; z;
}
{
const [x,] = o;
const [x] = o;
x;
}
{
@ -65,7 +65,7 @@ verify.codeFixAll({
y;
}
{
const [, y,] = o;
const [, y] = o;
y;
}
{