Skip to content

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
2 commits merged into from
Aug 13, 2018

Conversation

ghost
Copy link

@ghost ghost commented Aug 11, 2018

Fixes #26355 and #26380

Discovered but did not fix #26379

@ghost ghost force-pushed the destructuringAssignment_private branch from 66dc4ee to 774c6be Compare August 11, 2018 00:50
@ghost ghost requested review from sheetalkamat and sandersn August 11, 2018 01:15
*/
function checkPropertyAccessibility(node: PropertyAccessExpression | QualifiedName | VariableLikeDeclaration | ImportTypeNode, left: Expression | QualifiedName | ImportTypeNode, type: Type, prop: Symbol): boolean {
Copy link
Member

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?

Copy link
Author

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.

else {
// non-shorthand property assignments should always have initializers
return checkDestructuringAssignment(property.initializer, type);
let type: Type | undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth extracting this to a function? I think it’s self-contained.

const prop = getPropertyOfType(objectLiteralType, text);
if (prop) {
markPropertyAsReferenced(prop, property, rightIsThis);
checkPropertyAccessibility(property, /*isSuper*/ false, objectLiteralType, prop);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you be getting type only if propertyAccessibility doesn't have issues?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we normally just call this for the diagnostic and don't change the type, e.g.:

class C { private x!: number; }
const x = new C().x; // Error, but doesn't affect type
x; // number

@ghost ghost merged commit e8b72aa into master Aug 13, 2018
@ghost ghost deleted the destructuringAssignment_private branch August 13, 2018 21:08
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants