Skip to content

fix(transformer/class-properties): replace references to class name with temp var in static prop initializers#7610

Merged
graphite-app[bot] merged 1 commit intomainfrom
12-03-fix_transformer_class-properties_replace_references_to_class_name_with_temp_var_in_static_prop_initializers
Dec 3, 2024
Merged

fix(transformer/class-properties): replace references to class name with temp var in static prop initializers#7610
graphite-app[bot] merged 1 commit intomainfrom
12-03-fix_transformer_class-properties_replace_references_to_class_name_with_temp_var_in_static_prop_initializers

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Dec 3, 2024

Similar to #7516. Fix class properties transform to replace references to class name in static prop initializers with temp var.

Input:

class C {
  static getSelf = () => C;
}
const C2 = C;
C = 123;
assert(C2.getSelf() === C);

Output:

var _C;
class C {}
_C = C;
_defineProperty(C, "getSelf", () => _C);
const C2 = C;
C = 123;
assert(C2.getSelf() === C);

Previously, temp var wasn't used so code was _defineProperty(C, "getSelf", () => C);. C is altered later by C = 123, so C2.getSelf() returned 123, instead of reference to the class.

@graphite-app
Copy link
Contributor

graphite-app bot commented Dec 3, 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.

Copy link
Member Author

overlookmotel commented Dec 3, 2024

@overlookmotel overlookmotel marked this pull request as ready for review December 3, 2024 12:29
@github-actions github-actions bot added A-transformer Area - Transformer / Transpiler C-bug Category - Bug labels Dec 3, 2024
@Dunqing Dunqing added the 0-merge Merge with Graphite Merge Queue label Dec 3, 2024
Copy link
Member

Dunqing commented Dec 3, 2024

Merge activity

  • Dec 3, 7:42 AM EST: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Dec 3, 7:42 AM EST: A user added this pull request to the Graphite merge queue.
  • Dec 3, 7:58 AM EST: A user merged this pull request with the Graphite merge queue.

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 3, 2024

CodSpeed Performance Report

Merging #7610 will not alter performance

Comparing 12-03-fix_transformer_class-properties_replace_references_to_class_name_with_temp_var_in_static_prop_initializers (eb825ed) with main (e80214c)

Summary

✅ 29 untouched benchmarks

…ith temp var in static prop initializers (#7610)

Similar to #7516. Fix class properties transform to replace references to class name in static prop initializers with temp var.

Input:

```js
class C {
  static getSelf = () => C;
}
const C2 = C;
C = 123;
assert(C2.getSelf() === C);
```

Output:

```js
var _C;
class C {}
_C = C;
_defineProperty(C, "getSelf", () => _C);
const C2 = C;
C = 123;
assert(C2.getSelf() === C);
```

Previously, temp var wasn't used so code was `_defineProperty(C, "getSelf", () => C);`. `C` is altered later by `C = 123`, so `C2.getSelf()` returned `123`, instead of reference to the class.
@Dunqing Dunqing force-pushed the 12-03-refactor_transformer_class-properties_rename_misleadingly-named_method branch from 34acef5 to 7d1c12e Compare December 3, 2024 12:43
@Dunqing Dunqing requested a review from Boshen as a code owner December 3, 2024 12:43
@Dunqing Dunqing force-pushed the 12-03-fix_transformer_class-properties_replace_references_to_class_name_with_temp_var_in_static_prop_initializers branch from a15ca31 to eb825ed Compare December 3, 2024 12:44
Base automatically changed from 12-03-refactor_transformer_class-properties_rename_misleadingly-named_method to main December 3, 2024 12:53
@graphite-app graphite-app bot merged commit eb825ed into main Dec 3, 2024
@graphite-app graphite-app bot deleted the 12-03-fix_transformer_class-properties_replace_references_to_class_name_with_temp_var_in_static_prop_initializers branch December 3, 2024 12:58
@oxc-bot oxc-bot mentioned this pull request Dec 4, 2024
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-transformer Area - Transformer / Transpiler C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants