Skip to content

Bad TS class translation #11605

Description

What version of Bun is running?

1.1.12

What platform is your computer?

Linux 5.15.0-107-generic x86_64 x86_64

What steps can reproduce the bug?

Considering following TS code:

abstract class Cparent {
    public parentVal: string;
    constructor() {
        this.parentVal = 'parent';
        this.init();
    }
    init() { }
}

class Achild extends Cparent {
    public childVal!: string;
    constructor() {
        super();
    }
    override init() {
        this.childVal = 'child';
    }
}

const a = new Achild();
console.log(a.parentVal, a.childVal);

What is the expected behavior?

Expected behavior when compiling with TS:

"use strict";
class Cparent {
    constructor() {
        this.parentVal = 'parent';
        this.init();
    }
    init() { }
}
class Achild extends Cparent {
    constructor() {
        super();
    }
    init() {
        this.childVal = 'child';
    }
}
const a = new Achild();
console.log(a.parentVal, a.childVal);

And when running:

"parent",  "child"

What do you see instead?

When building with bun:

// buntest.ts
class Cparent {
  parentVal;
  constructor() {
    this.parentVal = "parent";
    this.init();
  }
  init() {
  }
}

class Achild extends Cparent {
  childVal;
  constructor() {
    super();
  }
  init() {
    this.childVal = "child";
  }
}
var a = new Achild;
console.log(a.parentVal, a.childVal);

When running:

parent undefined

Additional information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions