You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using typeorm we are often lead to use circular reference with decorators.
This configuration fails with the error "ReferenceError: Cannot access 'XXX' before initialization"
This is due to the metadata export that tries to set the exported class before it is initialized.
Reading tsc output we see that tsc exports empty classes before anything and fix the exports when the class is correctly defined. Therefore, the playground link should be fixed with
exports.ClassA = void 0;
var __decorate = this && this.__decorate || function(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = this && this.__metadata || function(k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { Entity, JoinColumn, OneToOne, PrimaryGeneratedColumn } from "typeorm";
import { ClassB } from "./classB";
let ClassA = class ClassA {
constructor(id){
this.id = id;
}
};
__decorate([
PrimaryGeneratedColumn(),
__metadata("design:type", Number)
], ClassA.prototype, "id", void 0);
__decorate([
OneToOne(()=>ClassB),
JoinColumn([
{
name: 'other_id',
referencedColumnName: 'id'
}
]),
__metadata("design:type", typeof ClassB === "undefined" ? Object : ClassB)
], ClassA.prototype, "other", void 0);
ClassA = __decorate([
Entity(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [
Number
])
], ClassA);
exports.ClassA = ClassA;
Actual behavior
No response
Version
1.3.8
Additional context
No response
The text was updated successfully, but these errors were encountered:
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
Describe the bug
Using typeorm we are often lead to use circular reference with decorators.
This configuration fails with the error "ReferenceError: Cannot access 'XXX' before initialization"
This is due to the metadata export that tries to set the exported class before it is initialized.
I made a 3 files reproduction repository here https://github.com/matthieuMay/swc-repro.
In this repro we have two class that references each other with decorated fields. Running the tests with
npm run test
fails.Input code
https://github.com/matthieuMay/swc-repro
Config
Playground link
https://play.swc.rs/?version=1.3.8&code=H4sIAAAAAAAAA21PPWvDMBDdDf4PjyyRwSS7Q4rbUAoZ2g7dSimufSGC6BTOMtQY%2F%2Fdakp0sPYGGe5%2BnzdWKw4Bndtr1OY5W88FeOsM53pg%2B7PTleBdtKulfiEkqR01kYMRJrMHK9VeyYla7NNGL4eFSte3TjbLZ1mHhOf6VMVBlaUK%2FQRLwKHvEkCaYpvw%2F2Ks8rJsC3JkfkuAaFEtppTLsH%2BYaM7%2B8X6c%2BB3BlqMDaujPJt27WOYROJMT1EvQaGROG8SsDok0QFLP1Lbm23DrpamdF3Ytlyyl%2B3Fm3G91gPzXfxfWYJuMflgCMP4UBAAA%3D&config=H4sIAAAAAAAAA0WOQQ7DIAwE%2F%2BJzDhWHHvhDH4GIE1EBRrYjFSH%2BXoLS5mbt7ozc4C0ebIPiWJDPS2pW9wELWguK51AUFlAZ0eai4AIremKnxAJW%2BcA%2Basc76oBQzMOYAUQiwT%2BSQg5bPfWeUmEUuSuX9%2Fhb9uFKtB5n0OYH0%2FmEfjsuLsjrGs4fvucDfqLKAAAA
Expected behavior
Reading tsc output we see that tsc exports empty classes before anything and fix the exports when the class is correctly defined. Therefore, the playground link should be fixed with
Actual behavior
No response
Version
1.3.8
Additional context
No response
The text was updated successfully, but these errors were encountered: