Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Improve temporary variables for decorators#16218

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
nicolo-ribaudo merged 2 commits intobabel:mainfromliuxingbaoyu:dec-var
Jan 18, 2024

Conversation

liuxingbaoyu
Copy link
Member

@liuxingbaoyuliuxingbaoyu commentedJan 17, 2024
edited
Loading

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?
LicenseMIT

before

var_initClass,_dec,_dec2,_dec3,_dec4,_dec5,_dec6,_dec7,_dec8,_initProto;constdec=()=>{};_dec=call();_dec2=chain.expr();_dec3=arbitrary+expr;_dec4=array[expr];_dec5=call();_dec6=chain.expr();_dec7=arbitrary+expr;_dec8=array[expr];let_Foo;classFoo{static{[_initProto,_Foo,_initClass]=babelHelpers.applyDecs(this,[[[dec,_dec5,_dec6,_dec7,_dec8],2,"method"]],[dec,_dec,_dec2,_dec3,_dec4]);}constructor(...args){_initProto(this);}  #a;method(){}makeClass(){var_dec9,_init_bar;return_dec9=this.#a,classNested{static{[_init_bar]=babelHelpers.applyDecs(this,[[_dec9,0,"bar"]],[]);}bar=_init_bar(this);};}static{_initClass();}}

after:

var_initClass,_classDecs,_dec,_dec2,_dec3,_dec4,_initProto;constdec=()=>{};_classDecs=[dec,call(),chain.expr(),arbitrary+expr,array[expr]];_dec=call();_dec2=chain.expr();_dec3=arbitrary+expr;_dec4=array[expr];let_Foo;classFoo{static{[_initProto,_Foo,_initClass]=babelHelpers.applyDecs(this,[[[dec,_dec,_dec2,_dec3,_dec4],2,"method"]],_classDecs);}constructor(){_initProto(this);}  #a;method(){}makeClass(){var_dec5,_init_bar;return_dec5=this.#a,classNested{static{[_init_bar]=babelHelpers.applyDecs(this,[[_dec5,0,"bar"]],[]);}bar=_init_bar(this);};}static{_initClass();}}

In addition, some class reference variable naming logic has been improved.

@liuxingbaoyuliuxingbaoyu added Spec: Decorators PR: Output optimization 🔬A type of pull request used for our changelog categories labelsJan 17, 2024
@babel-bot
Copy link
Collaborator

babel-bot commentedJan 17, 2024
edited
Loading

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

@nicolo-ribaudo
Copy link
Member

Can we do the same for method decorators, other than class decorators?

@liuxingbaoyu
Copy link
MemberAuthor

I tried it, but it's a little complicated.
Because the order of memoise is inconsistent with the order of execution.
I haven't read the spec yet, but current testing is like this, the saved decorator function will be based on the order of the fields from front to back, and the decorator execution will be based on the ordering of the different types of groupings.
image

JLHwung and nicolo-ribaudo reacted with thumbs up emoji

Copy link
Contributor

@JLHwungJLHwung left a comment

Choose a reason for hiding this comment

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

Changes summary:

  1. Memoise the array of class decorators. This can reduce the number of required memoisers when there are multiple class decorators.

  2. Create temporary inner class binding uid from the class binding name, either provided by the class name or from the named evaluation.

object = expression.object;
const maybeExtractDecorators = (
decorators: t.Decorator[],
memoise = false,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: How aboutmemoiseInPlace? And ifmemoiseInPlace is true, the return value of this function should befalse since decorator expressions have already been memoised.

maybeExtractDecorators is used twice: one is in class decorator and the other is in element decorator. At this moment we could have avoided the default parameter and pass thememoiseInPlace explicitly.

liuxingbaoyu reacted with thumbs up emoji
@liuxingbaoyuliuxingbaoyu changed the titleImprove temporary variables for decoratorsImprove temporary variables for class decoratorsJan 17, 2024
@liuxingbaoyuliuxingbaoyu changed the titleImprove temporary variables for class decoratorsImprove temporary variables for decoratorsJan 17, 2024
Copy link
Member

@nicolo-ribaudonicolo-ribaudo left a comment

Choose a reason for hiding this comment

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

Great!

@nicolo-ribaudonicolo-ribaudo merged commit87a67bf intobabel:mainJan 18, 2024
Vylpes pushed a commit to Vylpes/random-bunny that referenced this pull requestApr 10, 2024
This PR contains the following updates:| Package | Type | Update | Change ||---|---|---|---|| [@babel/traverse](https://babel.dev/docs/en/next/babel-traverse) ([source](https://github.com/babel/babel)) | resolutions | patch | [`7.23.7` -> `7.23.9`](https://renovatebot.com/diffs/npm/@babel%2ftraverse/7.23.7/7.23.9) |---### Release Notes<details><summary>babel/babel (@&#8203;babel/traverse)</summary>### [`v7.23.9`](https://github.com/babel/babel/blob/HEAD/CHANGELOG.md#v7239-2024-01-25)[Compare Source](babel/babel@v7.23.7...v7.23.9)##### 🐛 Bug Fix-   `babel-helper-transform-fixture-test-runner`, `babel-plugin-transform-function-name`, `babel-plugin-transform-modules-systemjs`, `babel-preset-env`    -   [#&#8203;16225](babel/babel#16225) fix: `systemjs` re-traverses helpers ([@&#8203;liuxingbaoyu](https://github.com/liuxingbaoyu))-   `babel-helper-create-class-features-plugin`, `babel-plugin-proposal-decorators`    -   [#&#8203;16226](babel/babel#16226) Improve decorated private method check ([@&#8203;JLHwung](https://github.com/JLHwung))-   `babel-plugin-proposal-decorators`, `babel-plugin-transform-async-generator-functions`, `babel-plugin-transform-runtime`, `babel-preset-env`    -   [#&#8203;16224](babel/babel#16224) Properly sort `core-js@3` imports ([@&#8203;nicolo-ribaudo](https://github.com/nicolo-ribaudo))-   `babel-traverse`    -   [#&#8203;15383](babel/babel#15383) fix: Don't throw in `getTypeAnnotation` when using TS+inference ([@&#8203;liuxingbaoyu](https://github.com/liuxingbaoyu))-   Other    -   [#&#8203;16210](babel/babel#16210) \[eslint] Fix `no-use-before-define` for class ref in fields ([@&#8203;nicolo-ribaudo](https://github.com/nicolo-ribaudo))##### 🏠 Internal-   `babel-core`, `babel-parser`, `babel-template`    -   [#&#8203;16222](babel/babel#16222) Migrate `eslint-parser` to cts ([@&#8203;liuxingbaoyu](https://github.com/liuxingbaoyu))-   `babel-types`    -   [#&#8203;16213](babel/babel#16213) Remove `@babel/types` props that are not produced by the parser ([@&#8203;liuxingbaoyu](https://github.com/liuxingbaoyu))##### 🏃‍♀️ Performance-   `babel-parser`    -   [#&#8203;16072](babel/babel#16072) perf: Improve parser performance for typescript ([@&#8203;liuxingbaoyu](https://github.com/liuxingbaoyu))##### 🔬 Output optimization-   `babel-helper-create-class-features-plugin`, `babel-plugin-proposal-decorators`, `babel-plugin-proposal-destructuring-private`, `babel-plugin-proposal-pipeline-operator`, `babel-plugin-transform-class-properties`, `babel-plugin-transform-class-static-block`, `babel-plugin-transform-new-target`, `babel-plugin-transform-parameters`, `babel-plugin-transform-private-methods`, `babel-preset-env`    -   [#&#8203;16218](babel/babel#16218) Improve temporary variables for decorators ([@&#8203;liuxingbaoyu](https://github.com/liuxingbaoyu))-   `babel-helpers`, `babel-plugin-proposal-explicit-resource-management`, `babel-runtime-corejs2`, `babel-runtime-corejs3`, `babel-runtime`    -   [#&#8203;15959](babel/babel#15959) Improve output of `using` ([@&#8203;liuxingbaoyu](https://github.com/liuxingbaoyu))</details>---### Configuration📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.🔕 **Ignore**: Close this PR and you won't be reminded about this update again.--- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box---This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4wLjAiLCJ1cGRhdGVkSW5WZXIiOiIzNy4wLjAiLCJ0YXJnZXRCcmFuY2giOiJkZXZlbG9wIn0=-->Reviewed-on:https://gitea.vylpes.xyz/RabbitLabs/random-bunny/pulls/142Reviewed-by: Vylpes <ethan@vylpes.com>Co-authored-by: Renovate Bot <renovate@vylpes.com>Co-committed-by: Renovate Bot <renovate@vylpes.com>
@github-actionsgithub-actionsbot added the outdatedA closed issue/PR that is archived due to age. Recommended to make a new issue labelApr 19, 2024
@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsApr 19, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@JLHwungJLHwungJLHwung approved these changes

@nicolo-ribaudonicolo-ribaudonicolo-ribaudo approved these changes

Assignees
No one assigned
Labels
outdatedA closed issue/PR that is archived due to age. Recommended to make a new issuePR: Output optimization 🔬A type of pull request used for our changelog categoriesSpec: Decorators
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@liuxingbaoyu@babel-bot@nicolo-ribaudo@JLHwung

[8]ページ先頭

©2009-2025 Movatter.jp