Skip to content

Commit

Permalink
Merge pull request #26625 from ajafff/revert-destructuring-private-co…
Browse files Browse the repository at this point in the history
…mputed-name

Revert #26360: Don't error on destructure of private property with computed property syntax
  • Loading branch information
RyanCavanaugh authored Aug 24, 2018
2 parents 0043ba1 + bedf776 commit b5998d9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24250,7 +24250,7 @@ namespace ts {
if (nameText) {
const property = getPropertyOfType(parentType!, nameText)!; // TODO: GH#18217
markPropertyAsReferenced(property, /*nodeForCheckWriteOnly*/ undefined, /*isThisAccess*/ false); // A destructuring is never a write-only reference.
if (parent.initializer && property && !isComputedPropertyName(name)) {
if (parent.initializer && property) {
checkPropertyAccessibility(parent, parent.initializer.kind === SyntaxKind.SuperKeyword, parentType!, property);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
tests/cases/compiler/destructureComputedProperty.ts(7,7): error TS2341: Property 'p' is private and only accessible within class 'C'.
tests/cases/compiler/destructureComputedProperty.ts(8,7): error TS2341: Property 'p' is private and only accessible within class 'C'.
tests/cases/compiler/destructureComputedProperty.ts(10,7): error TS2341: Property 'p' is private and only accessible within class 'C'.


==== tests/cases/compiler/destructureComputedProperty.ts (2 errors) ====
==== tests/cases/compiler/destructureComputedProperty.ts (3 errors) ====
declare const ab: { n: number } | { n: string };
const nameN = "n";
const { [nameN]: n } = ab;
Expand All @@ -13,6 +14,8 @@ tests/cases/compiler/destructureComputedProperty.ts(10,7): error TS2341: Propert
~~~~~~~~~~~
!!! error TS2341: Property 'p' is private and only accessible within class 'C'.
const { ["p"]: p1 } = new C();
~~~~~~~~~~~~~
!!! error TS2341: Property 'p' is private and only accessible within class 'C'.
const { [nameP]: p2 } = new C();
const { p: p3 } = new C();
~~~~~~~~~
Expand Down

0 comments on commit b5998d9

Please sign in to comment.