-
Notifications
You must be signed in to change notification settings - Fork 7
Class-body directive prologue is incompatible with class fields #21
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
Comments
This comment has been minimized.
This comment has been minimized.
That is a function call |
lol oops, not so clever after all |
In particular, if we're going to add any new syntax, I think it should be either:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
What about a different prologue for hiding class implementations, specified in the constructor: class Foo {
constructor() {
"hide class implementation";
}
} |
I like that - considering the constructor function is what |
I would imagine |
Although now that i think about it, it’d be weird if the constructor pragma impacted static methods :-/ |
@rbuckton The constructor does not always appear first (or even early) in the class body. I wouldn't want to be unable to tell that we're in a special kind of context until the whole class body is read. |
@ljharb: Possibly sounds like https://github.com/tc39/proposal-class-static-block#readme could be an option: class Foo {
static {
"hide implementation";
}
} @michaelficarra: True, but there's still value in the simple solution. |
Another option could be this: class Foo {
("hide implementation");
} This keeps the pragma at the top of the class and doesn't conflict with public fields, for the added cost of two characters. |
We're no longer interested in adding new directive placements. |
@michaelficarra so what's the plan for hiding the implementation of the constructor/class body? a pragma inside the constructor? |
@ljharb If you want to affect only the constructor, put it in the constructor. If you want it to apply to all of the methods of the class, wrap the class in an IIFE or just put the directive in the enclosing scope if you don't mind the over-application. |
Gotcha - i ask because the constructor’s implementation is the entire class body, so hiding it is hiding the class (altho not necessarily all its methods) |
Discovered in TC39 today.
declares a public field named
"hide implementation"
. Whee!Solutions
Omit directive prologue in class bodies
We could just omit this capability. Then developers would have several more-awkward options, such as:
or
or
Don't use directive prologues
Basically #13.
Something else clever
TBD.
The text was updated successfully, but these errors were encountered: