-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Error on accessing private property through destructuring assignment, and mark property used #26381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
tests/baselines/reference/destructuringAssignment_private.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
tests/cases/compiler/destructuringAssignment_private.ts(6,10): error TS2341: Property 'x' is private and only accessible within class 'C'. | ||
tests/cases/compiler/destructuringAssignment_private.ts(7,4): error TS2341: Property 'o' is private and only accessible within class 'C'. | ||
|
||
|
||
==== tests/cases/compiler/destructuringAssignment_private.ts (2 errors) ==== | ||
class C { | ||
private x = 0; | ||
private o = [{ a: 1 }]; | ||
} | ||
let x: number; | ||
([{ a: { x } }] = [{ a: new C() }]); | ||
~ | ||
!!! error TS2341: Property 'x' is private and only accessible within class 'C'. | ||
({ o: [{ a: x }]} = new C()); | ||
~ | ||
!!! error TS2341: Property 'o' is private and only accessible within class 'C'. | ||
|
21 changes: 21 additions & 0 deletions
21
tests/baselines/reference/destructuringAssignment_private.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//// [destructuringAssignment_private.ts] | ||
class C { | ||
private x = 0; | ||
private o = [{ a: 1 }]; | ||
} | ||
let x: number; | ||
([{ a: { x } }] = [{ a: new C() }]); | ||
({ o: [{ a: x }]} = new C()); | ||
|
||
|
||
//// [destructuringAssignment_private.js] | ||
var C = /** @class */ (function () { | ||
function C() { | ||
this.x = 0; | ||
this.o = [{ a: 1 }]; | ||
} | ||
return C; | ||
}()); | ||
var x; | ||
(x = [{ a: new C() }][0].a.x); | ||
(x = new C().o[0].a); |
26 changes: 26 additions & 0 deletions
26
tests/baselines/reference/destructuringAssignment_private.symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
=== tests/cases/compiler/destructuringAssignment_private.ts === | ||
class C { | ||
>C : Symbol(C, Decl(destructuringAssignment_private.ts, 0, 0)) | ||
|
||
private x = 0; | ||
>x : Symbol(C.x, Decl(destructuringAssignment_private.ts, 0, 9)) | ||
|
||
private o = [{ a: 1 }]; | ||
>o : Symbol(C.o, Decl(destructuringAssignment_private.ts, 1, 18)) | ||
>a : Symbol(a, Decl(destructuringAssignment_private.ts, 2, 18)) | ||
} | ||
let x: number; | ||
>x : Symbol(x, Decl(destructuringAssignment_private.ts, 4, 3)) | ||
|
||
([{ a: { x } }] = [{ a: new C() }]); | ||
>a : Symbol(a, Decl(destructuringAssignment_private.ts, 5, 3)) | ||
>x : Symbol(x, Decl(destructuringAssignment_private.ts, 5, 8)) | ||
>a : Symbol(a, Decl(destructuringAssignment_private.ts, 5, 20)) | ||
>C : Symbol(C, Decl(destructuringAssignment_private.ts, 0, 0)) | ||
|
||
({ o: [{ a: x }]} = new C()); | ||
>o : Symbol(o, Decl(destructuringAssignment_private.ts, 6, 2)) | ||
>a : Symbol(a, Decl(destructuringAssignment_private.ts, 6, 8)) | ||
>x : Symbol(x, Decl(destructuringAssignment_private.ts, 4, 3)) | ||
>C : Symbol(C, Decl(destructuringAssignment_private.ts, 0, 0)) | ||
|
44 changes: 44 additions & 0 deletions
44
tests/baselines/reference/destructuringAssignment_private.types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
=== tests/cases/compiler/destructuringAssignment_private.ts === | ||
class C { | ||
>C : C | ||
|
||
private x = 0; | ||
>x : number | ||
>0 : 0 | ||
|
||
private o = [{ a: 1 }]; | ||
>o : { a: number; }[] | ||
>[{ a: 1 }] : { a: number; }[] | ||
>{ a: 1 } : { a: number; } | ||
>a : number | ||
>1 : 1 | ||
} | ||
let x: number; | ||
>x : number | ||
|
||
([{ a: { x } }] = [{ a: new C() }]); | ||
>([{ a: { x } }] = [{ a: new C() }]) : [{ a: C; }] | ||
>[{ a: { x } }] = [{ a: new C() }] : [{ a: C; }] | ||
>[{ a: { x } }] : [{ a: { x: number; }; }] | ||
>{ a: { x } } : { a: { x: number; }; } | ||
>a : { x: number; } | ||
>{ x } : { x: number; } | ||
>x : number | ||
>[{ a: new C() }] : [{ a: C; }] | ||
>{ a: new C() } : { a: C; } | ||
>a : C | ||
>new C() : C | ||
>C : typeof C | ||
|
||
({ o: [{ a: x }]} = new C()); | ||
>({ o: [{ a: x }]} = new C()) : C | ||
>{ o: [{ a: x }]} = new C() : C | ||
>{ o: [{ a: x }]} : { o: [{ a: number; }]; } | ||
>o : [{ a: number; }] | ||
>[{ a: x }] : [{ a: number; }] | ||
>{ a: x } : { a: number; } | ||
>a : number | ||
>x : number | ||
>new C() : C | ||
>C : typeof C | ||
|
22 changes: 22 additions & 0 deletions
22
tests/baselines/reference/noUnusedLocals_destructuringAssignment.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
tests/cases/compiler/noUnusedLocals_destructuringAssignment.ts(10,13): error TS6133: 'f' is declared but its value is never read. | ||
|
||
|
||
==== tests/cases/compiler/noUnusedLocals_destructuringAssignment.ts (1 errors) ==== | ||
class C { | ||
private x = 0; | ||
|
||
m(): number { | ||
let x: number; | ||
({ x } = this); | ||
return x; | ||
} | ||
|
||
private f(): Function { | ||
~ | ||
!!! error TS6133: 'f' is declared but its value is never read. | ||
let f: Function; | ||
({ f } = this); | ||
return f; | ||
} | ||
} | ||
|
35 changes: 35 additions & 0 deletions
35
tests/baselines/reference/noUnusedLocals_destructuringAssignment.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//// [noUnusedLocals_destructuringAssignment.ts] | ||
class C { | ||
private x = 0; | ||
|
||
m(): number { | ||
let x: number; | ||
({ x } = this); | ||
return x; | ||
} | ||
|
||
private f(): Function { | ||
let f: Function; | ||
({ f } = this); | ||
return f; | ||
} | ||
} | ||
|
||
|
||
//// [noUnusedLocals_destructuringAssignment.js] | ||
var C = /** @class */ (function () { | ||
function C() { | ||
this.x = 0; | ||
} | ||
C.prototype.m = function () { | ||
var x; | ||
(x = this.x); | ||
return x; | ||
}; | ||
C.prototype.f = function () { | ||
var f; | ||
(f = this.f); | ||
return f; | ||
}; | ||
return C; | ||
}()); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just checking: are the changes to this function just cleanup or do they actually fix one of the bugs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the parameters changed. We no longer pass in the LHS (since destructuring doesn't have one), we just pass in whether it's a
super.
access.