8000 Fix breakpoints in object literal pattern destructuring assignment · johnangularjs/TypeScript@ff00a0c · GitHub
[go: up one dir, main page]

Skip to content

Commit ff00a0c

Browse files
committed
Fix breakpoints in object literal pattern destructuring assignment
1 parent db0ab40 commit ff00a0c

File tree

4 files changed

+2673
-7
lines changed

4 files changed

+2673
-7
lines changed

src/services/breakpoints.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,12 @@ namespace ts.BreakpointResolver {
261261
}
262262

263263
// Set breakpoint on identifier element of destructuring pattern
264-
// a or ...c from
265-
// [a, b, ...c] or { a, b } from destructuring pattern
266-
if ((node.kind === SyntaxKind.Identifier || node.kind == SyntaxKind.SpreadElementExpression) &&
264+
// a or ...c or d: x from
265+
// [a, b, ...c] or { a, b } or { d: x } from destructuring pattern
266+
if ((node.kind === SyntaxKind.Identifier ||
267+
node.kind == SyntaxKind.SpreadElementExpression ||
268+
node.kind === SyntaxKind.PropertyAssignment ||
269+
node.kind === SyntaxKind.ShorthandPropertyAssignment) &&
267270
isArrayLiteralOrObjectLiteralDestructuringPattern(node.parent)) {
268271
return textSpan(node);
269272
}
@@ -322,12 +325,14 @@ namespace ts.BreakpointResolver {
322325
break;
323326
}
324327
}
325-
328+
326329
// If this is name of property assignment, set breakpoint in the initializer
327-
if (node.parent.kind === SyntaxKind.PropertyAssignment && (<PropertyDeclaration>node.parent).name === node) {
330+
if (node.parent.kind === SyntaxKind.PropertyAssignment &&
331+
(<PropertyDeclaration>node.parent).name === node &&
332+
!isArrayLiteralOrObjectLiteralDestructuringPattern(node.parent.parent)) {
328333
return spanInNode((<PropertyDeclaration>node.parent).initializer);
329334
}
330-
335+
331336
// Breakpoint in type assertion goes to its operand
332337
if (node.parent.kind === SyntaxKind.TypeAssertionExpression && (<TypeAssertion>node.parent).type === node) {
333338
return spanInNextNode((<TypeAssertion>node.parent).type);
@@ -609,6 +614,11 @@ namespace ts.BreakpointResolver {
609614

610615
// Default to parent node
611616
default:
617+
if (isArrayLiteralOrObjectLiteralDestructuringPattern(node.parent)) {
618+
// Breakpoint in last binding element or binding pattern if it contains no elements
619+
let objectLiteral = <ObjectLiteralExpression>node.parent;
620+
return textSpan(lastOrUndefined(objectLiteral.properties) || objectLiteral);
621+
}
612622
return spanInNode(node.parent);
613623
}
614624
}

src/services/utilities.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,9 @@ namespace ts {
629629

630630
// [a, b, c] of
631631
// [x, [a, b, c] ] = someExpression
632-
if (isArrayLiteralOrObjectLiteralDestructuringPattern(node.parent)) {
632+
// or
633+
// {x, a: {a, b, c} } = someExpression
634+
if (isArrayLiteralOrObjectLiteralDestructuringPattern(node.parent.kind === SyntaxKind.PropertyAssignment ? node.parent.parent : node.parent)) {
633635
return true;
634636
}
635637
}

0 commit comments

Comments
 (0)
0