Skip to content

environmentVisitor should skip decorator expressions#14371

Merged
nicolo-ribaudo merged 12 commits intobabel:mainfrom
JLHwung:environment-visitor
May 21, 2022
Merged

environmentVisitor should skip decorator expressions#14371
nicolo-ribaudo merged 12 commits intobabel:mainfrom
JLHwung:environment-visitor

Conversation

@JLHwung
Copy link
Copy Markdown
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
Copy Markdown
Collaborator

babel-bot commented Mar 18, 2022

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

skipAndrequeueComputedKeysAndDecorators(path);
},
} as Visitor<PluginPass>;
} as Visitor<any>;
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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();

@JLHwung JLHwung force-pushed the environment-visitor branch from 5717af3 to b35e893 Compare March 24, 2022 15:55
const keys = VISITOR_KEYS[path.type];
for (const key of keys) {
if (key !== "key") path.skipKey(key);
export function requeueComputedKeyAndDecorator(
Copy link
Copy Markdown
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!

@JLHwung JLHwung force-pushed the environment-visitor branch from 8f8ccae to 34fb84c Compare March 28, 2022 14:02
@nicolo-ribaudo
Copy link
Copy Markdown
Member

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

@JLHwung JLHwung force-pushed the environment-visitor branch from 34fb84c to 791d2f4 Compare May 20, 2022 14:55
"ClassProperty|ClassPrivateProperty"(
path: NodePath<t.ClassProperty | t.ClassPrivateProperty>,
) {
Property(path) {
Copy link
Copy Markdown
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.


babelHelpers.classCallCheck(this, Outer);
_dec = _this = _super.call(this)
_dec = _this = _super.call(this);
Copy link
Copy Markdown
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

#14398 probably


const [newPath] = element.replaceWith(newField);
addProxyAccessorsFor(newPath, key, newId, element.node.computed);
addProxyAccessorsFor(newPath, key, newId, computed);
Copy link
Copy Markdown
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
Copy Markdown
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.

3 participants