Potential TDZ accessing static methods from instance decorators.
**Context**
The following (working in Chrome DevTools) code _feels_ natural. I can depend on constructor information when defining prototype information:
```js
class Foo {
#two = Foo.#one + 1;
#three = this.#two + 1;
static #one = 1;
}
```
**Issue**
But, the following does _not_ appear to work (using latest Babel transpiler) which feels _surprising_ compared to the above code:
```js
class MyElement {
@computed(MyElement.#computeFoo) // TDZ!
accessor foo;
static #computeFoo() {
return 'foo';
}
}
```
I believe the current specification will cause a `ReferenceError` due to accessing `MyElement.#computeFoo` in the `@computed` accessor decorator.
**Workaround**
I think the current workaround would be to do something like:
```js
class MyElement {
@computed(() => MyElement.#computeFoo) // works if you can find just the right moment to call this
accessor foo;
static #computeFoo() {
return 'foo';
}
}
```
**Discussion / Motivation**
As a developer, it _feels_ like configuration of _prototype_-related information would be able to rely on _constructor_-information. I am used to doing this sort of thing when I declare static / non-static _fields_ on classes. The current behavior (again, via the Babel transpiler) _feels surprising_ to me as an experienced developer.
Apologies if I’ve missed something in the specification or if the transpiler is causing me to misinterpret the eventual implementation! Thanks much for taking a look ❤️
7 条评论