Skip to content

allow access protected member in this parameter context #24645

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 4 commits into from
Jun 11, 2018

Conversation

Kingwl
Copy link
Contributor

@Kingwl Kingwl commented Jun 4, 2018

this PR take a simple implement

  • lookup ThisParameter when cannot find enclosingClass in protected accessibility check
  • get Constraint if typeof this is generic parameter

Fixes #10302

return false;
let thisParameter: ParameterDeclaration | undefined;
const thisContainer = getThisContainer(node, /* includeArrowFunctions */ false);
if (!thisContainer || !isFunctionLike(thisContainer) || !(thisParameter = getThisParameter(thisContainer)) || !thisParameter.type) {
Copy link
Contributor

Choose a reason for hiding this comment

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

it is kind of weird that this works for static properties without this.. i think we should prohibit this. e.g.:

class C { 
    protected static S = 0;
}

C.S;  // Error

function f(this: C) { 
    C.S; // OK
}

@mhegazy mhegazy requested a review from weswigham June 4, 2018 17:36
@mhegazy
Copy link
Contributor

mhegazy commented Jun 4, 2018

@weswigham can you please review this change.

// static member access is disallow
let thisParameter: ParameterDeclaration | undefined;
const thisContainer = getThisContainer(node, /* includeArrowFunctions */ false);
if (flags & ModifierFlags.Static || !thisContainer || !isFunctionLike(thisContainer) || !(thisParameter = getThisParameter(thisContainer)) || !thisParameter.type) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit. i would move the check for the flag above the request for getThisContainer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants