Skip to content

Commit

Permalink
fixUnusedIdentifier: Delete trailing comma in array binding pattern (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy authored Jun 8, 2018
1 parent 7b2e092 commit 855c3a6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
15 changes: 6 additions & 9 deletions src/services/codefixes/fixUnusedIdentifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ verify.codeFixAll({
x; z;
}
{
const [x,] = o;
const [x] = o;
x;
}
{
const [, y] = o;
y;
}
{
const [, y,] = o;
const [, y] = o;
y;
}
{
Expand Down

0 comments on commit 855c3a6

Please sign in to comment.