-
Notifications
You must be signed in to change notification settings - Fork 106
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
Should @super.dec be allowed? #461
Comments
Also new.target, and arguments |
AFAIK |
Doesn't the evaluation of the decorator itself happen at the same time as computed fields? In which case i.e. Like this isn't allowed today with computed fields: class AbstractFoo {
static methodKey = Symbol();
}
class Bar extends AbstractFoo {
// Uncaught SyntaxError: 'super' keyword unexpected here
[super.methodKey]() {
// ...
}
} |
class Base {
foo() {}
}
class Outer extends Base {
foo() {
return @super.foo class Inner {}
}
} ? |
Ah true, yeah for class level decorators probably makes sense to just allow it. And make it an early error for inside-class decorators like computed fields are. |
My understanding was that it's a different phase. There's no reason it can't work the same way it does in a Assuming it refers to the superclass, class A {
static capture() {}
}
class B extends A {
@super.caputure
foo() {}
} is a totally reasonable thing to write. |
Decorator evaluations are interwoven with dynamic field evaluations, timing wise: class C {
[(console.log(1), 'a')];
@(console.log(2), dec)
[(console.log(3), 'b')];
}
// 1, 2, 3 Decorator application is in a different phase, after these expressions are evaluated. It would be odd to me that dynamic properties would be interwoven with decorator expressions and have a different meaning for |
Ehhh I don't think the timing concern is particularly important. For most readers the fact that the timing is interwoven is obscure trivia; the visible fact is that the syntax is interwoven, and we've already bitten that bullet with static fields and blocks having a different |
Even with class elements decorators, this code is already valid and has well-defined semantics: class A {
decorator() { console.log("Do something"); }
}
class B extends A {
method() {
class C {
@(super.decorator) foo() {};
}
}
} I think this issue should only focus on the syntax aspect, i.e. if also this is valid (and if it is, it must have the same semantics of the other already valid code): class A {
decorator() { console.log("Do something"); }
}
class B extends A {
method() {
class C {
@super.decorator foo() {};
}
}
} |
A related question: should we allow class C extends class B {
constructor() { return () => () => "hello" }
}
{
constructor() {
return class D {
@super() p;
}
}
} |
Probably not unless there’s a definite use case? It could be done with parentheses regardless and if really doing this, parentheses would probably make it more “readable” anyway (relatively i mean. the readability bar to clear is pretty low there lol). Since SuperCall is its own thing with unique semantics and doesn’t “come along for the ride” with SuperProperty, it doesn’t (afaict) make things simpler to permit it either — is there an advantage to permitting it I’m not catching? |
super isn’t it’s own expression thing, so i don’t think it would work at all if not allowed in this way. |
@ljharb If I understood it correctly, @JLHwung’s example intended the parentheses to be those of new class extends Map {
constructor() {
console.assert("[object Map]" in class { static [super()]; });
}
} I think the answer to the question oughta be “no” despite |
@bathos i read |
The question "should we allow Expanding |
If a minifier can remove two bytes from an expression that nobody’s writing in a rainforest, does it still burn? :) |
"Nobody is writing For example, the code function id(x) {
return x;
}
class DecoratorFactoryGen {
construtor() {}
}
class C extends DecoratorFactoryGen {
constructor() {
const b = super();
return id(b);
}
}
new C(); will be minified by Terser as new class extends class{construtor(){}}{constructor(){return super()}}; where |
Is the possibility of it being intermediate substantially higher than the possibility of it being written directly? Wouldn’t you still need to be authoring decorators as classes which use return override? I’m an unapologetic return override lover myself (🤫) but am having a hard time picturing scenarios where it would be useful for that. In any case I don’t think this is a consideration which should inform language design. A language is created to benefit people, not minifiers, and half the time brotli alone produces comparable savings. |
Right now my syntax is: class Button extends CustomElement {
//
}
// Uses CustomElement.idl(), but `Button` instead for `this`
// Assignment just to appease Typescript
Button.prototype.disabled = Button.idl('disabled', {type: 'boolean'}); From my understanding decorators will pass class Button extends CustomElement {
@super.idl
disabled;
} Side note: I'm not sure where to put the options though because I also have some things like: Input.prototype.formEnctype = Input.idl('formEnctype', { attr: 'formenctype', ...DOMString }); I think that could be: @super.idl formEncType = super.idlOptions({ attr: 'formenctype', ...DOMString }); |
@trusktr This is a syntax-only issue as // They are equivalent.
@(foo.bar)
@foo.bar @(super.foo) // Already valid
@super.foo // Should we allow this form? If so they should be equivalent |
The current syntax
disallows
super.dec
as a decorator member expression, instead one would have to parenthesize it into@(super.dec)
.Similar to #460.
The text was updated successfully, but these errors were encountered: