Conversation
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/8016/ |
|
One thing we talked about at the last Babel meeting was the possibility of merging the decorator transform into public/private, so we'd have a single one to cover
since it seems like, for decorators to work, especially with private fields, they are going to end up needing intricate knowledge of the output produced by the other transforms. That's not to say that these would all by on by default, but you could imagine for instance only enabling public fields, for instance. Decorators for instance are going to require ways to programmatically access private fields from within the decorator function, and it seems like it'd be essentially impossible if written as two separate, tightly-coupled transforms, especially when long-term maintenance will be important. What are your thoughts on that, and is this PR merges private and public already, would now be a good time to do that plugin rename to get away from the "class properties" name? |
nicolo-ribaudo
left a comment
There was a problem hiding this comment.
It throws 🤔
class A {
#foo;
method() {
this.#foo;
}
}Method WeakMap.prototype.has called on incompatible receiver #
| }, | ||
|
|
||
| memoize(memberPath) { | ||
| memoise(memberPath) { |
There was a problem hiding this comment.
maybeGenerateMemoised. @kittens uses British spellings. Personally, it's all wrong.
There was a problem hiding this comment.
It's fine to change it 😛if it's easier for everyone
There was a problem hiding this comment.
Followup PR. For now, let's keep the codebase consistent.
|
|
||
| helpers.classPrivateFieldKey = () => template.program.ast` | ||
| var id = 0; | ||
| export default function _classPrivateFieldKey(name) { |
There was a problem hiding this comment.
Could you add Loose to the names of these two helpers?
| const { name } = this; | ||
| const { node, parentPath } = path; | ||
|
|
||
| if (!parentPath.isMemberExpression({ property: node })) return; |
There was a problem hiding this comment.
The private name of a private field/method. Also if we ever allow bare privates.
| const propNode = prop.node; | ||
| if (propNode.decorators && propNode.decorators.length > 0) continue; | ||
| const inits = []; | ||
| privateInits.push(inits); |
There was a problem hiding this comment.
Nit: this two lines can be moved inside the if statement.
Also, why can't these loops be merged?
There was a problem hiding this comment.
Also, why can't these loops be merged?
The privates need to be transformed first in case a public field references one. I should probably test that a private field that references another transforms correctly...
Honestly, I'd rather the presence of a decorators go down a completely separate path, ripping out everything with one out of the class. I imagine that'll make everything considerably easier, even if it does duplicate some of the transform in runtime.
Ugh, subclassing |
nicolo-ribaudo
left a comment
There was a problem hiding this comment.
The code looks good, apart from the WeakMap error.
| @@ -0,0 +1,3 @@ | |||
| { | |||
| "minNodeVersion": "6.0.0" | |||
There was a problem hiding this comment.
This isn't needed, since we only run the tests on node >= 6
| return Foo; | ||
| }(); | ||
|
|
||
| var _foo = babelHelpers.classPrivateFieldLooseKey("foo"); |
|
Which weakmap error? |
|
|
1. Babel using British spellings, so `memoise` 2. Provide a helper `AssignmentMemoiser` class, which will assign the memo'd value with the `n`th access.
98caf52 to
cca792f
Compare
|
Ach, updated to remove the |
|
🎉 |
|
What version will this be published in |
|
@piranna The next one. The same as in spec. Nope, until any browser will implement it. Use stage-3 or class-properties plugin. |

Supersedes #7555.
Let's see if we can land it this time.
/cc @littledan