Skip to content

no private name environment stack #6

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

Closed

Conversation

mheiber
Copy link

@mheiber mheiber commented Oct 13, 2018

instead of keeping an array of private name environment stacks, use the JS function stack.

Advantages:

  • consistent with how this sort of thing is done elsewhere in the TS codebase
  • simpler

@joeywatts
Copy link
Owner

joeywatts commented Oct 13, 2018

I originally did this to be consistent with how the lexical environment stuff works in src/compiler/transformer.ts because private names follow lexical scoping rules. We need to store a stack of them for this use case:

class A {
      #numberOfXInstances = 0;
      x = class B {
            constructor(instance: A) {
                 instance.#numberOfXInstances++;
            }
      };
}

The inner class B accesses a private name on an instance of class A.

I know the accessPrivateName doesn't currently search up the stack, I'm addressing this when implementing the private fields on top of the ESnext refactor code.

@mheiber mheiber closed this Oct 14, 2018
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.

2 participants