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

fix(es/preset-env): Disable all class passes for target with native class support #9774

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

kdy1
Copy link
Member

@kdy1 kdy1 commented Dec 2, 2024

Description:

This is just PoC to ask for opinion @magic-akari. I think it sounds reasonable to disable all class properties transform where it's natively supported. So I made this, but I want to hear opinion about it.

Related issue:

@kdy1 kdy1 added this to the Planned milestone Dec 2, 2024
@kdy1 kdy1 requested a review from magic-akari December 2, 2024 01:33
@kdy1 kdy1 requested a review from a team as a code owner December 2, 2024 01:33
Copy link

changeset-bot bot commented Dec 2, 2024

⚠️ No Changeset found

Latest commit: 9e654fa

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@kdy1 kdy1 changed the title fix(es/preset-env): Disable properties transforms for target with native class support fix(es/preset-env): Disable all class passes for target with native class support Dec 2, 2024
Copy link

codspeed-hq bot commented Dec 2, 2024

CodSpeed Performance Report

Merging #9774 will not alter performance

Comparing kdy1:issue-9743 (9e654fa) with main (bd77f44)

Summary

✅ 194 untouched benchmarks

Copy link
Member

@magic-akari magic-akari left a comment

Choose a reason for hiding this comment

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

I tested it in Babel's Playground. With native support for class fields, there are indeed no related transformations.
However, this raises concerns about TypeScript's useDefineForClassFields option.

@kdy1
Copy link
Member Author

kdy1 commented Dec 2, 2024

Does it work even for the targets with native class support?

@magic-akari
Copy link
Member

magic-akari commented Dec 2, 2024

Does it work even for the targets with native class support?

Yes, in TypeScript, even with native support for class fields, useDefineForClassFields can still influence the generated code.

input:

class Foo {
    bar: any;
}

output:
https://www.typescriptlang.org/play/?useDefineForClassFields=true&target=99#code/PTAEAEFcGcFMBFYDMCWA7WAxA9gJwMIA2AhtNJirIQCbQBcoALrpLAFAgSPG4DmsjBrGgYAHozZsAxiTKgc2UAG82oNaABGPBsTQBPANxsAvkA

"use strict";
// @useDefineForClassFields: true
// @target: esnext
class Foo {
    bar;
}

output:
https://www.typescriptlang.org/play/?target=99&useDefineForClassFields=false#code/PTAEAEFcGcFMBFYDMCWA7WAxA9gJwMIA2AhtNJirIQCbQBcoSxhcAUCBAC7G4DmsnBrGgYAHp1asAxiTKgc2UAG9WoNaABGPBsTQBPANysAvkA

"use strict";
// @useDefineForClassFields: false
// @target: esnext
class Foo {
}

@magic-akari
Copy link
Member

Perhaps we should redesign the transformation options for the class fields; I suggest we include at least three options:

  • spec [[DEFINE]]
  • [[SET]]
  • loose (preserve class fields if native support is available, otherwise use [[SET]] semantics)

@Austaras
Copy link
Member

Austaras commented Dec 5, 2024

Perhaps we should redesign the transformation options for the class fields; I suggest we include at least three options:

* spec `[[DEFINE]]`

* `[[SET]]`

* loose (preserve class fields if native support is available, otherwise use `[[SET]]` semantics)

Maybe 1 and 3 would be enough?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Disable define/set issue transform for targets with native class properties support
3 participants