Skip to content
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

Implement setPublicClassFields and privateFieldsAsProperties assumptions #12497

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Dec 12, 2020

Q                       A
Fixed Issues?
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature? Yes
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

Main PR: #12219
RFC: babel/rfcs#5

I also introduced a warning when both loose and setPublicClassFields/privateFieldsAsProperties are set (while still maintianing the fallback behavior we have for the other assumptions).
This is because loose support for these class features plugins is a mess and easily breaks: it was what initially lead me to the assumptions RFC. We should encourage users to fully migrate to assumptions for 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.

@babel-bot
Copy link
Collaborator

babel-bot commented Dec 12, 2020

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/37890/

@codesandbox-ci
Copy link

codesandbox-ci bot commented Dec 12, 2020

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:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

}) {
const setPublicClassFields = api.assumption("setPublicClassFields");
Copy link
Contributor

@JLHwung JLHwung Dec 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

JLHwung
JLHwung previously approved these changes Dec 14, 2020
@JLHwung JLHwung dismissed their stale review December 14, 2020 16:27

CI error is related.

@nicolo-ribaudo
Copy link
Member Author

The CI failure caught an assumption I didn't notice while writing the RFC.

The super binding of a class instance is mutable:

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 super.method to _get(_getPrototypeOf(A.prototype), "method", this).

However, in loose mode we assume that it's never mutated and thus we compile it to _B.prototype.method.

I'm going to add this to the RFC.

@@ -361,13 +366,15 @@ export function transformPrivateNamesUsage(
ref,
path,
privateNamesMap,
loose,
privateFieldsAsProperties,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@nicolo-ribaudo nicolo-ribaudo force-pushed the assumption/class-features branch 2 times, most recently from dac1080 to 63e45fe Compare January 12, 2021 16:33
@nicolo-ribaudo nicolo-ribaudo merged commit b634b01 into babel:feat-7.13.0/babel-core-features Jan 23, 2021
@nicolo-ribaudo nicolo-ribaudo deleted the assumption/class-features branch January 23, 2021 02:41
nicolo-ribaudo added a commit to nicolo-ribaudo/babel that referenced this pull request Feb 4, 2021
nicolo-ribaudo added a commit to nicolo-ribaudo/babel that referenced this pull request Feb 10, 2021
nicolo-ribaudo added a commit to nicolo-ribaudo/babel that referenced this pull request Feb 11, 2021
nicolo-ribaudo added a commit that referenced this pull request Feb 16, 2021
- `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>
nicolo-ribaudo added a commit that referenced this pull request Feb 16, 2021
- `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>
nicolo-ribaudo added a commit that referenced this pull request Feb 21, 2021
- `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>
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Apr 24, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: assumptions outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: New Feature 🚀 A type of pull request used for our changelog categories Spec: Brand Check for Private Fields Spec: Class Fields Spec: Private Methods
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants