Skip to content

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

Signed-off-by: Max Heiber <mheiber@bloomberg.net>
@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