Compare commits

...

3 Commits

Author SHA1 Message Date
dave caruso
7e1df90def Fix throwing within setTimeout 2024-06-06 20:03:49 -07:00
dave caruso
df6266df27 fix(bundler): do not emit useless constructors 2024-06-06 16:05:37 -07:00
dave caruso
7d098f4020 Bump to v1.1.13 2024-06-05 18:41:43 -07:00
6 changed files with 41 additions and 39 deletions

View File

@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.22)
cmake_policy(SET CMP0091 NEW)
cmake_policy(SET CMP0067 NEW)
set(Bun_VERSION "1.1.12")
set(Bun_VERSION "1.1.13")
set(WEBKIT_TAG cb7336ca75f6152adb75cd823a1e10da27739c29)
set(BUN_WORKDIR "${CMAKE_CURRENT_BINARY_DIR}")

View File

@@ -41,7 +41,7 @@ await Bun.$`git reset`;
await Bun.write("./CMakeLists.txt", cmakelists.replace(version[1], updated_version));
await Bun.$`git add CMakeLists.txt`;
await Bun.$`git commit -m "Release Bun v${updated_version}"`;
await Bun.$`git commit -m "Bump to v${updated_version}"`;
console.log("");
console.log("Done.");

View File

@@ -964,7 +964,7 @@ pub const VirtualMachine = struct {
}
this.is_handling_uncaught_exception = true;
defer this.is_handling_uncaught_exception = false;
const handled = Bun__handleUncaughtException(globalObject, err, if (is_rejection) 1 else 0) > 0;
const handled = Bun__handleUncaughtException(globalObject, err.toError() orelse err, if (is_rejection) 1 else 0) > 0;
if (!handled) {
// TODO maybe we want a separate code path for uncaught exceptions
this.unhandled_error_counter += 1;

View File

@@ -20203,38 +20203,8 @@ fn NewParser_(
class.properties = class_properties.items;
if (instance_members.items.len > 0 or class.extends != null) {
if (constructor_function == null) {
var properties = ListManaged(Property).fromOwnedSlice(p.allocator, class.properties);
var constructor_stmts = ListManaged(Stmt).init(p.allocator);
if (class.extends != null) {
const target = p.newExpr(E.Super{}, stmt.loc);
const arguments_ref = p.newSymbol(.unbound, arguments_str) catch unreachable;
p.current_scope.generated.push(p.allocator, arguments_ref) catch unreachable;
const super = p.newExpr(E.Spread{ .value = p.newExpr(E.Identifier{ .ref = arguments_ref }, stmt.loc) }, stmt.loc);
const args = ExprNodeList.one(p.allocator, super) catch unreachable;
constructor_stmts.append(p.s(S.SExpr{ .value = p.newExpr(E.Call{ .target = target, .args = args }, stmt.loc) }, stmt.loc)) catch unreachable;
}
constructor_stmts.appendSlice(instance_members.items) catch unreachable;
properties.insert(0, G.Property{
.flags = Flags.Property.init(.{ .is_method = true }),
.key = p.newExpr(E.String{ .data = "constructor" }, stmt.loc),
.value = p.newExpr(E.Function{ .func = G.Fn{
.name = null,
.open_parens_loc = logger.Loc.Empty,
.args = &[_]Arg{},
.body = .{ .loc = stmt.loc, .stmts = constructor_stmts.items },
.flags = Flags.Function.init(.{}),
} }, stmt.loc),
}) catch unreachable;
class.properties = properties.items;
} else {
var constructor_stmts = ListManaged(Stmt).fromOwnedSlice(p.allocator, constructor_function.?.func.body.stmts);
if (constructor_function) |constructor| {
var constructor_stmts = ListManaged(Stmt).fromOwnedSlice(p.allocator, constructor.func.body.stmts);
// statements coming from class body inserted after super call or beginning of constructor.
var super_index: ?usize = null;
for (constructor_stmts.items, 0..) |item, index| {
@@ -20246,11 +20216,8 @@ fn NewParser_(
const i = if (super_index) |j| j + 1 else 0;
constructor_stmts.insertSlice(i, instance_members.items) catch unreachable;
constructor_function.?.func.body.stmts = constructor_stmts.items;
constructor.func.body.stmts = constructor_stmts.items;
}
// TODO: make sure "super()" comes before instance field initializers
// https://github.com/evanw/esbuild/blob/e9413cc4f7ab87263ea244a999c6fa1f1e34dc65/internal/js_parser/js_parser_lower.go#L2742
}
var stmts_count: usize = 1 + static_members.items.len + instance_decorators.items.len + static_decorators.items.len;

View File

@@ -1136,6 +1136,36 @@ 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}}
`,
},
});
// TODO(@paperdave): test every case of this. I had already tested it manually, but it may break later
const requireTranspilationListESM = [

View File

@@ -601,6 +601,11 @@ it("catches exceptions with process.on('uncaughtException', fn)", async () => {
expect(await proc.exited).toBe(42);
});
it("catches exceptions with process.on('uncaughtException', fn) from setTimeout", async () => {
const proc = Bun.spawn([bunExe(), join(import.meta.dir, "process-onUncaughtExceptionSetTimeout.js")]);
expect(await proc.exited).toBe(42);
});
it("catches exceptions with process.on('unhandledRejection', fn)", async () => {
const proc = Bun.spawn([bunExe(), join(import.meta.dir, "process-onUnhandledRejection.js")]);
expect(await proc.exited).toBe(42);