Implement setPublicClassFields and privateFieldsAsProperties assumptions#12497
Conversation
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/37890/ |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 2fce14d:
|
| // TODO(Babel 8): Remove the default falue | ||
| api = { assumption: () => {} }, | ||
| }) { | ||
| const setPublicClassFields = api.assumption("setPublicClassFields"); |
There was a problem hiding this comment.
This will throw on @babel/core 7.12 + @babel/plugin-class-properties 7.13 because api is defined but api.assumption is not provided.
Never mind, I always forget the fact that api.assumption has been provided by helper plugin utils.
|
The CI failure caught an assumption I didn't notice while writing the RFC. The class B {
method() { alert("B!"); }
}
class C {
method() { alert("C!"); }
}
class A extends B {
run() { super.method(); }
}
Object.setPrototypeOf(A.prototype, C.prototype);
new A().run();For this reason, we compile However, in loose mode we assume that it's never mutated and thus we compile it to I'm going to add this to the RFC. |
| path, | ||
| privateNamesMap, | ||
| loose, | ||
| privateFieldsAsProperties, |
There was a problem hiding this comment.
Consider change the signature to { privateFieldsAsProperties: boolean } so we can pass noDocumentAll later. This function is not a public interface so it should be okay.
1864522 to
98ad298
Compare
dac1080 to
63e45fe
Compare
63c7a5a to
caa4fda
Compare
63e45fe to
2fce14d
Compare
- `mutableTemplateObject` and `ignoreToPrimitiveHint` (#12408) - `setClassMethods` (#12407) - `setComputedProperties` (#12490) - `ignoreFunctionLength` (#12491) - `noDocumentAll` (#12481) - `iterableIsArray` and `arrayLikeIsIterable` (#12489) - `pureGetters` (#12504) - `skipForOfIteratorClosing` (#12496) - `objectRestNoSymbols`, `setSpreadProperties` and `pureGetters` (#12505) - `noNewArrows` (#12613, #12793) - `setPublicClassFields` and `privateFieldsAsProperties` (#12497) - `constantReexports` and `enumerableModuleMeta` (#12618) - `constantSuper`, `superIsCallableConstructor` and `noClassCalls` (#12726) Co-authored-by: Justin Ridgewell <justin@ridgewell.name> Co-authored-by: Huáng Jùnliàng <JLHwung@users.noreply.github.com>
- `mutableTemplateObject` and `ignoreToPrimitiveHint` (#12408) - `setClassMethods` (#12407) - `setComputedProperties` (#12490) - `ignoreFunctionLength` (#12491) - `noDocumentAll` (#12481) - `iterableIsArray` and `arrayLikeIsIterable` (#12489) - `pureGetters` (#12504) - `skipForOfIteratorClosing` (#12496) - `objectRestNoSymbols`, `setSpreadProperties` and `pureGetters` (#12505) - `noNewArrows` (#12613, #12793) - `setPublicClassFields` and `privateFieldsAsProperties` (#12497) - `constantReexports` and `enumerableModuleMeta` (#12618) - `constantSuper`, `superIsCallableConstructor` and `noClassCalls` (#12726) Co-authored-by: Justin Ridgewell <justin@ridgewell.name> Co-authored-by: Huáng Jùnliàng <JLHwung@users.noreply.github.com>
- `mutableTemplateObject` and `ignoreToPrimitiveHint` (#12408) - `setClassMethods` (#12407) - `setComputedProperties` (#12490) - `ignoreFunctionLength` (#12491) - `noDocumentAll` (#12481) - `iterableIsArray` and `arrayLikeIsIterable` (#12489) - `pureGetters` (#12504) - `skipForOfIteratorClosing` (#12496) - `objectRestNoSymbols`, `setSpreadProperties` and `pureGetters` (#12505) - `noNewArrows` (#12613, #12793) - `setPublicClassFields` and `privateFieldsAsProperties` (#12497) - `constantReexports` and `enumerableModuleMeta` (#12618) - `constantSuper`, `superIsCallableConstructor` and `noClassCalls` (#12726) Co-authored-by: Justin Ridgewell <justin@ridgewell.name> Co-authored-by: Huáng Jùnliàng <JLHwung@users.noreply.github.com>
Main PR: #12219
RFC: babel/rfcs#5
I also introduced a warning when both
looseandsetPublicClassFields/privateFieldsAsPropertiesare set (while still maintianing the fallback behavior we have for the other assumptions).This is because
loosesupport for these class features plugins is a mess and easily breaks: it was what initially lead me to theassumptionsRFC. We should encourage users to fully migrate toassumptionsfor these plugins when they start using them, to avoid other possible configuration conflicts caused by the implicit dependencies between them.The tests are what we already had for
loose.