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

feat(transformer): class properties transform #7011

Merged

Conversation

overlookmotel
Copy link
Contributor

@overlookmotel overlookmotel commented Oct 29, 2024

Add class properties transform.

Implementation is incomplete. Notable missing parts:

  • Scopes are not updated where property initializers move from class body into class constructor / _super function.
  • Does not handle binding shadowing problems when property initializers move from class body into class constructor.
  • this and references to class name in static property initializers need to be transformed to point to a temp var.
  • Not all usages of private properties are supported (see below).
  • Code which is moved to outside of class body is not transformed by other transforms for class declarations (works OK for class expressions). This includes static property initializers, static blocks, and computed property/method keys.
  • Only basic checks for whether computed property/method keys may have side effects.
  • Numerous other small issues noted in TODO comments through the code.

Private properties

Currently does not handle the following usages of private properties:

class Class {
  #prop;
  static #static;
  
  method() {
    object?.#prop;
    object?.#prop();
    [object.#prop] = [1];
    ({x: object.#prop} = {x: 1});
    object.#prop`xyz`;
    
    object?.#static;
    object?.#static();
    [object.#static] = [1];
    ({x: object.#static} = {x: 1});
    object.#static`xyz`;
  }
}

Copy link

graphite-app bot commented Oct 29, 2024

Your org has enabled the Graphite merge queue for merging into main

Add the label “0-merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

@github-actions github-actions bot added A-ast Area - AST A-transformer Area - Transformer / Transpiler C-enhancement Category - New feature or request labels Oct 29, 2024
@overlookmotel overlookmotel force-pushed the 10-29-feat_transformer_class_properties_transform branch from 0eb3ad7 to 906e8fd Compare October 29, 2024 23:39
Copy link

codspeed-hq bot commented Oct 30, 2024

CodSpeed Performance Report

Merging #7011 will degrade performances by 19.21%

Comparing 10-29-feat_transformer_class_properties_transform (9778298) with main (0b9da38)

Summary

❌ 3 regressions
✅ 27 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark main 10-29-feat_transformer_class_properties_transform Change
transformer[antd.js] 49.6 ms 53.9 ms -7.98%
transformer[checker.ts] 20.8 ms 23.1 ms -9.97%
transformer[pdf.mjs] 7.8 ms 9.6 ms -19.21%

@overlookmotel overlookmotel force-pushed the 10-29-feat_transformer_class_properties_transform branch 3 times, most recently from 7b2ad83 to 1f4eef9 Compare October 30, 2024 18:48
@overlookmotel overlookmotel changed the base branch from main to 10-30-test_transformer_support_exec_tests_in_oxc_folder October 30, 2024 18:48
@overlookmotel overlookmotel marked this pull request as ready for review October 30, 2024 18:49
@overlookmotel overlookmotel force-pushed the 10-29-feat_transformer_class_properties_transform branch 2 times, most recently from 366cc8f to 65400df Compare October 30, 2024 19:59
@Boshen Boshen changed the base branch from 10-30-test_transformer_support_exec_tests_in_oxc_folder to graphite-base/7011 October 31, 2024 01:18
Copy link
Member

@Boshen Boshen left a comment

Choose a reason for hiding this comment

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

Too much fixtures committed to this repo, let me think about #4048

@Boshen Boshen force-pushed the graphite-base/7011 branch from 96a98ba to 2a57a66 Compare October 31, 2024 01:26
@Boshen Boshen force-pushed the 10-29-feat_transformer_class_properties_transform branch from 5663771 to 0c69972 Compare October 31, 2024 01:26
@Boshen Boshen changed the base branch from graphite-base/7011 to main October 31, 2024 01:27
@Boshen Boshen force-pushed the 10-29-feat_transformer_class_properties_transform branch from 0c69972 to 3970e03 Compare October 31, 2024 01:27
@overlookmotel
Copy link
Contributor Author

Yes, I hope there's a better solution. I just wanted some working tests while I'm building the transform.

@Boshen Boshen marked this pull request as draft October 31, 2024 09:55
Boshen pushed a commit that referenced this pull request Oct 31, 2024
Skeleton of class properties transform. #7011 contains WIP implementation.
@overlookmotel overlookmotel force-pushed the 10-29-feat_transformer_class_properties_transform branch 3 times, most recently from c71dda8 to 78b7bed Compare October 31, 2024 20:40
@overlookmotel overlookmotel changed the base branch from main to 10-31-refactor_transformer_common_vardeclarations_insert_either_var_or_let_statements October 31, 2024 20:40
@overlookmotel overlookmotel force-pushed the 11-04-test_transformer_script_to_amend_babel_fixtures branch from 7f0dd2c to eeeccba Compare November 22, 2024 11:05
@overlookmotel overlookmotel force-pushed the 10-29-feat_transformer_class_properties_transform branch from 3629c39 to 139ac62 Compare November 22, 2024 11:06
@Boshen Boshen force-pushed the 11-04-test_transformer_script_to_amend_babel_fixtures branch 2 times, most recently from 3d4a890 to 8d1ea70 Compare November 22, 2024 12:37
@Boshen Boshen force-pushed the 10-29-feat_transformer_class_properties_transform branch from 139ac62 to c986cf7 Compare November 22, 2024 12:37
@overlookmotel overlookmotel force-pushed the 11-04-test_transformer_script_to_amend_babel_fixtures branch from 8d1ea70 to b4c5bea Compare November 22, 2024 13:06
@overlookmotel overlookmotel force-pushed the 10-29-feat_transformer_class_properties_transform branch 2 times, most recently from 303e42d to 11d7479 Compare November 22, 2024 15:07
@overlookmotel overlookmotel force-pushed the 11-04-test_transformer_script_to_amend_babel_fixtures branch from b4c5bea to 8248e29 Compare November 24, 2024 12:09
@overlookmotel overlookmotel force-pushed the 10-29-feat_transformer_class_properties_transform branch 2 times, most recently from 84b9b88 to 7a52127 Compare November 24, 2024 14:11
@overlookmotel overlookmotel marked this pull request as ready for review November 24, 2024 14:21
@overlookmotel
Copy link
Contributor Author

overlookmotel commented Nov 24, 2024

@Boshen @Dunqing As noted above, this transform is incomplete. But I think it's in a fit state to merge at this point so we can iterate on it.

Note: Transform is not enabled by default, so I think monitor-oxc won't fail if we merge this.

@overlookmotel overlookmotel force-pushed the 10-29-feat_transformer_class_properties_transform branch from 7a52127 to f8bcbcc Compare November 24, 2024 14:42
@overlookmotel overlookmotel force-pushed the 11-04-test_transformer_script_to_amend_babel_fixtures branch from 8248e29 to 2c34991 Compare November 24, 2024 17:42
@overlookmotel overlookmotel force-pushed the 10-29-feat_transformer_class_properties_transform branch from f8bcbcc to 5247d52 Compare November 24, 2024 17:42
@overlookmotel overlookmotel requested a review from Boshen November 24, 2024 17:47
@overlookmotel overlookmotel force-pushed the 11-04-test_transformer_script_to_amend_babel_fixtures branch from 2c34991 to 25f2a20 Compare November 24, 2024 17:59
@overlookmotel overlookmotel force-pushed the 10-29-feat_transformer_class_properties_transform branch from 5247d52 to 1fdf61f Compare November 24, 2024 17:59
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Nov 25, 2024
Copy link
Member

Boshen commented Nov 25, 2024

Merge activity

  • Nov 25, 5:23 AM EST: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Nov 25, 5:23 AM EST: A user added this pull request to the Graphite merge queue.
  • Nov 25, 5:30 AM EST: A user merged this pull request with the Graphite merge queue.

Add class properties transform.

Implementation is incomplete. Notable missing parts:

* Scopes are not updated where property initializers move from class body into class constructor / `_super` function.
* Does not handle binding shadowing problems when property initializers move from class body into class constructor.
* `this` and references to class name in static property initializers need to be transformed to point to a temp var.
* Not all usages of private properties are supported (see below).
* Code which is moved to outside of class body is not transformed by other transforms for class declarations (works OK for class expressions). This includes static property initializers, static blocks, and computed property/method keys.
* Only basic checks for whether computed property/method keys may have side effects.
* Numerous other small issues noted in TODO comments through the code.

### Private properties

Currently does not handle the following usages of private properties:

```js
class Class {
  #prop;
  static #static;

  method() {
    object?.#prop;
    object?.#prop();
    [object.#prop] = [1];
    ({x: object.#prop} = {x: 1});
    object.#prop`xyz`;

    object?.#static;
    object?.#static();
    [object.#static] = [1];
    ({x: object.#static} = {x: 1});
    object.#static`xyz`;
  }
}
```
@Boshen Boshen force-pushed the 11-04-test_transformer_script_to_amend_babel_fixtures branch from 25f2a20 to 3b2a347 Compare November 25, 2024 10:24
@Boshen Boshen force-pushed the 10-29-feat_transformer_class_properties_transform branch from 1fdf61f to 9778298 Compare November 25, 2024 10:24
Base automatically changed from 11-04-test_transformer_script_to_amend_babel_fixtures to main November 25, 2024 10:28
@graphite-app graphite-app bot merged commit 9778298 into main Nov 25, 2024
28 checks passed
@graphite-app graphite-app bot deleted the 10-29-feat_transformer_class_properties_transform branch November 25, 2024 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0-merge Merge with Graphite Merge Queue A-ast Area - AST A-transformer Area - Transformer / Transpiler C-enhancement Category - New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants