Skip to content

fix(transformer/legacy-decorator): decorates insertion order is incorrect#11144

Merged
graphite-app[bot] merged 1 commit intomainfrom
05-19-fix_transformer_legacy-decorator_decorates_insertion_order_is_incorrect
May 20, 2025
Merged

fix(transformer/legacy-decorator): decorates insertion order is incorrect#11144
graphite-app[bot] merged 1 commit intomainfrom
05-19-fix_transformer_legacy-decorator_decorates_insertion_order_is_incorrect

Conversation

@Dunqing
Copy link
Member

@Dunqing Dunqing commented May 19, 2025

Insert the decorations early rather than waiting for the class assignment to insert them together. This is to avoid the decorators being inserted before the defineProperty(xxx) which could cause accessing an field still doesn't decorated yet.

Input:

function Bar(): ClassDecorator {
  return (_target) => {
    console.log(Bar.name)
  }
}

@Bar()
class Foo {
  static foo = `${Foo.name}`;
}

Before output:

var _Foo;
function Bar() {
  return (_target) => {
    console.log(Bar.name);
  };
}
let Foo = _Foo = class Foo {};
babelHelpers.defineProperty(Foo, "foo", `${_Foo.name}`);
Foo = _Foo = babelHelpers.decorate([Bar()], Foo);

After output:

var _Foo;
function Bar() {
  return (_target) => {
    console.log(Bar.name);
  };
}
let Foo = _Foo = class Foo {};
Foo = _Foo = babelHelpers.decorate([Bar()], Foo);
babelHelpers.defineProperty(Foo, "foo", `${_Foo.name}`);

Copy link
Member Author

Dunqing commented May 19, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codspeed-hq
Copy link

codspeed-hq bot commented May 19, 2025

CodSpeed Instrumentation Performance Report

Merging #11144 will degrade performances by 12.4%

Comparing 05-19-fix_transformer_legacy-decorator_decorates_insertion_order_is_incorrect (fcd5ba9) with main (f081757)

Summary

❌ 1 regressions
✅ 37 untouched benchmarks

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

Benchmarks breakdown

Benchmark BASE HEAD Change
mangler[cal.com.tsx] 3 ms 3.5 ms -12.4%

@Dunqing Dunqing force-pushed the 05-19-fix_transformer_legacy-decorator_decorates_insertion_order_is_incorrect branch from 6c3ec82 to 13d2b27 Compare May 19, 2025 08:54
@Dunqing Dunqing force-pushed the 05-19-fix_transformer_legacy-decorator_static_class_fields_cannot_be_accessed_in_static_field_initializer_when_class-properties_plugin_is_not_enabled branch 2 times, most recently from 404cdd4 to 38387b7 Compare May 19, 2025 09:22
@Dunqing Dunqing force-pushed the 05-19-fix_transformer_legacy-decorator_decorates_insertion_order_is_incorrect branch from 13d2b27 to 18d6d4e Compare May 19, 2025 09:22
@Dunqing Dunqing marked this pull request as ready for review May 19, 2025 10:18
@Dunqing Dunqing requested a review from overlookmotel as a code owner May 19, 2025 10:18
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label May 19, 2025
Copy link
Member

Boshen commented May 19, 2025

Merge activity

@graphite-app graphite-app bot changed the base branch from 05-19-fix_transformer_legacy-decorator_static_class_fields_cannot_be_accessed_in_static_field_initializer_when_class-properties_plugin_is_not_enabled to graphite-base/11144 May 19, 2025 13:54
@graphite-app graphite-app bot force-pushed the 05-19-fix_transformer_legacy-decorator_decorates_insertion_order_is_incorrect branch from 18d6d4e to 7b8f4b9 Compare May 19, 2025 14:01
@graphite-app graphite-app bot force-pushed the graphite-base/11144 branch from 38387b7 to 468ddf4 Compare May 19, 2025 14:01
@graphite-app graphite-app bot changed the base branch from graphite-base/11144 to main May 19, 2025 14:02
@graphite-app graphite-app bot force-pushed the 05-19-fix_transformer_legacy-decorator_decorates_insertion_order_is_incorrect branch from 7b8f4b9 to f8de471 Compare May 19, 2025 14:02
@Dunqing Dunqing force-pushed the 05-19-fix_transformer_legacy-decorator_decorates_insertion_order_is_incorrect branch from f8de471 to b07a2eb Compare May 20, 2025 01:38
…rect (#11144)

Insert the decorations early rather than waiting for the `class` assignment to insert them together. This is to avoid the decorators being inserted before the `defineProperty(xxx)` which could cause accessing an field still doesn't decorated yet.

Input:

```ts
function Bar(): ClassDecorator {
  return (_target) => {
    console.log(Bar.name)
  }
}

@bar()
class Foo {
  static foo = `${Foo.name}`;
}
```

Before output:
```js
var _Foo;
function Bar() {
  return (_target) => {
    console.log(Bar.name);
  };
}
let Foo = _Foo = class Foo {};
babelHelpers.defineProperty(Foo, "foo", `${_Foo.name}`);
Foo = _Foo = babelHelpers.decorate([Bar()], Foo);
```

After output:
```js
var _Foo;
function Bar() {
  return (_target) => {
    console.log(Bar.name);
  };
}
let Foo = _Foo = class Foo {};
Foo = _Foo = babelHelpers.decorate([Bar()], Foo);
babelHelpers.defineProperty(Foo, "foo", `${_Foo.name}`);
```
@graphite-app graphite-app bot force-pushed the 05-19-fix_transformer_legacy-decorator_decorates_insertion_order_is_incorrect branch from b07a2eb to fcd5ba9 Compare May 20, 2025 01:45
@graphite-app graphite-app bot merged commit fcd5ba9 into main May 20, 2025
24 checks passed
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label May 20, 2025
@graphite-app graphite-app bot deleted the 05-19-fix_transformer_legacy-decorator_decorates_insertion_order_is_incorrect branch May 20, 2025 01:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-transformer Area - Transformer / Transpiler C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants