Skip to main content

Changelog: swc v1.2.9

· 2 min read


hygiene of class properties (#892)#

Previously, swc miscompiled

const DURATION = 1000;
export class HygieneTest {  private readonly duration: number = DURATION;
  constructor(duration?: number) {    this.duration = duration ?? DURATION;  }
  getDuration() {    return this.duration;  }}


const DURATION1 = 1000;class HygieneTest {  getDuration() {    return this.duration;  }  constructor(duration) {    _defineProperty(this, "duration", DURATION1);    this.duration =      duration !== null && duration !== void 0 ? duration : DURATION;  }}exports.HygieneTest = HygieneTest;

This issue happened because class_properties pass did not check if an identifier used in a class constructor is reference. The bug is fixed by changing identifier only if it's used as a binding identifier.

The name collision check is required because in the code below, bar should be "bar", not "foo".

var foo = "bar";
class Foo {  bar = foo;  static bar = baz;
  constructor() {    var foo = "foo";    var baz = "baz";  }}

decorators on class and method (#862)#

swc now handle decorators on properties properly, even if it does not have default value. Previously typescript_strip pass removed class properties without value, but I removed such behavior and it works.

@Entity()export class Product extends TimestampedEntity {  @PrimaryGeneratedColumn("uuid")  public id!: string;
  @Column()  public price!: number;
  @Column({ enum: ProductType })  public type!: ProductType;
  @Column()  public productEntityId!: string;
  /* ANCHOR: Relations ------------------------------------------------------ */  @OneToMany(() => Order, (order) => order.product)  public orders!: Order[];
  @OneToMany(() => Discount, (discount) => discount.product)  public discounts!: Discount[];}

parameter decorators (#863)#

While babel does not support this feature, I implemented it because tsc supports it. Code like below now works well.

function foo() {  return function (target, member, ix) {    // ...  };}
class ProductController {  findById(    @foo()    id: number  ) {    // ...  }}


Parser (#893)#

swc_ecma_parser becomes faster by reducing the size of error struct and by providing single-threaded error reporting. Also it reduced possibility of stack overflow.


works with stable rustc (#886)#

Previously swc used nightly rustc, which can have some bugs. After very hard work, I've managed to make swc to use stable rustc.

This would allow more rust users to use swc as a crate for their own projects.