mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
fix(bundler): Do not emit useless constructor (#11668)
This commit is contained in:
@@ -20202,7 +20202,7 @@ fn NewParser_(
|
||||
|
||||
class.properties = class_properties.items;
|
||||
|
||||
if (instance_members.items.len > 0 or class.extends != null) {
|
||||
if (instance_members.items.len > 0) {
|
||||
if (constructor_function == null) {
|
||||
var properties = ListManaged(Property).fromOwnedSlice(p.allocator, class.properties);
|
||||
var constructor_stmts = ListManaged(Stmt).init(p.allocator);
|
||||
|
||||
@@ -1136,6 +1136,41 @@ describe("bundler", () => {
|
||||
},
|
||||
},
|
||||
});
|
||||
itBundled("edgecase/NoUselessConstructorTS", {
|
||||
files: {
|
||||
"/entry.ts": `
|
||||
class A {
|
||||
constructor(...args) {
|
||||
console.log(JSON.stringify({ args, self: this }));
|
||||
}
|
||||
field = 1;
|
||||
}
|
||||
class B extends A {}
|
||||
class C extends A { field = 2 }
|
||||
class D extends A { public field = 3 }
|
||||
class E extends A { constructor(public y: number, a) { super(a); }; public field = 4 }
|
||||
new A("arg1", "arg2");
|
||||
new B("arg1", "arg2");
|
||||
new C("arg1", "arg2");
|
||||
new D("arg1", "arg2");
|
||||
new E("arg1", "arg2");
|
||||
`,
|
||||
},
|
||||
run: {
|
||||
stdout: `
|
||||
{"args":["arg1","arg2"],"self":{"field":1}}
|
||||
{"args":["arg1","arg2"],"self":{"field":1}}
|
||||
{"args":["arg1","arg2"],"self":{"field":1}}
|
||||
{"args":["arg1","arg2"],"self":{"field":1}}
|
||||
{"args":["arg2"],"self":{"field":1}}
|
||||
`,
|
||||
},
|
||||
onAfterBundle(api) {
|
||||
const content = api.readFile("out.js");
|
||||
const count = content.split("constructor").length - 1;
|
||||
expect(count, "should only emit two constructors: " + content).toBe(2);
|
||||
},
|
||||
});
|
||||
|
||||
// TODO(@paperdave): test every case of this. I had already tested it manually, but it may break later
|
||||
const requireTranspilationListESM = [
|
||||
|
||||
Reference in New Issue
Block a user