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

environmentVisitor should skip decorator expressions #14371

Merged
merged 12 commits into from May 21, 2022

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Mar 18, 2022

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

In this PR we reimplement skipAllButComputedKey so we can remove @babel/types deps of the environment-visitor helper. In the 2nd commit we expand similar logic to decorator expressions as well. Note that the test cases are already passing in main because the decorator transforms will hoist the expression. In the last commit we apply similar changes to the renamer.

@JLHwung JLHwung added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label Mar 18, 2022
@babel-bot
Copy link
Collaborator

babel-bot commented Mar 18, 2022

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

@@ -47,4 +46,4 @@ export default {
ClassProperty(path) {
skipAndrequeueComputedKeysAndDecorators(path);
},
} as Visitor<PluginPass>;
} as Visitor<any>;
Copy link
Member

Choose a reason for hiding this comment

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

Does Visitor<unknown> work here? If it does, it's safer since it doesn't "disable" type checking.

const keys = VISITOR_KEYS[path.type];
for (const key of keys) {
if (key !== "key") path.skipKey(key);
function skipAndrequeueComputedKeysAndDecorators(
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
function skipAndrequeueComputedKeysAndDecorators(
function skipAndRequeueComputedKeysAndDecorators(

(or maybe something with less words like skipInternalContext or skipContents works too).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think skipInternalContext and skipContents are a bit vague since they are not formally defined in the spec. Maybe skipAndRequeueKeyAndDecorator? I also thought about skipParamAndBodyAndInitializer but it seems no better than skipAndRequeueKeyAndDecorator.

const keys = VISITOR_KEYS[path.type];
for (const key of keys) {
if (key !== "key") path.skipKey(key);
function skipAndrequeueComputedKeysAndDecorators(path: NodePath) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we import the logic from the helper?

path.isMethod() ? skipAndRequeueComputedKeysAndDecorators(path) : path.skip();

const keys = VISITOR_KEYS[path.type];
for (const key of keys) {
if (key !== "key") path.skipKey(key);
export function requeueComputedKeyAndDecorator(
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
export function requeueComputedKeyAndDecorator(
export function requeueComputedKeyAndDecorators(

I like how the new behavior gave us a more readable name!

@nicolo-ribaudo
Copy link
Member

@JLHwung It has been two months since your last update to this PR, time for a self-review? 🙏

"ClassProperty|ClassPrivateProperty"(
path: NodePath<t.ClassProperty | t.ClassPrivateProperty>,
) {
Property(path) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The visitor now hooks on Property alias so that it supports older @babel/types without ClassAccessorProperty definitions.

@@ -16,7 +16,7 @@ let Outer = /*#__PURE__*/function (_Hello) {
var _this;

babelHelpers.classCallCheck(this, Outer);
_dec = _this = _super.call(this)
_dec = _this = _super.call(this);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know why this line is changed after rebasing. Maybe a generator update?

Copy link
Member

Choose a reason for hiding this comment

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

#14398 probably

@@ -511,7 +511,7 @@ function transformClass(
const newField = generateClassProperty(newId, valueNode, isStatic);

const [newPath] = element.replaceWith(newField);
addProxyAccessorsFor(newPath, key, newId, element.node.computed);
addProxyAccessorsFor(newPath, key, newId, computed);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a bug fix, the element.node.computed is of the replacement node, which is always false.

Copy link
Contributor Author

@JLHwung JLHwung left a comment

Choose a reason for hiding this comment

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

✔️

@nicolo-ribaudo nicolo-ribaudo merged commit 1bc9949 into babel:main May 21, 2022
@nicolo-ribaudo nicolo-ribaudo deleted the environment-visitor branch May 21, 2022 20:50
@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 Aug 21, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants