Skip to content
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

Consider extending proposal to all class element definitions #9

Closed
pzuraq opened this issue Mar 27, 2022 · 1 comment
Closed

Consider extending proposal to all class element definitions #9

pzuraq opened this issue Mar 27, 2022 · 1 comment

Comments

@pzuraq
Copy link

pzuraq commented Mar 27, 2022

Following this thread, I think this proposal could be generalized to allow defining any type of class element in the class element block, not just accessors. This would add the ability set properties like writable and enumerable on class elements, and could also potentially be a reason to reconsider whether or not a syntactic opt-in is required (since this would be a much more general syntax than just auto accessors):

class C {
  identifier {
    writable?: boolean;
    enumerable?: boolean;
    configurable?: boolean;

    value?: unknown;
    get?: () => T;
    set?: (v: T) => void;
  }: T;
}

We could also have a much shorter opt-in keyword, define or def, instead of accessor:

class C {
  // `define` keyword
  define x { writable = false } = 123;
  @reactive define x { get; set; } = 123;

  // `def` keyword
  def x { writable = false } = 123;
  @reactive def x { get; set; } = 123;
}

I did a quick write-up of what this could potentially look like, it overlaps a lot with this proposal: https://gist.github.com/pzuraq/ae002a0f3e8745b57cd6c046bf9ff89f

@rbuckton
Copy link
Collaborator

I'm not comfortable with reifying property descriptors as an independent class element. If we want to give someone a way to modify other descriptor properties such as enumerability, I think we're better off introducing specific keywords or some kind of native decorator that has privileged access to the descriptor internally.

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

No branches or pull requests

2 participants