Commit 986c48e
committed
fix(transformer/decorator): transformed decorators should be injected after class-properties has run (oxc-project#12418)
* close rolldown/rolldown#5374
Example:
Input:
```ts
function myPropertyDecorator() {
return (target: any, propertyKey: number) => {
console.log(target.constructor.modelName, propertyKey);
};
}
class Test {
public static modelName = 'Test';
@myPropertyDecorator()
public myProperty = 1;
}
const instance = new Test();
export default instance;
```
Output diff:
```diff
function myPropertyDecorator() {
return (target, propertyKey) => {
console.log(target.constructor.modelName, propertyKey);
};
}
class Test {
constructor() {
babelHelpers.defineProperty(this, "myProperty", 1);
}
}
-babelHelpers.decorate([myPropertyDecorator()], Test.prototype, "myProperty", void 0);
-babelHelpers.defineProperty(Test, "modelName", "Test");
+babelHelpers.defineProperty(Test, "modelName", "Test");
+babelHelpers.decorate([myPropertyDecorator()], Test.prototype, "myProperty", void 0);
const instance = new Test();
export default instance;
```
The cause is that we transform class fields and decorators in two different plugins, and the decorator plugin should be transformed first, and then run the class-properties plugin, because class-properties might erase some decorator information. However, this cause transformed decorators injected before transformed class fields.
This PR fixes this problem by collecting all transformed decorators that wait for injection, and injecting them in batch after the `class-properties` plugin has run.1 parent 6838948 commit 986c48e
File tree
8 files changed
+158
-135
lines changed- crates/oxc_transformer/src
- decorator
- legacy
- napi/transform/test
- tasks
- coverage/snapshots
- transform_conformance
- snapshots
- tests/legacy-decorators/test/fixtures/oxc
- static-field-with-class-properties
- use-define-for-class-fields
8 files changed
+158
-135
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
| |||
92 | 93 | | |
93 | 94 | | |
94 | 95 | | |
| 96 | + | |
| 97 | + | |
95 | 98 | | |
96 | 99 | | |
97 | 100 | | |
| |||
102 | 105 | | |
103 | 106 | | |
104 | 107 | | |
| 108 | + | |
105 | 109 | | |
106 | 110 | | |
107 | 111 | | |
| |||
492 | 496 | | |
493 | 497 | | |
494 | 498 | | |
495 | | - | |
496 | | - | |
| 499 | + | |
| 500 | + | |
497 | 501 | | |
498 | 502 | | |
499 | 503 | | |
| |||
503 | 507 | | |
504 | 508 | | |
505 | 509 | | |
506 | | - | |
| 510 | + | |
507 | 511 | | |
508 | 512 | | |
509 | 513 | | |
| |||
561 | 565 | | |
562 | 566 | | |
563 | 567 | | |
564 | | - | |
| 568 | + | |
565 | 569 | | |
566 | 570 | | |
567 | 571 | | |
| |||
575 | 579 | | |
576 | 580 | | |
577 | 581 | | |
578 | | - | |
| 582 | + | |
579 | 583 | | |
580 | 584 | | |
581 | 585 | | |
| |||
587 | 591 | | |
588 | 592 | | |
589 | 593 | | |
590 | | - | |
| 594 | + | |
591 | 595 | | |
592 | 596 | | |
593 | 597 | | |
| |||
598 | 602 | | |
599 | 603 | | |
600 | 604 | | |
601 | | - | |
602 | | - | |
| 605 | + | |
| 606 | + | |
603 | 607 | | |
604 | 608 | | |
605 | 609 | | |
| |||
738 | 742 | | |
739 | 743 | | |
740 | 744 | | |
741 | | - | |
| 745 | + | |
742 | 746 | | |
743 | 747 | | |
744 | 748 | | |
| 749 | + | |
745 | 750 | | |
746 | 751 | | |
747 | 752 | | |
| |||
780 | 785 | | |
781 | 786 | | |
782 | 787 | | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
783 | 796 | | |
784 | 797 | | |
785 | 798 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
| 303 | + | |
| 304 | + | |
303 | 305 | | |
304 | 306 | | |
305 | 307 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
403 | 403 | | |
404 | 404 | | |
405 | 405 | | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
416 | | - | |
417 | | - | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
418 | 418 | | |
419 | 419 | | |
420 | 420 | | |
| |||
0 commit comments